alshabib | 1f36ab8 | 2016-04-29 15:38:19 -0700 | [diff] [blame] | 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 | } |