aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject')
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java105
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java2
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java113
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingConfig.java128
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/package-info.java2
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java2
6 files changed, 269 insertions, 83 deletions
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
index ef9d444a..8fdf81a2 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 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.
@@ -18,24 +18,26 @@ package org.onosproject.segmentrouting;
import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
-import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
+import org.onosproject.incubator.net.config.basics.ConfigException;
+import org.onosproject.incubator.net.config.basics.InterfaceConfig;
+import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.host.InterfaceIpAddress;
+import org.onosproject.segmentrouting.config.SegmentRoutingConfig;
+import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid;
import org.onosproject.segmentrouting.grouphandler.DeviceProperties;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
-import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig;
-import org.onosproject.segmentrouting.config.NetworkConfigManager;
-import org.onosproject.segmentrouting.config.SegmentRouterConfig;
-import org.onosproject.segmentrouting.config.SegmentRouterConfig.Subnet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Segment Routing configuration component that reads the
@@ -50,7 +52,6 @@ public class DeviceConfiguration implements DeviceProperties {
.getLogger(DeviceConfiguration.class);
private final List<Integer> allSegmentIds = new ArrayList<>();
private final HashMap<DeviceId, SegmentRouterInfo> deviceConfigMap = new HashMap<>();
- private final NetworkConfigManager configService;
private class SegmentRouterInfo {
int nodeSid;
@@ -60,48 +61,60 @@ public class DeviceConfiguration implements DeviceProperties {
boolean isEdge;
HashMap<PortNumber, Ip4Address> gatewayIps;
HashMap<PortNumber, Ip4Prefix> subnets;
- List<SegmentRouterConfig.AdjacencySid> adjacencySids;
+ List<AdjacencySid> adjacencySids;
}
/**
* Constructor. Reads all the configuration for all devices of type
* Segment Router and organizes into various maps for easier access.
- *
- * @param configService handle to network configuration manager
- * component from where the relevant configuration is retrieved.
*/
- public DeviceConfiguration(NetworkConfigManager configService) {
- this.configService = checkNotNull(configService);
- List<SwitchConfig> allSwitchCfg =
- this.configService.getConfiguredAllowedSwitches();
- for (SwitchConfig cfg : allSwitchCfg) {
- if (!(cfg instanceof SegmentRouterConfig)) {
- continue;
- }
+ public DeviceConfiguration(NetworkConfigRegistry cfgService) {
+ // Read config from device subject, excluding gatewayIps and subnets.
+ Set<DeviceId> deviceSubjects =
+ cfgService.getSubjects(DeviceId.class, SegmentRoutingConfig.class);
+ deviceSubjects.forEach(subject -> {
+ SegmentRoutingConfig config =
+ cfgService.getConfig(subject, SegmentRoutingConfig.class);
SegmentRouterInfo info = new SegmentRouterInfo();
- info.nodeSid = ((SegmentRouterConfig) cfg).getNodeSid();
- info.deviceId = ((SegmentRouterConfig) cfg).getDpid();
- info.mac = MacAddress.valueOf(((
- SegmentRouterConfig) cfg).getRouterMac());
- String routerIp = ((SegmentRouterConfig) cfg).getRouterIp();
- Ip4Prefix prefix = checkNotNull(IpPrefix.valueOf(routerIp).getIp4Prefix());
- info.ip = prefix.address();
- info.isEdge = ((SegmentRouterConfig) cfg).isEdgeRouter();
- info.subnets = new HashMap<>();
+ info.deviceId = subject;
+ info.nodeSid = config.getSid();
+ info.ip = config.getIp();
+ info.mac = config.getMac();
+ info.isEdge = config.isEdgeRouter();
+ info.adjacencySids = config.getAdjacencySids();
info.gatewayIps = new HashMap<>();
- for (Subnet s: ((SegmentRouterConfig) cfg).getSubnets()) {
- info.subnets.put(PortNumber.portNumber(s.getPortNo()),
- Ip4Prefix.valueOf(s.getSubnetIp()));
- String gatewayIp = s.getSubnetIp().
- substring(0, s.getSubnetIp().indexOf('/'));
- info.gatewayIps.put(PortNumber.portNumber(s.getPortNo()),
- Ip4Address.valueOf(gatewayIp));
- }
- info.adjacencySids = ((SegmentRouterConfig) cfg).getAdjacencySids();
+ info.subnets = new HashMap<>();
+
this.deviceConfigMap.put(info.deviceId, info);
this.allSegmentIds.add(info.nodeSid);
-
- }
+ });
+
+ // Read gatewayIps and subnets from port subject.
+ Set<ConnectPoint> portSubjects =
+ cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
+ portSubjects.forEach(subject -> {
+ InterfaceConfig config =
+ cfgService.getConfig(subject, InterfaceConfig.class);
+ Set<Interface> networkInterfaces;
+ try {
+ networkInterfaces = config.getInterfaces();
+ } catch (ConfigException e) {
+ log.error("Error loading port configuration");
+ return;
+ }
+ networkInterfaces.forEach(networkInterface -> {
+ DeviceId dpid = networkInterface.connectPoint().deviceId();
+ PortNumber port = networkInterface.connectPoint().port();
+ SegmentRouterInfo info = this.deviceConfigMap.get(dpid);
+
+ Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses();
+ interfaceAddresses.forEach(interfaceAddress -> {
+ info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address());
+ info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix());
+ });
+ });
+
+ });
}
/**
@@ -379,8 +392,8 @@ public class DeviceConfiguration implements DeviceProperties {
*/
public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) {
if (deviceConfigMap.get(deviceId) != null) {
- for (SegmentRouterConfig.AdjacencySid asid : deviceConfigMap.get(deviceId).adjacencySids) {
- if (asid.getAdjSid() == sid) {
+ for (AdjacencySid asid : deviceConfigMap.get(deviceId).adjacencySids) {
+ if (asid.getAsid() == sid) {
return asid.getPorts();
}
}
@@ -402,9 +415,9 @@ public class DeviceConfiguration implements DeviceProperties {
if (deviceConfigMap.get(deviceId).adjacencySids.isEmpty()) {
return false;
} else {
- for (SegmentRouterConfig.AdjacencySid asid:
+ for (AdjacencySid asid:
deviceConfigMap.get(deviceId).adjacencySids) {
- if (asid.getAdjSid() == sid) {
+ if (asid.getAsid() == sid) {
return true;
}
}
@@ -414,4 +427,4 @@ public class DeviceConfiguration implements DeviceProperties {
return false;
}
-}
+} \ No newline at end of file
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
index 0f8fa59d..f65f03e0 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
@@ -111,10 +111,10 @@ public class IcmpHandler {
icmpReplyIpv4.setChecksum((short) 0);
ICMP icmpReply = new ICMP();
+ icmpReply.setPayload(((ICMP) icmpRequestIpv4.getPayload()).getPayload());
icmpReply.setIcmpType(ICMP.TYPE_ECHO_REPLY);
icmpReply.setIcmpCode(ICMP.SUBTYPE_ECHO_REPLY);
icmpReply.setChecksum((short) 0);
-
icmpReplyIpv4.setPayload(icmpReply);
icmpReplyEth.setPayload(icmpReplyIpv4);
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 874faabf..05663129 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -27,6 +27,12 @@ import org.onlab.util.KryoNamespace;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.event.Event;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.segmentrouting.config.SegmentRoutingConfig;
import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
import org.onosproject.segmentrouting.grouphandler.NeighborSet;
import org.onosproject.segmentrouting.grouphandler.NeighborSetNextObjectiveStoreKey;
@@ -50,7 +56,6 @@ import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.topology.TopologyService;
-import org.onosproject.segmentrouting.config.NetworkConfigManager;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.store.service.EventuallyConsistentMapBuilder;
import org.onosproject.store.service.StorageService;
@@ -133,7 +138,21 @@ public class SegmentRoutingManager implements SegmentRoutingService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
- private NetworkConfigManager networkConfigService = new NetworkConfigManager();;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry cfgService;
+
+ private final InternalConfigListener cfgListener =
+ new InternalConfigListener(this);
+
+ private final ConfigFactory cfgFactory =
+ new ConfigFactory(SubjectFactories.DEVICE_SUBJECT_FACTORY,
+ SegmentRoutingConfig.class,
+ "segmentrouting") {
+ @Override
+ public SegmentRoutingConfig createConfig() {
+ return new SegmentRoutingConfig();
+ }
+ };
private Object threadSchedulerLock = new Object();
private static int numOfEventsQueued = 0;
@@ -192,44 +211,17 @@ public class SegmentRoutingManager implements SegmentRoutingService {
.withTimestampProvider((k, v) -> new WallClockTimestamp())
.build();
- networkConfigService.init();
- deviceConfiguration = new DeviceConfiguration(networkConfigService);
- arpHandler = new ArpHandler(this);
- icmpHandler = new IcmpHandler(this);
- ipHandler = new IpHandler(this);
- routingRulePopulator = new RoutingRulePopulator(this);
- defaultRoutingHandler = new DefaultRoutingHandler(this);
- tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
- groupHandlerMap, tunnelStore);
- policyHandler = new PolicyHandler(appId, deviceConfiguration,
- flowObjectiveService, tunnelHandler, policyStore);
-
- packetService.addProcessor(processor, PacketProcessor.director(2));
- linkService.addListener(new InternalLinkListener());
- deviceService.addListener(new InternalDeviceListener());
-
- for (Device device : deviceService.getDevices()) {
- //Irrespective whether the local is a MASTER or not for this device,
- //create group handler instance and push default TTP flow rules.
- //Because in a multi-instance setup, instances can initiate
- //groups for any devices. Also the default TTP rules are needed
- //to be pushed before inserting any IP table entries for any device
- DefaultGroupHandler groupHandler = DefaultGroupHandler
- .createGroupHandler(device.id(), appId,
- deviceConfiguration, linkService,
- flowObjectiveService,
- nsNextObjStore);
- groupHandlerMap.put(device.id(), groupHandler);
- defaultRoutingHandler.populateTtpRules(device.id());
- }
+ cfgService.addListener(cfgListener);
+ cfgService.registerConfigFactory(cfgFactory);
- defaultRoutingHandler.startPopulationProcess();
log.info("Started");
-
}
@Deactivate
protected void deactivate() {
+ cfgService.removeListener(cfgListener);
+ cfgService.unregisterConfigFactory(cfgFactory);
+
packetService.removeProcessor(processor);
processor = null;
log.info("Stopped");
@@ -512,6 +504,59 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
}
+ private class InternalConfigListener implements NetworkConfigListener {
+ SegmentRoutingManager segmentRoutingManager;
+
+ public InternalConfigListener(SegmentRoutingManager srMgr) {
+ this.segmentRoutingManager = srMgr;
+ }
+ public void configureNetwork() {
+ deviceConfiguration = new DeviceConfiguration(segmentRoutingManager.cfgService);
+
+ arpHandler = new ArpHandler(segmentRoutingManager);
+ icmpHandler = new IcmpHandler(segmentRoutingManager);
+ ipHandler = new IpHandler(segmentRoutingManager);
+ routingRulePopulator = new RoutingRulePopulator(segmentRoutingManager);
+ defaultRoutingHandler = new DefaultRoutingHandler(segmentRoutingManager);
+
+ tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
+ groupHandlerMap, tunnelStore);
+ policyHandler = new PolicyHandler(appId, deviceConfiguration,
+ flowObjectiveService,
+ tunnelHandler, policyStore);
+
+ packetService.addProcessor(processor, PacketProcessor.director(2));
+ linkService.addListener(new InternalLinkListener());
+ deviceService.addListener(new InternalDeviceListener());
+
+ for (Device device : deviceService.getDevices()) {
+ //Irrespective whether the local is a MASTER or not for this device,
+ //create group handler instance and push default TTP flow rules.
+ //Because in a multi-instance setup, instances can initiate
+ //groups for any devices. Also the default TTP rules are needed
+ //to be pushed before inserting any IP table entries for any device
+ DefaultGroupHandler groupHandler = DefaultGroupHandler
+ .createGroupHandler(device.id(), appId,
+ deviceConfiguration, linkService,
+ flowObjectiveService,
+ nsNextObjStore);
+ groupHandlerMap.put(device.id(), groupHandler);
+ defaultRoutingHandler.populateTtpRules(device.id());
+ }
+ defaultRoutingHandler.startPopulationProcess();
+ }
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
+ event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
+ event.configClass().equals(SegmentRoutingConfig.class)) {
+ log.info("Network configuration change detected. (Re)Configuring...");
+ configureNetwork();
+ return;
+ }
+ }
+ }
}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingConfig.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingConfig.java
new file mode 100644
index 00000000..6dc3f0db
--- /dev/null
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingConfig.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2014-2015 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.segmentrouting.config;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.basics.BasicElementConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Configuration object for Segment Routing Application.
+ */
+public class SegmentRoutingConfig extends Config<DeviceId> {
+ private static final String NAME = "name";
+ private static final String IP = "routerIp";
+ private static final String MAC = "routerMac";
+ private static final String SID = "nodeSid";
+ private static final String EDGE = "isEdgeRouter";
+ private static final String ADJSID = "adjacencySids";
+
+ public Optional<String> getName() {
+ String name = get(NAME, null);
+ return name != null ? Optional.of(name) : Optional.empty();
+ }
+
+ public BasicElementConfig setName(String name) {
+ return (BasicElementConfig) setOrClear(NAME, name);
+ }
+
+ public Ip4Address getIp() {
+ String ip = get(IP, null);
+ return ip != null ? Ip4Address.valueOf(ip) : null;
+ }
+
+ public BasicElementConfig setIp(String ip) {
+ return (BasicElementConfig) setOrClear(IP, ip);
+ }
+
+ public MacAddress getMac() {
+ String mac = get(MAC, null);
+ return mac != null ? MacAddress.valueOf(mac) : null;
+ }
+
+ public BasicElementConfig setMac(String mac) {
+ return (BasicElementConfig) setOrClear(MAC, mac);
+ }
+
+ public int getSid() {
+ return get(SID, -1);
+ }
+
+ public BasicElementConfig setSid(int sid) {
+ return (BasicElementConfig) setOrClear(SID, sid);
+ }
+
+ public boolean isEdgeRouter() {
+ return get(EDGE, false);
+ }
+
+ public BasicElementConfig setEdgeRouter(boolean isEdgeRouter) {
+ return (BasicElementConfig) setOrClear(EDGE, isEdgeRouter);
+ }
+
+ public List<AdjacencySid> getAdjacencySids() {
+ ArrayList<AdjacencySid> adjacencySids = new ArrayList<>();
+
+ if (!object.has(ADJSID)) {
+ return adjacencySids;
+ }
+
+ ArrayNode adjacencySidNodes = (ArrayNode) object.path(ADJSID);
+ adjacencySidNodes.forEach(adjacencySidNode -> {
+ int asid = adjacencySidNode.path(AdjacencySid.ASID).asInt();
+
+ ArrayList<Integer> ports = new ArrayList<Integer>();
+ ArrayNode portsNodes = (ArrayNode) adjacencySidNode.path(AdjacencySid.PORTS);
+ portsNodes.forEach(portNode -> {
+ ports.add(portNode.asInt());
+ });
+
+ AdjacencySid adjacencySid = new AdjacencySid(asid, ports);
+ adjacencySids.add(adjacencySid);
+ });
+
+ return adjacencySids;
+ }
+
+ public class AdjacencySid {
+ private static final String ASID = "adjSid";
+ private static final String PORTS = "ports";
+
+ int asid;
+ List<Integer> ports;
+
+ public AdjacencySid(int asid, List<Integer> ports) {
+ this.asid = asid;
+ this.ports = ports;
+ }
+
+ public int getAsid() {
+ return asid;
+ }
+
+ public List<Integer> getPorts() {
+ return ports;
+ }
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/package-info.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/package-info.java
index fdae9c9e..95f7e244 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/package-info.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 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.
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java
index 816ca7bc..497f5256 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 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.