adding agent config
Change-Id: Id6ca390d4aaeb7760a31d3327b16b953ed51df37
diff --git a/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentConfig.java b/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentConfig.java
new file mode 100644
index 0000000..ba655df
--- /dev/null
+++ b/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentConfig.java
@@ -0,0 +1,53 @@
+package org.onosproject.cordconfig.access;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Maps;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.Config;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Represents configuration for an OLT agent.
+ */
+public class AccessAgentConfig extends Config<DeviceId> {
+
+ private static final String OLTS = "olts";
+ private static final String AGENT_MAC = "mac";
+
+ // TODO: Remove this, it is only useful as long as XOS doesn't manage this.
+ private static final String VTN_LOCATION = "vtn-location";
+
+ /**
+ * Gets the access agent configuration for this device.
+ *
+ * @return access agent configuration
+ */
+ public AccessAgentData getAgent() {
+ JsonNode olts = node.get(OLTS);
+ if (!olts.isObject()) {
+ throw new IllegalArgumentException(OLTS + " should be an object");
+ }
+ Map<ConnectPoint, MacAddress> oltMacInfo = Maps.newHashMap();
+ olts.fields().forEachRemaining(item -> oltMacInfo.put(
+ new ConnectPoint(subject(), PortNumber.fromString(item.getKey())),
+ MacAddress.valueOf(item.getValue().asText())));
+
+ MacAddress agentMac = MacAddress.valueOf(node.path(AGENT_MAC).asText());
+
+ JsonNode vtn = node.path(VTN_LOCATION);
+ Optional<ConnectPoint> vtnLocation;
+ if (vtn.isMissingNode()) {
+ vtnLocation = Optional.empty();
+ } else {
+ vtnLocation = Optional.of(ConnectPoint.deviceConnectPoint(vtn.asText()));
+ }
+
+ return new AccessAgentData(subject(), oltMacInfo, agentMac, vtnLocation);
+ }
+
+}
diff --git a/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java b/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java
new file mode 100644
index 0000000..8d14dde
--- /dev/null
+++ b/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.cordconfig.access;
+
+import com.google.common.collect.ImmutableMap;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+
+import java.util.Map;
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Information about an access agent.
+ */
+public class AccessAgentData {
+ private static final String DEVICE_ID_MISSING = "Device ID cannot be null";
+ private static final String OLT_INFO_MISSING = "OLT information cannot be null";
+ private static final String AGENT_MAC_MISSING = "Agent mac cannot be null";
+ private static final String VTN_MISSING = "VTN location cannot be null";
+
+
+ private final Map<ConnectPoint, MacAddress> oltMacInfo;
+ private final MacAddress agentMac;
+ private final Optional<ConnectPoint> vtnLocation;
+ private final DeviceId deviceId;
+
+
+ /**
+ * Constucts an agent configuration for a given device.
+ *
+ * @param deviceId access device id
+ * @param oltMacInfo a map of olt chips and their mac address
+ * @param agentMac the mac address of the agent
+ * @param vtnLocation the location of the agent
+ */
+ public AccessAgentData(DeviceId deviceId, Map<ConnectPoint, MacAddress> oltMacInfo,
+ MacAddress agentMac, Optional<ConnectPoint> vtnLocation) {
+ this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING);
+ this.oltMacInfo = checkNotNull(oltMacInfo, OLT_INFO_MISSING);
+ this.agentMac = checkNotNull(agentMac, AGENT_MAC_MISSING);
+ this.vtnLocation = checkNotNull(vtnLocation, VTN_MISSING);
+ }
+
+ /**
+ * Retrieves the access device ID.
+ *
+ * @return device ID
+ */
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ /**
+ * Returns the mapping of olt chips to mac addresses. Each chip is
+ * symbolized by a connect point.
+ *
+ * @return a mapping of chips (as connect points) to mac addresses
+ */
+ public Map<ConnectPoint, MacAddress> getOltMacInfo() {
+ return ImmutableMap.copyOf(oltMacInfo);
+ }
+
+ /**
+ * Reuturns the agents mac address.
+ *
+ * @return a mac address
+ */
+ public MacAddress getAgentMac() {
+ return agentMac;
+ }
+
+ /**
+ * Returns the location of the agent.
+ *
+ * @return a connection point
+ */
+ public Optional<ConnectPoint> getVtnLocation() {
+ return vtnLocation;
+ }
+}