VOL-3818: Initial version of OLT Topology discovery app; used to find active links between OLT NNI and Leaf switch ports.

Change-Id: I058b603d028446e8176821d85a25af8963e28924
diff --git a/api/pom.xml b/api/pom.xml
new file mode 100644
index 0000000..7f7bd54
--- /dev/null
+++ b/api/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>olttopology</artifactId>
+        <groupId>org.opencord</groupId>
+        <version>1.0.1</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>olttopology-api</artifactId>
+    <packaging>bundle</packaging>
+
+    <url>http://opencord.org</url>
+
+    <description>OLT application API</description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/api/src/main/java/org/opencord/olttopology/OltNeighborInfo.java b/api/src/main/java/org/opencord/olttopology/OltNeighborInfo.java
new file mode 100755
index 0000000..acc27dc
--- /dev/null
+++ b/api/src/main/java/org/opencord/olttopology/OltNeighborInfo.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2017-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.olttopology;
+
+import org.onlab.packet.LLDPTLV;
+
+import org.onosproject.net.Port;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Information about an OLT's neighbor. An instance of this class stores
+ * information about an OLT and it's neighbour. The information contains
+ * which port of the OLT is connected to which port of the neighbor
+ */
+public class OltNeighborInfo {
+
+    private String neighborName;
+    private String neighborPort;
+    private String oltName;
+    private Port oltPort;
+
+    // Serial number of the OLT
+    private String oltSerialNo;
+
+    // The management IP address of the neighbor
+    private String mgmtAddr;
+
+    // The time when this entry was last updated
+    private Date lastUpdated;
+
+    // List of other optional TLVs that would have been received from the
+    // neighbor in the last LLDP message
+    private List<LLDPTLV> otherOptionalTlvs;
+
+    public OltNeighborInfo(String neighborName, String neighborPort,
+                           String oltName, Port oltPort, String oltSerialNo) {
+        this.neighborName = neighborName;
+        this.neighborPort = neighborPort;
+        this.oltName = oltName;
+        this.oltPort = oltPort;
+        this.oltSerialNo = oltSerialNo;
+        otherOptionalTlvs = new ArrayList<>();
+        updateTimeStamp();
+    }
+
+    public String neighborName() {
+        return neighborName;
+    }
+
+    public String neighborPort() {
+        return neighborPort;
+    }
+
+    public String oltName() {
+        return oltName;
+    }
+
+    public Port oltPort() {
+        return oltPort;
+    }
+
+    public String oltSerialNo() {
+        return oltSerialNo;
+    }
+
+    public Date getLastUpdated() {
+        return lastUpdated;
+    }
+
+    public void updateTimeStamp() {
+        lastUpdated = new Date();
+    }
+
+    public String mgmtAddr() {
+        return mgmtAddr;
+    }
+
+    public void setMgmtAddress(String neighborManagementAddress) {
+        mgmtAddr = neighborManagementAddress;
+    }
+
+    public void addOtherOptionalLldpTlvs(LLDPTLV lldptlv) {
+        otherOptionalTlvs.add(lldptlv);
+    }
+
+    public List<LLDPTLV> getOtherOptionalTlvs() {
+        return otherOptionalTlvs;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        OltNeighborInfo that = (OltNeighborInfo) o;
+        return Objects.equals(neighborName, that.neighborName) &&
+                Objects.equals(neighborPort, that.neighborPort) &&
+                Objects.equals(oltName, that.oltName) &&
+                Objects.equals(oltPort, that.oltPort) &&
+                Objects.equals(oltSerialNo, that.oltSerialNo) &&
+                Objects.equals(mgmtAddr, that.mgmtAddr) &&
+                Objects.equals(lastUpdated, that.lastUpdated);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(neighborName, neighborPort, oltName,
+                oltPort, oltSerialNo, mgmtAddr, lastUpdated);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        final StringBuilder buf = new StringBuilder();
+        buf.append('[');
+        buf.append("neighborName:");
+        buf.append(this.neighborName);
+        buf.append(",neighborPort:");
+        buf.append(this.neighborPort);
+        buf.append(",oltName:");
+        buf.append(this.oltName);
+        buf.append(",oltPort:");
+        buf.append((this.oltPort.annotations().value("portName").isEmpty()) ? "" :
+                this.oltPort.annotations().value("portName"));
+        buf.append(",oltSerialNo:");
+        buf.append(this.oltSerialNo);
+        buf.append(",neighbor_mgmt_address:");
+        buf.append(this.mgmtAddr);
+        buf.append(",lastUpdated:");
+        buf.append(this.lastUpdated);
+        buf.append(']');
+        return buf.toString();
+    }
+}
diff --git a/api/src/main/java/org/opencord/olttopology/OltTopologyInformationService.java b/api/src/main/java/org/opencord/olttopology/OltTopologyInformationService.java
new file mode 100644
index 0000000..9ce5a0d
--- /dev/null
+++ b/api/src/main/java/org/opencord/olttopology/OltTopologyInformationService.java
@@ -0,0 +1,43 @@
+/*
+ * 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.olttopology;
+
+
+import org.onosproject.net.ConnectPoint;
+
+import java.util.Map;
+
+/**
+ * Service for configuring the OLT topology collection and for
+ * viewing the topology information.
+ */
+public interface OltTopologyInformationService {
+
+    /**
+     * Get a collection of OLT ports and their neighbors.
+     *
+     * @return OLT Connect points and it's neighbors
+     */
+    Map<ConnectPoint, OltNeighborInfo> getNeighbours();
+
+    /**
+     * Provision Timer for sending LLDP packets to OLT NNI Ports.
+     *
+     * @param timer Periodicity in minutes for sending out LLDP packet to OLT NNI ports.
+     */
+    void lldpPeriodicity(int timer);
+}
diff --git a/api/src/main/java/org/opencord/olttopology/package-info.java b/api/src/main/java/org/opencord/olttopology/package-info.java
new file mode 100644
index 0000000..31900e1
--- /dev/null
+++ b/api/src/main/java/org/opencord/olttopology/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.
+ */
+
+/**
+ * OltTopology application api.
+ */
+package org.opencord.olttopology;