[ONOS-5751] Initial implementation of LISP mapping provider
Change-Id: Ibddfc9f92e4d385c9995e7baa3613a2562499fbf
diff --git a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java
index 7c6d016..09bf3e6 100644
--- a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java
+++ b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java
@@ -24,9 +24,17 @@
import org.onosproject.lisp.ctl.LispMessageListener;
import org.onosproject.lisp.ctl.LispRouterId;
import org.onosproject.lisp.ctl.LispRouterListener;
+import org.onosproject.lisp.msg.protocols.LispMapNotify;
+import org.onosproject.lisp.msg.protocols.LispMapReply;
import org.onosproject.lisp.msg.protocols.LispMessage;
+import org.onosproject.mapping.MappingEntry;
+import org.onosproject.mapping.MappingProvider;
+import org.onosproject.mapping.MappingProviderRegistry;
+import org.onosproject.mapping.MappingProviderService;
+import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
+import org.onosproject.provider.lisp.mapping.util.MappingEntryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,13 +42,18 @@
* Provider which uses a LISP controller to manage EID-RLOC mapping.
*/
@Component(immediate = true)
-public class LispMappingProvider extends AbstractProvider {
+public class LispMappingProvider extends AbstractProvider implements MappingProvider {
private static final Logger log = LoggerFactory.getLogger(LispMappingProvider.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LispController controller;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MappingProviderRegistry providerRegistry;
+
+ protected MappingProviderService providerService;
+
private static final String SCHEME_NAME = "lisp";
private static final String MAPPING_PROVIDER_PACKAGE =
"org.onosproject.lisp.provider.mapping";
@@ -57,6 +70,8 @@
@Activate
public void activate() {
+ providerService = providerRegistry.register(this);
+
// listens all LISP router related events
controller.addRouterListener(listener);
@@ -69,12 +84,16 @@
@Deactivate
public void deactivate() {
+ providerRegistry.unregister(this);
+
// stops listening all LISP router related events
controller.removeRouterListener(listener);
// stops listening all LISP control messages
controller.removeMessageListener(listener);
+ providerService = null;
+
log.info("Stopped");
}
@@ -106,7 +125,31 @@
@Override
public void handleOutgoingMessage(LispRouterId routerId, LispMessage msg) {
+ if (providerService == null) {
+ // We are shutting down, nothing to be done
+ return;
+ }
+ DeviceId deviceId = DeviceId.deviceId(routerId.toString());
+ switch (msg.getType()) {
+
+ case LISP_MAP_REPLY:
+ LispMapReply reply = (LispMapReply) msg;
+
+ MappingEntry replyMe = new MappingEntryBuilder(deviceId, reply).build();
+ providerService.mappingAdded(replyMe, false);
+ break;
+
+ case LISP_MAP_NOTIFY:
+ LispMapNotify notify = (LispMapNotify) msg;
+
+ MappingEntry notifyMe = new MappingEntryBuilder(deviceId, notify).build();
+ providerService.mappingAdded(notifyMe, true);
+ break;
+
+ default:
+ log.warn("Unhandled message type: {}", msg.getType());
+ }
}
}
}
diff --git a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java
new file mode 100644
index 0000000..12a58e4
--- /dev/null
+++ b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017-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.provider.lisp.mapping.util;
+
+import org.onosproject.lisp.msg.protocols.LispMapNotify;
+import org.onosproject.lisp.msg.protocols.LispMapReply;
+import org.onosproject.mapping.MappingEntry;
+import org.onosproject.net.DeviceId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Mapping entry builder class.
+ */
+public class MappingEntryBuilder {
+ private static final Logger log = LoggerFactory.getLogger(MappingEntryBuilder.class);
+
+ private final DeviceId deviceId;
+ private final LispMapReply mapReply;
+ private final LispMapNotify mapNotify;
+
+ /**
+ * Default constructor for MappingEntryBuilder.
+ *
+ * @param deviceId device identifier
+ * @param mapReply map reply message
+ */
+ public MappingEntryBuilder(DeviceId deviceId, LispMapReply mapReply) {
+ this.deviceId = deviceId;
+ this.mapReply = mapReply;
+ this.mapNotify = null;
+ }
+
+ /**
+ * Default constructor for MappingEntryBuilder.
+ *
+ * @param deviceId device identifier
+ * @param mapNotify map notify message
+ */
+ public MappingEntryBuilder(DeviceId deviceId, LispMapNotify mapNotify) {
+ this.deviceId = deviceId;
+ this.mapNotify = mapNotify;
+ this.mapReply = null;
+ }
+
+ public MappingEntry build() {
+ // TODO: provide a way to build mapping entry from input parameters
+ return null;
+ }
+}
diff --git a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/package-info.java b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/package-info.java
new file mode 100644
index 0000000..8538009
--- /dev/null
+++ b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * LISP provider utility package.
+ */
+package org.onosproject.provider.lisp.mapping.util;
\ No newline at end of file