blob: ba655dfe621b24e1af955c8f1ea2beb92d6f3801 [file] [log] [blame]
alshabib1f36ab82016-04-29 15:38:19 -07001package org.onosproject.cordconfig.access;
2
3import com.fasterxml.jackson.databind.JsonNode;
4import com.google.common.collect.Maps;
5import org.onlab.packet.MacAddress;
6import org.onosproject.net.ConnectPoint;
7import org.onosproject.net.DeviceId;
8import org.onosproject.net.PortNumber;
9import org.onosproject.net.config.Config;
10
11import java.util.Map;
12import java.util.Optional;
13
14/**
15 * Represents configuration for an OLT agent.
16 */
17public 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}