Add foo-app code (copy of config app)
Change-Id: I135ff8c7b9249bcbfbfd145c225f7b9375acf207
diff --git a/src/main/java/org/opencord/cordconfig/access/AccessAgentConfig.java b/src/main/java/org/opencord/cordconfig/access/AccessAgentConfig.java
new file mode 100644
index 0000000..a4e80da
--- /dev/null
+++ b/src/main/java/org/opencord/cordconfig/access/AccessAgentConfig.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * 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.opencord.cordconfig.access;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Iterators;
+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.config.Config;
+
+import java.util.Map;
+import java.util.Optional;
+
+import static org.onosproject.net.config.Config.FieldPresence.MANDATORY;
+import static org.onosproject.net.config.Config.FieldPresence.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";
+
+ @Override
+ public boolean isValid() {
+ return hasOnlyFields(OLTS, AGENT_MAC, VTN_LOCATION) &&
+ isMacAddress(AGENT_MAC, MANDATORY) &&
+ isConnectPoint(VTN_LOCATION, OPTIONAL) &&
+ areOltsValid();
+ }
+
+ /**
+ * Gets the access agent configuration for this device.
+ *
+ * @return access agent configuration
+ */
+ public AccessAgentData getAgent() {
+ JsonNode olts = node.get(OLTS);
+ Map<ConnectPoint, MacAddress> oltMacInfo = Maps.newHashMap();
+ olts.fields().forEachRemaining(item -> oltMacInfo.put(
+ ConnectPoint.deviceConnectPoint(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);
+ }
+
+ private boolean areOltsValid() {
+ JsonNode olts = node.get(OLTS);
+ if (!olts.isObject()) {
+ return false;
+ }
+ return Iterators.all(olts.fields(),
+ item -> ConnectPoint.deviceConnectPoint(item.getKey()) != null &&
+ isMacAddress((ObjectNode) olts, item.getKey(), MANDATORY));
+ }
+}
diff --git a/src/main/java/org/opencord/cordconfig/access/AccessAgentData.java b/src/main/java/org/opencord/cordconfig/access/AccessAgentData.java
new file mode 100644
index 0000000..128352e
--- /dev/null
+++ b/src/main/java/org/opencord/cordconfig/access/AccessAgentData.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * 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.opencord.cordconfig.access;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+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 static final int CHIP_PORT_RANGE_SIZE = 130;
+
+ private final Map<ConnectPoint, MacAddress> oltMacInfo;
+ private final MacAddress agentMac;
+ private final Optional<ConnectPoint> vtnLocation;
+ private final DeviceId deviceId;
+
+ // OLT chip information sorted by ascending MAC address
+ private final List<Pair<ConnectPoint, MacAddress>> sortedOltChips;
+
+ /**
+ * Constructs 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 = ImmutableMap.copyOf(checkNotNull(oltMacInfo, OLT_INFO_MISSING));
+ this.agentMac = checkNotNull(agentMac, AGENT_MAC_MISSING);
+ this.vtnLocation = checkNotNull(vtnLocation, VTN_MISSING);
+
+ this.sortedOltChips = oltMacInfo.entrySet().stream()
+ .sorted((e1, e2) -> Long.compare(e1.getValue().toLong(), e2.getValue().toLong()))
+ .map(e -> Pair.of(e.getKey(), e.getValue()))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * 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 oltMacInfo;
+ }
+
+ /**
+ * Returns the agent's 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;
+ }
+
+ /**
+ * Returns the point where the OLT is connected to the fabric given a
+ * connect point on the agent device.
+ *
+ * @param agentConnectPoint connect point on the agent device
+ * @return point were OLT is connected to fabric
+ */
+ public Optional<ConnectPoint> getOltConnectPoint(ConnectPoint agentConnectPoint) {
+ int index = ((int) agentConnectPoint.port().toLong()) / CHIP_PORT_RANGE_SIZE;
+
+ if (index >= sortedOltChips.size()) {
+ return Optional.empty();
+ }
+
+ return Optional.of(sortedOltChips.get(index).getKey());
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("oltMacInfo", oltMacInfo)
+ .add("agentMac", agentMac)
+ .add("vtnLocation", vtnLocation)
+ .add("deviceId", deviceId)
+ .toString();
+ }
+}
diff --git a/src/main/java/org/opencord/cordconfig/access/AccessDeviceConfig.java b/src/main/java/org/opencord/cordconfig/access/AccessDeviceConfig.java
new file mode 100644
index 0000000..7572a2f
--- /dev/null
+++ b/src/main/java/org/opencord/cordconfig/access/AccessDeviceConfig.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * 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.opencord.cordconfig.access;
+
+import org.onosproject.net.DeviceId;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onlab.packet.VlanId;
+
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.Config;
+
+import java.util.Optional;
+
+/**
+ * Config object for access device data.
+ */
+public class AccessDeviceConfig extends Config<DeviceId> {
+
+ private static final String UPLINK = "uplink";
+ private static final String VLAN = "vlan";
+ private static final String DEFAULT_VLAN = "defaultVlan";
+
+ /**
+ * Gets the access device configuration for this device.
+ *
+ * @return access device configuration
+ * @deprecated in Goldeneye release. Use {@link #getAccessDevice()} instead.
+ */
+ @Deprecated
+ public AccessDeviceData getOlt() {
+ return getAccessDevice();
+ }
+
+ /**
+ * Gets the access device configuration for this device.
+ *
+ * @return access device configuration
+ */
+ public AccessDeviceData getAccessDevice() {
+ PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText());
+ VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText()));
+ JsonNode defaultVlanNode = node.path(DEFAULT_VLAN);
+
+ Optional<VlanId> defaultVlan;
+ if (defaultVlanNode.isMissingNode()) {
+ defaultVlan = Optional.empty();
+ } else {
+ defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText())));
+ }
+
+ return new AccessDeviceData(subject(), uplink, vlan, defaultVlan);
+ }
+}
diff --git a/src/main/java/org/opencord/cordconfig/access/AccessDeviceData.java b/src/main/java/org/opencord/cordconfig/access/AccessDeviceData.java
new file mode 100644
index 0000000..c2f076c
--- /dev/null
+++ b/src/main/java/org/opencord/cordconfig/access/AccessDeviceData.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * 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.opencord.cordconfig.access;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Information about an access device.
+ */
+public class AccessDeviceData {
+ private static final String DEVICE_ID_MISSING = "Device ID cannot be null";
+ private static final String UPLINK_MISSING = "Uplink cannot be null";
+ private static final String VLAN_MISSING = "VLAN ID cannot be null";
+
+ private final DeviceId deviceId;
+ private final PortNumber uplink;
+ private final VlanId vlan;
+ private final Optional<VlanId> defaultVlan;
+
+ /**
+ * Class constructor.
+ *
+ * @param deviceId access device ID
+ * @param uplink uplink port number
+ * @param vlan device VLAN ID
+ * @param defaultVlan default device VLAN ID
+ */
+ public AccessDeviceData(DeviceId deviceId, PortNumber uplink, VlanId vlan,
+ Optional<VlanId> defaultVlan) {
+ this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING);
+ this.uplink = checkNotNull(uplink, UPLINK_MISSING);
+ this.vlan = checkNotNull(vlan, VLAN_MISSING);
+ this.defaultVlan = checkNotNull(defaultVlan);
+ }
+
+ /**
+ * Retrieves the access device ID.
+ *
+ * @return device ID
+ */
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ /**
+ * Retrieves the uplink port number.
+ *
+ * @return port number
+ */
+ public PortNumber uplink() {
+ return uplink;
+ }
+
+ /**
+ * Retrieves the VLAN ID assigned to the device.
+ *
+ * @return VLAN ID
+ */
+ public VlanId vlan() {
+ return vlan;
+ }
+
+ /**
+ * Retrieves the default VLAN ID that will be used for this device.
+ *
+ * @return default VLAN ID
+ */
+ public Optional<VlanId> defaultVlan() {
+ return defaultVlan;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("deviceId", deviceId)
+ .add("uplink", uplink)
+ .add("vlan", vlan)
+ .add("defaultVlan", defaultVlan)
+ .toString();
+ }
+}
diff --git a/src/main/java/org/opencord/cordconfig/access/package-info.java b/src/main/java/org/opencord/cordconfig/access/package-info.java
new file mode 100644
index 0000000..f6dcfd5
--- /dev/null
+++ b/src/main/java/org/opencord/cordconfig/access/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * CORD access configuration classes.
+ */
+package org.opencord.cordconfig.access;
\ No newline at end of file