Extend ControlPlaneRedirect (vRouter) to allow multiple redirects
CORD-787
Change-Id: I9e5a6f74b7239eb0dcb42b52e562698ce415debc
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfigHelper.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfigHelper.java
new file mode 100644
index 0000000..ddfd1db
--- /dev/null
+++ b/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfigHelper.java
@@ -0,0 +1,75 @@
+/*
+ * 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.google.common.collect.Sets;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.routing.RoutingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Helper class to manage retrieving config from multiple Config sections.
+ * Should be unnecessary once old config is removed.
+ */
+public final class RouterConfigHelper {
+
+ private static final String WARNING =
+ "Config apps/org.onosproject.routing/router is deprecated "
+ + "and will be removed in a future release.";
+ private static final String WARNING2 =
+ "Use apps/org.onosproject.routing/routers instead";
+
+ private static final Logger log = LoggerFactory.getLogger(RouterConfigHelper.class);
+
+ private RouterConfigHelper() {
+ // make checkstyle happy
+ }
+
+ /**
+ * Retrieves the router configurations.
+ *
+ * @param configService network config service
+ * @param routingAppId routing app ID
+ * @return set of router configurations
+ */
+ public static Set<RoutersConfig.Router> getRouterConfigurations(
+ NetworkConfigService configService, ApplicationId routingAppId) {
+
+ RouterConfig config = configService.getConfig(
+ routingAppId, RoutingService.ROUTER_CONFIG_CLASS);
+ RoutersConfig multiConfig = configService.getConfig(routingAppId, RoutersConfig.class);
+
+ if (config != null) {
+ log.warn(WARNING);
+ log.warn(WARNING2);
+
+ return Collections.singleton(
+ new RoutersConfig.Router(config.getControlPlaneConnectPoint(),
+ config.getOspfEnabled(),
+ Sets.newHashSet(config.getInterfaces())));
+ } else if (multiConfig != null) {
+ return multiConfig.getRouters();
+ } else {
+ return Collections.emptySet();
+ }
+ }
+}
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
index 940a727..0a60023 100644
--- 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
@@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.config.Config;
@@ -50,19 +51,18 @@
JsonNode intfNode = routerNode.path(INTERFACES);
- if (intfNode.isMissingNode() || !intfNode.isArray()) {
- continue;
- }
- ArrayNode array = (ArrayNode) intfNode;
Set<String> interfaces = new HashSet<>(array.size());
- for (JsonNode intf : array) {
- interfaces.add(intf.asText());
+ if (!intfNode.isMissingNode()) {
+ ArrayNode array = (ArrayNode) intfNode;
+ for (JsonNode intf : array) {
+ interfaces.add(intf.asText());
+ }
}
routers.add(new Router(connectPoint, ospfEnabled, interfaces));
}
- return routers;
+ return ImmutableSet.copyOf(routers);
}
@Override