use of org.onosproject.net.intf.Interface in project trellis-control by opennetworkinglab.
the class IcmpHandler method sendIcmpv6Response.
/**
* Sends an ICMPv6 reply message.
*
* @param ethRequest the original ICMP request
* @param outport the output port where the ICMP reply should be sent to
*/
private void sendIcmpv6Response(Ethernet ethRequest, ConnectPoint outport) {
int destSid = -1;
Ethernet ethReply = ICMP6.buildIcmp6Reply(ethRequest);
IPv6 icmpRequestIpv6 = (IPv6) ethRequest.getPayload();
IPv6 icmpReplyIpv6 = (IPv6) ethRequest.getPayload();
// Source IP of the echo "reply"
Ip6Address srcIpAddress = Ip6Address.valueOf(icmpRequestIpv6.getDestinationAddress());
// Destination IP of the echo "reply"
Ip6Address destIpAddress = Ip6Address.valueOf(icmpRequestIpv6.getSourceAddress());
Optional<Ip6Address> linkLocalIp = getLinkLocalIp(outport);
// Fast path if the echo request targets the link-local address of switch interface
if (linkLocalIp.isPresent() && srcIpAddress.equals(linkLocalIp.get())) {
sendPacketOut(outport, ethReply, destSid, destIpAddress, icmpReplyIpv6.getHopLimit());
return;
}
// Get the available connect points
Set<ConnectPoint> destConnectPoints = config.getConnectPointsForASubnetHost(destIpAddress);
// Select a router
Ip6Address destRouterAddress = selectRouterIp6Address(destIpAddress, outport, destConnectPoints);
// Lookup the route store for the nexthop instead.
if (destRouterAddress == null) {
Optional<DeviceId> deviceId = srManager.routeService.longestPrefixLookup(destIpAddress).map(srManager::nextHopLocations).flatMap(locations -> locations.stream().findFirst()).map(ConnectPoint::deviceId);
if (deviceId.isPresent()) {
try {
destRouterAddress = config.getRouterIpv6(deviceId.get());
} catch (DeviceConfigNotFoundException e) {
log.warn("Device config for {} not found. Abort ICMPv6 processing", deviceId);
return;
}
}
}
destSid = config.getIPv6SegmentId(destRouterAddress);
if (destSid < 0) {
log.warn("Failed to lookup SID of the switch that {} attaches to. " + "Unable to process ICMPv6 request.", destIpAddress);
return;
}
sendPacketOut(outport, ethReply, destSid, destIpAddress, icmpReplyIpv6.getHopLimit());
}
use of org.onosproject.net.intf.Interface in project TFG by mattinelorza.
the class NdpReplyComponent method setUpDevice.
/**
* Performs setup of the given device by creating a flow rule to generate
* NDP NA packets for IPv6 addresses associated to the device interfaces.
*
* @param deviceId device ID
*/
private void setUpDevice(DeviceId deviceId) {
// Get this device config from netcfg.json.
final FabricDeviceConfig config = configService.getConfig(deviceId, FabricDeviceConfig.class);
if (config == null) {
// Config not available yet
throw new ItemNotFoundException("Missing fabricDeviceConfig for " + deviceId);
}
// Get this device myStation mac.
final MacAddress deviceMac = config.myStationMac();
// Get all interfaces currently configured for the device
final Collection<Interface> interfaces = interfaceService.getInterfaces().stream().filter(iface -> iface.connectPoint().deviceId().equals(deviceId)).collect(Collectors.toSet());
if (interfaces.isEmpty()) {
log.info("{} does not have any IPv6 interface configured", deviceId);
return;
}
// Generate and install flow rules.
log.info("Adding rules to {} to generate NDP NA for {} IPv6 interfaces...", deviceId, interfaces.size());
final Collection<FlowRule> flowRules = interfaces.stream().map(this::getIp6Addresses).flatMap(Collection::stream).map(ipv6addr -> buildNdpReplyFlowRule(deviceId, ipv6addr, deviceMac)).collect(Collectors.toSet());
installRules(flowRules);
}
Aggregations