Search in sources :

Example 11 with ConnectPoint

use of org.onosproject.net.ConnectPoint 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 12 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class SegmentRoutingAppConfig method suppressHostByPort.

/**
 * Gets connect points to which SegmentRouting does not push host rules.
 *
 * @return Set of connect points, empty if not specified, or null
 *         if not valid
 */
public Set<ConnectPoint> suppressHostByPort() {
    if (!object.has(SUPPRESS_HOST_BY_PORT)) {
        return ImmutableSet.of();
    }
    ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
    ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST_BY_PORT);
    for (JsonNode jsonNode : arrayNode) {
        String portName = jsonNode.asText(null);
        if (portName == null) {
            return null;
        }
        try {
            builder.add(ConnectPoint.deviceConnectPoint(portName));
        } catch (IllegalArgumentException e) {
            return null;
        }
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 13 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method bridgingFwdObjBuilder.

/**
 * Generates a forwarding objective builder for bridging rules.
 * <p>
 * The forwarding objective bridges packets destined to a given MAC to
 * given port on given device.
 *
 * @param deviceId Device that host attaches to
 * @param mac MAC address of the host
 * @param hostVlanId VLAN ID of the host
 * @param outport Port that host attaches to
 * @param revoke true if forwarding objective is meant to revoke forwarding rule
 * @return Forwarding objective builder
 */
private ForwardingObjective.Builder bridgingFwdObjBuilder(DeviceId deviceId, MacAddress mac, VlanId hostVlanId, PortNumber outport, boolean revoke) {
    ConnectPoint connectPoint = new ConnectPoint(deviceId, outport);
    VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
    Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
    VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
    // Create host selector
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    sbuilder.matchEthDst(mac);
    // Create host treatment
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.immediate().setOutput(outport);
    // Create host meta
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
    // Adjust the selector, treatment and meta according to VLAN configuration
    if (taggedVlans.contains(hostVlanId)) {
        sbuilder.matchVlanId(hostVlanId);
        mbuilder.matchVlanId(hostVlanId);
    } else if (hostVlanId.equals(VlanId.NONE)) {
        if (untaggedVlan != null) {
            sbuilder.matchVlanId(untaggedVlan);
            mbuilder.matchVlanId(untaggedVlan);
            tbuilder.immediate().popVlan();
        } else if (nativeVlan != null) {
            sbuilder.matchVlanId(nativeVlan);
            mbuilder.matchVlanId(nativeVlan);
            tbuilder.immediate().popVlan();
        } else {
            log.warn("Untagged host {}/{} is not allowed on {} without untagged or native " + "vlan config", mac, hostVlanId, connectPoint);
            return null;
        }
    } else {
        log.warn("Tagged host {}/{} is not allowed on {} without VLAN listed in tagged vlan", mac, hostVlanId, connectPoint);
        return null;
    }
    // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed.
    // If the objective is to revoke an existing rule, and for some reason
    // the next-objective does not exist, then a new one should not be created
    int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport, tbuilder.build(), mbuilder.build(), !revoke);
    if (portNextObjId == -1) {
        // Warning log will come from getPortNextObjective method
        return null;
    }
    return DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.SPECIFIC).withSelector(sbuilder.build()).nextStep(portNextObjId).withPriority(100).fromApp(srManager.appId).makePermanent();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 14 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method anyDoubleTaggedHost.

/**
 * Checks if there is any double tagged host attached to given location.
 * This method will match on the effective location of a host.
 * That is, it will match on auxLocations when auxLocations is not null. Otherwise, it will match on locations.
 *
 * @param deviceId device ID
 * @param portNum port number
 * @return true if there is any host attached to given location.
 */
private boolean anyDoubleTaggedHost(DeviceId deviceId, PortNumber portNum) {
    ConnectPoint cp = new ConnectPoint(deviceId, portNum);
    Set<Host> connectedHosts = srManager.hostService.getConnectedHosts(cp, false);
    Set<Host> auxConnectedHosts = srManager.hostService.getConnectedHosts(cp, true);
    return !auxConnectedHosts.isEmpty() || connectedHosts.stream().anyMatch(host -> host.auxLocations() == null);
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) TYPE_IPV6(org.onlab.packet.Ethernet.TYPE_IPV6) CLEANUP_DOUBLE_TAGGED_HOST_ENTRIES(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.CLEANUP_DOUBLE_TAGGED_HOST_ENTRIES) Interface(org.onosproject.net.intf.Interface) INTERFACE_CONFIG_UPDATE(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.INTERFACE_CONFIG_UPDATE) ROUTER_ADVERTISEMENT(org.onlab.packet.ICMP6.ROUTER_ADVERTISEMENT) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) TYPE_ARP(org.onlab.packet.Ethernet.TYPE_ARP) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) NEIGHBOR_SOLICITATION(org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION) Port(org.onosproject.net.Port) Map(java.util.Map) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) Device(org.onosproject.net.Device) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) Set(java.util.Set) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Optional(java.util.Optional) NEIGHBOR_ADVERTISEMENT(org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) INFRA_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.INFRA_PORT) Flag(org.onosproject.net.flowobjective.ForwardingObjective.Flag) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) PAIR_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.PAIR_PORT) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PROTOCOL_ICMP6(org.onlab.packet.IPv6.PROTOCOL_ICMP6) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) IPv6(org.onlab.packet.IPv6) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) DestinationSet(org.onosproject.segmentrouting.grouphandler.DestinationSet) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) PacketPriority(org.onosproject.net.packet.PacketPriority) Collections(java.util.Collections) ROUTER_SOLICITATION(org.onlab.packet.ICMP6.ROUTER_SOLICITATION) Host(org.onosproject.net.Host) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 15 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method getTreatmentAndMeta.

private ImmutablePair<TrafficTreatment, TrafficSelector> getTreatmentAndMeta(DeviceId deviceId, MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, VlanId innerVlan, EthType outerTpid) throws DeviceConfigNotFoundException {
    MacAddress routerMac;
    routerMac = config.getDeviceMac(deviceId);
    ConnectPoint connectPoint = new ConnectPoint(deviceId, outPort);
    VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
    Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
    VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
    // Create route treatment
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().deferred().setEthDst(hostMac).setEthSrc(routerMac).setOutput(outPort);
    // Create route meta
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
    // Adjust treatment and meta according to VLAN configuration
    if (taggedVlans.contains(hostVlanId)) {
        mbuilder.matchVlanId(hostVlanId);
        tbuilder.setVlanId(hostVlanId);
    } else if (hostVlanId.equals(VlanId.NONE)) {
        if (untaggedVlan != null) {
            mbuilder.matchVlanId(untaggedVlan);
            tbuilder.popVlan();
        } else if (nativeVlan != null) {
            mbuilder.matchVlanId(nativeVlan);
            tbuilder.popVlan();
        } else {
            log.warn("Untagged nexthop {}/{} is not allowed on {} without untagged or native vlan", hostMac, hostVlanId, connectPoint);
            return null;
        }
    } else {
        // Double tagged hosts
        if (innerVlan == null || outerTpid == null) {
            log.warn("Failed to construct NextObj for double tagged hosts {}/{}. {} {}", hostMac, hostVlanId, (innerVlan == null) ? "innerVlan = null." : "", (outerTpid == null) ? "outerTpid = null." : "");
            return null;
        }
        tbuilder.setVlanId(innerVlan);
        tbuilder.pushVlan(outerTpid);
        tbuilder.setVlanId(hostVlanId);
        mbuilder.matchVlanId(VlanId.ANY);
    }
    return ImmutablePair.of(tbuilder.build(), mbuilder.build());
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId)

Aggregations

ConnectPoint (org.onosproject.net.ConnectPoint)536 Test (org.junit.Test)149 DeviceId (org.onosproject.net.DeviceId)125 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)91 Link (org.onosproject.net.Link)88 Set (java.util.Set)86 PortNumber (org.onosproject.net.PortNumber)86 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)83 VlanId (org.onlab.packet.VlanId)78 TrafficSelector (org.onosproject.net.flow.TrafficSelector)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)72 Logger (org.slf4j.Logger)71 Port (org.onosproject.net.Port)70 List (java.util.List)69 Ethernet (org.onlab.packet.Ethernet)69 DeviceService (org.onosproject.net.device.DeviceService)67 Collectors (java.util.stream.Collectors)66 MacAddress (org.onlab.packet.MacAddress)64 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)64 Intent (org.onosproject.net.intent.Intent)62