aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/segmentrouting
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-10-19 10:14:31 -0700
committerAshlee Young <ashlee@onosfw.com>2015-10-19 10:14:31 -0700
commite9bb60be43af477f17b30ee1f2ba205565b7fa15 (patch)
tree981fd759a44b751fc45cde774f46fda37c11c257 /framework/src/onos/apps/segmentrouting
parent74f3941756a1386cbc1fa99ee73fdc8376a0b6a0 (diff)
Updated onos src tree to commit id 1e60f97ae50c05b94fcb6a10520738bfb5efdfd1
Diffstat (limited to 'framework/src/onos/apps/segmentrouting')
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java19
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java22
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigHandler.java157
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java56
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfig.java351
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigException.java215
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigManager.java338
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigService.java271
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/PktLinkConfig.java159
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRouterConfig.java445
10 files changed, 54 insertions, 1979 deletions
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
index 6ca6d193..f42f84b1 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
@@ -88,7 +88,6 @@ public class ArpHandler {
}
private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) {
-
ARP arpRequest = (ARP) payload.getPayload();
HostId targetHostId = HostId.hostId(MacAddress.valueOf(
arpRequest.getTargetHardwareAddress()));
@@ -98,14 +97,16 @@ public class ArpHandler {
Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress());
sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress));
- // ARP request for known hosts
- } else if (srManager.hostService.getHost(targetHostId) != null) {
- MacAddress targetMac = srManager.hostService.getHost(targetHostId).mac();
- sendArpResponse(arpRequest, targetMac);
-
- // ARP request for unknown host in the subnet
- } else if (isArpReqForSubnet(deviceId, arpRequest)) {
- flood(payload, inPort);
+ } else {
+ Host targetHost = srManager.hostService.getHost(targetHostId);
+ // ARP request for known hosts
+ if (targetHost != null) {
+ sendArpResponse(arpRequest, targetHost.mac());
+
+ // ARP request for unknown host in the subnet
+ } else if (isArpReqForSubnet(deviceId, arpRequest)) {
+ flood(payload, inPort);
+ }
}
}
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 8fdf81a2..eef1b147 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
@@ -62,11 +62,18 @@ public class DeviceConfiguration implements DeviceProperties {
HashMap<PortNumber, Ip4Address> gatewayIps;
HashMap<PortNumber, Ip4Prefix> subnets;
List<AdjacencySid> adjacencySids;
+
+ public SegmentRouterInfo() {
+ this.gatewayIps = new HashMap<>();
+ this.subnets = new HashMap<>();
+ }
}
/**
* Constructor. Reads all the configuration for all devices of type
* Segment Router and organizes into various maps for easier access.
+ *
+ * @param cfgService config service
*/
public DeviceConfiguration(NetworkConfigRegistry cfgService) {
// Read config from device subject, excluding gatewayIps and subnets.
@@ -82,8 +89,6 @@ public class DeviceConfiguration implements DeviceProperties {
info.mac = config.getMac();
info.isEdge = config.isEdgeRouter();
info.adjacencySids = config.getAdjacencySids();
- info.gatewayIps = new HashMap<>();
- info.subnets = new HashMap<>();
this.deviceConfigMap.put(info.deviceId, info);
this.allSegmentIds.add(info.nodeSid);
@@ -107,11 +112,14 @@ public class DeviceConfiguration implements DeviceProperties {
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());
- });
+ // skip if there is no corresponding device for this ConenctPoint
+ if (info != null) {
+ Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses();
+ interfaceAddresses.forEach(interfaceAddress -> {
+ info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address());
+ info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix());
+ });
+ }
});
});
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigHandler.java
deleted file mode 100644
index d3468178..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigHandler.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 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;
-
-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.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * This class is temporary class and used only for test.
- * It will be replaced with "real" Network Config Manager.
- *
- * TODO: Knock off this wrapper and directly use DeviceConfiguration class
- */
-
-public class NetworkConfigHandler {
-
- private static Logger log = LoggerFactory.getLogger(NetworkConfigHandler.class);
- private SegmentRoutingManager srManager;
- private DeviceConfiguration deviceConfig;
-
- public NetworkConfigHandler(SegmentRoutingManager srManager,
- DeviceConfiguration deviceConfig) {
- this.srManager = srManager;
- this.deviceConfig = deviceConfig;
- }
-
- public List<Ip4Address> getGatewayIpAddress(DeviceId deviceId) {
- return this.deviceConfig.getSubnetGatewayIps(deviceId);
- }
-
- public IpPrefix getRouterIpAddress(DeviceId deviceId) {
- return IpPrefix.valueOf(deviceConfig.getRouterIp(deviceId), 32);
- }
-
- public MacAddress getRouterMacAddress(DeviceId deviceId) {
- return deviceConfig.getDeviceMac(deviceId);
- }
-
- public boolean inSameSubnet(DeviceId deviceId, Ip4Address destIp) {
-
- List<Ip4Prefix> subnets = getSubnetInfo(deviceId);
- if (subnets == null) {
- return false;
- }
-
- return subnets.stream()
- .anyMatch((subnet) -> subnet.contains(destIp));
- }
-
- public boolean inSameSubnet(Ip4Address address, int sid) {
- DeviceId deviceId = deviceConfig.getDeviceId(sid);
- if (deviceId == null) {
- log.warn("Cannot find a device for SID {}", sid);
- return false;
- }
-
- return inSameSubnet(deviceId, address);
- }
-
- public List<Ip4Prefix> getSubnetInfo(DeviceId deviceId) {
- return deviceConfig.getSubnets(deviceId);
- }
-
- public int getMplsId(DeviceId deviceId) {
- return deviceConfig.getSegmentId(deviceId);
- }
-
- public int getMplsId(MacAddress routerMac) {
- return deviceConfig.getSegmentId(routerMac);
- }
-
- public int getMplsId(Ip4Address routerIpAddress) {
- return deviceConfig.getSegmentId(routerIpAddress);
- }
-
- public boolean isEcmpNotSupportedInTransit(DeviceId deviceId) {
- //TODO: temporarily changing to true to test with Dell
- return true;
- }
-
- public boolean isTransitRouter(DeviceId deviceId) {
- return !(deviceConfig.isEdgeDevice(deviceId));
- }
-
-
- public boolean isEdgeRouter(DeviceId deviceId) {
- return deviceConfig.isEdgeDevice(deviceId);
- }
-
- private List<PortNumber> getPortsToNeighbors(DeviceId deviceId, List<DeviceId> fwdSws) {
-
- List<PortNumber> portNumbers = Lists.newArrayList();
-
- Set<Link> links = srManager.linkService.getDeviceEgressLinks(deviceId);
- for (Link link: links) {
- for (DeviceId swId: fwdSws) {
- if (link.dst().deviceId().equals(swId)) {
- portNumbers.add(link.src().port());
- break;
- }
- }
- }
-
- return portNumbers;
- }
-
- public List<PortNumber> getPortsToDevice(DeviceId deviceId) {
- List<PortNumber> portNumbers = Lists.newArrayList();
-
- Set<Link> links = srManager.linkService.getDeviceEgressLinks(deviceId);
- for (Link link: links) {
- if (link.dst().deviceId().equals(deviceId)) {
- portNumbers.add(link.src().port());
- }
- }
-
- return portNumbers;
- }
-
-
- public Ip4Address getDestinationRouterAddress(Ip4Address destIpAddress) {
- return deviceConfig.getRouterIpAddressForASubnetHost(destIpAddress);
- }
-
- public DeviceId getDeviceId(Ip4Address ip4Address) {
- return deviceConfig.getDeviceId(ip4Address);
- }
-
- public MacAddress getRouterMac(Ip4Address targetAddress) {
- return deviceConfig.getRouterMacForAGatewayIp(targetAddress);
- }
-}
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 05663129..9011160c 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
@@ -116,11 +116,12 @@ public class SegmentRoutingManager implements SegmentRoutingService {
protected ApplicationId appId;
protected DeviceConfiguration deviceConfiguration = null;
-
private DefaultRoutingHandler defaultRoutingHandler = null;
private TunnelHandler tunnelHandler = null;
private PolicyHandler policyHandler = null;
- private InternalPacketProcessor processor = new InternalPacketProcessor();
+ private InternalPacketProcessor processor = null;
+ private InternalLinkListener linkListener = null;
+ private InternalDeviceListener deviceListener = null;
private InternalEventHandler eventHandler = new InternalEventHandler();
private ScheduledExecutorService executorService = Executors
@@ -214,6 +215,16 @@ public class SegmentRoutingManager implements SegmentRoutingService {
cfgService.addListener(cfgListener);
cfgService.registerConfigFactory(cfgFactory);
+ processor = new InternalPacketProcessor();
+ linkListener = new InternalLinkListener();
+ deviceListener = new InternalDeviceListener();
+
+ packetService.addProcessor(processor, PacketProcessor.director(2));
+ linkService.addListener(linkListener);
+ deviceService.addListener(deviceListener);
+
+ cfgListener.configureNetwork();
+
log.info("Started");
}
@@ -223,7 +234,14 @@ public class SegmentRoutingManager implements SegmentRoutingService {
cfgService.unregisterConfigFactory(cfgFactory);
packetService.removeProcessor(processor);
+ linkService.removeListener(linkListener);
+ deviceService.removeListener(deviceListener);
processor = null;
+ linkListener = null;
+ deviceService = null;
+
+ groupHandlerMap.clear();
+
log.info("Stopped");
}
@@ -284,7 +302,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
* @return GroupKey object for the NeighborSet
*/
public GroupKey getGroupKey(NeighborSet ns) {
-
for (DefaultGroupHandler groupHandler : groupHandlerMap.values()) {
return groupHandler.getGroupKey(ns);
}
@@ -301,7 +318,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
* @return next objective ID
*/
public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) {
-
if (groupHandlerMap.get(deviceId) != null) {
log.trace("getNextObjectiveId query in device {}", deviceId);
return groupHandlerMap
@@ -313,7 +329,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
private class InternalPacketProcessor implements PacketProcessor {
-
@Override
public void process(PacketContext context) {
@@ -350,16 +365,8 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
private class InternalDeviceListener implements DeviceListener {
-
@Override
public void event(DeviceEvent event) {
- /*if (mastershipService.getLocalRole(event.subject().id()) != MastershipRole.MASTER) {
- log.debug("Local role {} is not MASTER for device {}",
- mastershipService.getLocalRole(event.subject().id()),
- event.subject().id());
- return;
- }*/
-
switch (event.type()) {
case DEVICE_ADDED:
case PORT_REMOVED:
@@ -374,7 +381,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
private void scheduleEventHandlerIfNotScheduled(Event event) {
-
synchronized (threadSchedulerLock) {
eventQueue.add(event);
numOfEventsQueued++;
@@ -392,7 +398,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
private class InternalEventHandler implements Runnable {
-
@Override
public void run() {
try {
@@ -413,8 +418,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
processLinkAdded((Link) event.subject());
} else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
processLinkRemoved((Link) event.subject());
- //} else if (event.type() == GroupEvent.Type.GROUP_ADDED) {
- // processGroupAdded((Group) event.subject());
} else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
@@ -526,10 +529,6 @@ public class SegmentRoutingManager implements SegmentRoutingService {
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.
@@ -550,12 +549,15 @@ public class SegmentRoutingManager implements SegmentRoutingService {
@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;
+ if (event.configClass().equals(SegmentRoutingConfig.class)) {
+ if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
+ log.info("Network configuration added.");
+ configureNetwork();
+ }
+ if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) {
+ log.info("Network configuration updated.");
+ // TODO support dynamic configuration
+ }
}
}
}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfig.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfig.java
deleted file mode 100644
index 0c7749e6..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfig.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * Copyright 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 java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.onosproject.net.DeviceId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.JsonNode;
-
-/**
- * Public class corresponding to JSON described data model. Defines the network
- * configuration at startup.
- */
-public class NetworkConfig {
- protected static final Logger log = LoggerFactory.getLogger(NetworkConfig.class);
-
- @SuppressWarnings("unused")
- private String comment;
-
- private Boolean restrictSwitches;
- private Boolean restrictLinks;
- private List<SwitchConfig> switches;
- private List<LinkConfig> links;
-
- /**
- * Default constructor.
- */
- public NetworkConfig() {
- switches = new ArrayList<>();
- links = new ArrayList<>();
- }
-
- @JsonProperty("comment")
- public void setComment(String c) {
- log.trace("NetworkConfig: comment={}", c);
- comment = c;
- }
-
- @JsonProperty("restrictSwitches")
- public void setRestrictSwitches(boolean rs) {
- log.trace("NetworkConfig: restrictSwitches={}", rs);
- restrictSwitches = rs;
- }
-
- /**
- * Returns default restrict configuration for switches.
- *
- * @return boolean
- */
- public Boolean getRestrictSwitches() {
- return restrictSwitches;
- }
-
- @JsonProperty("restrictLinks")
- public void setRestrictLinks(boolean rl) {
- log.trace("NetworkConfig: restrictLinks={}", rl);
- restrictLinks = rl;
- }
-
- /**
- * Returns default restrict configuration for links.
- *
- * @return boolean
- */
- public Boolean getRestrictLinks() {
- return restrictLinks;
- }
-
- /**
- * Returns configuration for switches.
- *
- * @return list of switch configuration
- */
- public List<SwitchConfig> getSwitchConfig() {
- return switches;
- }
-
- @JsonProperty("switchConfig")
- public void setSwitchConfig(List<SwitchConfig> switches2) {
- log.trace("NetworkConfig: switchConfig={}", switches2);
- this.switches = switches2;
- }
-
- /**
- * Java class corresponding to JSON described switch
- * configuration data model.
- */
- public static class SwitchConfig {
- protected String nodeDpid;
- protected String name;
- protected String type;
- protected boolean allowed;
- protected double latitude;
- protected double longitude;
- protected Map<String, JsonNode> params;
- protected Map<String, String> publishAttributes;
- protected DeviceId dpid;
-
- /**
- * Returns the configured "name" of a switch.
- *
- * @return string
- */
- public String getName() {
- return name;
- }
-
- @JsonProperty("name")
- public void setName(String name) {
- log.trace("SwitchConfig: name={}", name);
- this.name = name;
- }
-
- /**
- * Returns the data plane identifier of a switch.
- *
- * @return ONOS device identifier
- */
- public DeviceId getDpid() {
- return dpid;
- }
-
- public void setDpid(DeviceId dpid) {
- this.dpid = dpid;
- this.nodeDpid = dpid.toString();
- }
-
- /**
- * Returns the data plane identifier of a switch.
- *
- * @return string
- */
- public String getNodeDpid() {
- return nodeDpid;
- }
-
- // mapper sets both DeviceId and string fields for dpid
- @JsonProperty("nodeDpid")
- public void setNodeDpid(String nodeDpid) {
- log.trace("SwitchConfig: nodeDpid={}", nodeDpid);
- this.nodeDpid = nodeDpid;
- this.dpid = DeviceId.deviceId(nodeDpid);
- }
-
- /**
- * Returns the type of a switch.
- *
- * @return string
- */
- public String getType() {
- return type;
- }
-
- @JsonProperty("type")
- public void setType(String type) {
- log.trace("SwitchConfig: type={}", type);
- this.type = type;
- }
-
- /**
- * Returns the latitude of a switch.
- *
- * @return double
- */
- public double getLatitude() {
- return latitude;
- }
-
- @JsonProperty("latitude")
- public void setLatitude(double latitude) {
- log.trace("SwitchConfig: latitude={}", latitude);
- this.latitude = latitude;
- }
-
- /**
- * Returns the longitude of a switch.
- *
- * @return double
- */
- public double getLongitude() {
- return longitude;
- }
-
- @JsonProperty("longitude")
- public void setLongitude(double longitude) {
- log.trace("SwitchConfig: longitude={}", longitude);
- this.longitude = longitude;
- }
-
- /**
- * Returns the allowed flag for a switch.
- *
- * @return boolean
- */
- public boolean isAllowed() {
- return allowed;
- }
-
- @JsonProperty("allowed")
- public void setAllowed(boolean allowed) {
- this.allowed = allowed;
- }
-
- /**
- * Returns the additional configured parameters of a switch.
- *
- * @return key value map
- */
- public Map<String, JsonNode> getParams() {
- return params;
- }
-
- @JsonProperty("params")
- public void setParams(Map<String, JsonNode> params) {
- this.params = params;
- }
-
- /**
- * Reserved for future use.
- *
- * @return key value map
- */
- public Map<String, String> getPublishAttributes() {
- return publishAttributes;
- }
-
- @JsonProperty("publishAttributes")
- public void setPublishAttributes(Map<String, String> publishAttributes) {
- this.publishAttributes = publishAttributes;
- }
-
- }
-
- @JsonProperty("linkConfig")
- public void setLinkConfig(List<LinkConfig> links2) {
- this.links = links2;
- }
-
- /**
- * Reserved for future use.
- *
- * @return list of configured link configuration
- */
- public List<LinkConfig> getLinkConfig() {
- return links;
- }
-
- /**
- * Reserved for future use.
- */
- public static class LinkConfig {
- protected String type;
- protected Boolean allowed;
- protected DeviceId dpid1;
- protected DeviceId dpid2;
- protected String nodeDpid1;
- protected String nodeDpid2;
- protected Map<String, JsonNode> params;
- protected Map<String, String> publishAttributes;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public Boolean isAllowed() {
- return allowed;
- }
-
- public void setAllowed(Boolean allowed) {
- this.allowed = allowed;
- }
-
- public String getNodeDpid1() {
- return nodeDpid1;
- }
-
- // mapper sets both long and string fields for dpid
- public void setNodeDpid1(String nodeDpid1) {
- this.nodeDpid1 = nodeDpid1;
- this.dpid1 = DeviceId.deviceId(nodeDpid1);
- }
-
- public String getNodeDpid2() {
- return nodeDpid2;
- }
-
- // mapper sets both long and string fields for dpid
- public void setNodeDpid2(String nodeDpid2) {
- this.nodeDpid2 = nodeDpid2;
- this.dpid2 = DeviceId.deviceId(nodeDpid2);
- }
-
- public DeviceId getDpid1() {
- return dpid1;
- }
-
- public void setDpid1(DeviceId dpid1) {
- this.dpid1 = dpid1;
- this.nodeDpid1 = dpid1.toString();
- }
-
- public DeviceId getDpid2() {
- return dpid2;
- }
-
- public void setDpid2(DeviceId dpid2) {
- this.dpid2 = dpid2;
- this.nodeDpid2 = dpid2.toString();
- }
-
- public Map<String, JsonNode> getParams() {
- return params;
- }
-
- public void setParams(Map<String, JsonNode> params) {
- this.params = params;
- }
-
- public Map<String, String> getPublishAttributes() {
- return publishAttributes;
- }
-
- public void setPublishAttributes(Map<String, String> publishAttributes) {
- this.publishAttributes = publishAttributes;
- }
- }
-}
-
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigException.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigException.java
deleted file mode 100644
index 0c0dac86..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigException.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright 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 org.onosproject.net.DeviceId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * NetworkConfigExceptions specifies a set of unchecked runtime exceptions that
- * can be thrown by the {@link NetworkConfigManager}. It indicates errors that
- * must be fixed in the config file before controller execution can proceed.
- */
-public class NetworkConfigException extends RuntimeException {
-
- private static final long serialVersionUID = 4959684709803000652L;
- protected static final Logger log = LoggerFactory
- .getLogger(NetworkConfigException.class);
-
- /**
- * Exception for duplicate device identifier configuration.
- */
- public static class DuplicateDpid extends RuntimeException {
- private static final long serialVersionUID = 5491113234592145335L;
-
- public DuplicateDpid(DeviceId dpid) {
- super();
- log.error("Duplicate dpid found in switch-config Dpid:{}",
- dpid);
- }
- }
-
- /**
- * Exception for duplicate device name configuration.
- */
- public static class DuplicateName extends RuntimeException {
- private static final long serialVersionUID = -4090171438031376129L;
-
- public DuplicateName(String name) {
- super();
- log.error("Duplicate name found in switch-config name:{}", name);
- }
- }
-
- /**
- * Exception for unspecified device identifier for a switch.
- */
- public static class DpidNotSpecified extends RuntimeException {
- private static final long serialVersionUID = -8494418855597117254L;
-
- public DpidNotSpecified(String name) {
- super();
- log.error("Dpid not specified for switch-config name:{}", name);
- }
- }
-
- /**
- * Exception for unspecified device name for a switch.
- */
- public static class NameNotSpecified extends RuntimeException {
- private static final long serialVersionUID = -3518881744110422891L;
-
- public NameNotSpecified(DeviceId dpid) {
- super();
- log.error("Name not specified for switch-config dpid:{}",
- dpid);
- }
- }
-
- /**
- * Exception for unspecified device type for a switch.
- */
- public static class SwitchTypeNotSpecified extends RuntimeException {
- private static final long serialVersionUID = 2527453336226053753L;
-
- public SwitchTypeNotSpecified(DeviceId dpid) {
- super();
- log.error("Switch type not specified for switch-config dpid:{}",
- dpid);
- }
- }
-
- /**
- * Exception for unknown device type configured for a switch.
- */
- public static class UnknownSwitchType extends RuntimeException {
- private static final long serialVersionUID = 7758418165512249170L;
-
- public UnknownSwitchType(String type, String name) {
- super();
- log.error("Unknown switch type {} for switch name:{}", type, name);
- }
- }
-
- /**
- * Exception for missing required parameter configuration for a switch.
- */
- public static class ParamsNotSpecified extends RuntimeException {
- private static final long serialVersionUID = 6247582323691265513L;
-
- public ParamsNotSpecified(String name) {
- super();
- log.error("Params required - not specified for switch:{}", name);
- }
- }
-
- /**
- * Reserved for future use.
- */
- public static class LinkTypeNotSpecified extends RuntimeException {
- private static final long serialVersionUID = -2089470389588542215L;
-
- public LinkTypeNotSpecified(String dpid1, String dpid2) {
- super();
- log.error("Link type not specified for link-config between "
- + "dpid1:{} and dpid2:{}", dpid1, dpid2);
- }
- }
-
- /**
- * Reserved for future use.
- */
- public static class LinkDpidNotSpecified extends RuntimeException {
- private static final long serialVersionUID = -5701825916378616004L;
-
- public LinkDpidNotSpecified(String dpid1, String dpid2) {
- super();
- if (dpid1 == null) {
- log.error("nodeDpid1 not specified for link-config ");
- }
- if (dpid2 == null) {
- log.error("nodeDpid2 not specified for link-config ");
- }
- }
- }
-
- /**
- * Reserved for future use.
- */
- public static class LinkForUnknownSwitchConfig extends RuntimeException {
- private static final long serialVersionUID = -2910458439881964094L;
-
- public LinkForUnknownSwitchConfig(String dpid) {
- super();
- log.error("Link configuration was specified for a switch-dpid {} "
- + "that has not been configured", dpid);
- }
- }
-
- /**
- * Reserved for future use.
- */
- public static class UnknownLinkType extends RuntimeException {
- private static final long serialVersionUID = -5505376193106542305L;
-
- public UnknownLinkType(String linktype, String dpid1, String dpid2) {
- super();
- log.error("unknown link type {} for links between dpid1:{} "
- + "and dpid2:{}", linktype, dpid1, dpid2);
- }
- }
-
- /**
- * Exception for generic configuration errors.
- */
- public static class ErrorConfig extends RuntimeException {
- private static final long serialVersionUID = -2827406314700193147L;
-
- public ErrorConfig(String errorMsg) {
- super();
- log.error(errorMsg);
- }
-
- }
-
- /**
- * Reserved for future use.
- */
- public static class SwitchDpidNotConverted extends RuntimeException {
- private static final long serialVersionUID = 5640347104590170426L;
-
- public SwitchDpidNotConverted(String name) {
- super();
- log.error("Switch dpid specified as a HexString {} does not match "
- + "with long value", name);
- }
- }
-
- /**
- * Reserved for future use.
- */
- public static class LinkDpidNotConverted extends RuntimeException {
- private static final long serialVersionUID = 2397245646094080774L;
-
- public LinkDpidNotConverted(String dpid1, String dpid2) {
- log.error("Dpids expressed as HexStrings for links between dpid1:{} "
- + "and dpid2:{} do not match with long values", dpid1, dpid2);
- }
- }
-
-}
-
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigManager.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigManager.java
deleted file mode 100644
index f034f372..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigManager.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * Copyright 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 java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig;
-import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * NetworkConfigManager manages all network configuration for switches, links
- * and any other state that needs to be configured for correct network
- * operation.
- *
- */
-public class NetworkConfigManager implements NetworkConfigService {
- protected static final Logger log = LoggerFactory
- .getLogger(NetworkConfigManager.class);
- private static final String CONFIG_DIR = "../config";
- private static final String DEFAULT_CONFIG_FILE = "segmentrouting.conf";
- private final String configFileName = DEFAULT_CONFIG_FILE;
- /**
- * JSON Config file needs to use one of the following types for defining the
- * kind of switch or link it wishes to configure.
- */
- public static final String SEGMENT_ROUTER = "Router_SR";
-
- public static final String PKT_LINK = "pktLink";
-
- NetworkConfig networkConfig;
- private ConcurrentMap<DeviceId, SwitchConfig> configuredSwitches;
- private ConcurrentMap<Link, LinkConfig> configuredLinks;
- private Map<String, DeviceId> nameToDpid;
-
- @Override
- public SwitchConfigStatus checkSwitchConfig(DeviceId dpid) {
- SwitchConfig swc = configuredSwitches.get(dpid);
- if (networkConfig.getRestrictSwitches()) {
- // default deny behavior
- if (swc == null) {
- // switch is not configured - we deny this switch
- return new SwitchConfigStatus(NetworkConfigState.DENY, null,
- "Switch not configured, in network denying switches by default.");
- }
- if (swc.isAllowed()) {
- // switch is allowed in config, return configured attributes
- return new SwitchConfigStatus(NetworkConfigState.ACCEPT_ADD, swc);
- } else {
- // switch has been configured off (administratively down)
- return new SwitchConfigStatus(NetworkConfigState.DENY, null,
- "Switch configured down (allowed=false).");
- }
- } else {
- // default allow behavior
- if (swc == null) {
- // no config to add
- return new SwitchConfigStatus(NetworkConfigState.ACCEPT, null);
- }
- if (swc.isAllowed()) {
- // switch is allowed in config, return configured attributes
- return new SwitchConfigStatus(NetworkConfigState.ACCEPT_ADD, swc);
- } else {
- // switch has been configured off (administratively down)
- return new SwitchConfigStatus(NetworkConfigState.DENY, null,
- "Switch configured down (allowed=false).");
- }
- }
-
- }
-
- @Override
- public LinkConfigStatus checkLinkConfig(Link linkTuple) {
- LinkConfig lkc = getConfiguredLink(linkTuple);
- // links are always disallowed if any one of the nodes that make up the
- // link are disallowed
- DeviceId linkNode1 = linkTuple.src().deviceId();
- SwitchConfigStatus scs1 = checkSwitchConfig(linkNode1);
- if (scs1.getConfigState() == NetworkConfigState.DENY) {
- return new LinkConfigStatus(NetworkConfigState.DENY, null,
- "Link-node: " + linkNode1 + " denied by config: " + scs1.getMsg());
- }
- DeviceId linkNode2 = linkTuple.dst().deviceId();
- SwitchConfigStatus scs2 = checkSwitchConfig(linkNode2);
- if (scs2.getConfigState() == NetworkConfigState.DENY) {
- return new LinkConfigStatus(NetworkConfigState.DENY, null,
- "Link-node: " + linkNode2 + " denied by config: " + scs2.getMsg());
- }
- if (networkConfig.getRestrictLinks()) {
- // default deny behavior
- if (lkc == null) {
- // link is not configured - we deny this link
- return new LinkConfigStatus(NetworkConfigState.DENY, null,
- "Link not configured, in network denying links by default.");
- }
- if (lkc.isAllowed()) {
- // link is allowed in config, return configured attributes
- return new LinkConfigStatus(NetworkConfigState.ACCEPT_ADD, lkc);
- } else {
- // link has been configured off (administratively down)
- return new LinkConfigStatus(NetworkConfigState.DENY, null,
- "Link configured down (allowed=false).");
- }
- } else {
- // default allow behavior
- if (lkc == null) {
- // no config to add
- return new LinkConfigStatus(NetworkConfigState.ACCEPT, null);
- }
- if (lkc.isAllowed()) {
- // link is allowed in config, return configured attributes
- return new LinkConfigStatus(NetworkConfigState.ACCEPT_ADD, lkc);
- } else {
- // link has been configured off (administratively down)
- return new LinkConfigStatus(NetworkConfigState.DENY, null,
- "Link configured down (allowed=false).");
- }
- }
-
- }
-
- @Override
- public List<SwitchConfig> getConfiguredAllowedSwitches() {
- List<SwitchConfig> allowed = new ArrayList<>();
- for (SwitchConfig swc : configuredSwitches.values()) {
- if (swc.isAllowed()) {
- allowed.add(swc);
- }
- }
- return allowed;
- }
-
- @Override
- public List<LinkConfig> getConfiguredAllowedLinks() {
- List<LinkConfig> allowed = new ArrayList<>();
- for (LinkConfig lkc : configuredLinks.values()) {
- if (lkc.isAllowed()) {
- allowed.add(lkc);
- }
- }
- return allowed;
- }
-
- @Override
- public DeviceId getDpidForName(String name) {
- if (nameToDpid.get(name) != null) {
- return nameToDpid.get(name);
- }
- return null;
- }
-
- // **************
- // Private methods
- // **************
-
- private void loadNetworkConfig() {
- File configFile = new File(CONFIG_DIR, configFileName);
- ObjectMapper mapper = new ObjectMapper();
- networkConfig = new NetworkConfig();
-
- try {
- networkConfig = mapper.readValue(configFile,
- NetworkConfig.class);
- } catch (JsonParseException e) {
- String err = String.format("JsonParseException while loading network "
- + "config from file: %s: %s", configFileName,
- e.getMessage());
- throw new NetworkConfigException.ErrorConfig(err);
- } catch (JsonMappingException e) {
- String err = String.format(
- "JsonMappingException while loading network config "
- + "from file: %s: %s",
- configFileName,
- e.getMessage());
- throw new NetworkConfigException.ErrorConfig(err);
- } catch (IOException e) {
- String err = String.format("IOException while loading network config "
- + "from file: %s %s", configFileName, e.getMessage());
- throw new NetworkConfigException.ErrorConfig(err);
- }
-
- log.info("Network config specifies: {} switches and {} links",
- (networkConfig.getRestrictSwitches())
- ? networkConfig.getSwitchConfig().size() : "default allow",
- (networkConfig.getRestrictLinks())
- ? networkConfig.getLinkConfig().size() : "default allow");
- }
-
- private void parseNetworkConfig() {
- List<SwitchConfig> swConfList = networkConfig.getSwitchConfig();
- List<LinkConfig> lkConfList = networkConfig.getLinkConfig();
- validateSwitchConfig(swConfList);
- createTypeSpecificSwitchConfig(swConfList);
- validateLinkConfig(lkConfList);
- createTypeSpecificLinkConfig(lkConfList);
- // TODO validate reachability matrix 'names' for configured dpids
- }
-
- private void createTypeSpecificSwitchConfig(List<SwitchConfig> swConfList) {
- for (SwitchConfig swc : swConfList) {
- nameToDpid.put(swc.getName(), swc.getDpid());
- String swtype = swc.getType();
- switch (swtype) {
- case SEGMENT_ROUTER:
- SwitchConfig sr = new SegmentRouterConfig(swc);
- configuredSwitches.put(sr.getDpid(), sr);
- break;
- default:
- throw new NetworkConfigException.UnknownSwitchType(swtype,
- swc.getName());
- }
- }
- }
-
- private void createTypeSpecificLinkConfig(List<LinkConfig> lkConfList) {
- for (LinkConfig lkc : lkConfList) {
- String lktype = lkc.getType();
- switch (lktype) {
- case PKT_LINK:
- PktLinkConfig pk = new PktLinkConfig(lkc);
- for (Link lt : pk.getLinkTupleList()) {
- configuredLinks.put(lt, pk);
- }
- break;
- default:
- throw new NetworkConfigException.UnknownLinkType(lktype,
- lkc.getNodeDpid1(), lkc.getNodeDpid2());
- }
- }
- }
-
- private void validateSwitchConfig(List<SwitchConfig> swConfList) {
- Set<DeviceId> swDpids = new HashSet<>();
- Set<String> swNames = new HashSet<>();
- for (SwitchConfig swc : swConfList) {
- if (swc.getNodeDpid() == null || swc.getDpid() == null) {
- throw new NetworkConfigException.DpidNotSpecified(swc.getName());
- }
- // ensure both String and DeviceId values of dpid are set
- if (!swc.getDpid().equals(DeviceId.deviceId(swc.getNodeDpid()))) {
- throw new NetworkConfigException.SwitchDpidNotConverted(
- swc.getName());
- }
- if (swc.getName() == null) {
- throw new NetworkConfigException.NameNotSpecified(swc.getDpid());
- }
- if (swc.getType() == null) {
- throw new NetworkConfigException.SwitchTypeNotSpecified(
- swc.getDpid());
- }
- if (!swDpids.add(swc.getDpid())) {
- throw new NetworkConfigException.DuplicateDpid(swc.getDpid());
- }
- if (!swNames.add(swc.getName())) {
- throw new NetworkConfigException.DuplicateName(swc.getName());
- }
- // TODO Add more validations
- }
- }
-
- private void validateLinkConfig(List<LinkConfig> lkConfList) {
- for (LinkConfig lkc : lkConfList) {
- if (lkc.getNodeDpid1() == null || lkc.getNodeDpid2() == null) {
- throw new NetworkConfigException.LinkDpidNotSpecified(
- lkc.getNodeDpid1(), lkc.getNodeDpid2());
- }
- // ensure both String and Long values are set
- if (!lkc.getDpid1().equals(DeviceId.deviceId(lkc.getNodeDpid1())) ||
- !lkc.getDpid2().equals(DeviceId.deviceId(lkc.getNodeDpid2()))) {
- throw new NetworkConfigException.LinkDpidNotConverted(
- lkc.getNodeDpid1(), lkc.getNodeDpid2());
- }
- if (lkc.getType() == null) {
- throw new NetworkConfigException.LinkTypeNotSpecified(
- lkc.getNodeDpid1(), lkc.getNodeDpid2());
- }
- if (configuredSwitches.get(lkc.getDpid1()) == null) {
- throw new NetworkConfigException.LinkForUnknownSwitchConfig(
- lkc.getNodeDpid1());
- }
- if (configuredSwitches.get(lkc.getDpid2()) == null) {
- throw new NetworkConfigException.LinkForUnknownSwitchConfig(
- lkc.getNodeDpid2());
- }
- // TODO add more validations
- }
-
- }
-
- private LinkConfig getConfiguredLink(Link linkTuple) {
- LinkConfig lkc = null;
- // first try the unidirectional link with the ports assigned
- lkc = configuredLinks.get(linkTuple);
- return lkc;
- }
-
-
- /**
- * Initializes the network configuration manager module by
- * loading and parsing the network configuration file.
- */
- public void init() {
- loadNetworkConfig();
- configuredSwitches = new ConcurrentHashMap<>();
- configuredLinks = new ConcurrentHashMap<>();
- nameToDpid = new HashMap<>();
- parseNetworkConfig();
- }
-}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigService.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigService.java
deleted file mode 100644
index afbb0fcc..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/NetworkConfigService.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Copyright 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 java.util.List;
-
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig;
-import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig;
-
-/**
- * Exposes methods to retrieve network configuration.
- *
- * TODO: currently only startup-configuration is exposed and such configuration
- * cannot be changed at runtime. Need to add runtime support for changes to
- * configuration (via REST/CLI) in future releases.
- *
- * TODO: return immutable objects or defensive copies of network config so that
- * users of this API do not inadvertently or maliciously change network config.
- *
- * @deprecated in Drake; see org.onosproject.net.config
- */
-@Deprecated
-public interface NetworkConfigService {
-
- /**
- * Suggests the action to be taken by the caller given the configuration
- * associated with the queried network-object (eg. switch, link etc.).
- */
- enum NetworkConfigState {
- /**
- * Associated network object has been configured to not be allowed in
- * the network.
- */
- DENY,
-
- /**
- * Associated network object has been configured to be allowed in the
- * network.
- */
- ACCEPT,
-
- /**
- * Associated network object has been configured to be allowed in the
- * network. In addition, there are configured parameters that should be
- * added to the object.
- */
- ACCEPT_ADD,
- }
-
- /**
- * Returns the configuration outcome (accept, deny etc.), and any configured
- * parameters to the caller, in response to a query for the configuration
- * associated with a switch.
- */
- class SwitchConfigStatus {
- private NetworkConfigState configState;
- private SwitchConfig switchConfig;
- private String msg;
-
- SwitchConfigStatus(NetworkConfigState configState,
- SwitchConfig switchConfig, String msg) {
- this.configState = configState;
- this.switchConfig = switchConfig;
- this.msg = msg;
- }
-
- SwitchConfigStatus(NetworkConfigState configState,
- SwitchConfig switchConfig) {
- this.configState = configState;
- this.switchConfig = switchConfig;
- this.msg = "";
- }
-
- /**
- * Returns the configuration state for the switch.
- *
- * @return non-null NetworkConfigState
- */
- public NetworkConfigState getConfigState() {
- return configState;
- }
-
- /**
- * Returns the switch configuration, which may be null if no
- * configuration exists, or if the configuration state disallows the
- * switch.
- *
- * @return SwitchConfig, the switch configuration, or null
- */
- public SwitchConfig getSwitchConfig() {
- return switchConfig;
- }
-
- /**
- * User readable string typically used to specify the reason why a
- * switch is being disallowed.
- *
- * @return A non-null but possibly empty String
- */
- public String getMsg() {
- return msg;
- }
-
- }
-
- /**
- * Reserved for future use.
- *
- * Returns the configuration outcome (accept, deny etc.), and any configured
- * parameters to the caller, in response to a query for the configuration
- * associated with a link.
- */
- class LinkConfigStatus {
- private NetworkConfigState configState;
- private LinkConfig linkConfig;
- private String msg;
-
- LinkConfigStatus(NetworkConfigState configState,
- LinkConfig linkConfig, String msg) {
- this.configState = configState;
- this.linkConfig = linkConfig;
- this.msg = msg;
- }
-
- LinkConfigStatus(NetworkConfigState configState,
- LinkConfig linkConfig) {
- this.configState = configState;
- this.linkConfig = linkConfig;
- this.msg = "";
- }
-
- /**
- * Returns the configuration state for the link.
- *
- * @return non-null NetworkConfigState
- */
- public NetworkConfigState getConfigState() {
- return configState;
- }
-
- /**
- * Returns the link configuration, which may be null if no configuration
- * exists, or if the configuration state disallows the link.
- *
- * @return SwitchConfig, the switch configuration, or null
- */
- public LinkConfig getLinkConfig() {
- return linkConfig;
- }
-
- /**
- * User readable string typically used to specify the reason why a link
- * is being disallowed.
- *
- * @return msg A non-null but possibly empty String
- */
- public String getMsg() {
- return msg;
- }
-
- }
-
- /**
- * Checks the switch configuration (if any) associated with the 'dpid'.
- * Determines if the switch should be allowed or denied according to
- * configuration rules.
- *
- * The method always returns a non-null SwitchConfigStatus. The enclosed
- * ConfigState contains the result of the check. The enclosed SwitchConfig
- * may or may not be null, depending on the outcome of the check.
- *
- * @param dpid device id of the switch to be queried
- * @return SwitchConfigStatus with outcome of check and associated config.
- */
- SwitchConfigStatus checkSwitchConfig(DeviceId dpid);
-
- /**
- * Reserved for future use.
- *
- * Checks the link configuration (if any) associated with the 'link'.
- * Determines if the link should be allowed or denied according to
- * configuration rules. Note that the 'link' is a unidirectional link which
- * checked against configuration that is typically defined for a
- * bidirectional link. The caller may make a second call if it wishes to
- * check the 'reverse' direction.
- *
- * Also note that the configuration may not specify ports for a given
- * bidirectional link. In such cases, the configuration applies to all links
- * between the two switches. This method will check the given 'link' against
- * such configuration.
-
- * The method always returns a non-null LinkConfigStatus. The enclosed
- * ConfigState contains the result of the check. The enclosed LinkConfig may
- * or may not be null, depending on the outcome of the check.
- *
- * @param linkTuple unidirectional link to be queried
- * @return LinkConfigStatus with outcome of check and associated config.
- */
- LinkConfigStatus checkLinkConfig(Link linkTuple);
-
- /**
- * Retrieves a list of switches that have been configured, and have been
- * determined to be 'allowed' in the network, according to configuration
- * rules.
- *
- * Note that it is possible that there are other switches that are allowed
- * in the network that have NOT been configured. Such switches will not be a
- * part of the returned list.
- *
- * Also note that it is possible that some switches will not be discovered
- * and the only way the controller can know about these switches is via
- * configuration. Such switches will be included in this list. It is up to
- * the caller to determine which SwitchConfig applies to non-discovered
- * switches.
- *
- * @return a non-null List of SwitchConfig which may be empty
- */
- List<SwitchConfig> getConfiguredAllowedSwitches();
-
- /**
- * Reserved for future use.
- *
- * Retrieves a list of links that have been configured, and have been
- * determined to be 'allowed' in the network, according to configuration
- * rules.
- *
- * Note that it is possible that there are other links that are allowed in
- * the network that have NOT been configured. Such links will not be a part
- * of the returned list.
- *
- * Also note that it is possible that some links will not be discovered and
- * the only way the controller can know about these links is via
- * configuration. Such links will be included in this list. It is up to the
- * caller to determine which LinkConfig applies to non-discovered links.
- *
- * In addition, note that the LinkConfig applies to the configured
- * bi-directional link, which may or may not have declared ports. The
- * associated unidirectional LinkTuple can be retrieved from the
- * getLinkTupleList() method in the LinkConfig object.
- *
- * @return a non-null List of LinkConfig which may be empty
- */
- List<LinkConfig> getConfiguredAllowedLinks();
-
- /**
- * Retrieves the Dpid associated with a 'name' for a configured switch
- * object. This method does not check of the switches are 'allowed' by
- * config.
- *
- * @param name device name
- * @return the Dpid corresponding to a given 'name', or null if no
- * configured switch was found for the given 'name'.
- */
- DeviceId getDpidForName(String name);
-
-}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/PktLinkConfig.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/PktLinkConfig.java
deleted file mode 100644
index 3c51fa9d..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/PktLinkConfig.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 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 java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.onosproject.net.Link;
-import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-/**
- * Reserved for future use.
- * Configuration for a link between two packet-switches.
- */
-public class PktLinkConfig extends LinkConfig {
- protected static final Logger log = LoggerFactory
- .getLogger(PktLinkConfig.class);
- private int port1;
- private int port2;
- private String nodeName1;
- private String nodeName2;
- private List<Link> linkTupleList;
-
- public PktLinkConfig(LinkConfig lkc) {
- nodeDpid1 = lkc.getNodeDpid1();
- nodeDpid2 = lkc.getNodeDpid2();
- dpid1 = lkc.getDpid1();
- dpid2 = lkc.getDpid2();
- type = lkc.getType();
- allowed = lkc.isAllowed();
- params = lkc.getParams();
- publishAttributes = new ConcurrentHashMap<>();
- parseParams();
- validateParams();
- setPublishAttributes();
- }
-
- // ********************
- // Packet Link Configuration
- // ********************
-
- public int getPort1() {
- return port1;
- }
-
- public void setPort1(int port1) {
- this.port1 = port1;
- }
-
- public int getPort2() {
- return port2;
- }
-
- public void setPort2(int port2) {
- this.port2 = port2;
- }
-
- public String getNodeName1() {
- return nodeName1;
- }
-
- public void setNodeName1(String nodeName1) {
- this.nodeName1 = nodeName1;
- }
-
- public String getNodeName2() {
- return nodeName2;
- }
-
- public void setNodeName2(String nodeName2) {
- this.nodeName2 = nodeName2;
- }
-
- /**
- * Returns the two unidirectional links corresponding to the packet-link
- * configuration. It is possible that the ports in the LinkTuple have
- * portnumber '0', implying that the configuration applies to all links
- * between the two switches.
- *
- * @return a list of LinkTuple with exactly 2 unidirectional links
- */
- public List<Link> getLinkTupleList() {
- return linkTupleList;
- }
-
- private void setPublishAttributes() {
-
- }
-
- private void parseParams() {
- if (params == null) {
- throw new PktLinkParamsNotSpecified(nodeDpid1, nodeDpid2);
- }
- Set<Entry<String, JsonNode>> m = params.entrySet();
- for (Entry<String, JsonNode> e : m) {
- String key = e.getKey();
- JsonNode j = e.getValue();
- if (key.equals("nodeName1")) {
- setNodeName1(j.asText());
- } else if (key.equals("nodeName2")) {
- setNodeName2(j.asText());
- } else if (key.equals("port1")) {
- setPort1(j.asInt());
- } else if (key.equals("port2")) {
- setPort2(j.asInt());
- } else {
- throw new UnknownPktLinkConfig(key, nodeDpid1, nodeDpid2);
- }
- }
- }
-
- private void validateParams() {
- // TODO - wrong-names, duplicate links,
- // duplicate use of port, is switch-allowed for which link is allowed?
- // valid port numbers
- }
-
- public static class PktLinkParamsNotSpecified extends RuntimeException {
- private static final long serialVersionUID = 6247582323691265513L;
-
- public PktLinkParamsNotSpecified(String dpidA, String dpidB) {
- super();
- log.error("Params required for packet link - not specified "
- + "for link between switch1:{} and switch2:{}",
- dpidA, dpidB);
- }
- }
-
- public static class UnknownPktLinkConfig extends RuntimeException {
- private static final long serialVersionUID = -5750132094884129179L;
-
- public UnknownPktLinkConfig(String key, String dpidA, String dpidB) {
- super();
- log.error("Unknown packet-link config {} for link between"
- + " dpid1: {} and dpid2: {}", key,
- dpidA, dpidB);
- }
- }
-
-}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRouterConfig.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRouterConfig.java
deleted file mode 100644
index c8d4a54a..00000000
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/SegmentRouterConfig.java
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Copyright 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 java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.onosproject.net.DeviceId;
-import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * Manages additional configuration for switches configured as Segment Routers.
- */
-public class SegmentRouterConfig extends SwitchConfig {
- protected static final Logger log = LoggerFactory
- .getLogger(SegmentRouterConfig.class);
- private String routerIp;
- private String routerMac;
- private int nodeSid;
- private boolean isEdgeRouter;
- private List<AdjacencySid> adjacencySids;
- private List<Subnet> subnets;
-
- public static final String ROUTER_IP = "routerIp";
- public static final String ROUTER_MAC = "routerMac";
- public static final String NODE_SID = "nodeSid";
- public static final String ADJACENCY_SIDS = "adjacencySids";
- public static final String SUBNETS = "subnets";
- public static final String ISEDGE = "isEdgeRouter";
- private static final int SRGB_MAX = 1000;
-
- /**
- * Parses and validates the additional configuration parameters applicable
- * to segment routers.
- *
- * @param swc switch configuration
- */
- public SegmentRouterConfig(SwitchConfig swc) {
- this.setName(swc.getName());
- this.setDpid(swc.getDpid());
- this.setType(swc.getType());
- this.setLatitude(swc.getLatitude());
- this.setLongitude(swc.getLongitude());
- this.setParams(swc.getParams());
- this.setAllowed(swc.isAllowed());
- publishAttributes = new ConcurrentHashMap<>();
- adjacencySids = new ArrayList<>();
- subnets = new ArrayList<>();
- parseParams();
- validateParams();
- setPublishAttributes();
- }
-
- /**
- * Returns the configured segment router IP address.
- *
- * @return ip address in string format
- */
- public String getRouterIp() {
- return routerIp;
- }
-
- public void setRouterIp(String routerIp) {
- this.routerIp = routerIp;
- }
-
- /**
- * Returns the configured segment router mac address.
- *
- * @return mac address in string format
- */
- public String getRouterMac() {
- return routerMac;
- }
-
- public void setRouterMac(String routerMac) {
- this.routerMac = routerMac;
- }
-
- /**
- * Returns the configured sID for a segment router.
- *
- * @return segment identifier
- */
- public int getNodeSid() {
- return nodeSid;
- }
-
- public void setNodeSid(int nodeSid) {
- this.nodeSid = nodeSid;
- }
-
- /**
- * Returns the flag that indicates the configured segment router
- * is edge or backbone router.
- *
- * @return boolean
- */
- public boolean isEdgeRouter() {
- return isEdgeRouter;
- }
-
- public void setIsEdgeRouter(boolean isEdge) {
- this.isEdgeRouter = isEdge;
- }
-
- /**
- * Class representing segment router adjacency identifier.
- */
- public static class AdjacencySid {
- private int adjSid;
- private List<Integer> ports;
-
- public AdjacencySid(int adjSid, List<Integer> ports) {
- this.ports = ports;
- this.adjSid = adjSid;
- }
-
- /**
- * Returns the list of ports part of a segment
- * router adjacency identifier.
- *
- * @return list of integers
- */
- public List<Integer> getPorts() {
- return ports;
- }
-
- public void setPorts(List<Integer> ports) {
- this.ports = ports;
- }
-
- /**
- * Returns the configured adjacency id of a segment router.
- *
- * @return integer
- */
- public int getAdjSid() {
- return adjSid;
- }
-
- public void setAdjSid(int adjSid) {
- this.adjSid = adjSid;
- }
- }
-
- /**
- * Returns the configured adjacent segment IDs for a segment router.
- *
- * @return list of adjacency identifier
- */
- public List<AdjacencySid> getAdjacencySids() {
- return adjacencySids;
- }
-
- public void setAdjacencySids(List<AdjacencySid> adjacencySids) {
- this.adjacencySids = adjacencySids;
- }
-
- /**
- * Class representing a subnet attached to a segment router.
- */
- public static class Subnet {
- private int portNo;
- private String subnetIp;
-
- public Subnet(int portNo, String subnetIp) {
- this.portNo = portNo;
- this.subnetIp = subnetIp;
- }
-
- /**
- * Returns the port number of segment router on
- * which subnet is attached.
- *
- * @return integer
- */
- public int getPortNo() {
- return portNo;
- }
-
- public void setPortNo(int portNo) {
- this.portNo = portNo;
- }
-
- /**
- * Returns the configured subnet address.
- *
- * @return subnet ip address in string format
- */
- public String getSubnetIp() {
- return subnetIp;
- }
-
- public void setSubnetIp(String subnetIp) {
- this.subnetIp = subnetIp;
- }
- }
-
- /**
- * Returns the configured subnets for a segment router.
- *
- * @return list of subnets
- */
- public List<Subnet> getSubnets() {
- return subnets;
- }
-
- public void setSubnets(List<Subnet> subnets) {
- this.subnets = subnets;
- }
-
- // ********************
- // Helper methods
- // ********************
-
- private void parseParams() {
- if (params == null) {
- throw new NetworkConfigException.ParamsNotSpecified(name);
- }
-
- Set<Entry<String, JsonNode>> m = params.entrySet();
- for (Entry<String, JsonNode> e : m) {
- String key = e.getKey();
- JsonNode j = e.getValue();
- if (key.equals("routerIp")) {
- setRouterIp(j.asText());
- } else if (key.equals("routerMac")) {
- setRouterMac(j.asText());
- } else if (key.equals("nodeSid")) {
- setNodeSid(j.asInt());
- } else if (key.equals("isEdgeRouter")) {
- setIsEdgeRouter(j.asBoolean());
- } else if (key.equals("adjacencySids") || key.equals("subnets")) {
- getInnerParams(j, key);
- } else {
- throw new UnknownSegmentRouterConfig(key, dpid);
- }
- }
- }
-
- private void getInnerParams(JsonNode j, String innerParam) {
- Iterator<JsonNode> innerList = j.elements();
- while (innerList.hasNext()) {
- Iterator<Entry<String, JsonNode>> f = innerList.next().fields();
- int portNo = -1;
- int adjSid = -1;
- String subnetIp = null;
- List<Integer> ports = null;
- while (f.hasNext()) {
- Entry<String, JsonNode> fe = f.next();
- if (fe.getKey().equals("portNo")) {
- portNo = fe.getValue().asInt();
- } else if (fe.getKey().equals("adjSid")) {
- adjSid = fe.getValue().asInt();
- } else if (fe.getKey().equals("subnetIp")) {
- subnetIp = fe.getValue().asText();
- } else if (fe.getKey().equals("ports")) {
- if (fe.getValue().isArray()) {
- Iterator<JsonNode> i = fe.getValue().elements();
- ports = new ArrayList<>();
- while (i.hasNext()) {
- ports.add(i.next().asInt());
- }
- }
- } else {
- throw new UnknownSegmentRouterConfig(fe.getKey(), dpid);
- }
- }
- if (innerParam.equals("adjacencySids")) {
- AdjacencySid ads = new AdjacencySid(adjSid, ports);
- adjacencySids.add(ads);
- } else {
- Subnet sip = new Subnet(portNo, subnetIp);
- subnets.add(sip);
- }
- }
- }
-
- private void validateParams() {
- if (routerIp == null) {
- throw new IpNotSpecified(dpid);
- }
- if (routerMac == null) {
- throw new MacNotSpecified(dpid);
- }
- if (isEdgeRouter && subnets.isEmpty()) {
- throw new SubnetNotSpecifiedInEdgeRouter(dpid);
- }
- if (!isEdgeRouter && !subnets.isEmpty()) {
- throw new SubnetSpecifiedInBackboneRouter(dpid);
- }
- if (nodeSid > SRGB_MAX) {
- throw new NodeLabelNotInSRGB(nodeSid, dpid);
- }
- for (AdjacencySid as : adjacencySids) {
- int label = as.getAdjSid();
- List<Integer> plist = as.getPorts();
- if (label <= SRGB_MAX) {
- throw new AdjacencyLabelInSRGB(label, dpid);
- }
- if (plist.size() <= 1) {
- throw new AdjacencyLabelNotEnoughPorts(label, dpid);
- }
- }
-
-
- // TODO more validations
- }
-
- /**
- * Setting publishAttributes implies that this is the configuration that
- * will be added to Topology.Switch object before it is published on the
- * channel to other controller instances.
- */
- private void setPublishAttributes() {
- publishAttributes.put(ROUTER_IP, routerIp);
- publishAttributes.put(ROUTER_MAC, routerMac);
- publishAttributes.put(NODE_SID, String.valueOf(nodeSid));
- publishAttributes.put(ISEDGE, String.valueOf(isEdgeRouter));
- ObjectMapper mapper = new ObjectMapper();
- try {
- publishAttributes.put(ADJACENCY_SIDS,
- mapper.writeValueAsString(adjacencySids));
- publishAttributes.put(SUBNETS,
- mapper.writeValueAsString(subnets));
- } catch (JsonProcessingException e) {
- log.error("Error while writing SR config: {}", e.getCause());
- } catch (IOException e) {
- log.error("Error while writing SR config: {}", e.getCause());
- }
- }
-
- // ********************
- // Exceptions
- // ********************
-
- public static class IpNotSpecified extends RuntimeException {
- private static final long serialVersionUID = -3001502553646331686L;
-
- public IpNotSpecified(DeviceId dpid) {
- super();
- log.error("Router IP address not specified for SR config dpid:{}",
- dpid);
- }
- }
-
- public static class MacNotSpecified extends RuntimeException {
- private static final long serialVersionUID = -5850132094884129179L;
-
- public MacNotSpecified(DeviceId dpid) {
- super();
- log.error("Router Mac address not specified for SR config dpid:{}",
- dpid);
- }
- }
-
- public static class UnknownSegmentRouterConfig extends RuntimeException {
- private static final long serialVersionUID = -5750132094884129179L;
-
- public UnknownSegmentRouterConfig(String key, DeviceId dpid) {
- super();
- log.error("Unknown Segment Router config {} in dpid: {}", key,
- dpid);
- }
- }
-
- public static class SubnetNotSpecifiedInEdgeRouter extends RuntimeException {
- private static final long serialVersionUID = -5855458472668581268L;
-
- public SubnetNotSpecifiedInEdgeRouter(DeviceId dpid) {
- super();
- log.error("Subnet was not specified for edge router in dpid: {}",
- dpid);
- }
- }
-
- public static class SubnetSpecifiedInBackboneRouter extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
- public SubnetSpecifiedInBackboneRouter(DeviceId dpid) {
- super();
- log.error("Subnet was specified in backbone router in dpid: {}",
- dpid);
- }
- }
-
- public static class NodeLabelNotInSRGB extends RuntimeException {
- private static final long serialVersionUID = -8482670903748519526L;
-
- public NodeLabelNotInSRGB(int label, DeviceId dpid) {
- super();
- log.error("Node sif {} specified in not in global label-base "
- + "in dpid: {}", label,
- dpid);
- }
- }
-
- public static class AdjacencyLabelInSRGB extends RuntimeException {
- private static final long serialVersionUID = -8482670903748519526L;
-
- public AdjacencyLabelInSRGB(int label, DeviceId dpid) {
- super();
- log.error("Adjaceny label {} specified from global label-base "
- + "in dpid: {}", label,
- dpid);
- }
- }
-
- public static class AdjacencyLabelNotEnoughPorts extends RuntimeException {
- private static final long serialVersionUID = -8482670903748519526L;
-
- public AdjacencyLabelNotEnoughPorts(int label, DeviceId dpid) {
- super();
- log.error("Adjaceny label {} must be specified for at least 2 ports. "
- + "Adjacency labels for single ports are auto-generated "
- + "in dpid: {}", label,
- dpid);
- }
- }
-}