Search in sources :

Example 91 with Interface

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());
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ICMP6(org.onlab.packet.ICMP6) Arrays(java.util.Arrays) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) OutboundPacket(org.onosproject.net.packet.OutboundPacket) NeighbourMessageType(org.onosproject.net.neighbour.NeighbourMessageType) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ICMP(org.onlab.packet.ICMP) Collectors(java.util.stream.Collectors) IPv6(org.onlab.packet.IPv6) Objects(java.util.Objects) IPv4(org.onlab.packet.IPv4) MPLS(org.onlab.packet.MPLS) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Ip6Address(org.onlab.packet.Ip6Address) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Ethernet(org.onlab.packet.Ethernet) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 92 with Interface

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);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) InterfaceService(org.onosproject.net.intf.InterfaceService) Component(org.osgi.service.component.annotations.Component) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) Activate(org.osgi.service.component.annotations.Activate) MastershipService(org.onosproject.mastership.MastershipService) Utils(org.onosproject.ngsdn.tutorial.common.Utils) IpAddress(org.onlab.packet.IpAddress) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Ip6Address(org.onlab.packet.Ip6Address) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ItemNotFoundException(org.onlab.util.ItemNotFoundException) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PiAction(org.onosproject.net.pi.runtime.PiAction) INITIAL_SETUP_DELAY(org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY) FlowRule(org.onosproject.net.flow.FlowRule) DeviceEvent(org.onosproject.net.device.DeviceEvent) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) PiActionId(org.onosproject.net.pi.model.PiActionId) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Collection(java.util.Collection) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress) Interface(org.onosproject.net.intf.Interface) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Aggregations

Interface (org.onosproject.net.intf.Interface)92 ConnectPoint (org.onosproject.net.ConnectPoint)51 MacAddress (org.onlab.packet.MacAddress)35 VlanId (org.onlab.packet.VlanId)34 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)32 Ethernet (org.onlab.packet.Ethernet)28 IpAddress (org.onlab.packet.IpAddress)28 ArrayList (java.util.ArrayList)26 DeviceId (org.onosproject.net.DeviceId)26 Host (org.onosproject.net.Host)25 InterfaceService (org.onosproject.net.intf.InterfaceService)25 Logger (org.slf4j.Logger)25 Set (java.util.Set)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)23 LoggerFactory (org.slf4j.LoggerFactory)23 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)22 Test (org.junit.Test)21 ApplicationId (org.onosproject.core.ApplicationId)21 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)20 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)20