[ONOS-5607] Add LISP router, controller and listener interfaces
Change-Id: If01738d1b0e4e264618392844d96a9cf31cbd7c7
diff --git a/protocols/lisp/api/BUCK b/protocols/lisp/api/BUCK
index 2b27800..7e70e4e 100644
--- a/protocols/lisp/api/BUCK
+++ b/protocols/lisp/api/BUCK
@@ -1,5 +1,7 @@
COMPILE_DEPS = [
'//lib:CORE_DEPS',
+ '//lib:netty-transport',
+ '//protocols/lisp/msg:onos-protocols-lisp-msg',
]
osgi_jar_with_tests (
diff --git a/protocols/lisp/api/pom.xml b/protocols/lisp/api/pom.xml
index 4e7506b..6772669 100644
--- a/protocols/lisp/api/pom.xml
+++ b/protocols/lisp/api/pom.xml
@@ -40,9 +40,9 @@
<artifactId>netty-transport</artifactId>
</dependency>
<dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-transport-native-epoll</artifactId>
- <version>${netty4.version}</version>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-lisp-msg</artifactId>
+ <version>${project.version}</version>
</dependency>
</dependencies>
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispController.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispController.java
index be9141d..5c47109 100644
--- a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispController.java
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispController.java
@@ -21,4 +21,47 @@
*/
public interface LispController {
+ /**
+ * Obtains all LISP routers known to this LISP controller.
+ *
+ * @return Iterable of LISP router elements
+ */
+ Iterable<LispRouter> getRouters();
+
+ /**
+ * Obtains the actual router for the given LispRouterId.
+ *
+ * @param routerId the router to fetch
+ * @return the interface to this router
+ */
+ LispRouter getRouter(LispRouterId routerId);
+
+ /**
+ * Registers a router listener to track router status.
+ * (e.g., router add and removal)
+ *
+ * @param listener the listener to notify
+ */
+ void addRouterListener(LispRouterListener listener);
+
+ /**
+ * Unregisters a router listener.
+ *
+ * @param listener the listener to unregister
+ */
+ void removeRouterListener(LispRouterListener listener);
+
+ /**
+ * Registers a listener for all LISP message types.
+ *
+ * @param listener the listener to notify
+ */
+ void addMessageListener(LispMessageListener listener);
+
+ /**
+ * Unregisters a listener.
+ *
+ * @param listener the listener to unregister
+ */
+ void removeMessageListener(LispMessageListener listener);
}
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispMessageListener.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispMessageListener.java
new file mode 100644
index 0000000..ffc540c
--- /dev/null
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispMessageListener.java
@@ -0,0 +1,40 @@
+/*
+ * 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.lisp.ctl;
+
+import org.onosproject.lisp.msg.protocols.LispMessage;
+
+/**
+ * Notifies providers about all LISP messages.
+ */
+public interface LispMessageListener {
+
+ /**
+ * Handles all incoming LISP messages.
+ *
+ * @param routerId the router where the message generated
+ * @param msg raw LISP message
+ */
+ void handleIncomingMessage(LispRouterId routerId, LispMessage msg);
+
+ /**
+ * Handles all outgoing LISP messages.
+ *
+ * @param routerId the router where the message to be sent
+ * @param msg raw LISP message
+ */
+ void handleOutgoingMessage(LispRouterId routerId, LispMessage msg);
+}
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouter.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouter.java
new file mode 100644
index 0000000..a6fa99f
--- /dev/null
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouter.java
@@ -0,0 +1,83 @@
+/*
+ * 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.lisp.ctl;
+
+import io.netty.channel.Channel;
+import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.protocols.LispMessage;
+import org.onosproject.net.Device;
+
+/**
+ * Represents to provider facing side of a router.
+ */
+public interface LispRouter {
+
+ /**
+ * Writes the LISP control message to the channel.
+ *
+ * @param msg the message to be written
+ */
+ void sendMessage(LispMessage msg);
+
+ /**
+ * Handles the LISP control message from the channel.
+ *
+ * @param msg the message to be handled
+ */
+ void handleMessage(LispMessage msg);
+
+ /**
+ * Returns the router device type.
+ *
+ * @return device type
+ */
+ Device.Type deviceType();
+
+ /**
+ * Identifies the channel used to communicate with the router.
+ *
+ * @return string representation of the connection to the device
+ */
+ String channelId();
+
+ /**
+ * Sets the associated Netty channel for this router.
+ *
+ * @param channel the Netty channel
+ */
+ void setChannel(Channel channel);
+
+ /**
+ * Obtains a string version of the ID for this router.
+ *
+ * @return string representation of the device identifier
+ */
+ String stringId();
+
+ /**
+ * Obtains an IpAddress version of the ID for this router.
+ *
+ * @return raw IP address of the device identifier
+ */
+ IpAddress routerId();
+
+ /**
+ * Checks if the router is connected.
+ *
+ * @return whether the router is connected
+ */
+ boolean isConnected();
+}
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterAgent.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterAgent.java
new file mode 100644
index 0000000..bdafa86
--- /dev/null
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterAgent.java
@@ -0,0 +1,63 @@
+/*
+ * 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.lisp.ctl;
+
+import org.onosproject.lisp.msg.protocols.LispMessage;
+
+/**
+ * Responsible for keeping track of the current set of
+ * routers connected to the system.
+ */
+public interface LispRouterAgent {
+
+ /**
+ * Adds a router that has just connected to the system.
+ * We try to add the router into connectedRouter pool when the router is
+ * initially sending Map-Register message to the controller.
+ *
+ * @param routerId the routerId to add
+ * @param router the actual router object
+ * @return true if added, false otherwise
+ */
+ boolean addConnectedRouter(LispRouterId routerId, LispRouter router);
+
+ /**
+ * Clears all state in controller router maps for a router that has
+ * disconnected from the local controller. Also release control for that
+ * router from the global repository. Notify router listener.
+ *
+ * @param routerId the routerId to rmove
+ */
+ void removeConnectedRouter(LispRouterId routerId);
+
+ /**
+ * Processes a message coming from a router. Notifies message listeners on
+ * all incoming message event.
+ *
+ * @param routerId the routerId of a router where the message comes from
+ * @param message the message to process
+ */
+ void processUpstreamMessage(LispRouterId routerId, LispMessage message);
+
+ /**
+ * Processes a message going to a router. Notifies message listeners on
+ * all outgoing message event.
+ *
+ * @param routerId the routerId of a router where the message goes to
+ * @param message the message to process
+ */
+ void processDownstreamMessage(LispRouterId routerId, LispMessage message);
+}
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java
new file mode 100644
index 0000000..d6b3c9c
--- /dev/null
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java
@@ -0,0 +1,94 @@
+/*
+ * 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.lisp.ctl;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.util.Identifier;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * The class representing a network router identifier.
+ * This class is immutable.
+ */
+public final class LispRouterId extends Identifier<IpAddress> {
+
+ private static final String SCHEME = "lisp";
+ private static final IpAddress UNKNOWN = IpAddress.valueOf("0.0.0.0");
+
+ /**
+ * A default constructor.
+ */
+ public LispRouterId() {
+ super(UNKNOWN);
+ }
+
+ /**
+ * A constructor with an IpAddress value specified.
+ *
+ * @param value the value to use
+ */
+ public LispRouterId(IpAddress value) {
+ super(value);
+ }
+
+ /**
+ * A constructor with a String value specified.
+ *
+ * @param value the value to use
+ */
+ public LispRouterId(String value) {
+ super(IpAddress.valueOf(value));
+ }
+
+ /**
+ * Returns LispRouterId created from a given device URI.
+ *
+ * @param uri device URI
+ * @return object of LispRouterId
+ */
+ public static LispRouterId routerId(URI uri) {
+ checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme");
+ return new LispRouterId(IpAddress.valueOf(uri.getSchemeSpecificPart()));
+ }
+
+ /**
+ * Produces a device URI from the given LispRouterId.
+ *
+ * @param routerId device identifier
+ * @return device URI
+ */
+ public static URI uri(LispRouterId routerId) {
+ return uri(routerId.id());
+ }
+
+ /**
+ * Produces device URI from the given device IpAddress.
+ *
+ * @param ipAddress device ip address
+ * @return device URI
+ */
+ public static URI uri(IpAddress ipAddress) {
+ try {
+ return new URI(SCHEME, ipAddress.toString(), null);
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+}
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterListener.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterListener.java
new file mode 100644
index 0000000..f7a7857
--- /dev/null
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterListener.java
@@ -0,0 +1,43 @@
+/*
+ * 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.lisp.ctl;
+
+/**
+ * Allows for providers interested in Router events to be notified.
+ */
+public interface LispRouterListener {
+
+ /**
+ * Notifies that the router was added.
+ *
+ * @param routerId the router where the event occurred
+ */
+ void routerAdded(LispRouterId routerId);
+
+ /**
+ * Notifies that the router was removed.
+ *
+ * @param routerId the router where the event occurred
+ */
+ void routerRemoved(LispRouterId routerId);
+
+ /**
+ * Notifies that the router has changed in some way.
+ *
+ * @param routerId the router that changed
+ */
+ void routerChanged(LispRouterId routerId);
+}
diff --git a/protocols/lisp/api/src/test/java/org/onosproject/lisp/ctl/LispControllerAdapter.java b/protocols/lisp/api/src/test/java/org/onosproject/lisp/ctl/LispControllerAdapter.java
new file mode 100644
index 0000000..c096131
--- /dev/null
+++ b/protocols/lisp/api/src/test/java/org/onosproject/lisp/ctl/LispControllerAdapter.java
@@ -0,0 +1,51 @@
+/*
+ * 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.lisp.ctl;
+
+/**
+ * Test adapter for the LISP controller interface.
+ */
+public class LispControllerAdapter implements LispController {
+ @Override
+ public Iterable<LispRouter> getRouters() {
+ return null;
+ }
+
+ @Override
+ public LispRouter getRouter(LispRouterId routerId) {
+ return null;
+ }
+
+ @Override
+ public void addRouterListener(LispRouterListener listener) {
+
+ }
+
+ @Override
+ public void removeRouterListener(LispRouterListener listener) {
+
+ }
+
+ @Override
+ public void addMessageListener(LispMessageListener listener) {
+
+ }
+
+ @Override
+ public void removeMessageListener(LispMessageListener listener) {
+
+ }
+}
diff --git a/protocols/lisp/api/src/test/java/org/onosproject/lisp/ctl/LispRouterAdapter.java b/protocols/lisp/api/src/test/java/org/onosproject/lisp/ctl/LispRouterAdapter.java
new file mode 100644
index 0000000..4dcc736
--- /dev/null
+++ b/protocols/lisp/api/src/test/java/org/onosproject/lisp/ctl/LispRouterAdapter.java
@@ -0,0 +1,66 @@
+/*
+ * 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.lisp.ctl;
+
+import io.netty.channel.Channel;
+import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.protocols.LispMessage;
+import org.onosproject.net.Device;
+
+/**
+ * Test adapter for the LISP router interface.
+ */
+public class LispRouterAdapter implements LispRouter {
+ @Override
+ public void sendMessage(LispMessage msg) {
+
+ }
+
+ @Override
+ public void handleMessage(LispMessage msg) {
+
+ }
+
+ @Override
+ public Device.Type deviceType() {
+ return null;
+ }
+
+ @Override
+ public String channelId() {
+ return null;
+ }
+
+ @Override
+ public void setChannel(Channel channel) {
+
+ }
+
+ @Override
+ public String stringId() {
+ return null;
+ }
+
+ @Override
+ public IpAddress routerId() {
+ return null;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return false;
+ }
+}