OSPF protocol manual merge from 1.6, due to cherry pick merge conflict
Change-Id: I93653e745468722ce95533537a79e897b4292f5d
diff --git a/providers/ospf/BUCK b/providers/ospf/BUCK
new file mode 100644
index 0000000..829827e
--- /dev/null
+++ b/providers/ospf/BUCK
@@ -0,0 +1,16 @@
+BUNDLES = [
+ '//protocols/ospf/api:onos-protocols-ospf-api',
+ '//protocols/ospf/ctl:onos-protocols-ospf-ctl',
+ '//protocols/ospf/protocol:onos-protocols-ospf-protocol',
+ '//providers/ospf/cfg:onos-providers-ospf-cfg',
+ '//providers/ospf/topology:onos-providers-ospf-topology',
+]
+
+onos_app (
+ title = 'OSPF Provider',
+ category = 'Provider',
+ url = 'http://onosproject.org',
+ description = 'ONOS OSPF protocol adapters.',
+ included_bundles = BUNDLES,
+)
+
diff --git a/providers/ospf/app/app.xml b/providers/ospf/app/app.xml
new file mode 100644
index 0000000..b98afc2
--- /dev/null
+++ b/providers/ospf/app/app.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<app name="org.onosproject.ospf" origin="ON.Lab" version="${project.version}"
+ featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+ features="${project.artifactId}">
+ <description>${project.description}</description>
+ <artifact>mvn:${project.groupId}/onos-ospf-api/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-ospf-ctl/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-ospf-protocol/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-ospf-provider-topology/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-ospf-provider-cfg/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-ospf-provider-cli/${project.version}</artifact>
+</app>
diff --git a/providers/ospf/app/features.xml b/providers/ospf/app/features.xml
new file mode 100644
index 0000000..f04e131
--- /dev/null
+++ b/providers/ospf/app/features.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ 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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature>onos-api</feature>
+ <bundle>mvn:${project.groupId}/onos-ospf-api/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-ospf-ctl/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-ospf-protocol/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-ospf-provider-topology/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-ospf-provider-cfg/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-ospf-provider-cli/${project.version}</bundle>
+ </feature>
+</features>
diff --git a/providers/ospf/app/pom.xml b/providers/ospf/app/pom.xml
new file mode 100644
index 0000000..49e8ef3
--- /dev/null
+++ b/providers/ospf/app/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-providers</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-ospf-app</artifactId>
+ <packaging>pom</packaging>
+ <description>OSPF protocol southbound providers</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-ctl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-protocol</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-provider-topology</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-provider-cfg</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-provider-cli</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/providers/ospf/cfg/BUCK b/providers/ospf/cfg/BUCK
new file mode 100644
index 0000000..c884550
--- /dev/null
+++ b/providers/ospf/cfg/BUCK
@@ -0,0 +1,9 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//protocols/ospf/api:onos-protocols-ospf-api',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+)
+
diff --git a/providers/ospf/cfg/pom.xml b/providers/ospf/cfg/pom.xml
new file mode 100644
index 0000000..fce0cc4
--- /dev/null
+++ b/providers/ospf/cfg/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-providers</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-ospf-provider-cfg</artifactId>
+ <packaging>bundle</packaging>
+ <description>ONOS OSPF Providers</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-ctl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/OspfAppConfig.java b/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/OspfAppConfig.java
new file mode 100644
index 0000000..162ec30
--- /dev/null
+++ b/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/OspfAppConfig.java
@@ -0,0 +1,72 @@
+/*
+* 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.provider.ospf.cfg.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.onosproject.ospf.controller.OspfController;
+
+/**
+ * Configuration object for OSPF.
+ */
+public class OspfAppConfig extends Config<ApplicationId> {
+ public static final String METHOD = "method";
+ public static final String ATTRIBUTE = "attribute";
+ public static final String PROCESSES = "processes";
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private OspfController ospfController;
+
+ /**
+ * Returns the configuration method, add, delete etc.
+ *
+ * @return the configuration method, add, delete etc
+ */
+ public String method() {
+ return get(METHOD, null);
+ }
+
+ /**
+ * Returns the configuration attribute, area, process etc.
+ *
+ * @return the configuration attribute, area, process etc
+ */
+ public String attribute() {
+ return get(ATTRIBUTE, null);
+ }
+
+ /**
+ * Returns the configured processes.
+ *
+ * @return the configured processes
+ */
+ public JsonNode processes() {
+ JsonNode jsonNodes = object.get(PROCESSES);
+
+ return jsonNodes;
+ }
+
+ @Override
+ public boolean isValid() {
+ this.ospfController = DefaultServiceDirectory.getService(OspfController.class);
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/OspfCfgProvider.java b/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/OspfCfgProvider.java
new file mode 100644
index 0000000..7e91fbd
--- /dev/null
+++ b/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/OspfCfgProvider.java
@@ -0,0 +1,129 @@
+/*
+ * 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.provider.ospf.cfg.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.ospf.controller.OspfController;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provider which advertises device descriptions to the core.
+ */
+@Component(immediate = true)
+@Service
+public class OspfCfgProvider extends AbstractProvider {
+
+ static final String PROVIDER_ID = "org.onosproject.provider.ospf.cfg";
+ private static final Logger log = getLogger(OspfCfgProvider.class);
+ private final ConfigFactory configFactory =
+ new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, OspfAppConfig.class, "ospfapp") {
+ @Override
+ public OspfAppConfig createConfig() {
+ return new OspfAppConfig();
+ }
+ };
+ private final NetworkConfigListener configListener = new InternalConfigListener();
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected OspfController ospfController;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry configRegistry;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService configService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected OspfController controller;
+ private ApplicationId appId;
+
+ /**
+ * Creates an OSPF device provider.
+ */
+ public OspfCfgProvider() {
+ super(new ProviderId("ospf", PROVIDER_ID));
+ }
+
+ public void setOspfController(OspfController ospfController) {
+ this.ospfController = ospfController;
+ }
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(PROVIDER_ID);
+ configService.addListener(configListener);
+ configRegistry.registerConfigFactory(configFactory);
+ log.info("activated...!!!");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ configRegistry.unregisterConfigFactory(configFactory);
+ configService.removeListener(configListener);
+ log.info("deactivated...!!!");
+ }
+
+ private void updateConfig() {
+ OspfAppConfig ospfAppConfig = configRegistry.getConfig(appId, OspfAppConfig.class);
+ if ("ADD".equalsIgnoreCase(ospfAppConfig.method())) {
+ JsonNode jsonNode = ospfAppConfig.processes();
+ ospfController.updateConfig(jsonNode);
+ } else {
+ log.debug("Please signify prop1 and prop2");
+ }
+ }
+
+ /**
+ * OSPF config listener to populate the configuration.
+ */
+ private class InternalConfigListener implements NetworkConfigListener {
+ @Override
+ public void event(NetworkConfigEvent event) {
+ log.debug("InternalConfigListener:: event is getting called");
+ if (!event.configClass().equals(OspfAppConfig.class)) {
+ return;
+ }
+ switch (event.type()) {
+ case CONFIG_ADDED:
+ updateConfig();
+ break;
+ case CONFIG_UPDATED:
+ updateConfig();
+ break;
+ case CONFIG_REMOVED:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/package-info.java b/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/package-info.java
new file mode 100644
index 0000000..c2cd733
--- /dev/null
+++ b/providers/ospf/cfg/src/main/java/org/onosproject/provider/ospf/cfg/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provider that uses OSPF capability request as a means of infrastructure device discovery.
+ */
+package org.onosproject.provider.ospf.cfg.impl;
diff --git a/providers/ospf/cli/pom.xml b/providers/ospf/cli/pom.xml
new file mode 100644
index 0000000..545f27f
--- /dev/null
+++ b/providers/ospf/cli/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-providers</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-ospf-provider-cli</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>OSPF cli implementation</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-cli</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-ctl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-protocol</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/providers/ospf/cli/src/main/java/org/onosproject/ospf/cli/ApplicationOspfCommand.java b/providers/ospf/cli/src/main/java/org/onosproject/ospf/cli/ApplicationOspfCommand.java
new file mode 100644
index 0000000..2027b74
--- /dev/null
+++ b/providers/ospf/cli/src/main/java/org/onosproject/ospf/cli/ApplicationOspfCommand.java
@@ -0,0 +1,401 @@
+/*
+* 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.ospf.cli;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.ospf.controller.OspfArea;
+import org.onosproject.ospf.controller.OspfController;
+import org.onosproject.ospf.controller.OspfInterface;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.controller.OspfNbr;
+import org.onosproject.ospf.controller.OspfProcess;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Representation of OSPF cli commands.
+ */
+@Component(immediate = true)
+@Command(scope = "onos", name = "ospf", description = "list database")
+public class ApplicationOspfCommand extends AbstractShellCommand {
+
+ protected static final String FORMAT6 = "%-20s%-20s%-20s%-20s%-20s%-20s\n";
+ protected static final String FORMAT5 = "%-20s%-20s%-20s%-20s%-20s\n";
+ protected static final String NETWORK = "NETWORK";
+ protected static final String SUMMARY = "SUMMARY";
+ protected static final String ASBR = "ABSR";
+ protected static final String EXTERNAL = "EXTERNAL";
+ protected static final String LINKLOOPAQ = "LINKLOCALOPAQUE";
+ protected static final String AREALOCOPAQ = "AREALOCALOPAQUE";
+ protected static final String ASOPAQ = "ASOPAQUE";
+ protected static final String DR = "DR";
+ protected static final String BACKUP = "BACKUP";
+ protected static final String DROTHER = "DROther";
+ static final String DATABASE = "database";
+ static final String NEIGHBORLIST = "neighbors";
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected OspfController ospfController;
+ @Argument(index = 0, name = "name",
+ description = "database|neighborlist",
+ required = true, multiValued = false)
+ private String name = null;
+ @Argument(index = 1, name = "processid",
+ description = "processId",
+ required = true, multiValued = false)
+ private String process = null;
+ @Argument(index = 2, name = "areaid",
+ description = "areaId",
+ required = false, multiValued = false)
+ private String area = null;
+ private List<String> routerLsa = new ArrayList<>();
+ private List<String> networkLsa = new ArrayList<>();
+ private List<String> summaryLsa = new ArrayList<>();
+ private List<String> externalLsa = new ArrayList<>();
+ private List<String> asbrSumm = new ArrayList<>();
+ private List<String> areaLocalOpaqLsa = new ArrayList<>();
+ private List<String> linkLocalOpqLsa = new ArrayList<>();
+ private List<String> asOpqLsa = new ArrayList<>();
+ private List<String> undefinedLsa = new ArrayList<>();
+ private List<OspfArea> areaList = new ArrayList<>();
+
+
+ @Activate
+ public void activate() {
+ print("OSPF cli activated...!!!");
+ log.debug("OSPF cli activated...!!!");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.debug("OSPF cli deactivated...!!!");
+ }
+
+ @Override
+ protected void execute() {
+ if (DATABASE.equals(name)) {
+ buildOspfDatabaseInformation();
+ } else if (NEIGHBORLIST.equals(name)) {
+ buildNeighborInformation();
+ } else {
+ print("Please check the command (database|neighbor)");
+ }
+ }
+
+ /**
+ * Clears all the lists.
+ */
+ private void clearLists() {
+ routerLsa.clear();
+ networkLsa.clear();
+ summaryLsa.clear();
+ externalLsa.clear();
+ asbrSumm.clear();
+ areaLocalOpaqLsa.clear();
+ linkLocalOpqLsa.clear();
+ asOpqLsa.clear();
+ undefinedLsa.clear();
+ areaList.clear();
+ }
+
+ /**
+ * Builds OSPF database information.
+ */
+ private void buildOspfDatabaseInformation() {
+ try {
+ //Builds LSA details
+ buildLsaLists();
+ for (OspfArea area : areaList) {
+ if (routerLsa.size() > 0) {
+ printRouterFormat(area.areaId().toString(), area.routerId().toString(), process);
+ for (String str : routerLsa) {
+ String[] lsaVal = str.split("\\,");
+ if (area.areaId().toString().equalsIgnoreCase(lsaVal[0])) {
+ print(FORMAT6, lsaVal[2], lsaVal[3], lsaVal[4], lsaVal[5], lsaVal[6], lsaVal[7]);
+ }
+ }
+ }
+ if (networkLsa.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), NETWORK);
+ printDetails(networkLsa, area.areaId().toString());
+ }
+ if (summaryLsa.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), SUMMARY);
+ printDetails(summaryLsa, area.areaId().toString());
+ }
+ if (externalLsa.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), EXTERNAL);
+ printDetails(externalLsa, area.areaId().toString());
+ }
+ if (asbrSumm.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), ASBR);
+ printDetails(asbrSumm, area.areaId().toString());
+ }
+ if (areaLocalOpaqLsa.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), AREALOCOPAQ);
+ printDetails(areaLocalOpaqLsa, area.areaId().toString());
+ }
+ if (linkLocalOpqLsa.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), LINKLOOPAQ);
+ printDetails(linkLocalOpqLsa, area.areaId().toString());
+ }
+ if (asOpqLsa.size() > 0) {
+ printNetworkFormat(area.areaId().toString(), ASOPAQ);
+ printDetails(asOpqLsa, area.areaId().toString());
+ }
+ if (undefinedLsa.size() > 0) {
+ printRouterFormat(area.areaId().toString(), area.routerId().toString(), process);
+ printDetails(undefinedLsa, area.areaId().toString());
+ }
+ }
+ clearLists();
+ } catch (Exception ex) {
+ clearLists();
+ print("Error occured while Ospf controller getting called" + ex.getMessage());
+ }
+ }
+
+ /**
+ * Prints LSA details.
+ *
+ * @param lsaDetails LSA details
+ * @param areaId area ID
+ */
+ private void printDetails(List<String> lsaDetails, String areaId) {
+ for (String str : lsaDetails) {
+ String[] lsaVal = str.split("\\,");
+ if (areaId.equalsIgnoreCase(lsaVal[0])) {
+ print(FORMAT5, lsaVal[2], lsaVal[3], lsaVal[4], lsaVal[5], lsaVal[6]);
+ }
+ }
+ }
+
+ /**
+ * Builds all LSA lists with LSA details.
+ */
+ private void buildLsaLists() {
+ this.ospfController = get(OspfController.class);
+ List<OspfProcess> listOfProcess = ospfController.getAllConfiguredProcesses();
+ Iterator<OspfProcess> itrProcess = listOfProcess.iterator();
+ while (itrProcess.hasNext()) {
+ OspfProcess ospfProcess = itrProcess.next();
+ if (process.equalsIgnoreCase(ospfProcess.processId())) {
+ List<OspfArea> listAreas = ospfProcess.areas();
+ Iterator<OspfArea> itrArea = listAreas.iterator();
+ while (itrArea.hasNext()) {
+ OspfArea area = itrArea.next();
+ List<LsaHeader> lsas = area.database()
+ .getAllLsaHeaders(false, area.isOpaqueEnabled());
+ List<LsaHeader> tmpLsaList = new ArrayList<>(lsas);
+ log.debug("OSPFController::size of database::" + (lsas != null ? lsas.size() : null));
+ Iterator<LsaHeader> itrLsaHeader = tmpLsaList.iterator();
+ areaList.add(area);
+ if (itrLsaHeader != null) {
+ while (itrLsaHeader.hasNext()) {
+ LsaHeader header = itrLsaHeader.next();
+ populateLsaLists(header, area);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Populates the LSA lists based on the input.
+ *
+ * @param header LSA header instance
+ * @param area OSPF area instance
+ */
+ private void populateLsaLists(LsaHeader header, OspfArea area) {
+ String seqNo = Long.toHexString(header.lsSequenceNo());
+ String checkSum = Long.toHexString(header.lsCheckSum());
+ if (seqNo.length() == 16) {
+ seqNo = seqNo.substring(8, seqNo.length());
+ }
+ if (checkSum.length() == 16) {
+ checkSum = checkSum.substring(8, checkSum.length());
+ }
+ StringBuffer strBuf = getBuffList(area.areaId().toString(), area.routerId().toString(),
+ header.linkStateId(),
+ header.advertisingRouter().toString(),
+ header.age(), seqNo, checkSum);
+ if (header.lsType() == OspfLsaType.ROUTER.value()) {
+ strBuf.append(",");
+ strBuf.append(((RouterLsa) header).noLink());
+ routerLsa.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.NETWORK.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ networkLsa.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.SUMMARY.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ summaryLsa.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.EXTERNAL_LSA.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ externalLsa.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.ASBR_SUMMARY.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ asbrSumm.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ areaLocalOpaqLsa.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ linkLocalOpqLsa.add(strBuf.toString());
+ } else if (header.lsType() == OspfLsaType.AS_OPAQUE_LSA.value()) {
+ strBuf.append(",");
+ strBuf.append("0");
+ asOpqLsa.add(strBuf.toString());
+ } else {
+ strBuf.append(",");
+ strBuf.append("0");
+ undefinedLsa.add(strBuf.toString());
+ }
+ }
+
+ /**
+ * Builds OSPF neighbor information.
+ */
+ private void buildNeighborInformation() {
+ try {
+ this.ospfController = get(OspfController.class);
+ List<OspfProcess> listOfProcess = ospfController.getAllConfiguredProcesses();
+ boolean flag = false;
+ printNeighborsFormat();
+ Iterator<OspfProcess> itrProcess = listOfProcess.iterator();
+ while (itrProcess.hasNext()) {
+ OspfProcess process = itrProcess.next();
+ List<OspfArea> listAreas = process.areas();
+ Iterator<OspfArea> itrArea = listAreas.iterator();
+ while (itrArea.hasNext()) {
+ OspfArea area = itrArea.next();
+ List<OspfInterface> itrefaceList = area.ospfInterfaceList();
+ for (OspfInterface interfc : itrefaceList) {
+ List<OspfNbr> nghbrList = new ArrayList<>(interfc.listOfNeighbors().values());
+ for (OspfNbr neigbor : nghbrList) {
+ print("%-20s%-20s%-20s%-20s%-20s\n", neigbor.neighborId(), neigbor.routerPriority(),
+ neigbor.getState() + "/" + checkDrBdrOther(neigbor.neighborIpAddr().toString(),
+ neigbor.neighborDr().toString(),
+ neigbor.neighborBdr().toString()),
+ neigbor.neighborIpAddr().toString(), interfc.ipAddress());
+ }
+ }
+ }
+ }
+ } catch (Exception ex) {
+ print("Error occured while Ospf controller getting called" + ex.getMessage());
+ }
+ }
+
+ /**
+ * Prints input after formatting.
+ *
+ * @param areaId area ID
+ * @param routerId router ID
+ * @param processId process ID
+ */
+ private void printRouterFormat(String areaId, String routerId, String processId) {
+ print("%s (%s) %s %s\n", "OSPF Router with ID", routerId, "Process Id", processId);
+ print("%s ( Area %s)\n", "Router Link States", areaId);
+ print("%-20s%-20s%-20s%-20s%-20s%-20s\n", "Link Id", "ADV Router", "Age", "Seq#",
+ "CkSum", "Link Count");
+ }
+
+ /**
+ * Prints input after formatting.
+ *
+ * @param areaId area ID
+ * @param type network type
+ */
+ private void printNetworkFormat(String areaId, String type) {
+ print("%s %s ( Area %s)\n", type, "Link States", areaId);
+ print("%-20s%-20s%-20s%-20s%-20s\n", "Link Id", "ADV Router", "Age", "Seq#", "CkSum");
+ }
+
+ /**
+ * Prints input after formatting.
+ */
+ private void printNeighborsFormat() {
+ print("%-20s%-20s%-20s%-20s%-20s\n", "Neighbor Id", "Pri", "State",
+ "Address", "Interface");
+ }
+
+ /**
+ * Checks whether the neighbor is DR or BDR.
+ *
+ * @param ip IP address to check
+ * @param drIP DRs IP address
+ * @param bdrIp BDRs IP address
+ * @return 1- neighbor is DR, 2- neighbor is BDR, 3- DROTHER
+ */
+ public String checkDrBdrOther(String ip, String drIP, String bdrIp) {
+
+ if (ip.equalsIgnoreCase(drIP)) {
+ return DR;
+ } else if (ip.equalsIgnoreCase(bdrIp)) {
+ return BACKUP;
+ } else {
+ return DROTHER;
+ }
+ }
+
+ /**
+ * Returns inputs as formatted string.
+ *
+ * @param areaId area id
+ * @param routerId router id
+ * @param linkStateId link state id
+ * @param advertisingRouter advertising router
+ * @param age age
+ * @param seqNo sequence number
+ * @param checkSum checksum
+ * @return formatted string
+ */
+ private StringBuffer getBuffList(String areaId, String routerId, String linkStateId,
+ String advertisingRouter, int age, String seqNo, String checkSum) {
+ StringBuffer strBuf = new StringBuffer();
+ strBuf.append(areaId);
+ strBuf.append(",");
+ strBuf.append(routerId);
+ strBuf.append(",");
+ strBuf.append(linkStateId);
+ strBuf.append(",");
+ strBuf.append(advertisingRouter);
+ strBuf.append(",");
+ strBuf.append(age);
+ strBuf.append(",");
+ strBuf.append(seqNo);
+ strBuf.append(",");
+ strBuf.append(checkSum);
+ return strBuf;
+ }
+}
\ No newline at end of file
diff --git a/providers/ospf/cli/src/main/java/org/onosproject/ospf/cli/package-info.java b/providers/ospf/cli/src/main/java/org/onosproject/ospf/cli/package-info.java
new file mode 100644
index 0000000..d040733
--- /dev/null
+++ b/providers/ospf/cli/src/main/java/org/onosproject/ospf/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * OSPF cli implementation.
+ */
+package org.onosproject.ospf.cli;
diff --git a/providers/ospf/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/providers/ospf/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..d261dee
--- /dev/null
+++ b/providers/ospf/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ 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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.onosproject.ospf.cli.ApplicationOspfCommand"/>
+ </command>
+ </command-bundle>
+
+</blueprint>
diff --git a/providers/ospf/pom.xml b/providers/ospf/pom.xml
new file mode 100644
index 0000000..690598b
--- /dev/null
+++ b/providers/ospf/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-providers</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-ospf-providers</artifactId>
+ <packaging>pom</packaging>
+
+ <description>ONOS OSPF protocol adapters</description>
+
+ <modules>
+ <module>app</module>
+ <module>cfg</module>
+ <module>cli</module>
+ <module>topology</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-ctl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/providers/ospf/topology/BUCK b/providers/ospf/topology/BUCK
new file mode 100644
index 0000000..4197711
--- /dev/null
+++ b/providers/ospf/topology/BUCK
@@ -0,0 +1,15 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//protocols/ospf/api:onos-protocols-ospf-api',
+ '//protocols/ospf/ctl:onos-protocols-ospf-ctl',
+]
+
+TEST_DEPS = [
+ '//lib:TEST_ADAPTERS',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+ test_deps = TEST_DEPS,
+)
+
diff --git a/providers/ospf/topology/pom.xml b/providers/ospf/topology/pom.xml
new file mode 100644
index 0000000..370c7a5
--- /dev/null
+++ b/providers/ospf/topology/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-ospf-providers</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-ospf-provider-topology</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS OSPF Topology Providers</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/providers/ospf/topology/src/main/java/org/onosproject/provider/ospf/topology/impl/OspfTopologyProvider.java b/providers/ospf/topology/src/main/java/org/onosproject/provider/ospf/topology/impl/OspfTopologyProvider.java
new file mode 100644
index 0000000..1b76de2
--- /dev/null
+++ b/providers/ospf/topology/src/main/java/org/onosproject/provider/ospf/topology/impl/OspfTopologyProvider.java
@@ -0,0 +1,246 @@
+/*
+ * 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.provider.ospf.topology.impl;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.ChassisId;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.ospf.controller.OspfController;
+import org.onosproject.ospf.controller.OspfLinkTed;
+import org.onosproject.ospf.controller.OspfRouter;
+import org.onosproject.ospf.controller.OspfRouterId;
+import org.onosproject.ospf.controller.OspfRouterListener;
+import org.onosproject.ospf.controller.OspfLinkListener;
+import org.slf4j.Logger;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provider which advertises device descriptions to the core.
+ */
+@Component(immediate = true)
+public class OspfTopologyProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
+
+ public static final long PSEUDO_PORT = 0xffffffff;
+ private static final Logger log = getLogger(OspfTopologyProvider.class);
+ // Default values for tunable parameters
+ private static final String UNKNOWN = "unknown";
+ final InternalTopologyProvider listener = new InternalTopologyProvider();
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceProviderRegistry deviceProviderRegistry;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkProviderRegistry linkProviderRegistry;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkService linkService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected OspfController controller;
+ //This Interface that defines how this provider can interact with the core.
+ private LinkProviderService linkProviderService;
+ // The interface that defines how this Provider can interact with the core
+ private DeviceProviderService deviceProviderService;
+
+ /**
+ * Creates an OSPF device provider.
+ */
+ public OspfTopologyProvider() {
+ super(new ProviderId("l3", "org.onosproject.provider.ospf"));
+ }
+
+ @Activate
+ public void activate() {
+ deviceProviderService = deviceProviderRegistry.register(this);
+ linkProviderService = linkProviderRegistry.register(this);
+ controller.addRouterListener(listener);
+ controller.addLinkListener(listener);
+ log.debug("IsisDeviceProvider::activate...!!!!");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.debug("IsisDeviceProvider::deactivate...!!!!");
+ deviceProviderRegistry.unregister(this);
+ deviceProviderService = null;
+ linkProviderRegistry.unregister(this);
+ linkProviderService = null;
+ controller.removeRouterListener(listener);
+ controller.removeLinkListener(listener);
+ log.info("deactivated...!!!");
+ }
+
+ @Override
+ public boolean isReachable(DeviceId deviceId) {
+ return true;
+ }
+
+ @Override
+ public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
+ log.info("changePortState on device {}", deviceId);
+ }
+
+ @Override
+ public void triggerProbe(DeviceId deviceId) {
+ log.info("Triggering probe on device {}", deviceId);
+ }
+
+ @Override
+ public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+ log.info("Accepting mastership role change for device {}", deviceId);
+ }
+
+ /**
+ * Builds link description.
+ *
+ * @param ospfRouter OSPF router instance
+ * @param ospfLinkTed OSPF link TED instance
+ * @return link description instance
+ */
+ private LinkDescription buildLinkDes(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
+ long srcAddress = 0;
+ long dstAddress = 0;
+ boolean localPseduo = false;
+ //Changing of port numbers
+ srcAddress = Ip4Address.valueOf(ospfRouter.routerIp().toString()).toInt();
+ dstAddress = Ip4Address.valueOf(ospfRouter.neighborRouterId().toString()).toInt();
+ DeviceId srcId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
+ DeviceId dstId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.neighborRouterId()));
+ if (ospfRouter.isDr()) {
+ localPseduo = true;
+ }
+ if (localPseduo && srcAddress == 0) {
+ srcAddress = PSEUDO_PORT;
+ }
+
+ ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress));
+ ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress));
+
+ return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false);
+ }
+
+ /**
+ * Internal topology Provider implementation.
+ */
+ protected class InternalTopologyProvider implements OspfRouterListener, OspfLinkListener {
+
+ @Override
+ public void routerAdded(OspfRouter ospfRouter) {
+ String routerId = ospfRouter.routerIp().toString();
+ log.info("Added device {}", routerId);
+ DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
+ Device.Type deviceType = Device.Type.ROUTER;
+ //If our routerType is Dr or Bdr type is PSEUDO
+ if (ospfRouter.isDr()) {
+ deviceType = Device.Type.ROUTER;
+ } else {
+ deviceType = Device.Type.VIRTUAL;
+ }
+ //deviceId = DeviceId.deviceId(routerDetails);
+ ChassisId cId = new ChassisId();
+ DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
+
+ newBuilder.set(AnnotationKeys.TYPE, "l3");
+ newBuilder.set("routerId", routerId);
+ DeviceDescription description =
+ new DefaultDeviceDescription(OspfRouterId.uri(ospfRouter.routerIp()),
+ deviceType, UNKNOWN, UNKNOWN, UNKNOWN,
+ UNKNOWN, cId, newBuilder.build());
+ deviceProviderService.deviceConnected(deviceId, description);
+ }
+
+ @Override
+ public void routerRemoved(OspfRouter ospfRouter) {
+ String routerId = ospfRouter.routerIp().toString();
+ log.info("Delete device {}", routerId);
+ DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
+ if (deviceProviderService == null) {
+ return;
+ }
+ deviceProviderService.deviceDisconnected(deviceId);
+ log.info("delete device {}", routerId);
+ }
+
+ @Override
+ public void addLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
+ log.debug("Addlink {}", ospfRouter.routerIp());
+ LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed);
+ //If already link exists, return
+ if (linkService.getLink(linkDes.src(), linkDes.dst()) != null || linkProviderService == null) {
+ return;
+ }
+ //Updating ports of the link
+ List<PortDescription> srcPortDescriptions = new LinkedList<>();
+ srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
+ deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
+
+ List<PortDescription> dstPortDescriptions = new LinkedList<>();
+ dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
+ deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
+ linkProviderService.linkDetected(linkDes);
+ }
+
+ @Override
+ public void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
+ log.debug("Delete link {}", ospfRouter.routerIp().toString());
+ if (linkProviderService == null) {
+ return;
+ }
+ LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed);
+ //Updating ports of the link
+ List<PortDescription> srcPortDescriptions = new LinkedList<>();
+ srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
+ deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
+
+ List<PortDescription> dstPortDescriptions = new LinkedList<>();
+ dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
+ deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
+ linkProviderService.linkVanished(linkDes);
+ }
+
+ @Override
+ public void routerChanged(OspfRouter ospfRouter) {
+ log.info("Router changed is not supported currently");
+ }
+ }
+}
\ No newline at end of file
diff --git a/providers/ospf/topology/src/main/java/org/onosproject/provider/ospf/topology/impl/package-info.java b/providers/ospf/topology/src/main/java/org/onosproject/provider/ospf/topology/impl/package-info.java
new file mode 100644
index 0000000..63f733e
--- /dev/null
+++ b/providers/ospf/topology/src/main/java/org/onosproject/provider/ospf/topology/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provider that uses OSPF as a means of topology discovery.
+ */
+package org.onosproject.provider.ospf.topology.impl;
diff --git a/providers/ospf/topology/src/test/java/org/onosproject/provider/ospf/topology/impl/OspfTopologyProviderTest.java b/providers/ospf/topology/src/test/java/org/onosproject/provider/ospf/topology/impl/OspfTopologyProviderTest.java
new file mode 100644
index 0000000..a667a0e
--- /dev/null
+++ b/providers/ospf/topology/src/test/java/org/onosproject/provider/ospf/topology/impl/OspfTopologyProviderTest.java
@@ -0,0 +1,380 @@
+/*
+ * 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.provider.ospf.topology.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkListener;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.link.LinkServiceAdapter;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.ospf.controller.OspfController;
+import org.onosproject.ospf.controller.OspfDeviceTed;
+import org.onosproject.ospf.controller.OspfLinkListener;
+import org.onosproject.ospf.controller.OspfLinkTed;
+import org.onosproject.ospf.controller.OspfProcess;
+import org.onosproject.ospf.controller.OspfRouter;
+import org.onosproject.ospf.controller.OspfRouterListener;
+import org.onosproject.ospf.controller.impl.OspfDeviceTedImpl;
+import org.onosproject.ospf.controller.impl.OspfLinkTedImpl;
+import org.onosproject.ospf.controller.impl.OspfRouterImpl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for OSPF topology provider.
+ */
+public class OspfTopologyProviderTest {
+
+ private final OspfTopologyProvider provider = new OspfTopologyProvider();
+ private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry();
+ private final TestLinkRegistry linkRegistry = new TestLinkRegistry();
+ private final TestController controller = new TestController();
+ private final TestLinkService linkService = new TestLinkService();
+
+ @Before
+ public void setUp() throws Exception {
+ provider.deviceProviderRegistry = nodeRegistry;
+ provider.linkProviderRegistry = linkRegistry;
+ provider.controller = controller;
+ provider.linkService = linkService;
+ provider.activate();
+ assertNotNull("provider should be registered", nodeRegistry.provider);
+ assertNotNull("listener should be registered", controller.nodeListener);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ provider.deactivate();
+ assertNull("listener should be removed", controller.nodeListener);
+ provider.controller = null;
+ provider.deviceProviderRegistry = null;
+ }
+
+ @Test
+ public void triggerProbe() {
+ DeviceId deviceId = DeviceId.deviceId("2.2.2.2");
+ provider.triggerProbe(deviceId);
+ }
+
+ @Test
+ public void roleChanged() {
+ DeviceId deviceId = DeviceId.deviceId("2.2.2.2");
+ provider.roleChanged(deviceId, MastershipRole.MASTER);
+ }
+
+ @Test
+ public void changePortState() {
+ DeviceId deviceId = DeviceId.deviceId("2.2.2.2");
+ provider.changePortState(deviceId, PortNumber.portNumber(0), false);
+ }
+
+ @Test
+ public void isReachable() {
+ DeviceId deviceId = DeviceId.deviceId("1.1.1.1");
+ provider.isReachable(deviceId);
+ }
+
+ /* Validate node is added to the device validating URI, RIB should get updated properly */
+ @Test
+ public void ospfTopologyProviderTestAddDevice1() {
+ int deviceAddCount = 0;
+ OspfRouter ospfRouter = new OspfRouterImpl();
+ ospfRouter.setDr(false);
+ ospfRouter.setOpaque(false);
+ ospfRouter.setNeighborRouterId(Ip4Address.valueOf("2.2.2.2"));
+ ospfRouter.setInterfaceId(Ip4Address.valueOf("10.10.10.2"));
+ ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("5.5.5.5"));
+ ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1"));
+ OspfDeviceTed ospfDeviceTed = new OspfDeviceTedImpl();
+ ospfDeviceTed.setAbr(false);
+ ospfDeviceTed.setAsbr(false);
+ ospfRouter.setDeviceTed(ospfDeviceTed);
+ OspfLinkTed ospfLinkTed = new OspfLinkTedImpl();
+ ospfLinkTed.setMaximumLink(Bandwidth.bps(10));
+ ospfLinkTed.setMaxReserved(Bandwidth.bps(20));
+ ospfLinkTed.setTeMetric(10);
+ OspfRouter ospfRouter1 = new OspfRouterImpl();
+ ospfRouter1.setDr(true);
+ ospfRouter1.setOpaque(true);
+ ospfRouter1.setNeighborRouterId(Ip4Address.valueOf("2.2.2.2"));
+ ospfRouter1.setInterfaceId(Ip4Address.valueOf("10.10.10.2"));
+ ospfRouter1.setAreaIdOfInterface(Ip4Address.valueOf("5.5.5.5"));
+ ospfRouter1.setRouterIp(Ip4Address.valueOf("1.1.1.1"));
+ OspfDeviceTed ospfDeviceTed1 = new OspfDeviceTedImpl();
+ ospfDeviceTed1.setAbr(false);
+ ospfDeviceTed1.setAsbr(false);
+ ospfRouter.setDeviceTed(ospfDeviceTed);
+ OspfLinkTed ospfLinkTed1 = new OspfLinkTedImpl();
+ ospfLinkTed1.setMaximumLink(Bandwidth.bps(10));
+ ospfLinkTed1.setMaxReserved(Bandwidth.bps(20));
+ ospfLinkTed1.setTeMetric(10);
+ for (OspfRouterListener l : controller.nodeListener) {
+ l.routerAdded(ospfRouter);
+
+ deviceAddCount = nodeRegistry.connected.size();
+ assertTrue(deviceAddCount == 1);
+ l.routerRemoved(ospfRouter);
+ deviceAddCount = nodeRegistry.connected.size();
+ assertTrue(deviceAddCount == 0);
+ }
+ for (OspfLinkListener l : controller.linkListener) {
+ l.addLink(ospfRouter, ospfLinkTed);
+ l.deleteLink(ospfRouter, ospfLinkTed);
+
+ }
+ }
+
+ @Test
+ public void ospfTopologyProviderTestAddDevice2() {
+ int deviceAddCount = 0;
+ OspfRouter ospfRouter = new OspfRouterImpl();
+ ospfRouter.setDr(true);
+ ospfRouter.setOpaque(true);
+ ospfRouter.setNeighborRouterId(Ip4Address.valueOf("3.3.3.3"));
+ ospfRouter.setInterfaceId(Ip4Address.valueOf("10.10.10.3"));
+ ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("6.6.6.6"));
+ ospfRouter.setRouterIp(Ip4Address.valueOf("7.7.7.7"));
+ OspfDeviceTed ospfDeviceTed = new OspfDeviceTedImpl();
+ ospfDeviceTed.setAbr(true);
+ ospfDeviceTed.setAsbr(true);
+ ospfRouter.setDeviceTed(ospfDeviceTed);
+ OspfLinkTed ospfLinkTed = new OspfLinkTedImpl();
+ ospfLinkTed.setMaximumLink(Bandwidth.bps(30));
+ ospfLinkTed.setMaxReserved(Bandwidth.bps(40));
+ ospfLinkTed.setTeMetric(50);
+ for (OspfRouterListener l : controller.nodeListener) {
+ l.routerAdded(ospfRouter);
+ deviceAddCount = nodeRegistry.connected.size();
+ assertTrue(deviceAddCount == 1);
+ l.routerRemoved(ospfRouter);
+ deviceAddCount = nodeRegistry.connected.size();
+ assertTrue(deviceAddCount == 0);
+ }
+ }
+
+
+ /* Class implement device test registry */
+ private class TestDeviceRegistry implements DeviceProviderRegistry {
+ DeviceProvider provider;
+ Set<DeviceId> connected = new HashSet<>();
+
+ @Override
+ public DeviceProviderService register(DeviceProvider provider) {
+ this.provider = provider;
+ return new TestProviderService();
+ }
+
+ @Override
+ public void unregister(DeviceProvider provider) {
+ }
+
+ @Override
+ public Set<ProviderId> getProviders() {
+ return null;
+ }
+
+ private class TestProviderService implements DeviceProviderService {
+
+ @Override
+ public DeviceProvider provider() {
+ return null;
+ }
+
+ @Override
+ public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
+ connected.add(deviceId);
+ }
+
+ @Override
+ public void deviceDisconnected(DeviceId deviceId) {
+ connected.remove(deviceId);
+ }
+
+ @Override
+ public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
+ // TODO Auto-generated method stub
+ }
+ }
+ }
+
+ private class TestDeviceService extends DeviceServiceAdapter {
+ private DeviceListener listener;
+
+ @Override
+ public void addListener(DeviceListener listener) {
+ this.listener = listener;
+ }
+
+ @Override
+ public Iterable<Device> getDevices() {
+ return Collections.emptyList();
+ }
+ }
+
+ private class TestLinkService extends LinkServiceAdapter {
+ private LinkListener listener;
+
+ @Override
+ public void addListener(LinkListener listener) {
+ this.listener = listener;
+ }
+
+ @Override
+ public Iterable<Link> getLinks() {
+ return Collections.emptyList();
+ }
+ }
+
+ /* Class implement device test registry */
+ private class TestLinkRegistry implements LinkProviderRegistry {
+ LinkProvider provider;
+ Set<DeviceId> connected = new HashSet<>();
+
+ @Override
+ public LinkProviderService register(LinkProvider provider) {
+ this.provider = provider;
+ return new TestLinkProviderService();
+ }
+
+ @Override
+ public void unregister(LinkProvider provider) {
+ }
+
+ @Override
+ public Set<ProviderId> getProviders() {
+ return null;
+ }
+
+ private class TestLinkProviderService implements LinkProviderService {
+ @Override
+ public void linkDetected(LinkDescription linkDescription) {
+ }
+
+ @Override
+ public void linkVanished(LinkDescription linkDescription) {
+ }
+
+ @Override
+ public void linksVanished(ConnectPoint connectPoint) {
+ }
+
+ @Override
+ public void linksVanished(DeviceId deviceId) {
+ }
+
+ @Override
+ public LinkProvider provider() {
+ return null;
+ }
+ }
+ }
+
+ /* class implement test controller */
+ private class TestController implements OspfController {
+ protected Set<OspfRouterListener> nodeListener = new CopyOnWriteArraySet<>();
+ protected Set<OspfLinkListener> linkListener = new CopyOnWriteArraySet<>();
+
+ @Override
+ public void addRouterListener(OspfRouterListener nodeListener) {
+ this.nodeListener.add(nodeListener);
+ }
+
+ @Override
+ public void removeRouterListener(OspfRouterListener nodeListener) {
+ this.nodeListener = null;
+ }
+
+ @Override
+ public void addLinkListener(OspfLinkListener listener) {
+ this.linkListener.add(listener);
+ }
+
+ @Override
+ public void removeLinkListener(OspfLinkListener listener) {
+ this.nodeListener = null;
+ }
+
+ @Override
+ public void updateConfig(JsonNode processesNode) {
+ }
+
+
+ @Override
+ public void deleteConfig(List<OspfProcess> processes, String attribute) {
+ }
+
+ @Override
+ public Set<OspfRouterListener> listener() {
+ return null;
+ }
+
+ @Override
+ public Set<OspfLinkListener> linkListener() {
+ return null;
+ }
+
+ @Override
+ public List<OspfProcess> getAllConfiguredProcesses() {
+ return null;
+ }
+ }
+}
\ No newline at end of file