use of org.onosproject.net.DeviceId 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.DeviceId in project trellis-control by opennetworkinglab.
the class IcmpHandler method processIcmpv6.
// /////////////////////////////////////////
// ICMPv6 Echo/Reply Protocol //
// /////////////////////////////////////////
/**
* Process incoming ICMPv6 packet.
* If it is an ICMPv6 request to router, then sends an ICMPv6 response.
* Otherwise ignore the packet.
*
* @param eth the incoming ICMPv6 packet
* @param inPort the input port
*/
public void processIcmpv6(Ethernet eth, ConnectPoint inPort) {
DeviceId deviceId = inPort.deviceId();
IPv6 ipv6Packet = (IPv6) eth.getPayload();
ICMP6 icmp6 = (ICMP6) ipv6Packet.getPayload();
Ip6Address destinationAddress = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
IpAddress routerIp;
// Only proceed with echo request
if (icmp6.getIcmpType() != ICMP6.ECHO_REQUEST) {
return;
}
try {
routerIp = config.getRouterIpv6(deviceId);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting processPacketIn.");
return;
}
// Get pair ip - if it exists
IpAddress pairRouterIp;
try {
DeviceId pairDeviceId = config.getPairDeviceId(deviceId);
pairRouterIp = pairDeviceId != null ? config.getRouterIpv6(pairDeviceId) : null;
} catch (DeviceConfigNotFoundException e) {
pairRouterIp = null;
}
Optional<Ip6Address> linkLocalIp = getLinkLocalIp(inPort);
// Ensure ICMP to the router IP, EUI-64 link-local IP, or gateway IP
if (destinationAddress.equals(routerIp.getIp6Address()) || (linkLocalIp.isPresent() && destinationAddress.equals(linkLocalIp.get())) || (pairRouterIp != null && destinationAddress.equals(pairRouterIp.getIp6Address())) || gatewayIpAddresses.contains(destinationAddress)) {
sendIcmpv6Response(eth, inPort);
} else {
log.trace("Ignore ICMPv6 that targets for {}", destinationAddress);
}
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class IcmpHandler method processIcmp.
// ////////////////////////////////////
// ICMP Echo/Reply Protocol //
// ////////////////////////////////////
/**
* Process incoming ICMP packet.
* If it is an ICMP request to router, then sends an ICMP response.
* Otherwise ignore the packet.
*
* @param eth inbound ICMP packet
* @param inPort the input port
*/
public void processIcmp(Ethernet eth, ConnectPoint inPort) {
DeviceId deviceId = inPort.deviceId();
IPv4 ipv4Packet = (IPv4) eth.getPayload();
ICMP icmp = (ICMP) ipv4Packet.getPayload();
Ip4Address destinationAddress = Ip4Address.valueOf(ipv4Packet.getDestinationAddress());
Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
IpAddress routerIp;
// Only proceed with echo request
if (icmp.getIcmpType() != ICMP.TYPE_ECHO_REQUEST) {
return;
}
try {
routerIp = config.getRouterIpv4(deviceId);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting processPacketIn.");
return;
}
// Get pair ip - if it exists
IpAddress pairRouterIp;
try {
DeviceId pairDeviceId = config.getPairDeviceId(deviceId);
pairRouterIp = pairDeviceId != null ? config.getRouterIpv4(pairDeviceId) : null;
} catch (DeviceConfigNotFoundException e) {
pairRouterIp = null;
}
// ICMP to the router IP or gateway IP
if (destinationAddress.equals(routerIp.getIp4Address()) || (pairRouterIp != null && destinationAddress.equals(pairRouterIp.getIp4Address())) || gatewayIpAddresses.contains(destinationAddress)) {
sendIcmpResponse(eth, inPort);
} else {
log.trace("Ignore ICMP that targets for {}", destinationAddress);
}
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class ArpHandler method validateArpSpa.
/**
* Check if the source protocol address of an ARP packet belongs to the same
* subnet configured on the port it is seen.
*
* @param pkt ARP packet and context information
* @return true if the source protocol address belongs to the configured subnet
*/
private boolean validateArpSpa(NeighbourMessageContext pkt) {
Ip4Address spa = pkt.sender().getIp4Address();
Set<IpPrefix> subnet = config.getPortSubnets(pkt.inPort().deviceId(), pkt.inPort().port()).stream().filter(ipPrefix -> ipPrefix.isIp4() && ipPrefix.contains(spa)).collect(Collectors.toSet());
return !subnet.isEmpty();
}
use of org.onosproject.net.DeviceId in project trellis-control by opennetworkinglab.
the class DefaultRoutingHandler method processHashGroupChangeForFailure.
/**
* Processes a set a route-path changes due to a switch/link failure by editing hash groups.
*
* @param routeChanges a set of route-path changes, where each route-path is
* a list with its first element the src-switch of the path
* and the second element the dst-switch of the path.
* @param failedSwitch the switchId if the route changes are for a failed switch,
* otherwise null
*/
private void processHashGroupChangeForFailure(Set<ArrayList<DeviceId>> routeChanges, DeviceId failedSwitch) {
// first, ensure each routeChanges entry has two elements
Set<ArrayList<DeviceId>> changedRoutes = getAllExpandedRoutes(routeChanges);
boolean someFailed = false;
boolean success;
Set<DeviceId> updatedDevices = Sets.newHashSet();
for (ArrayList<DeviceId> route : changedRoutes) {
DeviceId targetSw = route.get(0);
DeviceId dstSw = route.get(1);
success = fixHashGroupsForRoute(route, true);
// for the impacted switch must still be updated.
if (!success && failedSwitch != null && targetSw.equals(failedSwitch)) {
currentEcmpSpgMap.put(dstSw, updatedEcmpSpgMap.get(dstSw));
currentEcmpSpgMap.remove(targetSw);
log.debug("Updating ECMPspg for dst:{} removing failed switch " + "target:{}", dstSw, targetSw);
updatedDevices.add(targetSw);
updatedDevices.add(dstSw);
continue;
}
// linkfailed - update both sides
if (success) {
currentEcmpSpgMap.put(targetSw, updatedEcmpSpgMap.get(targetSw));
currentEcmpSpgMap.put(dstSw, updatedEcmpSpgMap.get(dstSw));
log.debug("Updating ECMPspg for dst:{} and target:{} for linkdown" + " or switchdown", dstSw, targetSw);
updatedDevices.add(targetSw);
updatedDevices.add(dstSw);
} else {
someFailed = true;
}
}
if (!someFailed) {
// here is where we update all devices not touched by this instance
updatedEcmpSpgMap.keySet().stream().filter(devId -> !updatedDevices.contains(devId)).forEach(devId -> {
currentEcmpSpgMap.put(devId, updatedEcmpSpgMap.get(devId));
log.debug("Updating ECMPspg for remaining dev:{}", devId);
});
}
}
Aggregations