Search in sources :

Example 16 with DeviceId

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));
    }
}
Also used : HostLocation(org.onosproject.net.HostLocation) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) PredictableExecutor(org.onlab.util.PredictableExecutor) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) CompletableFuture(java.util.concurrent.CompletableFuture) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) PhasedRecoveryService(org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService) HostEvent(org.onosproject.net.host.HostEvent) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Phase(org.onosproject.segmentrouting.phasedrecovery.api.Phase) ProbeMode(org.onosproject.net.host.ProbeMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) List(java.util.List) Objective(org.onosproject.net.flowobjective.Objective) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) CompletableFuture(java.util.concurrent.CompletableFuture) Host(org.onosproject.net.Host) ExecutionException(java.util.concurrent.ExecutionException) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 17 with DeviceId

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);
    }
}
Also used : Ip6Address(org.onlab.packet.Ip6Address) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) IpAddress(org.onlab.packet.IpAddress) ICMP6(org.onlab.packet.ICMP6) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 18 with DeviceId

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);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) IpAddress(org.onlab.packet.IpAddress) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ICMP(org.onlab.packet.ICMP)

Example 19 with DeviceId

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();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) LoggerFactory(org.slf4j.LoggerFactory) ARP(org.onlab.packet.ARP) Set(java.util.Set) HostService(org.onosproject.net.host.HostService) Collectors(java.util.stream.Collectors) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) REQUEST(org.onosproject.net.neighbour.NeighbourMessageType.REQUEST) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) Ip4Address(org.onlab.packet.Ip4Address)

Example 20 with DeviceId

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);
        });
    }
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) PredictableExecutor(org.onlab.util.PredictableExecutor) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ConsistentMultimap(org.onosproject.store.service.ConsistentMultimap) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) Future(java.util.concurrent.Future) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Map(java.util.Map) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Ip6Address(org.onlab.packet.Ip6Address) ImmutableSet(com.google.common.collect.ImmutableSet) Ip4Address(org.onlab.packet.Ip4Address) ImmutableMap(com.google.common.collect.ImmutableMap) Device(org.onosproject.net.Device) Set(java.util.Set) Streams(com.google.common.collect.Streams) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Hashing(com.google.common.hash.Hashing) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Builder(com.google.common.collect.ImmutableMap.Builder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MastershipEvent(org.onosproject.mastership.MastershipEvent) Lists(com.google.common.collect.Lists) DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Hasher(com.google.common.hash.Hasher) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Maps(com.google.common.collect.Maps) PickyCallable(org.onlab.util.PredictableExecutor.PickyCallable) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Lock(java.util.concurrent.locks.Lock) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Collections(java.util.Collections) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList)

Aggregations

DeviceId (org.onosproject.net.DeviceId)782 List (java.util.List)178 PortNumber (org.onosproject.net.PortNumber)170 Collectors (java.util.stream.Collectors)152 ConnectPoint (org.onosproject.net.ConnectPoint)152 Set (java.util.Set)138 DeviceService (org.onosproject.net.device.DeviceService)122 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)118 ArrayList (java.util.ArrayList)115 VlanId (org.onlab.packet.VlanId)115 Logger (org.slf4j.Logger)114 Collections (java.util.Collections)109 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)109 Device (org.onosproject.net.Device)107 Collection (java.util.Collection)106 Test (org.junit.Test)104 CoreService (org.onosproject.core.CoreService)103 FlowRule (org.onosproject.net.flow.FlowRule)101 ImmutableSet (com.google.common.collect.ImmutableSet)99 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)96