use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class EcmpShortestPathGraph method getAllLearnedSwitchesAndVia.
/**
* Returns the complete info of the computed ECMP paths for each target device
* learned in multiple iterations from the root Device. The computed info
* returned is per iteration (Integer key of outer HashMap). In each
* iteration, for the target devices reached (DeviceId key of inner HashMap),
* the ECMP paths are detailed (2D array).
*
* @return the hash table of target Devices learned in multiple Dijkstra
* iterations and corresponding ECMP paths in terms of Devices to
* be traversed (via) from the root Device to the target Device
*/
public HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> getAllLearnedSwitchesAndVia() {
HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> deviceViaMap = new HashMap<>();
for (Integer itrIndx : distanceDeviceMap.keySet()) {
HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swMap = new HashMap<>();
for (DeviceId sw : distanceDeviceMap.get(itrIndx)) {
ArrayList<ArrayList<DeviceId>> swViaArray = new ArrayList<>();
for (Path path : getECMPPaths(sw)) {
ArrayList<DeviceId> swVia = new ArrayList<>();
for (Link link : path.links()) {
if (link.src().deviceId().equals(rootDevice)) {
/* No need to add the root Device again in
* the Via list
*/
continue;
}
swVia.add(link.src().deviceId());
}
swViaArray.add(swVia);
}
swMap.put(sw, swViaArray);
}
deviceViaMap.put(itrIndx, swMap);
}
return deviceViaMap;
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class EcmpShortestPathGraph method getDFSPaths.
private void getDFSPaths(DeviceId dstDeviceDeviceId, Path path, ArrayList<Path> paths) {
DeviceId rootDeviceDeviceId = rootDevice;
for (Link upstreamLink : upstreamLinks.get(dstDeviceDeviceId)) {
/* Deep clone the path object */
Path sofarPath;
ArrayList<Link> sofarLinks = new ArrayList<>();
if (path != null && !path.links().isEmpty()) {
sofarLinks.addAll(path.links());
}
sofarLinks.add(upstreamLink);
sofarPath = new DefaultPath(ProviderId.NONE, sofarLinks, ScalarWeight.toWeight(0));
if (upstreamLink.src().deviceId().equals(rootDeviceDeviceId)) {
paths.add(sofarPath);
return;
} else {
getDFSPaths(upstreamLink.src().deviceId(), sofarPath, paths);
}
}
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class EcmpShortestPathGraph method getCompleteLearnedDeviceesAndPaths.
/**
* Return the complete info of the computed ECMP paths for each Device
* learned in multiple iterations from the root Device.
*
* @return the hash table of Devices learned in multiple Dijkstra
* iterations and corresponding ECMP paths to it from the root
* Device
*/
public HashMap<Integer, HashMap<DeviceId, ArrayList<Path>>> getCompleteLearnedDeviceesAndPaths() {
HashMap<Integer, HashMap<DeviceId, ArrayList<Path>>> pathGraph = new HashMap<>();
for (Integer itrIndx : distanceDeviceMap.keySet()) {
HashMap<DeviceId, ArrayList<Path>> swMap = new HashMap<>();
for (DeviceId sw : distanceDeviceMap.get(itrIndx)) {
swMap.put(sw, getECMPPaths(sw));
}
pathGraph.put(itrIndx, swMap);
}
return pathGraph;
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class HostHandler method processHostRemoved.
private void processHostRemoved(Host host) {
MacAddress hostMac = host.mac();
VlanId hostVlanId = host.vlan();
Set<HostLocation> locations = effectiveLocations(host);
Set<IpAddress> ips = host.ipAddresses();
log.info("Host {}/{} is removed from {}", hostMac, hostVlanId, locations);
locations.forEach(location -> {
if (isDoubleTaggedHost(host)) {
ips.forEach(ip -> processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac, host.innerVlan(), hostVlanId, host.tpid(), ip, true));
} else {
processBridgingRule(location.deviceId(), location.port(), hostMac, hostVlanId, true);
ips.forEach(ip -> processRoutingRule(location.deviceId(), location.port(), hostMac, hostVlanId, ip, true));
}
// Also remove redirection flows on the pair device if exists.
Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId());
Optional<PortNumber> pairLocalPort = srManager.getPairLocalPort(location.deviceId());
if (pairDeviceId.isPresent() && pairLocalPort.isPresent()) {
// NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port
// when the host is untagged
VlanId vlanId = vlanForPairPort(hostVlanId, location);
if (vlanId == null) {
return;
}
processBridgingRule(pairDeviceId.get(), pairLocalPort.get(), hostMac, vlanId, true);
ips.forEach(ip -> processRoutingRule(pairDeviceId.get(), pairLocalPort.get(), hostMac, vlanId, ip, true));
}
// Delete prefix from sr-device-subnet when the next hop host is removed
srManager.routeService.getRouteTables().forEach(tableId -> {
srManager.routeService.getRoutes(tableId).forEach(routeInfo -> {
if (routeInfo.allRoutes().stream().anyMatch(rr -> ips.contains(rr.nextHop()))) {
log.debug("HostRemoved. removeSubnet {}, {}", location, routeInfo.prefix());
srManager.deviceConfiguration.removeSubnet(location, routeInfo.prefix());
}
});
});
});
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class HostHandler method isHostInVlanOfPort.
/**
* Checks if given host located on given device id matches VLAN config of current port.
*
* @param host host to check
* @param deviceId device id to check
* @param cp current connect point
* @return true if the host located at deviceId matches the VLAN config on cp
*/
private boolean isHostInVlanOfPort(Host host, DeviceId deviceId, ConnectPoint cp) {
VlanId internalVlan = srManager.getInternalVlanId(cp);
Set<VlanId> taggedVlan = srManager.interfaceService.getTaggedVlanId(cp);
return taggedVlan.contains(host.vlan()) || (internalVlan != null && effectiveLocations(host).stream().filter(l -> l.deviceId().equals(deviceId)).map(srManager::getInternalVlanId).anyMatch(internalVlan::equals));
}
Aggregations