Search in sources :

Example 21 with IPCriterion

use of org.onosproject.net.flow.criteria.IPCriterion in project fabric-tna by stratum.

the class ForwardingObjectiveTranslator method ipv4RoutingRule.

private void ipv4RoutingRule(ForwardingObjective obj, Set<Criterion> criteriaWithMeta, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    final IPCriterion ipDstCriterion = (IPCriterion) criterionNotNull(criteriaWithMeta, Criterion.Type.IPV4_DST);
    if (ipDstCriterion.ip().prefixLength() == 0) {
        defaultIpv4Route(obj, resultBuilder);
        return;
    }
    final TrafficSelector selector = DefaultTrafficSelector.builder().add(ipDstCriterion).build();
    resultBuilder.addFlowRule(flowRule(obj, P4InfoConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, selector));
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Example 22 with IPCriterion

use of org.onosproject.net.flow.criteria.IPCriterion in project fabric-tna by stratum.

the class FabricIntProgrammable method buildCollectorSelector.

private TrafficSelector buildCollectorSelector(Set<Criterion> criteria) {
    TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
    // We always match packets with valid IPv4 header
    PiCriterion.Builder piBuilder = PiCriterion.builder().matchExact(P4InfoConstants.HDR_IPV4_VALID, 1);
    for (Criterion criterion : criteria) {
        switch(criterion.type()) {
            case IP_PROTO:
                builder.matchIPProtocol((byte) ((IPProtocolCriterion) criterion).protocol());
                break;
            case IPV4_SRC:
                builder.matchIPSrc(((IPCriterion) criterion).ip());
                break;
            case IPV4_DST:
                builder.matchIPDst(((IPCriterion) criterion).ip());
                break;
            case TCP_SRC:
                // TODO: Match a range of TCP port
                piBuilder.matchRange(P4InfoConstants.HDR_L4_SPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), ((TcpPortCriterion) criterion).tcpPort().toInt());
                break;
            case UDP_SRC:
                // TODO: Match a range of UDP port
                piBuilder.matchRange(P4InfoConstants.HDR_L4_SPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), ((UdpPortCriterion) criterion).udpPort().toInt());
                break;
            case TCP_DST:
                // TODO: Match a range of TCP port
                piBuilder.matchRange(P4InfoConstants.HDR_L4_DPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), ((TcpPortCriterion) criterion).tcpPort().toInt());
                break;
            case UDP_DST:
                // TODO: Match a range of UDP port
                piBuilder.matchRange(P4InfoConstants.HDR_L4_DPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), ((UdpPortCriterion) criterion).udpPort().toInt());
                break;
            default:
                log.warn("Unsupported criterion type: {}", criterion.type());
        }
    }
    return builder.matchPi(piBuilder.build()).build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Example 23 with IPCriterion

use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.

the class FlowRuleJuniperImpl method manageRules.

private Collection<FlowRule> manageRules(Collection<FlowRule> rules, OperationType type) {
    DeviceId deviceId = this.data().deviceId();
    log.debug("{} flow entries to NETCONF device {}", type, deviceId);
    NetconfSession session = lookupNetconfSession(deviceId);
    Collection<FlowRule> managedRules = new HashSet<>();
    for (FlowRule flowRule : rules) {
        Optional<IPCriterion> ipCriterion = getIpCriterion(flowRule);
        if (!ipCriterion.isPresent()) {
            log.error("Currently not supported: IPv4 destination match must be used");
            continue;
        }
        Optional<OutputInstruction> output = getOutput(flowRule);
        if (!output.isPresent()) {
            log.error("Currently not supported: the output action is needed");
            continue;
        }
        getStaticRoute(deviceId, ipCriterion.get(), output.get(), flowRule.priority()).ifPresent(staticRoute -> {
            // If the static route is not local, the driver tries to install
            if (!staticRoute.isLocalRoute()) {
                // FlowRule as installed.
                if (editRoute(session, type, staticRoute)) {
                    managedRules.add(flowRule);
                }
            // If static route are local, they are not installed
            // because are not required. Directly connected routes
            // are automatically forwarded.
            } else {
                managedRules.add(flowRule);
            }
        });
    }
    return rules;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DeviceId(org.onosproject.net.DeviceId) FlowRule(org.onosproject.net.flow.FlowRule) HashSet(java.util.HashSet)

Example 24 with IPCriterion

use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.

the class FlowRuleJuniperImpl method getStaticRoute.

/**
 * Helper method to convert FlowRule into an abstraction of static route
 * {@link StaticRoute}.
 *
 * @param devId    the device id
 * @param criteria the IP destination criteria
 * @param output   the output instruction
 * @return optional of Static Route
 */
private Optional<StaticRoute> getStaticRoute(DeviceId devId, IPCriterion criteria, OutputInstruction output, int priority) {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Collection<Port> ports = deviceService.getPorts(devId);
    Optional<Port> port = ports.stream().filter(x -> x.number().equals(output.port())).findAny();
    if (!port.isPresent()) {
        log.error("The port {} does not exist in the device", output.port());
        return Optional.empty();
    }
    // Find if the route refers to a local interface.
    Optional<Port> local = deviceService.getPorts(devId).stream().filter(this::isIp).filter(p -> criteria.ip().getIp4Prefix().contains(Ip4Address.valueOf(p.annotations().value(JuniperUtils.AK_IP)))).findAny();
    if (local.isPresent()) {
        return Optional.of(new StaticRoute(criteria.ip().getIp4Prefix(), criteria.ip().getIp4Prefix().address(), true, priority));
    }
    Optional<Ip4Address> nextHop = findIpDst(devId, port.get());
    if (nextHop.isPresent()) {
        return Optional.of(new StaticRoute(criteria.ip().getIp4Prefix(), nextHop.get(), false, priority));
    } else {
        log.error("The destination interface has not an IP {}", port.get());
        return Optional.empty();
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) StringUtils(org.apache.commons.lang.StringUtils) JuniperUtils.commitBuilder(org.onosproject.drivers.juniper.JuniperUtils.commitBuilder) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) AnnotationKeys(org.onosproject.net.AnnotationKeys) JuniperUtils.routeAddBuilder(org.onosproject.drivers.juniper.JuniperUtils.routeAddBuilder) Link(org.onosproject.net.Link) NetconfSession(org.onosproject.netconf.NetconfSession) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) Strings(com.google.common.base.Strings) FlowRuleService(org.onosproject.net.flow.FlowRuleService) JuniperUtils.routeDeleteBuilder(org.onosproject.drivers.juniper.JuniperUtils.routeDeleteBuilder) Port(org.onosproject.net.Port) Map(java.util.Map) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Ip4Address(org.onlab.packet.Ip4Address) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) PENDING_REMOVE(org.onosproject.net.flow.FlowEntry.FlowEntryState.PENDING_REMOVE) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Collectors(java.util.stream.Collectors) ADD(org.onosproject.drivers.juniper.JuniperUtils.OperationType.ADD) REMOVED(org.onosproject.net.flow.FlowEntry.FlowEntryState.REMOVED) Beta(com.google.common.annotations.Beta) DatastoreId(org.onosproject.netconf.DatastoreId) OperationType(org.onosproject.drivers.juniper.JuniperUtils.OperationType) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) REMOVE(org.onosproject.drivers.juniper.JuniperUtils.OperationType.REMOVE) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) JuniperUtils.rollbackBuilder(org.onosproject.drivers.juniper.JuniperUtils.rollbackBuilder) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) Ip4Address(org.onlab.packet.Ip4Address)

Example 25 with IPCriterion

use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.

the class FlowRuleJuniperImpl method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    DeviceId devId = checkNotNull(this.data().deviceId());
    NetconfSession session = lookupNetconfSession(devId);
    if (session == null) {
        return Collections.emptyList();
    }
    // Installed static routes
    String reply;
    try {
        reply = session.get(routingTableBuilder());
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
    }
    Collection<StaticRoute> devicesStaticRoutes = JuniperUtils.parseRoutingTable(loadXmlString(reply));
    // Expected FlowEntries installed
    FlowRuleService flowRuleService = this.handler().get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = flowRuleService.getFlowEntries(devId);
    Collection<FlowEntry> installedRules = new HashSet<>();
    flowEntries.forEach(flowEntry -> {
        Optional<IPCriterion> ipCriterion = getIpCriterion(flowEntry);
        if (!ipCriterion.isPresent()) {
            return;
        }
        Optional<OutputInstruction> output = getOutput(flowEntry);
        if (!output.isPresent()) {
            return;
        }
        // convert FlowRule into static route
        getStaticRoute(devId, ipCriterion.get(), output.get(), flowEntry.priority()).ifPresent(staticRoute -> {
            if (staticRoute.isLocalRoute()) {
                // if the FlowRule is in PENDING_REMOVE or REMOVED, it is not reported.
                if (flowEntry.state() == PENDING_REMOVE || flowEntry.state() == REMOVED) {
                    devicesStaticRoutes.remove(staticRoute);
                } else {
                    // FlowRule is reported installed
                    installedRules.add(flowEntry);
                    devicesStaticRoutes.remove(staticRoute);
                }
            } else {
                // if the route is found in the device, the FlowRule is reported installed.
                if (devicesStaticRoutes.contains(staticRoute)) {
                    installedRules.add(flowEntry);
                    devicesStaticRoutes.remove(staticRoute);
                }
            }
        });
    });
    if (!devicesStaticRoutes.isEmpty()) {
        log.info("Found static routes on device {} not installed by ONOS: {}", devId, devicesStaticRoutes);
    // FIXME: enable configuration to purge already installed flows.
    // It cannot be allowed by default because it may remove needed management routes
    // log.warn("Removing from device {} the FlowEntries not expected {}", deviceId, devicesStaticRoutes);
    // devicesStaticRoutes.forEach(staticRoute -> editRoute(session, REMOVE, staticRoute));
    }
    return installedRules;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DeviceId(org.onosproject.net.DeviceId) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) NetconfException(org.onosproject.netconf.NetconfException) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) HashSet(java.util.HashSet)

Aggregations

IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)25 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)22 FlowRule (org.onosproject.net.flow.FlowRule)15 Criterion (org.onosproject.net.flow.criteria.Criterion)14 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)13 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)13 IpPrefix (org.onlab.packet.IpPrefix)11 IPProtocolCriterion (org.onosproject.net.flow.criteria.IPProtocolCriterion)9 TcpPortCriterion (org.onosproject.net.flow.criteria.TcpPortCriterion)9 UdpPortCriterion (org.onosproject.net.flow.criteria.UdpPortCriterion)9 NextGroup (org.onosproject.net.behaviour.NextGroup)8 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)8 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)8 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)8 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)7 Group (org.onosproject.net.group.Group)7 FlowEntry (org.onosproject.net.flow.FlowEntry)6