use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class DeviceConfiguration method getPortSubnets.
/**
* Returns the subnet configuration of given device and port.
*
* @param deviceId Device ID
* @param port Port number
* @return The subnets configured on given port or empty set if
* the port is unconfigured or suppressed.
*/
public Set<IpPrefix> getPortSubnets(DeviceId deviceId, PortNumber port) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
if (isSuppressedPort(connectPoint)) {
return Collections.emptySet();
}
Set<IpPrefix> subnets = srManager.interfaceService.getInterfacesByPort(connectPoint).stream().flatMap(intf -> intf.ipAddressesList().stream()).map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
if (subnets.isEmpty()) {
log.debug(NO_SUBNET, connectPoint);
return Collections.emptySet();
}
return subnets;
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class HostHandler method processRoutingRule.
/**
* Populate or revoke a routing rule on given deviceId that matches given ip,
* set destination mac to given mac, set vlan to given vlan and output to given port.
*
* @param deviceId device ID
* @param port port
* @param mac mac address
* @param vlanId VLAN ID
* @param ip IP address
* @param revoke true to revoke the rule; false to populate
* @return future that includes the flow objective if succeeded, null if otherwise
*/
private CompletableFuture<Objective> processRoutingRule(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId, IpAddress ip, boolean revoke) {
ConnectPoint location = new ConnectPoint(deviceId, port);
if (!srManager.deviceConfiguration.inSameSubnet(location, ip)) {
log.info("{} is not included in the subnet config of {}/{}. Ignored.", ip, deviceId, port);
return CompletableFuture.completedFuture(null);
}
log.info("{} routing rule for {} at {}", revoke ? "Revoking" : "Populating", ip, location);
if (revoke) {
return srManager.defaultRoutingHandler.revokeRoute(deviceId, ip.toIpPrefix(), mac, vlanId, port, true);
} else {
return srManager.defaultRoutingHandler.populateRoute(deviceId, ip.toIpPrefix(), mac, vlanId, port, true);
}
}
use of org.onosproject.net.ConnectPoint 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));
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class HostHandler method processIntfVlanUpdatedEvent.
/**
* Update forwarding objective for unicast bridging and unicast routing.
* Also check the validity of updated interface configuration on VLAN.
*
* @param deviceId device ID that host attaches to
* @param portNum port number that host attaches to
* @param vlanId Vlan ID configured on the switch port
* @param popVlan true to pop Vlan tag at TrafficTreatment, false otherwise
* @param install true to populate the objective, false to revoke
*/
// TODO Current implementation does not handle dual-homed hosts with auxiliary locations.
void processIntfVlanUpdatedEvent(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan, boolean install) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portNum);
Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
if (hosts == null || hosts.size() == 0) {
log.debug("processIntfVlanUpdatedEvent: No hosts connected to {}", connectPoint);
return;
}
List<CompletableFuture<Void>> hostFutures = Lists.newArrayList();
hosts.forEach(host -> hostFutures.add(hostWorkers.submit(() -> processIntfVlanUpdatedEventInternal(host, deviceId, portNum, vlanId, popVlan, install), host.id().hashCode())));
// Let's wait for the completion of all hosts
try {
CompletableFuture.allOf(hostFutures.toArray(new CompletableFuture[0])).thenApply(objectives -> hostFutures.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
} catch (InterruptedException | ExecutionException e) {
log.warn("Exception caught when executing processIntfVlanUpdatedEvent futures");
hostFutures.forEach(future -> future.cancel(false));
}
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class IcmpHandler method selectRouterIpAddress.
private IpAddress selectRouterIpAddress(IpAddress destIpAddress, ConnectPoint outPort, Set<ConnectPoint> connectPoints) {
IpAddress routerIpAddress;
// Let's get first the online connect points
Set<ConnectPoint> onlineCps = connectPoints.stream().filter(connectPoint -> srManager.deviceService.isAvailable(connectPoint.deviceId())).collect(Collectors.toSet());
// Check if ping is local
if (onlineCps.contains(outPort)) {
routerIpAddress = config.getRouterIpAddress(destIpAddress, outPort.deviceId());
log.trace("Local ping received from {} - send to {}", destIpAddress, routerIpAddress);
return routerIpAddress;
}
// Check if it comes from a remote device. Loopbacks are sorted comparing byte by byte
// FIXME if we lose both links from the chosen leaf to spine - ping will fail
routerIpAddress = onlineCps.stream().filter(onlineCp -> !onlineCp.deviceId().equals(outPort.deviceId())).map(selectedCp -> config.getRouterIpAddress(destIpAddress, selectedCp.deviceId())).filter(Objects::nonNull).sorted().findFirst().orElse(null);
if (routerIpAddress != null) {
log.trace("Remote ping received from {} - send to {}", destIpAddress, routerIpAddress);
} else {
log.warn("Not found a valid loopback for ping coming from {} - {}", destIpAddress, outPort);
}
return routerIpAddress;
}
Aggregations