aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java')
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java164
1 files changed, 107 insertions, 57 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 0bc155b8..828c51ce 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
@@ -15,6 +15,7 @@
*/
package org.onosproject.segmentrouting;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
@@ -38,20 +39,20 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Segment Routing configuration component that reads the
* segment routing related configuration from Network Configuration Manager
* component and organizes in more accessible formats.
- *
- * TODO: Merge multiple Segment Routing configuration wrapper classes into one.
*/
public class DeviceConfiguration implements DeviceProperties {
private static final Logger log = LoggerFactory
.getLogger(DeviceConfiguration.class);
private final List<Integer> allSegmentIds = new ArrayList<>();
- private final HashMap<DeviceId, SegmentRouterInfo> deviceConfigMap = new HashMap<>();
+ private final ConcurrentHashMap<DeviceId, SegmentRouterInfo> deviceConfigMap
+ = new ConcurrentHashMap<>();
private class SegmentRouterInfo {
int nodeSid;
@@ -126,18 +127,17 @@ public class DeviceConfiguration implements DeviceProperties {
}
/**
- * Returns the segment id of a segment router.
+ * Returns the Node segment id of a segment router.
*
* @param deviceId device identifier
* @return segment id
*/
@Override
public int getSegmentId(DeviceId deviceId) {
- if (deviceConfigMap.get(deviceId) != null) {
- log.trace("getSegmentId for device{} is {}",
- deviceId,
- deviceConfigMap.get(deviceId).nodeSid);
- return deviceConfigMap.get(deviceId).nodeSid;
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ log.trace("getSegmentId for device{} is {}", deviceId, srinfo.nodeSid);
+ return srinfo.nodeSid;
} else {
log.warn("getSegmentId for device {} "
+ "throwing IllegalStateException "
@@ -147,10 +147,10 @@ public class DeviceConfiguration implements DeviceProperties {
}
/**
- * Returns the segment id of a segment router given its mac address.
+ * Returns the Node segment id of a segment router given its Router mac address.
*
* @param routerMac router mac address
- * @return segment id
+ * @return node segment id, or -1 if not found in config
*/
public int getSegmentId(MacAddress routerMac) {
for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
@@ -164,10 +164,10 @@ public class DeviceConfiguration implements DeviceProperties {
}
/**
- * Returns the segment id of a segment router given its router ip address.
+ * Returns the Node segment id of a segment router given its Router ip address.
*
* @param routerAddress router ip address
- * @return segment id
+ * @return node segment id, or -1 if not found in config
*/
public int getSegmentId(Ip4Address routerAddress) {
for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
@@ -188,11 +188,10 @@ public class DeviceConfiguration implements DeviceProperties {
*/
@Override
public MacAddress getDeviceMac(DeviceId deviceId) {
- if (deviceConfigMap.get(deviceId) != null) {
- log.trace("getDeviceMac for device{} is {}",
- deviceId,
- deviceConfigMap.get(deviceId).mac);
- return deviceConfigMap.get(deviceId).mac;
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ log.trace("getDeviceMac for device{} is {}", deviceId, srinfo.mac);
+ return srinfo.mac;
} else {
log.warn("getDeviceMac for device {} "
+ "throwing IllegalStateException "
@@ -208,11 +207,10 @@ public class DeviceConfiguration implements DeviceProperties {
* @return router ip address
*/
public Ip4Address getRouterIp(DeviceId deviceId) {
- if (deviceConfigMap.get(deviceId) != null) {
- log.trace("getDeviceIp for device{} is {}",
- deviceId,
- deviceConfigMap.get(deviceId).ip);
- return deviceConfigMap.get(deviceId).ip;
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ log.trace("getDeviceIp for device{} is {}", deviceId, srinfo.ip);
+ return srinfo.ip;
} else {
log.warn("getRouterIp for device {} "
+ "throwing IllegalStateException "
@@ -223,18 +221,17 @@ public class DeviceConfiguration implements DeviceProperties {
/**
* Indicates if the segment router is a edge router or
- * a transit/back bone router.
+ * a core/backbone router.
*
* @param deviceId device identifier
* @return boolean
*/
@Override
public boolean isEdgeDevice(DeviceId deviceId) {
- if (deviceConfigMap.get(deviceId) != null) {
- log.trace("isEdgeDevice for device{} is {}",
- deviceId,
- deviceConfigMap.get(deviceId).isEdge);
- return deviceConfigMap.get(deviceId).isEdge;
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ log.trace("isEdgeDevice for device{} is {}", deviceId, srinfo.isEdge);
+ return srinfo.isEdge;
} else {
log.warn("isEdgeDevice for device {} "
+ "throwing IllegalStateException "
@@ -244,15 +241,35 @@ public class DeviceConfiguration implements DeviceProperties {
}
/**
- * Returns the segment ids of all configured segment routers.
+ * Returns the node segment ids of all configured segment routers.
*
- * @return list of segment ids
+ * @return list of node segment ids
*/
@Override
public List<Integer> getAllDeviceSegmentIds() {
return allSegmentIds;
}
+ @Override
+ public Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId) {
+ Map<Ip4Prefix, List<PortNumber>> subnetPortMap = new HashMap<>();
+
+ // Construct subnet-port mapping from port-subnet mapping
+ Map<PortNumber, Ip4Prefix> portSubnetMap =
+ this.deviceConfigMap.get(deviceId).subnets;
+ portSubnetMap.forEach((port, subnet) -> {
+ if (subnetPortMap.containsKey(subnet)) {
+ subnetPortMap.get(subnet).add(port);
+ } else {
+ ArrayList<PortNumber> ports = new ArrayList<>();
+ ports.add(port);
+ subnetPortMap.put(subnet, ports);
+ }
+ });
+
+ return subnetPortMap;
+ }
+
/**
* Returns the device identifier or data plane identifier (dpid)
* of a segment router given its segment id.
@@ -290,37 +307,68 @@ public class DeviceConfiguration implements DeviceProperties {
}
/**
- * Returns the configured subnet gateway ip addresses for a segment router.
+ * Returns the configured port ip addresses for a segment router.
+ * These addresses serve as gateway IP addresses for the subnets configured
+ * on those ports.
*
* @param deviceId device identifier
- * @return list of ip addresses
+ * @return immutable set of ip addresses configured on the ports or null if not found
*/
- public List<Ip4Address> getSubnetGatewayIps(DeviceId deviceId) {
- if (deviceConfigMap.get(deviceId) != null) {
- log.trace("getSubnetGatewayIps for device{} is {}",
- deviceId,
- deviceConfigMap.get(deviceId).gatewayIps.values());
- return new ArrayList<>(deviceConfigMap.get(deviceId).gatewayIps.values());
- } else {
- return null;
+ public Set<Ip4Address> getPortIPs(DeviceId deviceId) {
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ log.trace("getSubnetGatewayIps for device{} is {}", deviceId,
+ srinfo.gatewayIps.values());
+ return ImmutableSet.copyOf(srinfo.gatewayIps.values());
+ }
+ return null;
+ }
+
+ /**
+ * Returns the configured IP addresses per port
+ * for a segment router.
+ *
+ * @param deviceId device identifier
+ * @return map of port to gateway IP addresses or null if not found
+ */
+ public Map<PortNumber, Ip4Address> getPortIPMap(DeviceId deviceId) {
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ return srinfo.gatewayIps;
}
+ return null;
}
/**
* Returns the configured subnet prefixes for a segment router.
*
* @param deviceId device identifier
- * @return list of ip prefixes
+ * @return list of ip prefixes or null if not found
*/
- public List<Ip4Prefix> getSubnets(DeviceId deviceId) {
- if (deviceConfigMap.get(deviceId) != null) {
- log.trace("getSubnets for device{} is {}",
- deviceId,
- deviceConfigMap.get(deviceId).subnets.values());
- return new ArrayList<>(deviceConfigMap.get(deviceId).subnets.values());
- } else {
- return null;
+ public Set<Ip4Prefix> getSubnets(DeviceId deviceId) {
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ log.trace("getSubnets for device{} is {}", deviceId,
+ srinfo.subnets.values());
+ return ImmutableSet.copyOf(srinfo.subnets.values());
}
+ return null;
+ }
+
+ /**
+ * Returns the configured subnet on the given port, or null if no
+ * subnet has been configured on the port.
+ *
+ * @param deviceId device identifier
+ * @param pnum port identifier
+ * @return configured subnet on port, or null
+ */
+ public Ip4Prefix getPortSubnet(DeviceId deviceId, PortNumber pnum) {
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ return srinfo.subnets.get(pnum);
+ }
+ return null;
}
/**
@@ -349,7 +397,7 @@ public class DeviceConfiguration implements DeviceProperties {
* specified ip address as one of its subnet gateway ip address.
*
* @param gatewayIpAddress router gateway ip address
- * @return router mac address
+ * @return router mac address or null if not found
*/
public MacAddress getRouterMacForAGatewayIp(Ip4Address gatewayIpAddress) {
for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
@@ -377,7 +425,7 @@ public class DeviceConfiguration implements DeviceProperties {
*/
public boolean inSameSubnet(DeviceId deviceId, Ip4Address hostIp) {
- List<Ip4Prefix> subnets = getSubnets(deviceId);
+ Set<Ip4Prefix> subnets = getSubnets(deviceId);
if (subnets == null) {
return false;
}
@@ -399,8 +447,9 @@ public class DeviceConfiguration implements DeviceProperties {
* @return list of port numbers
*/
public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) {
- if (deviceConfigMap.get(deviceId) != null) {
- for (AdjacencySid asid : deviceConfigMap.get(deviceId).adjacencySids) {
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ for (AdjacencySid asid : srinfo.adjacencySids) {
if (asid.getAsid() == sid) {
return asid.getPorts();
}
@@ -419,12 +468,13 @@ public class DeviceConfiguration implements DeviceProperties {
* otherwise false
*/
public boolean isAdjacencySid(DeviceId deviceId, int sid) {
- if (deviceConfigMap.get(deviceId) != null) {
- if (deviceConfigMap.get(deviceId).adjacencySids.isEmpty()) {
+ SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
+ if (srinfo != null) {
+ if (srinfo.adjacencySids.isEmpty()) {
return false;
} else {
for (AdjacencySid asid:
- deviceConfigMap.get(deviceId).adjacencySids) {
+ srinfo.adjacencySids) {
if (asid.getAsid() == sid) {
return true;
}