use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class DefaultRoutingHandler method revokeSubnet.
/**
* Revoke rules of given subnet in all edge switches. Use the
* destination switch (if it is provided) to provide coordination
* among the instances. Otherwise, only the leader of the target
* switch can remove this subnet.
*
* @param subnets subnet being removed
* @param destSw destination switch. It is null when it is called from RouteHandler,
* in this context we don't have a way to remember the old locations.
* @return true if succeed
*/
protected boolean revokeSubnet(Set<IpPrefix> subnets, DeviceId destSw) {
DeviceId targetSw;
List<Future<Boolean>> futures = Lists.newArrayList();
for (Device sw : srManager.deviceService.getAvailableDevices()) {
targetSw = sw.id();
// In some calls, we dont know anymore the destination switch
if ((destSw != null && shouldProgram(destSw)) || shouldProgram(targetSw)) {
futures.add(routePopulators.submit(new RevokeSubnet(targetSw, subnets)));
} else {
futures.add(CompletableFuture.completedFuture(true));
}
}
// check the execution of each job
return checkJobs(futures);
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class DefaultRoutingHandler method compareGraphs.
/**
* For the root switch, searches all the target nodes reachable in the base
* graph, and compares paths to the ones in the comp graph.
*
* @param base the graph that is indexed for all reachable target nodes
* from the root node
* @param comp the graph that the base graph is compared to
* @param rootSw both ecmp graphs are calculated for the root node
* @return all the routes that have changed in the base graph
*/
private Set<ArrayList<DeviceId>> compareGraphs(EcmpShortestPathGraph base, EcmpShortestPathGraph comp, DeviceId rootSw) {
ImmutableSet.Builder<ArrayList<DeviceId>> changedRoutesBuilder = ImmutableSet.builder();
HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> baseMap = base.getAllLearnedSwitchesAndVia();
HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> compMap = comp.getAllLearnedSwitchesAndVia();
for (Integer itrIdx : baseMap.keySet()) {
HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> baseViaMap = baseMap.get(itrIdx);
for (DeviceId targetSw : baseViaMap.keySet()) {
ArrayList<ArrayList<DeviceId>> basePath = baseViaMap.get(targetSw);
ArrayList<ArrayList<DeviceId>> compPath = getVia(compMap, targetSw);
if ((compPath == null) || !basePath.equals(compPath)) {
log.trace("Impacted route:{} -> {}", targetSw, rootSw);
ArrayList<DeviceId> route = new ArrayList<>();
// switch with rules to populate
route.add(targetSw);
// towards this destination
route.add(rootSw);
changedRoutesBuilder.add(route);
}
}
}
return changedRoutesBuilder.build();
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class DeviceConfiguration method updateConfig.
public void updateConfig() {
// Read config from device subject, excluding gatewayIps and subnets.
Set<DeviceId> deviceSubjects = srManager.cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class);
deviceSubjects.forEach(subject -> {
SegmentRoutingDeviceConfig config = srManager.cfgService.getConfig(subject, SegmentRoutingDeviceConfig.class);
SegmentRouterInfo info = new SegmentRouterInfo();
info.deviceId = subject;
info.ipv4NodeSid = config.nodeSidIPv4();
info.ipv6NodeSid = config.nodeSidIPv6();
info.ipv4Loopback = config.routerIpv4();
info.ipv6Loopback = config.routerIpv6();
info.mac = config.routerMac();
info.isEdge = config.isEdgeRouter();
info.adjacencySids = config.adjacencySids();
info.pairDeviceId = config.pairDeviceId();
info.pairLocalPort = config.pairLocalPort();
info.pwRoutingLabel = info.ipv4NodeSid + 1000;
deviceConfigMap.put(info.deviceId, info);
log.debug("Read device config for device: {}", info.deviceId);
// IPv6 sid is not inserted. this part of the code is not used for now.
allSegmentIds.add(info.ipv4NodeSid);
// Block host with routerMac and untagged VLAN
blockHost(info.mac, VlanId.NONE);
});
// Read gatewayIps and subnets from port subject. Ignore suppressed ports.
Set<ConnectPoint> portSubjects = srManager.cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
portSubjects.stream().filter(subject -> deviceConfigMap.containsKey(subject.deviceId())).filter(subject -> !isSuppressedPort(subject)).forEach(subject -> {
InterfaceConfig config = srManager.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 -> {
VlanId vlanId = networkInterface.vlan();
ConnectPoint connectPoint = networkInterface.connectPoint();
DeviceId dpid = connectPoint.deviceId();
PortNumber port = connectPoint.port();
MacAddress mac = networkInterface.mac();
SegmentRouterInfo info = deviceConfigMap.get(dpid);
// skip if there is no corresponding device for this ConnectPoint
if (info != null) {
// Extract subnet information
List<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddressesList();
interfaceAddresses.forEach(interfaceAddress -> {
// Do not add /0, /32 and /128 to gateway IP list
int prefixLength = interfaceAddress.subnetAddress().prefixLength();
IpPrefix ipPrefix = interfaceAddress.subnetAddress();
if (ipPrefix.isIp4()) {
if (prefixLength != 0 && prefixLength != IpPrefix.MAX_INET_MASK_LENGTH) {
info.gatewayIps.put(port, interfaceAddress.ipAddress());
}
info.subnets.put(port, interfaceAddress.subnetAddress());
} else {
if (prefixLength != 0 && prefixLength != IpPrefix.MAX_INET6_MASK_LENGTH) {
info.gatewayIps.put(port, interfaceAddress.ipAddress());
}
info.subnets.put(port, interfaceAddress.subnetAddress());
}
});
// Override interface mac with router mac
if (!mac.equals(info.mac)) {
ArrayNode array = (ArrayNode) config.node();
for (JsonNode intfNode : array) {
ObjectNode objNode = (ObjectNode) intfNode;
objNode.put(InterfaceConfig.MAC, info.mac.toString());
}
srManager.cfgService.applyConfig(connectPoint, InterfaceConfig.class, array);
}
// Block host with routerMac and taggedVlan
networkInterface.vlanTagged().forEach(taggedVlan -> {
blockHost(info.mac, taggedVlan);
});
}
});
// We register the connect point with the NRS.
srManager.registerConnectPoint(subject);
});
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class EcmpShortestPathGraph method calcECMPShortestPathGraph.
/**
* Calculates the BFS tree.
*/
private void calcECMPShortestPathGraph() {
deviceQueue.add(rootDevice);
int currDistance = 0;
distanceQueue.add(currDistance);
deviceSearched.put(rootDevice, currDistance);
while (!deviceQueue.isEmpty()) {
DeviceId sw = deviceQueue.poll();
Set<DeviceId> prevSw = Sets.newHashSet();
currDistance = distanceQueue.poll();
for (Link link : srManager.linkHandler.getDeviceEgressLinks(sw)) {
if (srManager.linkHandler.avoidLink(link)) {
continue;
}
DeviceId reachedDevice = link.dst().deviceId();
if (prevSw.contains(reachedDevice)) {
// Ignore LAG links between the same set of Devices
continue;
} else {
prevSw.add(reachedDevice);
}
Integer distance = deviceSearched.get(reachedDevice);
if ((distance != null) && (distance < (currDistance + 1))) {
continue;
}
if (distance == null) {
// First time visiting this Device node
deviceQueue.add(reachedDevice);
distanceQueue.add(currDistance + 1);
deviceSearched.put(reachedDevice, currDistance + 1);
ArrayList<DeviceId> distanceSwArray = distanceDeviceMap.get(currDistance + 1);
if (distanceSwArray == null) {
distanceSwArray = new ArrayList<>();
distanceSwArray.add(reachedDevice);
distanceDeviceMap.put(currDistance + 1, distanceSwArray);
} else {
distanceSwArray.add(reachedDevice);
}
}
ArrayList<Link> upstreamLinkArray = upstreamLinks.get(reachedDevice);
if (upstreamLinkArray == null) {
upstreamLinkArray = new ArrayList<>();
upstreamLinkArray.add(copyDefaultLink(link));
// upstreamLinkArray.add(link);
upstreamLinks.put(reachedDevice, upstreamLinkArray);
} else {
// ECMP links
upstreamLinkArray.add(copyDefaultLink(link));
}
}
}
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class EcmpShortestPathGraph method getECMPPaths.
/**
* Return the computed ECMP paths from the root Device to a given Device in
* the network.
*
* @param targetDevice the target Device
* @return the list of ECMP Paths from the root Device to the target Device
*/
public ArrayList<Path> getECMPPaths(DeviceId targetDevice) {
ArrayList<Path> pathArray = paths.get(targetDevice);
if (pathArray == null && deviceSearched.containsKey(targetDevice)) {
pathArray = new ArrayList<>();
DeviceId sw = targetDevice;
getDFSPaths(sw, null, pathArray);
paths.put(targetDevice, pathArray);
}
return pathArray;
}
Aggregations