Application manages the IP layer topology information - Interfaces

Change-Id: Ie1dea035674ee98583e98a82cca7e33ab0858b92
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/DefaultIpLinkDescription.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/DefaultIpLinkDescription.java
new file mode 100644
index 0000000..4a3b46d
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/DefaultIpLinkDescription.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import com.google.common.base.MoreObjects;
+import org.onosproject.iptopology.api.IpLinkIdentifier;
+import org.onosproject.iptopology.api.LinkTed;
+import org.onosproject.iptopology.api.TerminationPoint;
+import org.onosproject.net.AbstractDescription;
+import org.onosproject.net.SparseAnnotations;
+
+/**
+ * Default implementation of immutable ip link description entity.
+ */
+public class DefaultIpLinkDescription extends AbstractDescription
+        implements IpLinkDescription {
+
+    private final TerminationPoint src;
+    private final TerminationPoint dst;
+    private final IpLinkIdentifier linkIdentifier;
+    private final LinkTed linkTed;
+
+    /**
+     * Creates an ip link description using the supplied information.
+     *
+     * @param src             link source
+     * @param dst             link destination
+     * @param linkIdentifier  link identifier
+     * @param linkTed         link traffic engineering parameters
+     * @param annotations optional key/value annotations
+     */
+    public DefaultIpLinkDescription(TerminationPoint src, TerminationPoint dst,
+                                    IpLinkIdentifier linkIdentifier, LinkTed linkTed,
+                                    SparseAnnotations... annotations) {
+        super(annotations);
+        this.src = src;
+        this.dst = dst;
+        this.linkIdentifier = linkIdentifier;
+        this.linkTed = linkTed;
+    }
+
+    /**
+     * Creates an ip link description using the supplied information.
+     *
+     * @param base        IpLinkDescription to basic information
+     * @param annotations optional key/value annotations
+     */
+    public DefaultIpLinkDescription(IpLinkDescription base, SparseAnnotations... annotations) {
+        this(base.src(), base.dst(), base.linkIdentifier(),
+                base.linkTed(), annotations);
+    }
+
+    @Override
+    public TerminationPoint src() {
+        return src;
+    }
+
+    @Override
+    public TerminationPoint dst() {
+        return dst;
+    }
+
+    @Override
+    public IpLinkIdentifier linkIdentifier() {
+        return linkIdentifier;
+    }
+
+    @Override
+    public LinkTed linkTed() {
+        return linkTed; }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("src", src())
+                .add("dst", dst())
+                .add("linkIdentifier", linkIdentifier())
+                .add("linkTed", linkTed())
+                .toString();
+    }
+
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkDescription.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkDescription.java
new file mode 100644
index 0000000..258e744
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkDescription.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.iptopology.api.IpLinkIdentifier;
+import org.onosproject.iptopology.api.LinkTed;
+import org.onosproject.iptopology.api.TerminationPoint;
+import org.onosproject.net.Description;
+
+/**
+ * Describes an ip link.
+ */
+public interface IpLinkDescription extends Description {
+
+    /**
+     * Returns the link source.
+     *
+     * @return links source
+     */
+    TerminationPoint src();
+
+    /**
+     * Returns the link destination.
+     *
+     * @return links destination
+     */
+    TerminationPoint dst();
+
+    /**
+     * Returns the link identifier.
+     *
+     * @return links identifier informations
+     */
+    IpLinkIdentifier linkIdentifier();
+
+    /**
+     * Returns the link traffic engineering parameters.
+     *
+     * @return links traffic engineering parameters
+     */
+    LinkTed linkTed();
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkEvent.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkEvent.java
new file mode 100644
index 0000000..4050734
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkEvent.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.iptopology.api.IpLink;
+
+/**
+ * Describes ip link event.
+ */
+public class IpLinkEvent extends AbstractEvent<IpLinkEvent.Type, IpLink> {
+
+    /**
+     * Type of link events.
+     */
+    public enum Type {
+        /**
+         * Signifies that a new ip link has been detected.
+         */
+        LINK_ADDED,
+
+        /**
+         * Signifies that an ip link has been updated or changed state.
+         */
+        LINK_UPDATED,
+
+        /**
+         * Signifies that an ip link has been removed.
+         */
+        LINK_REMOVED
+    }
+
+    /**
+     * Creates an event of a given type and for the specified ip link and the
+     * current time.
+     *
+     * @param type link event type
+     * @param link event link subject
+     */
+    public IpLinkEvent(Type type, IpLink link) {
+        super(type, link);
+    }
+
+    /**
+     * Creates an event of a given type and for the specified ip link and time.
+     *
+     * @param type link event type
+     * @param link event link subject
+     * @param time occurrence time
+     */
+    public IpLinkEvent(Type type, IpLink link, long time) {
+        super(type, link, time);
+    }
+
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkListener.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkListener.java
new file mode 100644
index 0000000..5acb73a
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving ip link related events.
+ */
+public interface IpLinkListener extends EventListener<IpLinkEvent> {
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProvider.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProvider.java
new file mode 100644
index 0000000..a58bf61
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProvider.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.net.provider.Provider;
+
+/**
+ * Abstraction of an entity providing information about ip links
+ * to the core.
+ */
+public interface IpLinkProvider extends Provider {
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProviderRegistry.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProviderRegistry.java
new file mode 100644
index 0000000..e060ae6
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProviderRegistry.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.net.provider.ProviderRegistry;
+
+/**
+ * Abstraction of an ip link provider registry.
+ */
+public interface IpLinkProviderRegistry
+        extends ProviderRegistry<IpLinkProvider, IpLinkProviderService> {
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProviderService.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProviderService.java
new file mode 100644
index 0000000..c255442
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkProviderService.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+
+import org.onosproject.iptopology.api.TerminationPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderService;
+
+/**
+ * Means for injecting ip link information into the core.
+ */
+public interface IpLinkProviderService extends ProviderService<IpLinkProvider> {
+
+    /**
+     * Signals that an ip link is added or updated with IP topology information.
+     *
+     * @param linkDescription ip link information
+     */
+    void addOrUpdateIpLink(IpLinkDescription linkDescription);
+
+    /**
+     * Signals that an ip link has disappeared.
+     *
+     * @param linkDescription ip link information
+     */
+    void removeIpLink(IpLinkDescription linkDescription);
+
+    /**
+     * Signals that ip links associated with the specified
+     * termination point have vanished.
+     *
+     * @param terminationPoint termination point
+     */
+    void removeIpLink(TerminationPoint terminationPoint);
+
+    /**
+     * Signals that ip links associated with the specified
+     * device have vanished.
+     *
+     * @param deviceId device identifier
+     */
+    void removeIpLink(DeviceId deviceId);
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkService.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkService.java
new file mode 100644
index 0000000..723e907
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkService.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import java.util.Set;
+
+import org.onosproject.event.ListenerService;
+import org.onosproject.iptopology.api.IpLink;
+import org.onosproject.iptopology.api.TerminationPoint;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Service for interacting with the inventory of infrastructure links.
+ */
+public interface IpLinkService
+    extends ListenerService<IpLinkEvent, IpLinkListener> {
+
+    /**
+     * Returns the count of all known ip links.
+     *
+     * @return number of ip links
+     */
+    int getIpLinkCount();
+
+    /**
+     * Returns a collection of all ip links.
+     *
+     * @return all ip links
+     */
+    Iterable<IpLink> getIpLinks();
+
+
+    /**
+     * Returns set of all ip links leading to and from the
+     * specified ip device.
+     *
+     * @param deviceId device identifier
+     * @return set of ip device links
+     */
+    Set<IpLink> getIpDeviceLinks(DeviceId deviceId);
+
+    /**
+     * Returns set of all ip links leading from the specified ip device.
+     *
+     * @param deviceId device identifier
+     * @return set of ip device egress links
+     */
+    Set<IpLink> getIpDeviceEgressLinks(DeviceId deviceId);
+
+    /**
+     * Returns set of all ip links leading to the specified ip device.
+     *
+     * @param deviceId device identifier
+     * @return set of ip device ingress links
+     */
+    Set<IpLink> getIpDeviceIngressLinks(DeviceId deviceId);
+
+    /**
+     * Returns set of all ip links leading to and from the
+     * specified termination point.
+     *
+     * @param terminationPoint termination point
+     * @return set of ip links
+     */
+    Set<IpLink> getIpLinks(TerminationPoint terminationPoint);
+
+    /**
+     * Returns set of all ip links leading from the specified
+     * termination point.
+     *
+     * @param terminationPoint termination point
+     * @return set of ip device egress links
+     */
+    Set<IpLink> getEgressIpLinks(TerminationPoint terminationPoint);
+
+    /**
+     * Returns set of all ip links leading to the specified
+     * termination point.
+     *
+     * @param terminationPoint termination point
+     * @return set of ip device ingress links
+     */
+    Set<IpLink> getIngressIpLinks(TerminationPoint terminationPoint);
+
+    /**
+     * Returns the ip links between the specified source
+     * and destination termination points.
+     *
+     * @param src source termination point
+     * @param dst destination termination point
+     * @return ip link from source to destination; null if none found
+     */
+    IpLink getIpLink(TerminationPoint src, TerminationPoint dst);
+
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkStore.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkStore.java
new file mode 100644
index 0000000..8f5c60f
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkStore.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.iptopology.api.IpLink;
+import org.onosproject.iptopology.api.TerminationPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of ip links; not intended for direct use.
+ */
+public interface IpLinkStore extends Store<IpLinkEvent, IpLinkStoreDelegate> {
+
+    /**
+     * Returns the number of ip links in the store.
+     *
+     * @return number of ip links
+     */
+    int getIpLinkCount();
+
+    /**
+     * Returns an iterable collection of all ip links in the inventory.
+     *
+     * @return collection of all ip links
+     */
+    Iterable<IpLink> getIpLinks();
+
+    /**
+     * Returns all ip links egressing from the specified device.
+     *
+     * @param deviceId device identifier
+     * @return set of ip device links
+     */
+    Set<IpLink> getIpDeviceEgressLinks(DeviceId deviceId);
+
+    /**
+     * Returns all ip links ingressing from the specified device.
+     *
+     * @param deviceId device identifier
+     * @return set of ip device links
+     */
+    Set<IpLink> getIpDeviceIngressLinks(DeviceId deviceId);
+
+    /**
+     * Returns the ip link between the two termination points.
+     *
+     * @param src source termination point
+     * @param dst destination termination point
+     * @return ip link or null if one not found between the termination points
+     */
+    IpLink getIpLink(TerminationPoint src, TerminationPoint dst);
+
+    /**
+     * Returns all ip links egressing from the specified termination point.
+     *
+     * @param src source termination point
+     * @return set of termination point ip links
+     */
+    Set<IpLink> getEgressIpLinks(TerminationPoint src);
+
+    /**
+     * Returns all ip links ingressing to the specified termination point.
+     *
+     * @param dst destination termination point
+     * @return set of termination point ip links
+     */
+    Set<IpLink> getIngressIpLinks(TerminationPoint dst);
+
+    /**
+     * Creates a new ip link, or updates an existing one, based on the given
+     * information.
+     *
+     * @param providerId      provider identity
+     * @param linkDescription ip link description
+     * @return create or update ip link event, or null if no change resulted
+     */
+    IpLinkEvent createOrUpdateIpLink(ProviderId providerId,
+                                        IpLinkDescription linkDescription);
+
+    /**
+     * Removes ip link, based on the specified information.
+     *
+     * @param src ip link source
+     * @param dst ip link destination
+     * @return remove or update ip link event, or null if no change resulted
+     */
+    IpLinkEvent removeOrDownIpLink(TerminationPoint src, TerminationPoint dst);
+
+    /**
+     * Removes ip link based on the specified information.
+     *
+     * @param src ip link source
+     * @param dst ip link destination
+     * @return remove ip link event, or null if no change resulted
+     */
+    IpLinkEvent removeIpLink(TerminationPoint src, TerminationPoint dst);
+
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkStoreDelegate.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkStoreDelegate.java
new file mode 100644
index 0000000..9397a49
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/IpLinkStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2014 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.iptopology.api.link;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Ip link store delegate abstraction.
+ */
+public interface IpLinkStoreDelegate extends StoreDelegate<IpLinkEvent> {
+}
diff --git a/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/package-info.java b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/package-info.java
new file mode 100644
index 0000000..581c236
--- /dev/null
+++ b/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/link/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2014 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.
+ */
+
+/**
+ * Ip link model &amp; related services API definitions.
+ */
+package org.onosproject.iptopology.api.link;