Add Config for configuration multiple routers.

Deprecate old single router config.

CORD-786

Change-Id: Iab48be10f7f9d77939842ab00d2bd4be2b2ca0f5
This commit is contained in:
Jonathan Hart 2017-02-02 16:13:57 -08:00
parent 917127ab8d
commit a7a24cf4db
3 changed files with 150 additions and 0 deletions

View File

@ -28,7 +28,10 @@ import java.util.List;
/**
* Routing configuration.
*
* @deprecated in Junco release. Use RoutersConfig instead.
*/
@Deprecated
public class RouterConfig extends Config<ApplicationId> {
private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint";

View File

@ -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<ApplicationId> {
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<Router> getRouters() {
Set<Router> 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<String> 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<String> interfaces;
Router(ConnectPoint controlPlaneConnectPoint, boolean ospfEnabled, Set<String> 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<String> interfaces() {
return interfaces;
}
}
}

View File

@ -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<ApplicationId, RoutersConfig> routersConfigFactory =
new ConfigFactory<ApplicationId, RoutersConfig>(
SubjectFactories.APP_SUBJECT_FACTORY, RoutersConfig.class, "routers", true) {
@Override
public RoutersConfig createConfig() {
return new RoutersConfig();
}
};
private ConfigFactory<ApplicationId, ReactiveRoutingConfig>
reactiveRoutingConfigFactory =
new ConfigFactory<ApplicationId, ReactiveRoutingConfig>(
@ -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");