Search in sources :

Example 1 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class DefaultRoutingHandler method populateEcmpRoutingRulePartial.

/**
 * Populate ECMP rules for subnets from target to destination via nexthops.
 *
 * @param targetSw Device ID of target switch in which rules will be programmed
 * @param destSw1 Device ID of final destination switch to which the rules will forward
 * @param destSw2 Device ID of paired destination switch to which the rules will forward
 *                A null deviceId indicates packets should only be sent to destSw1
 * @param nextHops Map of a set of next hops per destSw
 * @param subnets Subnets to be populated. If empty, populate all configured subnets.
 * @return true if it succeeds in populating rules
 */
// refactor
private boolean populateEcmpRoutingRulePartial(DeviceId targetSw, DeviceId destSw1, DeviceId destSw2, Map<DeviceId, Set<DeviceId>> nextHops, Set<IpPrefix> subnets) {
    boolean result;
    // If both target switch and dest switch are edge routers, then set IP
    // rule for both subnet and router IP.
    boolean targetIsEdge;
    boolean dest1IsEdge;
    Ip4Address dest1RouterIpv4, dest2RouterIpv4 = null;
    Ip6Address dest1RouterIpv6, dest2RouterIpv6 = null;
    try {
        targetIsEdge = config.isEdgeDevice(targetSw);
        dest1IsEdge = config.isEdgeDevice(destSw1);
        dest1RouterIpv4 = config.getRouterIpv4(destSw1);
        dest1RouterIpv6 = config.getRouterIpv6(destSw1);
        if (destSw2 != null) {
            dest2RouterIpv4 = config.getRouterIpv4(destSw2);
            dest2RouterIpv6 = config.getRouterIpv6(destSw2);
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting populateEcmpRoutingRulePartial.");
        return false;
    }
    if (targetIsEdge && dest1IsEdge) {
        List<Set<IpPrefix>> batchedSubnets;
        if (subnets != null && !subnets.isEmpty()) {
            batchedSubnets = Lists.<Set<IpPrefix>>newArrayList(Sets.newHashSet(subnets));
        } else {
            batchedSubnets = config.getBatchedSubnets(destSw1);
        }
        // XXX - Rethink this - ignoring routerIPs in all other switches
        // even edge to edge switches
        /*subnets.add(dest1RouterIpv4.toIpPrefix());
            if (dest1RouterIpv6 != null) {
                subnets.add(dest1RouterIpv6.toIpPrefix());
            }
            if (destSw2 != null && dest2RouterIpv4 != null) {
                subnets.add(dest2RouterIpv4.toIpPrefix());
                if (dest2RouterIpv6 != null) {
                    subnets.add(dest2RouterIpv6.toIpPrefix());
                }
            }*/
        log.trace("getSubnets on {}: {}", destSw1, batchedSubnets);
        for (Set<IpPrefix> prefixes : batchedSubnets) {
            log.debug(". populateEcmpRoutingRulePartial in device {} towards {} {} " + "for subnets {}", targetSw, destSw1, (destSw2 != null) ? ("& " + destSw2) : "", prefixes);
            if (!rulePopulator.populateIpRuleForSubnet(targetSw, prefixes, destSw1, destSw2, nextHops)) {
                return false;
            }
        }
    }
    if (!targetIsEdge && dest1IsEdge) {
        // MPLS rules in all non-edge target devices. These rules are for
        // individual destinations, even if the dsts are part of edge-pairs.
        log.debug(". populateEcmpRoutingRulePartial in device{} towards {} for " + "all MPLS rules", targetSw, destSw1);
        result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv4);
        if (!result) {
            return false;
        }
        if (dest1RouterIpv6 != null) {
            int v4sid = 0, v6sid = 0;
            try {
                v4sid = config.getIPv4SegmentId(destSw1);
                v6sid = config.getIPv6SegmentId(destSw1);
            } catch (DeviceConfigNotFoundException e) {
                log.warn(e.getMessage());
            }
            if (v4sid != v6sid) {
                result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv6);
                if (!result) {
                    return false;
                }
            }
        }
    }
    if (!targetIsEdge && !dest1IsEdge) {
        // MPLS rules for inter-connected spines
        // can be merged with above if, left it here for clarity
        log.debug(". populateEcmpRoutingRulePartial in device{} towards {} for " + "all MPLS rules", targetSw, destSw1);
        result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv4);
        if (!result) {
            return false;
        }
        if (dest1RouterIpv6 != null) {
            int v4sid = 0, v6sid = 0;
            try {
                v4sid = config.getIPv4SegmentId(destSw1);
                v6sid = config.getIPv6SegmentId(destSw1);
            } catch (DeviceConfigNotFoundException e) {
                log.warn(e.getMessage());
            }
            if (v4sid != v6sid) {
                result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv6);
                if (!result) {
                    return false;
                }
            }
        }
    }
    // avoid loopback IP rules in edge-devices to non-edge-devices
    return true;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException 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 3 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException 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 4 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class IcmpHandler method sendPacketOut.

/**
 * Utility function to send packet out.
 *
 * @param outport the output port
 * @param payload the packet to send
 * @param destSid the segment id of the dest device
 * @param destIpAddress the destination ip address
 * @param allowedHops the hop limit/ttl
 */
private void sendPacketOut(ConnectPoint outport, Ethernet payload, int destSid, IpAddress destIpAddress, byte allowedHops) {
    int origSid;
    try {
        if (destIpAddress.isIp4()) {
            origSid = config.getIPv4SegmentId(outport.deviceId());
        } else {
            origSid = config.getIPv6SegmentId(outport.deviceId());
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting sendPacketOut");
        return;
    }
    if (destSid == -1 || origSid == destSid || srManager.interfaceService.isConfigured(outport)) {
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
        OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
        log.trace("Sending packet {} to {}", payload, outport);
        srManager.packetService.emit(packet);
    } else {
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
        payload.setEtherType(Ethernet.MPLS_UNICAST);
        MPLS mplsPkt = new MPLS();
        mplsPkt.setLabel(destSid);
        mplsPkt.setTtl(allowedHops);
        mplsPkt.setPayload(payload.getPayload());
        payload.setPayload(mplsPkt);
        OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
        log.trace("Sending packet {} to {}", payload, outport);
        srManager.packetService.emit(packet);
    }
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MPLS(org.onlab.packet.MPLS)

Example 5 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method updateDefaultRouteBlackhole.

private void updateDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address, boolean install) {
    try {
        if (srManager.deviceConfiguration.isEdgeDevice(deviceId)) {
            TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
            if (address.isIp4()) {
                sbuilder.matchIPDst(address);
                sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort());
            } else {
                sbuilder.matchIPv6Dst(address);
                sbuilder.matchEthType(EthType.EtherType.IPV6.ethType().toShort());
            }
            TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
            tBuilder.wipeDeferred();
            ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
            fob.withFlag(Flag.SPECIFIC).withSelector(sbuilder.build()).withTreatment(tBuilder.build()).withPriority(getPriorityFromPrefix(address)).fromApp(srManager.appId).makePermanent();
            log.debug("{} blackhole forwarding objectives for dev: {}", install ? "Installing" : "Removing", deviceId);
            ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Forward for {} {}", deviceId, install ? "installed" : "removed"), (objective, error) -> log.warn("Failed to {} forward for {}: {}", install ? "install" : "remove", deviceId, error));
            if (install) {
                srManager.flowObjectiveService.forward(deviceId, fob.add(context));
            } else {
                srManager.flowObjectiveService.forward(deviceId, fob.remove(context));
            }
        }
    } catch (DeviceConfigNotFoundException e) {
        log.info("Not populating blackhole for un-configured device {}", deviceId);
    }
}
Also used : DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Aggregations

DeviceConfigNotFoundException (org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)48 DeviceId (org.onosproject.net.DeviceId)24 ConnectPoint (org.onosproject.net.ConnectPoint)22 MacAddress (org.onlab.packet.MacAddress)18 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)18 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)18 PortNumber (org.onosproject.net.PortNumber)11 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)11 Set (java.util.Set)10 IpAddress (org.onlab.packet.IpAddress)9 VlanId (org.onlab.packet.VlanId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)9 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)9 Ip4Address (org.onlab.packet.Ip4Address)8 Ip6Address (org.onlab.packet.Ip6Address)8 Logger (org.slf4j.Logger)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7