Java Code Examples for org.onosproject.net.flow.TrafficSelector#getCriterion()

The following examples show how to use org.onosproject.net.flow.TrafficSelector#getCriterion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethTypeCriterion =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    VlanIdCriterion vlanIdCriterion =
            (VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID);
    if (ethTypeCriterion != null) {
        short et = ethTypeCriterion.ethType().toShort();
        if (et == Ethernet.TYPE_IPV4) {
            return processSpecificRoute(fwd);
        } else if (et == Ethernet.TYPE_VLAN) {
            /* The ForwardingObjective must specify VLAN ethtype in order to use the Transit Circuit */
            return processSpecificSwitch(fwd);
        }
    } else if (vlanIdCriterion != null) {
        return processSpecificSwitch(fwd);
    }

    fail(fwd, ObjectiveError.UNSUPPORTED);
    return ImmutableSet.of();
}
 
Example 2
Source File: OpenRoadmFlowRule.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor. Build an OpenRoadm flow rule from the passed rule.
 *
 *  @param rule ONOS flow rule that we have to process
 *  @param linePorts List of ports that are line ports (degrees) used
 *   to know the Type of this connection.
 *
 * We store and construct attributes like interface names to support
 * this OpenROADM connection.
 */
public OpenRoadmFlowRule(FlowRule rule, List<PortNumber> linePorts) {
    super(rule);

    TrafficSelector trafficSelector = rule.selector();
    PortCriterion pc = (PortCriterion) trafficSelector.getCriterion(IN_PORT);
    checkArgument(pc != null, "Missing IN_PORT Criterion");
    inPortNumber = pc.port();

    // Generally, Sigtype and ochSignal could be null. This would mean e.g. a
    // port switching connection.
    OchSignalCriterion osc = (OchSignalCriterion) trafficSelector.getCriterion(OCH_SIGID);
    // checkArgument(osc != null, "Missing OCH_SIGID Criterion");
    if (osc != null) {
        ochSignal = osc.lambda();
    }

    TrafficTreatment trafficTreatment = rule.treatment();
    List<Instruction> instructions = trafficTreatment.immediate();

    outPortNumber = instructions.stream()
                      .filter(i -> i.type() == Instruction.Type.OUTPUT)
                      .map(i -> ((OutputInstruction) i).port())
                      .findFirst()
                      .orElse(null);
    checkArgument(outPortNumber != null, "Missing OUTPUT Instruction");

    if (linePorts.contains(inPortNumber) && linePorts.contains(outPortNumber)) {
        type = Type.EXPRESS_LINK;
    }
    if (!linePorts.contains(inPortNumber) && linePorts.contains(outPortNumber)) {
        type = Type.ADD_LINK;
    }
    if (linePorts.contains(inPortNumber) && !linePorts.contains(outPortNumber)) {
        type = Type.DROP_LINK;
    }
    if (!linePorts.contains(inPortNumber) && !linePorts.contains(outPortNumber)) {
        type = Type.LOCAL;
    }
}
 
Example 3
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
static Optional<Criterion> readFromSelector(TrafficSelector selector, Criterion.Type type) {
    if (selector == null) {
        return Optional.empty();
    }
    Criterion criterion = selector.getCriterion(type);
    return (criterion == null)
            ? Optional.empty() : Optional.of(criterion);
}
 
Example 4
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isSupportedEthDstObjective(ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    EthCriterion ethDst = (EthCriterion) selector
            .getCriterion(Criterion.Type.ETH_DST);
    VlanIdCriterion vlanId = (VlanIdCriterion) selector
            .getCriterion(Criterion.Type.VLAN_VID);
    return !(ethDst == null && vlanId == null);
}
 
Example 5
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing vesatile forwarding objective");
    TrafficSelector selector = fwd.selector();

    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null) {
        log.error("Versatile forwarding objective must include ethType");
        fail(fwd, ObjectiveError.UNKNOWN);
        return ImmutableSet.of();
    }
    Builder rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(fwd.selector())
            .withTreatment(fwd.treatment())
            .withPriority(fwd.priority())
            .fromApp(fwd.appId())
            .makePermanent();
    if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
        return processArpTraffic(fwd, rule);
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_LLDP ||
            ethType.ethType().toShort() == Ethernet.TYPE_BSN) {
        return processLinkDiscovery(fwd, rule);
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        return processIpTraffic(fwd, rule);
    }
    log.warn("Driver does not support given versatile forwarding objective");
    fail(fwd, ObjectiveError.UNSUPPORTED);
    return ImmutableSet.of();
}
 
Example 6
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector
            .getCriterion(Criterion.Type.ETH_TYPE);
    return !((ethType == null) ||
            ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
                    (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) &&
                    (ethType.ethType().toShort() != Ethernet.TYPE_IPV6));
}
 
Example 7
Source File: OplinkPowerConfigUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Find matching flow on device.
 *
 * @param portNum the port number
 * @param och channel signal
 * @return flow entry
 */
private FlowEntry findFlow(PortNumber portNum, OchSignal och) {
    final DriverHandler handler = behaviour.handler();
    FlowRuleService service = handler.get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId());

    // Return first matching flow
    for (FlowEntry entry : flowEntries) {
        TrafficSelector selector = entry.selector();
        OchSignalCriterion entrySigid =
                (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID);
        // Check channel
        if (entrySigid != null && och.equals(entrySigid.lambda())) {
            // Check input port
            PortCriterion entryPort =
                    (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT);
            if (entryPort != null && portNum.equals(entryPort.port())) {
                return entry;
            }

            // Check output port
            TrafficTreatment treatment = entry.treatment();
            for (Instruction instruction : treatment.allInstructions()) {
                if (instruction.type() == Instruction.Type.OUTPUT &&
                    ((Instructions.OutputInstruction) instruction).port().equals(portNum)) {
                    return entry;
                }
            }
        }
    }
    log.warn("No matching flow found");
    return null;
}
 
Example 8
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Reads eth dst from selector.
 *
 * @param selector the given match
 * @return the eth dst if found. null otherwise
 */
static MacAddress readEthDstFromSelector(TrafficSelector selector) {
    if (selector == null) {
        return null;
    }
    Criterion criterion = selector.getCriterion(Criterion.Type.ETH_DST);
    return (criterion == null)
            ? null : ((EthCriterion) criterion).mac();
}
 
Example 9
Source File: LinkCollectionCompiler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to define the match on the ethertype.
 * If the selector define an ethertype we will use it,
 * otherwise IPv4 will be used by default.
 *
 * @param selector the traffic selector
 * @return the ethertype we should match
 */
private EthType getEthType(TrafficSelector selector) {
    Criterion c = selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (c != null && c instanceof EthTypeCriterion) {
        EthTypeCriterion ethertype = (EthTypeCriterion) c;
        return ethertype.ethType();
    }
    return EthType.EtherType.IPV4.ethType();
}
 
Example 10
Source File: SoftRouterPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private boolean matchesIp(TrafficSelector selector) {
    EthTypeCriterion c = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    return c != null && (c.ethType().equals(EthType.EtherType.IPV4.ethType()) ||
                    c.ethType().equals(EthType.EtherType.IPV6.ethType()));
}
 
Example 11
Source File: CentecV350Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }

    // Must have metadata as key.
    TrafficSelector filteredSelector =
            DefaultTrafficSelector.builder()
                    .matchEthType(Ethernet.TYPE_IPV4)
                    .matchMetadata(DEFAULT_METADATA)
                    .matchIPDst(
                            ((IPCriterion)
                                    selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
                    .build();

    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();

    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        GroupKey key = appKryo.deserialize(next.data());
        Group group = groupService.getGroup(deviceId, key);
        if (group == null) {
            log.warn("The group left!");
            fail(fwd, ObjectiveError.GROUPMISSING);
            return Collections.emptySet();
        }
        tb.group(group.id());
    }

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(ROUTE_TABLE_PRIORITY)
            .forDevice(deviceId)
            .withSelector(filteredSelector)
            .withTreatment(tb.build());

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }

    ruleBuilder.forTable(ROUTE_TABLE);

    return Collections.singletonList(ruleBuilder.build());

}
 
Example 12
Source File: LinkCollectionIntentFlowObjectiveCompilerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Single point to multiple point intent with only one switch.
 * We test the proper compilation of sp2mp with
 * trivial selector, trivial treatment and 1 hop.
 */
@Test
public void singleHopTestForSp() {
    Set<Link> testLinks = ImmutableSet.of();

    Set<FilteredConnectPoint> ingress = ImmutableSet.of(
            new FilteredConnectPoint(of1p1, vlan100Selector)
    );

    Set<FilteredConnectPoint> egress = ImmutableSet.of(
            new FilteredConnectPoint(of1p2, vlan100Selector),
            new FilteredConnectPoint(of1p3, vlan100Selector)
    );


    LinkCollectionIntent intent = LinkCollectionIntent.builder()
            .appId(appId)
            .selector(ethDstSelector)
            .treatment(treatment)
            .links(testLinks)
            .filteredIngressPoints(ingress)
            .filteredEgressPoints(egress)
            .applyTreatmentOnEgress(true)
            .resourceGroup(resourceGroup2)
            .build();

    List<Intent> result = compiler.compile(intent, Collections.emptyList());
    assertThat(result, hasSize(1));
    assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));

    FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
    List<Objective> objectives = foIntent.objectives();
    assertThat(objectives, hasSize(3));

    TrafficSelector expectSelector = DefaultTrafficSelector
            .builder(ethDstSelector)
            .matchInPort(PortNumber.portNumber(1))
            .matchVlanId(VLAN_100)
            .build();

    List<TrafficTreatment> expectTreatments = ImmutableList.of(
            DefaultTrafficTreatment.builder()
                    .setOutput(PortNumber.portNumber(2))
                    .build(),
            DefaultTrafficTreatment.builder()
                    .setOutput(PortNumber.portNumber(3))
                    .build()
    );

    /*
     * First set of objective
     */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);

    PortCriterion inPortCriterion =
            (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);

    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(),
                   null, appId, true, vlan100Selector.criteria());

    // test case for first next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);

    // test case for first forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
 
Example 13
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles forwarding rules to the L2 bridging table. Flow actions are not
 * allowed in the bridging table - instead we use L2 Interface group or
 * L2 flood group
 *
 * @param fwd the forwarding objective
 * @return A collection of flow rules, or an empty set
 */
protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) {
    List<FlowRule> rules = new ArrayList<>();

    // Build filtered selector
    TrafficSelector selector = fwd.selector();
    EthCriterion ethCriterion = (EthCriterion) selector
            .getCriterion(Criterion.Type.ETH_DST);
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector
            .getCriterion(Criterion.Type.VLAN_VID);

    if (vlanIdCriterion == null) {
        log.warn("Forwarding objective for bridging requires vlan. Not "
                + "installing fwd:{} in dev:{}", fwd.id(), deviceId);
        fail(fwd, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }

    TrafficSelector.Builder filteredSelectorBuilder =
            DefaultTrafficSelector.builder();

    if (!ethCriterion.mac().equals(NONE) &&
            !ethCriterion.mac().equals(BROADCAST)) {
        filteredSelectorBuilder.matchEthDst(ethCriterion.mac());
        log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}",
                  fwd.id(), fwd.nextId(), deviceId);
    } else {
        // Use wildcard DST_MAC if the MacAddress is None or Broadcast
        log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} "
                + "in dev:{} for vlan:{}",
                  fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
    }
    if (requireVlanExtensions()) {
        OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId());
        filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId);
    } else {
        filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId());
    }
    TrafficSelector filteredSelector = filteredSelectorBuilder.build();

    if (fwd.treatment() != null) {
        log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table"
                + "for dev:{}. Expecting only nextId", fwd.id(), deviceId);
    }

    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (fwd.nextId() != null) {
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next != null) {
            List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
            // we only need the top level group's key to point the flow to it
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group != null) {
                treatmentBuilder.deferred().group(group.id());
            } else {
                log.warn("Group with key:{} for next-id:{} not found in dev:{}",
                         gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.GROUPMISSING);
                return Collections.emptySet();
            }
        }
    }
    treatmentBuilder.immediate().transition(ACL_TABLE);
    TrafficTreatment filteredTreatment = treatmentBuilder.build();

    // Build bridging table entries
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRuleBuilder.fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector)
            .withTreatment(filteredTreatment)
            .forTable(BRIDGING_TABLE);
    if (fwd.permanent()) {
        flowRuleBuilder.makePermanent();
    } else {
        flowRuleBuilder.makeTemporary(fwd.timeout());
    }
    rules.add(flowRuleBuilder.build());
    return rules;
}
 
Example 14
Source File: TelemetryVflowListCommand.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);

    List<FlowEntry> flows =
            Lists.newArrayList(flowService.getFlowEntriesById(appId));

    print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");

    for (FlowEntry entry : flows) {
        TrafficSelector selector = entry.selector();
        IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
        IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();

        TpPort srcPort = TpPort.tpPort(0);
        TpPort dstPort = TpPort.tpPort(0);
        String protocolStr = "ANY";

        Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);

        if (ipProtocolCriterion != null) {
            short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();

            if (protocol == PROTOCOL_TCP) {
                srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
                dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
                protocolStr = TCP;
            }

            if (protocol == PROTOCOL_UDP) {
                srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                protocolStr = UDP;
            }
        }

        print(FORMAT,
                srcIp.toString(),
                srcPort.toString(),
                dstIp.toString(),
                dstPort.toString(),
                protocolStr);
    }
}
 
Example 15
Source File: StatsFlowRuleManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Set<FlowInfo> getUnderlayFlowInfos() {

    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();

    for (Device device : getUnderlayDevices()) {

        if (!isEdgeSwitch(device.id())) {
            continue;
        }

        for (FlowEntry entry : flowRuleService.getFlowEntries(device.id())) {
            FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
            TrafficSelector selector = entry.selector();
            Criterion inPort = selector.getCriterion(Criterion.Type.IN_PORT);
            Criterion dstIpCriterion = selector.getCriterion(Criterion.Type.IPV4_DST);
            if (inPort != null && dstIpCriterion != null) {
                IpAddress srcIp = getIpAddress(device, (PortCriterion) inPort);
                IpAddress dstIp = ((IPCriterion) dstIpCriterion).ip().address();

                if (srcIp == null) {
                    continue;
                }

                fBuilder.withFlowType(FLOW_TYPE_SONA)
                        .withSrcIp(IpPrefix.valueOf(srcIp, ARBITRARY_LENGTH))
                        .withDstIp(IpPrefix.valueOf(dstIp, ARBITRARY_LENGTH))
                        .withSrcMac(getMacAddress(srcIp))
                        .withDstMac(getMacAddress(dstIp))
                        .withInputInterfaceId(getInterfaceId(srcIp))
                        .withOutputInterfaceId(getInterfaceId(dstIp))
                        .withDeviceId(entry.deviceId());

                StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();

                sBuilder.withStartupTime(System.currentTimeMillis())
                        .withFstPktArrTime(System.currentTimeMillis())
                        .withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS))
                        .withCurrAccPkts((int) entry.packets())
                        .withCurrAccBytes(entry.bytes())
                        .withErrorPkts((short) 0)
                        .withDropPkts((short) 0);

                fBuilder.withStatsInfo(sBuilder.build());

                FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);

                flowInfos.add(flowInfo);
            }
        }
    }

    return flowInfos;
}
 
Example 16
Source File: OpenVSwitchPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId()).withPriority(fwd.priority())
            .forDevice(deviceId).withSelector(selector)
            .withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    Integer transition = null;
    Integer forTable = null;
    // MAC table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null
            && (selector.getCriterion(Type.ETH_DST) != null
                    || selector.getCriterion(Type.ETH_SRC) != null)) {
        forTable = MAC_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // CLASSIFIER table flow rules
    if (selector.getCriterion(Type.IN_PORT) != null) {
        forTable = CLASSIFIER_TABLE;
        if (selector.getCriterion(Type.ETH_SRC) != null
                && selector.getCriterion(Type.ETH_DST) != null) {
            transition = L3FWD_TABLE;
        } else if (selector.getCriterion(Type.ETH_SRC) != null
                || selector.getCriterion(Type.TUNNEL_ID) != null) {
            transition = MAC_TABLE;
        } else if (selector.getCriterion(Type.IPV4_DST) != null) {
            transition = DNAT_TABLE;
        } else if (selector.getCriterion(Type.ETH_TYPE) != null
                && selector.getCriterion(Type.ETH_TYPE).equals(Criteria
                        .matchEthType(EtherType.ARP.ethType().toShort()))) {
            transition = ARP_TABLE;
        }
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // ARP table flow rules
    if (selector.getCriterion(Type.ETH_TYPE) != null
            && selector.getCriterion(Type.ETH_TYPE).equals(Criteria
                    .matchEthType(EtherType.ARP.ethType().toShort()))) {
        // CLASSIFIER table arp flow rules
        if (selector.getCriterion(Type.TUNNEL_ID) == null) {
            if (selector.getCriterion(Type.ARP_OP) != null) {
                forTable = CLASSIFIER_TABLE;
                return reassemblyFlowRule(ruleBuilder, tb, null, forTable);
            }
            transition = ARP_TABLE;
            forTable = CLASSIFIER_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        forTable = ARP_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // SNAT table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null
            && selector.getCriterion(Type.IPV4_SRC) != null) {
        transition = MAC_TABLE;
        forTable = SNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // L3FWD table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null
            && selector.getCriterion(Type.IPV4_DST) != null) {
        transition = MAC_TABLE;
        forTable = L3FWD_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // DNAT table flow rules
    if (selector.getCriterion(Type.IPV4_DST) != null) {
        IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(Type.IPV4_DST);
        IpPrefix ipPrefix = ipCriterion.ip();
        // specific CLASSIFIER table flow rules for userdata
        if (ipPrefix.address().equals(IpAddress.valueOf(USERDATA_IP))) {
            forTable = CLASSIFIER_TABLE;
            transition = MAC_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        transition = L3FWD_TABLE;
        forTable = DNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 17
Source File: FabricUtils.java    From onos with Apache License 2.0 4 votes vote down vote up
public static Criterion criterion(TrafficSelector selector, Criterion.Type type) {
    return selector.getCriterion(type);
}
 
Example 18
Source File: SoftRouterPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * SoftRouter has a single specific table - the FIB Table. It emulates
 * LPM matching of dstIP by using higher priority flows for longer prefixes.
 * Flows are forwarded using flow-actions
 *
 * @param fwd The forwarding objective of type simple
 * @return A collection of flow rules meant to be delivered to the flowrule
 *         subsystem. Typically the returned collection has a single flowrule.
 *         May return empty collection in case of failures.
 *
 */
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective to next:{}", fwd.nextId());
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    // XXX currently supporting only the L3 unicast table
    if (ethType == null || (ethType.ethType().toShort() != TYPE_IPV4
            && ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    //We build the selector according the eth type.
    IpPrefix ipPrefix;
    TrafficSelector.Builder filteredSelector;
    if (ethType.ethType().toShort() == TYPE_IPV4) {
        ipPrefix = ((IPCriterion)
                selector.getCriterion(Criterion.Type.IPV4_DST)).ip();

        filteredSelector = DefaultTrafficSelector.builder()
                .matchEthType(TYPE_IPV4);
    } else {
        ipPrefix = ((IPCriterion)
                selector.getCriterion(Criterion.Type.IPV6_DST)).ip();

        filteredSelector = DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV6);
    }
    // If the prefix is different from the default via.
    if (ipPrefix.prefixLength() != 0) {
        if (ethType.ethType().toShort() == TYPE_IPV4) {
            filteredSelector.matchIPDst(ipPrefix);
        } else {
            filteredSelector.matchIPv6Dst(ipPrefix);
        }
    }

    TrafficTreatment tt = null;
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next == null) {
            log.error("next-id {} does not exist in store", fwd.nextId());
            return Collections.emptySet();
        }
        tt = appKryo.deserialize(next.data());
        if (tt == null)  {
            log.error("Error in deserializing next-id {}", fwd.nextId());
            return Collections.emptySet();
        }
    }

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector.build());

    if (tt != null) {
        ruleBuilder.withTreatment(tt);
    }

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }

    ruleBuilder.forTable(FIB_TABLE);
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 19
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true iff the given selector matches on ethtype==ipv6, indicating
 * that the selector is trying to match on ipv6 traffic.
 *
 * @param selector the given match
 * @return true iff ethtype==ipv6; false otherwise
 */
static boolean isIpv6(TrafficSelector selector) {
    EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) selector.getCriterion(ETH_TYPE);
    return ethTypeCriterion != null && ethTypeCriterion.ethType().toShort() == Ethernet.TYPE_IPV6;
}
 
Example 20
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true iff the given selector matches on BOS==true, indicating that
 * the selector is trying to match on a label that is bottom-of-stack.
 *
 * @param selector the given match
 * @return true iff BoS==true; false if BOS==false, or BOS matching is not
 *         expressed in the given selector
 */
static boolean isMplsBos(TrafficSelector selector) {
    MplsBosCriterion bosCriterion = (MplsBosCriterion) selector.getCriterion(MPLS_BOS);
    return bosCriterion != null && bosCriterion.mplsBos();
}