Committed by
Jonathan Hart
adding agent config
Change-Id: Id6ca390d4aaeb7760a31d3327b16b953ed51df37
Showing
2 changed files
with
150 additions
and
0 deletions
1 | +package org.onosproject.cordconfig.access; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.databind.JsonNode; | ||
4 | +import com.google.common.collect.Maps; | ||
5 | +import org.onlab.packet.MacAddress; | ||
6 | +import org.onosproject.net.ConnectPoint; | ||
7 | +import org.onosproject.net.DeviceId; | ||
8 | +import org.onosproject.net.PortNumber; | ||
9 | +import org.onosproject.net.config.Config; | ||
10 | + | ||
11 | +import java.util.Map; | ||
12 | +import java.util.Optional; | ||
13 | + | ||
14 | +/** | ||
15 | + * Represents configuration for an OLT agent. | ||
16 | + */ | ||
17 | +public class AccessAgentConfig extends Config<DeviceId> { | ||
18 | + | ||
19 | + private static final String OLTS = "olts"; | ||
20 | + private static final String AGENT_MAC = "mac"; | ||
21 | + | ||
22 | + // TODO: Remove this, it is only useful as long as XOS doesn't manage this. | ||
23 | + private static final String VTN_LOCATION = "vtn-location"; | ||
24 | + | ||
25 | + /** | ||
26 | + * Gets the access agent configuration for this device. | ||
27 | + * | ||
28 | + * @return access agent configuration | ||
29 | + */ | ||
30 | + public AccessAgentData getAgent() { | ||
31 | + JsonNode olts = node.get(OLTS); | ||
32 | + if (!olts.isObject()) { | ||
33 | + throw new IllegalArgumentException(OLTS + " should be an object"); | ||
34 | + } | ||
35 | + Map<ConnectPoint, MacAddress> oltMacInfo = Maps.newHashMap(); | ||
36 | + olts.fields().forEachRemaining(item -> oltMacInfo.put( | ||
37 | + new ConnectPoint(subject(), PortNumber.fromString(item.getKey())), | ||
38 | + MacAddress.valueOf(item.getValue().asText()))); | ||
39 | + | ||
40 | + MacAddress agentMac = MacAddress.valueOf(node.path(AGENT_MAC).asText()); | ||
41 | + | ||
42 | + JsonNode vtn = node.path(VTN_LOCATION); | ||
43 | + Optional<ConnectPoint> vtnLocation; | ||
44 | + if (vtn.isMissingNode()) { | ||
45 | + vtnLocation = Optional.empty(); | ||
46 | + } else { | ||
47 | + vtnLocation = Optional.of(ConnectPoint.deviceConnectPoint(vtn.asText())); | ||
48 | + } | ||
49 | + | ||
50 | + return new AccessAgentData(subject(), oltMacInfo, agentMac, vtnLocation); | ||
51 | + } | ||
52 | + | ||
53 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.cordconfig.access; | ||
18 | + | ||
19 | +import com.google.common.collect.ImmutableMap; | ||
20 | +import org.onlab.packet.MacAddress; | ||
21 | +import org.onosproject.net.ConnectPoint; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | + | ||
24 | +import java.util.Map; | ||
25 | +import java.util.Optional; | ||
26 | + | ||
27 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
28 | + | ||
29 | +/** | ||
30 | + * Information about an access agent. | ||
31 | + */ | ||
32 | +public class AccessAgentData { | ||
33 | + private static final String DEVICE_ID_MISSING = "Device ID cannot be null"; | ||
34 | + private static final String OLT_INFO_MISSING = "OLT information cannot be null"; | ||
35 | + private static final String AGENT_MAC_MISSING = "Agent mac cannot be null"; | ||
36 | + private static final String VTN_MISSING = "VTN location cannot be null"; | ||
37 | + | ||
38 | + | ||
39 | + private final Map<ConnectPoint, MacAddress> oltMacInfo; | ||
40 | + private final MacAddress agentMac; | ||
41 | + private final Optional<ConnectPoint> vtnLocation; | ||
42 | + private final DeviceId deviceId; | ||
43 | + | ||
44 | + | ||
45 | + /** | ||
46 | + * Constucts an agent configuration for a given device. | ||
47 | + * | ||
48 | + * @param deviceId access device id | ||
49 | + * @param oltMacInfo a map of olt chips and their mac address | ||
50 | + * @param agentMac the mac address of the agent | ||
51 | + * @param vtnLocation the location of the agent | ||
52 | + */ | ||
53 | + public AccessAgentData(DeviceId deviceId, Map<ConnectPoint, MacAddress> oltMacInfo, | ||
54 | + MacAddress agentMac, Optional<ConnectPoint> vtnLocation) { | ||
55 | + this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING); | ||
56 | + this.oltMacInfo = checkNotNull(oltMacInfo, OLT_INFO_MISSING); | ||
57 | + this.agentMac = checkNotNull(agentMac, AGENT_MAC_MISSING); | ||
58 | + this.vtnLocation = checkNotNull(vtnLocation, VTN_MISSING); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Retrieves the access device ID. | ||
63 | + * | ||
64 | + * @return device ID | ||
65 | + */ | ||
66 | + public DeviceId deviceId() { | ||
67 | + return deviceId; | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns the mapping of olt chips to mac addresses. Each chip is | ||
72 | + * symbolized by a connect point. | ||
73 | + * | ||
74 | + * @return a mapping of chips (as connect points) to mac addresses | ||
75 | + */ | ||
76 | + public Map<ConnectPoint, MacAddress> getOltMacInfo() { | ||
77 | + return ImmutableMap.copyOf(oltMacInfo); | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * Reuturns the agents mac address. | ||
82 | + * | ||
83 | + * @return a mac address | ||
84 | + */ | ||
85 | + public MacAddress getAgentMac() { | ||
86 | + return agentMac; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns the location of the agent. | ||
91 | + * | ||
92 | + * @return a connection point | ||
93 | + */ | ||
94 | + public Optional<ConnectPoint> getVtnLocation() { | ||
95 | + return vtnLocation; | ||
96 | + } | ||
97 | +} |
-
Please register or login to post a comment