OSPF protocol manual merge from 1.6, due to cherry pick merge conflict
Change-Id: I93653e745468722ce95533537a79e897b4292f5d
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;