use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class PortAuthTracker method reportPortsAuthState.
private List<PortAuthState> reportPortsAuthState() {
List<PortAuthState> result = new ArrayList<>();
for (Map.Entry<DeviceId, Map<PortNumber, BlockState>> entry : blockedPorts.entrySet()) {
DeviceId d = entry.getKey();
Map<PortNumber, BlockState> portMap = entry.getValue();
for (PortNumber p : portMap.keySet()) {
result.add(new PortAuthState(d, p, portMap.get(p)));
}
}
Collections.sort(result);
return result;
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class PortAuthTracker method logPortsNoLongerBlocked.
private void logPortsNoLongerBlocked() {
for (Map.Entry<DeviceId, Map<PortNumber, BlockState>> entry : oldMap.entrySet()) {
DeviceId d = entry.getKey();
Map<PortNumber, BlockState> portMap = entry.getValue();
for (PortNumber p : portMap.keySet()) {
if (notInMap(d, p)) {
clearBlockingFlow(d, p);
log.info("De-configuring port {}/{} (UNCHECKED)", d, p);
}
}
}
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class RouteHandler method processHostMovedEvent.
void processHostMovedEvent(HostEvent event) {
log.info("processHostMovedEvent {}", event);
MacAddress hostMac = event.subject().mac();
VlanId hostVlanId = event.subject().vlan();
Set<ConnectPoint> prevLocations = event.prevSubject().locations().stream().map(h -> (ConnectPoint) h).collect(Collectors.toSet());
Set<ConnectPoint> newLocations = event.subject().locations().stream().map(h -> (ConnectPoint) h).collect(Collectors.toSet());
List<Set<IpPrefix>> batchedSubnets = srManager.deviceConfiguration.getBatchedSubnets(event.subject().id());
Set<DeviceId> newDeviceIds = newLocations.stream().map(ConnectPoint::deviceId).collect(Collectors.toSet());
// Set of deviceIDs of the previous locations where the host was connected
// Used to determine if host moved to different connect points
// on same device or moved to a different device altogether
Set<DeviceId> oldDeviceIds = prevLocations.stream().map(ConnectPoint::deviceId).collect(Collectors.toSet());
// and only when the no. of routes with the host as next-hop is not zero
if (!batchedSubnets.isEmpty()) {
// For each new location, if NextObj exists for the host, update with new location ..
Sets.difference(newLocations, prevLocations).forEach(newLocation -> {
// NOTE: that we use the nexthop vlanId to retrieve the nextId
// while the vlanId used to program the L3 unicast chain
// is derived from the port configuration. In case of
// a tagged interface we use host vlanId. Host vlan should
// be part of the tags configured for that port. See the
// code in DefaultGroupHandler.updateL3UcastGroupBucket
int nextId = srManager.getMacVlanNextObjectiveId(newLocation.deviceId(), hostMac, hostVlanId, null, false);
if (nextId != -1) {
// Update the nextId group bucket
log.debug("HostMoved. NextId exists, update L3 Ucast Group Bucket {}, {}, {} --> {}", newLocation, hostMac, hostVlanId, nextId);
srManager.updateMacVlanTreatment(newLocation.deviceId(), hostMac, hostVlanId, newLocation.port(), nextId);
} else {
log.debug("HostMoved. NextId does not exist for this location {}, host {}/{}", newLocation, hostMac, hostVlanId);
}
});
}
batchedSubnets.forEach(subnets -> {
log.debug("HostMoved. populateSubnet {}, {}", newLocations, subnets);
srManager.defaultRoutingHandler.populateSubnet(newLocations, subnets);
subnets.forEach(prefix -> {
// For each old location
Sets.difference(prevLocations, newLocations).forEach(prevLocation -> {
// Otherwise, do not remove and let the adding part update the old flow
if (newDeviceIds.contains(prevLocation.deviceId())) {
return;
}
log.debug("HostMoved. removeSubnet {}, {}", prevLocation, prefix);
srManager.deviceConfiguration.removeSubnet(prevLocation, prefix);
// Do not remove flow from a device if the route is still reachable via its pair device.
// If spine exists,
// populateSubnet above will update the flow to point to its pair device via spine.
// If spine does not exist,
// processSingleLeafPair below will update the flow to point to its pair device via pair port.
DeviceId pairDeviceId = srManager.getPairDeviceId(prevLocation.deviceId()).orElse(null);
if (newLocations.stream().anyMatch(n -> n.deviceId().equals(pairDeviceId))) {
return;
}
log.debug("HostMoved. revokeRoute {}, {}, {}, {}", prevLocation, prefix, hostMac, hostVlanId);
srManager.defaultRoutingHandler.revokeRoute(prevLocation.deviceId(), prefix, hostMac, hostVlanId, prevLocation.port(), false);
});
// For each new location, add all new IPs.
Sets.difference(newLocations, prevLocations).forEach(newLocation -> {
log.debug("HostMoved. addSubnet {}, {}", newLocation, prefix);
srManager.deviceConfiguration.addSubnet(newLocation, prefix);
// its a new connect point, not a move from an existing device, populateRoute
if (!oldDeviceIds.contains(newLocation.deviceId())) {
log.debug("HostMoved. populateRoute {}, {}, {}, {}", newLocation, prefix, hostMac, hostVlanId);
srManager.defaultRoutingHandler.populateRoute(newLocation.deviceId(), prefix, hostMac, hostVlanId, newLocation.port(), false);
}
});
newLocations.forEach(location -> {
processSingleLeafPairIfNeeded(newLocations, location, prefix, hostVlanId);
});
});
});
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class RouteHandler method processSingleLeafPairIfNeeded.
protected boolean processSingleLeafPairIfNeeded(Set<ConnectPoint> locations, ConnectPoint location, IpPrefix prefix, VlanId nextHopVlan) {
// Special handling for single leaf pair
if (!srManager.getInfraDeviceIds().isEmpty()) {
log.debug("Spine found. Skip single leaf pair handling");
return false;
}
Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId());
if (pairDeviceId.isEmpty()) {
log.debug("Pair device of {} not found", location.deviceId());
return false;
}
if (locations.stream().anyMatch(l -> l.deviceId().equals(pairDeviceId.get()))) {
log.debug("Pair device has a next hop available. Leave it as is.");
return false;
}
Optional<PortNumber> pairRemotePort = srManager.getPairLocalPort(pairDeviceId.get());
if (pairRemotePort.isEmpty()) {
log.debug("Pair remote port of {} not found", pairDeviceId.get());
return false;
}
// Use routerMac of the pair device as the next hop
MacAddress effectiveMac;
try {
effectiveMac = srManager.getDeviceMacAddress(location.deviceId());
} catch (DeviceConfigNotFoundException e) {
log.warn("Abort populateRoute on pair device {}. routerMac not found", pairDeviceId);
return false;
}
// Since the pairLocalPort is trunk port, use assigned vlan of original port
// when the host is untagged
VlanId effectiveVlan = Optional.ofNullable(srManager.getInternalVlanId(location)).orElse(nextHopVlan);
log.debug("Single leaf pair. populateRoute {}/{}, {}, {}, {}", pairDeviceId, pairRemotePort, prefix, effectiveMac, effectiveVlan);
srManager.defaultRoutingHandler.populateRoute(pairDeviceId.get(), prefix, effectiveMac, effectiveVlan, pairRemotePort.get(), false);
return true;
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class McastRoleListCommand method doExecute.
@Override
protected void doExecute() {
// Verify mcast group
IpAddress mcastGroup = null;
// We want to use source cp only for a specific group
ConnectPoint sourcecp = null;
if (!isNullOrEmpty(gAddr)) {
mcastGroup = IpAddress.valueOf(gAddr);
if (!isNullOrEmpty(source)) {
sourcecp = ConnectPoint.deviceConnectPoint(source);
}
}
// Get SR service, the roles and the groups
SegmentRoutingService srService = get(SegmentRoutingService.class);
Map<McastRoleStoreKey, McastRole> keyToRole = srService.getMcastRoles(mcastGroup, sourcecp);
Set<IpAddress> mcastGroups = keyToRole.keySet().stream().map(McastRoleStoreKey::mcastIp).collect(Collectors.toSet());
// Print the trees for each group
mcastGroups.forEach(group -> {
// Create a new map for the group
Map<ConnectPoint, Multimap<McastRole, DeviceId>> roleDeviceIdMap = Maps.newHashMap();
keyToRole.entrySet().stream().filter(entry -> entry.getKey().mcastIp().equals(group)).forEach(entry -> roleDeviceIdMap.compute(entry.getKey().source(), (gsource, map) -> {
map = map == null ? ArrayListMultimap.create() : map;
map.put(entry.getValue(), entry.getKey().deviceId());
return map;
}));
roleDeviceIdMap.forEach((gsource, map) -> {
// Print the map
printMcastRole(group, gsource, map.get(McastRole.INGRESS), map.get(McastRole.TRANSIT), map.get(McastRole.EGRESS));
});
});
}
Aggregations