diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfig.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfig.java index ae8c9fa868..a089a342ff 100644 --- a/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfig.java +++ b/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfig.java @@ -28,7 +28,10 @@ import java.util.List; /** * Routing configuration. + * + * @deprecated in Junco release. Use RoutersConfig instead. */ +@Deprecated public class RouterConfig extends Config { private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint"; diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutersConfig.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutersConfig.java new file mode 100644 index 0000000000..940a727d09 --- /dev/null +++ b/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutersConfig.java @@ -0,0 +1,135 @@ +/* + * 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.routing.config; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.config.Config; + +import java.util.HashSet; +import java.util.Set; + +/** + * Routing configuration. + */ +public class RoutersConfig extends Config { + + private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint"; + private static final String OSPF_ENABLED = "ospfEnabled"; + private static final String PIM_ENABLED = "pimEnabled"; + private static final String INTERFACES = "interfaces"; + + /** + * Gets the router configurations. + * + * @return set of router configurations + */ + public Set getRouters() { + Set routers = new HashSet<>(); + + for (JsonNode routerNode : array) { + ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(routerNode.path(CP_CONNECT_POINT).asText()); + boolean ospfEnabled = routerNode.path(OSPF_ENABLED).asBoolean(); + + + JsonNode intfNode = routerNode.path(INTERFACES); + if (intfNode.isMissingNode() || !intfNode.isArray()) { + continue; + } + ArrayNode array = (ArrayNode) intfNode; + Set interfaces = new HashSet<>(array.size()); + for (JsonNode intf : array) { + interfaces.add(intf.asText()); + } + + routers.add(new Router(connectPoint, ospfEnabled, interfaces)); + } + + return routers; + } + + @Override + public boolean isValid() { + for (JsonNode node : array) { + ObjectNode routerNode = (ObjectNode) node; + if (!hasOnlyFields(routerNode, INTERFACES, CP_CONNECT_POINT, OSPF_ENABLED, PIM_ENABLED)) { + return false; + } + + JsonNode intfNode = routerNode.path(INTERFACES); + if (!intfNode.isMissingNode() && !intfNode.isArray()) { + return false; + } + + boolean valid = isConnectPoint(routerNode, CP_CONNECT_POINT, FieldPresence.MANDATORY) && + isBoolean(routerNode, OSPF_ENABLED, FieldPresence.OPTIONAL) && + isBoolean(routerNode, PIM_ENABLED, FieldPresence.OPTIONAL); + + if (!valid) { + return false; + } + } + + return true; + } + + /** + * Router configuration. + */ + public static class Router { + private final ConnectPoint connectPoint; + private final boolean ospfEnabled; + private final Set interfaces; + + Router(ConnectPoint controlPlaneConnectPoint, boolean ospfEnabled, Set interfaces) { + this.connectPoint = controlPlaneConnectPoint; + this.ospfEnabled = ospfEnabled; + this.interfaces = interfaces; + } + + /** + * Returns the routing control plane connect point. + * + * @return control plane connect point + */ + public ConnectPoint controlPlaneConnectPoint() { + return connectPoint; + } + + /** + * Returns whether OSPF is enabled on this router. + * + * @return true if OSPF is enabled, otherwise false + */ + public boolean isOspfEnabled() { + return ospfEnabled; + } + + /** + * Returns the set of interfaces enabled on this router. + * + * @return set of interface names that are enabled, or an empty list if + * all available interfaces should be used + */ + public Set interfaces() { + return interfaces; + } + } +} diff --git a/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java b/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java index d9b792d2e5..ea22322463 100644 --- a/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java +++ b/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java @@ -46,6 +46,7 @@ import org.onosproject.routing.config.BgpConfig; import org.onosproject.routing.config.LocalIpPrefixEntry; import org.onosproject.routing.config.ReactiveRoutingConfig; import org.onosproject.routing.config.RouterConfig; +import org.onosproject.routing.config.RoutersConfig; import org.onosproject.routing.config.RoutingConfigurationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,6 +110,15 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { } }; + private ConfigFactory routersConfigFactory = + new ConfigFactory( + SubjectFactories.APP_SUBJECT_FACTORY, RoutersConfig.class, "routers", true) { + @Override + public RoutersConfig createConfig() { + return new RoutersConfig(); + } + }; + private ConfigFactory reactiveRoutingConfigFactory = new ConfigFactory( @@ -125,6 +135,7 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { configService.addListener(configListener); registry.registerConfigFactory(bgpConfigFactory); registry.registerConfigFactory(routerConfigFactory); + registry.registerConfigFactory(routersConfigFactory); registry.registerConfigFactory(reactiveRoutingConfigFactory); setUpConfiguration(); log.info("Routing configuration service started"); @@ -134,6 +145,7 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { public void deactivate() { registry.unregisterConfigFactory(bgpConfigFactory); registry.unregisterConfigFactory(routerConfigFactory); + registry.unregisterConfigFactory(routersConfigFactory); registry.unregisterConfigFactory(reactiveRoutingConfigFactory); configService.removeListener(configListener); log.info("Routing configuration service stopped");