org.onosproject.net.flow.criteria.PiCriterion Java Examples

The following examples show how to use org.onosproject.net.flow.criteria.PiCriterion. 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: MyTunnelApp.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts a flow rule in the system that using a PI criterion and action.
 *
 * @param switchId    switch ID
 * @param tableId     table ID
 * @param piCriterion PI criterion
 * @param piAction    PI action
 */
private void insertPiFlowRule(DeviceId switchId, PiTableId tableId,
                              PiCriterion piCriterion, PiAction piAction) {
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(switchId)
            .forTable(tableId)
            .fromApp(appId)
            .withPriority(FLOW_RULE_PRIORITY)
            .makePermanent()
            .withSelector(DefaultTrafficSelector.builder()
                                  .matchPi(piCriterion).build())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(piAction).build())
            .build();
    flowRuleService.applyFlowRules(rule);
}
 
Example #2
Source File: FabricBngProgrammable.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Build the flow rule for the table t_line_map of the BNG-U (common to both
 * upstream and downstream).
 */
private FlowRule buildTLineMapFlowRule(Attachment attachment)
        throws BngProgrammableException {
    PiCriterion criterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_S_TAG,
                    attachment.sTag().toShort())
            .matchExact(FabricConstants.HDR_C_TAG,
                    attachment.cTag().toShort())
            .build();
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder()
            .matchPi(criterion)
            .build();
    PiAction action = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_BNG_INGRESS_SET_LINE)
            .withParameter(new PiActionParam(FabricConstants.LINE_ID,
                    lineId(attachment)))
            .build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(action)
            .build();
    return buildFlowRule(trafficSelector,
            instTreatment,
            FabricConstants.FABRIC_INGRESS_BNG_INGRESS_T_LINE_MAP,
            attachment.appId());
}
 
Example #3
Source File: FabricBngProgrammable.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Build the flow rule for the table t_pppoe_cp of the ingress upstream.
 */
private FlowRule buildTPppoeCpFlowRule(PiCriterion criterion, ApplicationId appId) {
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder()
            .matchPi(criterion)
            .build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(PiAction.builder()
                    .withId(FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_PUNT_TO_CPU)
                    .build()
            )
            .build();
    return buildFlowRule(trafficSelector,
            instTreatment,
            FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_T_PPPOE_CP,
            appId);
}
 
Example #4
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    final String tableId = "IngressPipeImpl.routing_v6_table";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("hdr.ipv6.dst_addr"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #5
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a flow rule for the L2 table mapping the given next hop MAC to
 * the given output port.
 * <p>
 * This is called by the routing policy methods below to establish L2-based
 * forwarding inside the fabric, e.g., when deviceId is a leaf switch and
 * nextHopMac is the one of a spine switch.
 *
 * @param deviceId   the device
 * @param nexthopMac the next hop (destination) mac
 * @param outPort    the output port
 */
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac,
                                     PortNumber outPort) {

    final String tableId = "IngressPipeImpl.l2_exact_table";
    final PiCriterion match = PiCriterion.builder()
            .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
                        nexthopMac.toBytes())
            .build();


    final PiAction action = PiAction.builder()
            .withId(PiActionId.of("IngressPipeImpl.set_egress_port"))
            .withParameter(new PiActionParam(
                    PiActionParamId.of("port_num"),
                    outPort.toLong()))
            .build();

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #6
Source File: FabricBngProgrammable.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<Long> getLineIdsFromFlowRules(Iterable<? extends FlowRule> rules) {
    // Extract the line ID found in the flow rule selector.
    return StreamSupport.stream(rules.spliterator(), true)
            .map(f -> (PiCriterion) f.selector().getCriterion(Criterion.Type.PROTOCOL_INDEPENDENT))
            .filter(Objects::nonNull)
            .map(c -> c.fieldMatch(FabricConstants.HDR_LINE_ID))
            .filter(Optional::isPresent)
            .map(Optional::get)
            .filter(m -> m.type() == PiMatchType.EXACT)
            .map(m -> ((PiExactFieldMatch) m).value())
            .map(b -> {
                try {
                    return b.fit(Long.BYTES * 8);
                } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
                    log.error("Invalid line ID found in flow rule: {} is bigger than a long! BUG?", b);
                    return null;
                }
            })
            .filter(Objects::nonNull)
            .map(b -> b.asReadOnlyBuffer().getLong())
            .collect(Collectors.toSet());
}
 
Example #7
Source File: EncodeCriterionCodecHelper.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
    final PiCriterion piCriterion = (PiCriterion) criterion;
    ArrayNode matchNodes = context.mapper().createArrayNode();
    for (PiFieldMatch fieldMatch : piCriterion.fieldMatches()) {
        switch (fieldMatch.type()) {
            case EXACT:
                matchNodes.add(parsePiMatchExact((PiExactFieldMatch) fieldMatch));
                break;
            case LPM:
                matchNodes.add(parsePiMatchLpm((PiLpmFieldMatch) fieldMatch));
                break;
            case TERNARY:
                matchNodes.add(parsePiMatchTernary((PiTernaryFieldMatch) fieldMatch));
                break;
            case RANGE:
                matchNodes.add(parsePiMatchRange((PiRangeFieldMatch) fieldMatch));
                break;
            default:
                throw new IllegalArgumentException("Type " + fieldMatch.type().name() + " is unsupported");
        }
    }
    return (ObjectNode) root.set(CriterionCodec.PI_MATCHES, matchNodes);
}
 
Example #8
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a flow rule for the L2 table mapping the given next hop MAC to
 * the given output port.
 * <p>
 * This is called by the routing policy methods below to establish L2-based
 * forwarding inside the fabric, e.g., when deviceId is a leaf switch and
 * nextHopMac is the one of a spine switch.
 *
 * @param deviceId   the device
 * @param nexthopMac the next hop (destination) mac
 * @param outPort    the output port
 */
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac,
                                     PortNumber outPort) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "MODIFY ME";
    final PiCriterion match = PiCriterion.builder()
            .matchExact(PiMatchFieldId.of("MODIFY ME"),
                        nexthopMac.toBytes())
            .build();


    final PiAction action = PiAction.builder()
            .withId(PiActionId.of("MODIFY ME"))
            .withParameter(new PiActionParam(
                    PiActionParamId.of("MODIFY ME"),
                    outPort.toLong()))
            .build();
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #9
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "MODIFY ME";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("MODIFY ME"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #10
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l3_table";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("hdr.ipv6.dst_addr"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #11
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a flow rule for the L2 table mapping the given next hop MAC to
 * the given output port.
 * <p>
 * This is called by the routing policy methods below to establish L2-based
 * forwarding inside the fabric, e.g., when deviceId is a leaf switch and
 * nextHopMac is the one of a spine switch.
 *
 * @param deviceId   the device
 * @param nexthopMac the next hop (destination) mac
 * @param outPort    the output port
 */
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac,
                                     PortNumber outPort) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l2_exact_table";
    final PiCriterion match = PiCriterion.builder()
            .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
                        nexthopMac.toBytes())
            .build();


    final PiAction action = PiAction.builder()
            .withId(PiActionId.of("IngressPipeImpl.set_output_port"))
            .withParameter(new PiActionParam(
                    PiActionParamId.of("port_num"),
                    outPort.toLong()))
            .build();
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #12
Source File: FilteringObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowRule fwdClassifierRule(
        PortNumber inPort, short ethType, MacAddress dstMac, MacAddress dstMacMask,
        TrafficTreatment treatment, FilteringObjective obj)
        throws FabricPipelinerException {
    // Match on ip_eth_type that is the eth_type of the L3 protocol.
    // i.e., if the packet has an IP header, ip_eth_type should
    // contain the corresponding eth_type (for IPv4 or IPv6)
    final PiCriterion ethTypeCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_IP_ETH_TYPE, ethType)
            .build();
    final TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchInPort(inPort)
            .matchPi(ethTypeCriterion)
            .matchEthDstMasked(dstMac, dstMacMask == null
                    ? MacAddress.EXACT_MASK : dstMacMask)
            .build();
    return flowRule(
            obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
            selector, treatment);
}
 
Example #13
Source File: FilteringObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> mplsFwdClassifierRules(
        PortNumber inPort, MacAddress dstMac, FilteringObjective obj)
        throws FabricPipelinerException {
    // Forwarding classifier for MPLS is composed of 2 rules
    // with higher priority wrt standard forwarding classifier rules,
    // this is due to overlap on ternary matching.
    TrafficTreatment treatment = fwdClassifierTreatment(FWD_MPLS);
    final PiCriterion ethTypeMplsIpv4 = PiCriterion.builder()
            .matchTernary(FabricConstants.HDR_ETH_TYPE,
                          Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK)
            .matchExact(FabricConstants.HDR_IP_ETH_TYPE,
                        Ethernet.TYPE_IPV4)
            .build();
    final TrafficSelector selectorMplsIpv4 = DefaultTrafficSelector.builder()
            .matchInPort(inPort)
            .matchPi(ethTypeMplsIpv4)
            .matchEthDstMasked(dstMac, MacAddress.EXACT_MASK)
            .build();

    final PiCriterion ethTypeMplsIpv6 = PiCriterion.builder()
            .matchTernary(FabricConstants.HDR_ETH_TYPE,
                          Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK)
            .matchExact(FabricConstants.HDR_IP_ETH_TYPE,
                        Ethernet.TYPE_IPV6)
            .build();
    final TrafficSelector selectorMplsIpv6 = DefaultTrafficSelector.builder()
            .matchInPort(inPort)
            .matchPi(ethTypeMplsIpv6)
            .matchEthDstMasked(dstMac, MacAddress.EXACT_MASK)
            .build();

    return List.of(
            flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
                     selectorMplsIpv4, treatment, obj.priority() + 1),
            flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
                     selectorMplsIpv6, treatment, obj.priority() + 1)
    );
}
 
Example #14
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private TrafficSelector.Builder nextIdSelectorBuilder(int nextId) {
    final PiCriterion nextIdCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_NEXT_ID, nextId)
            .build();
    return DefaultTrafficSelector.builder()
            .matchPi(nextIdCriterion);
}
 
Example #15
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private void egressVlanPop(PortNumber outPort, NextObjective obj,
                           ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {

    if (obj.meta() == null) {
        throw new FabricPipelinerException(
                "Cannot process egress pop VLAN rule, NextObjective has null meta",
                ObjectiveError.BADPARAMS);
    }

    final VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion(
            obj.meta(), Criterion.Type.VLAN_VID);
    if (vlanIdCriterion == null) {
        throw new FabricPipelinerException(
                "Cannot process egress pop VLAN rule, missing VLAN_VID criterion " +
                        "in NextObjective meta",
                ObjectiveError.BADPARAMS);
    }

    final PiCriterion egressVlanTableMatch = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong())
            .build();
    final TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchPi(egressVlanTableMatch)
            .matchVlanId(vlanIdCriterion.vlanId())
            .build();
    final TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .popVlan()
            .build();

    resultBuilder.addFlowRule(flowRule(
            obj, FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN,
            selector, treatment));
}
 
Example #16
Source File: FabricIntProgrammable.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setSinkPort(PortNumber port) {

    if (!setupBehaviour()) {
        return false;
    }

    PiCriterion egressCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_EG_PORT, port.toLong())
            .build();
    TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
            .matchPi(egressCriterion)
            .build();
    PiAction setSinkAct = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SINK)
            .build();
    TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(setSinkAct)
            .build();
    FlowRule sinkFlowRule = DefaultFlowRule.builder()
            .withSelector(sinkSelector)
            .withTreatment(sinkTreatment)
            .fromApp(appId)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK)
            .build();
    flowRuleService.applyFlowRules(sinkFlowRule);
    return true;
}
 
Example #17
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the "My Station" table for the given device using the
 * myStationMac address found in the config.
 * <p>
 * This method will be called at component activation for each device
 * (switch) known by ONOS, and every time a new device-added event is
 * captured by the InternalDeviceListener defined below.
 *
 * @param deviceId the device ID
 */
private void setUpMyStationTable(DeviceId deviceId) {

    log.info("Adding My Station rules to {}...", deviceId);

    final MacAddress myStationMac = getMyStationMac(deviceId);

    // HINT: in our solution, the My Station table matches on the *ethernet
    // destination* and there is only one action called *NoAction*, which is
    // used as an indication of "table hit" in the control block.

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l2_my_station";

    final PiCriterion match = PiCriterion.builder()
            .matchExact(
                    PiMatchFieldId.of("hdr.ethernet.dst_addr"),
                    myStationMac.toBytes())
            .build();

    // Creates an action which do *NoAction* when hit.
    final PiTableAction action = PiAction.builder()
            .withId(PiActionId.of("NoAction"))
            .build();
    // ---- END SOLUTION ----

    final FlowRule myStationRule = Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);

    flowRuleService.applyFlowRules(myStationRule);
}
 
Example #18
Source File: CriterionCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests protocol-independent type criterion decoding.
 */
@Test
public void matchPiTypeDecodingTest() throws IOException {
    Criterion criterion = getCriterion("PiCriterion.json");
    Assert.assertThat(criterion.type(), is(Criterion.Type.PROTOCOL_INDEPENDENT));
    Collection<PiFieldMatch> piFieldMatches = ((PiCriterion) criterion).fieldMatches();
    for (PiFieldMatch piFieldMatch : piFieldMatches) {
        switch (piFieldMatch.type()) {
            case EXACT:
                Assert.assertThat(piFieldMatch.fieldId().id(), is("ingress_port"));
                Assert.assertThat(((PiExactFieldMatch) piFieldMatch).value(), is(
                        copyFrom((byte) 0x10)));
                break;
            case LPM:
                Assert.assertThat(piFieldMatch.fieldId().id(), is("src_addr"));
                Assert.assertThat(((PiLpmFieldMatch) piFieldMatch).value(),
                                  is(copyFrom(0xa010101)));
                Assert.assertThat(((PiLpmFieldMatch) piFieldMatch).prefixLength(), is(24));
                break;
            case TERNARY:
                Assert.assertThat(piFieldMatch.fieldId().id(), is("dst_addr"));
                Assert.assertThat(((PiTernaryFieldMatch) piFieldMatch).value(),
                                  is(copyFrom(0xa010101)));
                Assert.assertThat(((PiTernaryFieldMatch) piFieldMatch).mask(),
                                  is(copyFrom(0xfffffff)));
                break;
            case RANGE:
                Assert.assertThat(piFieldMatch.fieldId().id(), is("egress_port"));
                Assert.assertThat(((PiRangeFieldMatch) piFieldMatch).highValue(),
                                  is(copyFrom((byte) 0x20)));
                Assert.assertThat(((PiRangeFieldMatch) piFieldMatch).lowValue(),
                                  is(copyFrom((byte) 0x10)));
                break;
            default:
                Assert.fail();
        }
    }
}
 
Example #19
Source File: FabricIntProgrammable.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setSourcePort(PortNumber port) {

    if (!setupBehaviour()) {
        return false;
    }

    PiCriterion ingressCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_IG_PORT, port.toLong())
            .build();
    TrafficSelector srcSelector = DefaultTrafficSelector.builder()
            .matchPi(ingressCriterion)
            .build();
    PiAction setSourceAct = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE)
            .build();
    TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(setSourceAct)
            .build();
    FlowRule srcFlowRule = DefaultFlowRule.builder()
            .withSelector(srcSelector)
            .withTreatment(srcTreatment)
            .fromApp(appId)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE)
            .build();
    flowRuleService.applyFlowRules(srcFlowRule);
    return true;
}
 
Example #20
Source File: FabricBngProgrammable.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
     * Build the Flow Rule for the table t_pppoe_term_v4 of the ingress
     * upstream.
     */
    private FlowRule buildTPppoeTermV4FlowRule(Attachment attachment)
            throws BngProgrammableException {
        PiCriterion criterion = PiCriterion.builder()
                .matchExact(FabricConstants.HDR_LINE_ID,
                        lineId(attachment))
                .matchExact(FabricConstants.HDR_IPV4_SRC,
                        attachment.ipAddress().toOctets())
                .matchExact(FabricConstants.HDR_PPPOE_SESSION_ID,
                        attachment.pppoeSessionId())
                // TODO: match on MAC SRC address (antispoofing)
//                    .matchExact(FabricConstants.HDR_ETH_SRC,
//                                attachment.macAddress.toBytes())
                .build();
        TrafficSelector trafficSelector = DefaultTrafficSelector.builder()
                .matchPi(criterion)
                .build();
        PiAction action = PiAction.builder()
                .withId(attachment.lineActive() ?
                        FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_TERM_ENABLED_V4 :
                        FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_TERM_DISABLED)
                .build();
        TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
                .piTableAction(action)
                .build();
        return buildFlowRule(trafficSelector,
                instTreatment,
                FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_T_PPPOE_TERM_V4,
                attachment.appId());
    }
 
Example #21
Source File: FabricFilteringPipelinerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private PiCriterion buildPiCriterionVlan(VlanId vlanId,
                                         VlanId innerVlanId) {
    PiCriterion.Builder piCriterionBuilder = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_VLAN_IS_VALID,
                        vlanValid(vlanId) ? ONE : ZERO);
    return piCriterionBuilder.build();
}
 
Example #22
Source File: FabricFilteringPipelinerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> buildExpectedFwdClassifierRule(PortNumber inPort,
                                                            MacAddress dstMac,
                                                            MacAddress dstMacMask,
                                                            short ethType,
                                                            byte fwdClass) {
    PiActionParam classParam = new PiActionParam(FabricConstants.FWD_TYPE,
                                                 ImmutableByteSequence.copyFrom(fwdClass));
    PiAction fwdClassifierAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE)
            .withParameter(classParam)
            .build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(fwdClassifierAction)
            .build();

    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
            .matchInPort(inPort);
    if (dstMacMask != null) {
        sbuilder.matchEthDstMasked(dstMac, dstMacMask);
    } else {
        sbuilder.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK);
    }
    // Special case for MPLS UNICAST forwarding, need to build 2 rules for MPLS+IPv4 and MPLS+IPv6
    if (ethType == Ethernet.MPLS_UNICAST) {
        return buildExpectedFwdClassifierRulesMpls(fwdClassifierAction, treatment, sbuilder);
    }
    sbuilder.matchPi(PiCriterion.builder()
                             .matchExact(FabricConstants.HDR_IP_ETH_TYPE, ethType)
                             .build());
    TrafficSelector selector = sbuilder.build();
    return List.of(DefaultFlowRule.builder()
                           .withPriority(PRIORITY)
                           .withSelector(selector)
                           .withTreatment(treatment)
                           .fromApp(APP_ID)
                           .forDevice(DEVICE_ID)
                           .makePermanent()
                           .forTable(FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER)
                           .build());
}
 
Example #23
Source File: FabricFilteringPipelinerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> buildExpectedFwdClassifierRulesMpls(PiAction fwdClassifierAction,
                                                                 TrafficTreatment treatment,
                                                                 TrafficSelector.Builder selectorBuilder) {

    Collection<FlowRule> flowRules = Lists.newArrayList();
    TrafficSelector selectorIpv4 = selectorBuilder
            .add(PiCriterion.builder()
                         .matchTernary(FabricConstants.HDR_ETH_TYPE, Ethernet.MPLS_UNICAST, EXACT_MATCH_ETH_TYPE)
                         .matchExact(FabricConstants.HDR_IP_ETH_TYPE, Ethernet.TYPE_IPV4)
                         .build())
            .build();
    TrafficSelector selectorIpv6 = selectorBuilder
            .add(PiCriterion.builder()
                         .matchTernary(FabricConstants.HDR_ETH_TYPE, Ethernet.MPLS_UNICAST, EXACT_MATCH_ETH_TYPE)
                         .matchExact(FabricConstants.HDR_IP_ETH_TYPE, Ethernet.TYPE_IPV6)
                         .build())
            .build();
    flowRules.add(DefaultFlowRule.builder()
                          .withPriority(PRIORITY + 1)
                          .withSelector(selectorIpv4)
                          .withTreatment(treatment)
                          .fromApp(APP_ID)
                          .forDevice(DEVICE_ID)
                          .makePermanent()
                          .forTable(FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER)
                          .build());
    flowRules.add(DefaultFlowRule.builder()
                          .withPriority(PRIORITY + 1)
                          .withSelector(selectorIpv6)
                          .withTreatment(treatment)
                          .fromApp(APP_ID)
                          .forDevice(DEVICE_ID)
                          .makePermanent()
                          .forTable(FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER)
                          .build());
    return flowRules;
}
 
Example #24
Source File: FabricNextPipelinerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    super.doSetup();

    translatorHashed = new NextObjectiveTranslator(DEVICE_ID, capabilitiesHashed);
    translatorSimple = new NextObjectiveTranslator(DEVICE_ID, capabilitiesSimple);

    PiCriterion nextIdCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
            .build();
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchPi(nextIdCriterion)
            .build();
    PiAction piAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
            .withParameter(new PiActionParam(FabricConstants.VLAN_ID, VLAN_100.toShort()))
            .build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(piAction)
            .build();
    vlanMetaFlowRule = DefaultFlowRule.builder()
            .withSelector(selector)
            .withTreatment(treatment)
            .forTable(FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN)
            .makePermanent()
            // FIXME: currently next objective doesn't support priority, ignore this
            .withPriority(0)
            .forDevice(DEVICE_ID)
            .fromApp(APP_ID)
            .build();
}
 
Example #25
Source File: FabricNextPipelinerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testSimple(TrafficTreatment treatment, PiAction piAction) throws FabricPipelinerException {
    NextObjective nextObjective = DefaultNextObjective.builder()
            .withId(NEXT_ID_1)
            .withPriority(PRIORITY)
            .withMeta(VLAN_META)
            .addTreatment(treatment)
            .withType(NextObjective.Type.SIMPLE)
            .makePermanent()
            .fromApp(APP_ID)
            .add();

    ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);

    // Simple table
    PiCriterion nextIdCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
            .build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder()
            .matchPi(nextIdCriterion)
            .build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder()
            .forDevice(DEVICE_ID)
            .fromApp(APP_ID)
            .makePermanent()
            // FIXME: currently next objective doesn't support priority, ignore this
            .withPriority(0)
            .forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE)
            .withSelector(nextIdSelector)
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(piAction).build())
            .build();

    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder()
            .addFlowRule(vlanMetaFlowRule)
            .addFlowRule(expectedFlowRule)
            .build();

    assertEquals(expectedTranslation, actualTranslation);
}
 
Example #26
Source File: MyTunnelApp.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Generates and insert a flow rule to perform the tunnel INGRESS function
 * for the given switch, destination IP address and tunnel ID.
 *
 * @param switchId  switch ID
 * @param dstIpAddr IP address to forward inside the tunnel
 * @param tunId     tunnel ID
 */
private void insertTunnelIngressRule(DeviceId switchId,
                                     IpAddress dstIpAddr,
                                     int tunId) {


    PiTableId tunnelIngressTableId = PiTableId.of("c_ingress.t_tunnel_ingress");

    // Longest prefix match on IPv4 dest address.
    PiMatchFieldId ipDestMatchFieldId = PiMatchFieldId.of("hdr.ipv4.dst_addr");
    PiCriterion match = PiCriterion.builder()
            .matchLpm(ipDestMatchFieldId, dstIpAddr.toOctets(), 32)
            .build();

    PiActionParam tunIdParam = new PiActionParam(PiActionParamId.of("tun_id"), tunId);

    PiActionId ingressActionId = PiActionId.of("c_ingress.my_tunnel_ingress");
    PiAction action = PiAction.builder()
            .withId(ingressActionId)
            .withParameter(tunIdParam)
            .build();

    log.info("Inserting INGRESS rule on switch {}: table={}, match={}, action={}",
             switchId, tunnelIngressTableId, match, action);

    insertPiFlowRule(switchId, tunnelIngressTableId, match, action);
}
 
Example #27
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean init() {
    if (!setupBehaviour()) {
        return false;
    }

    PiActionParam transitIdParam = new PiActionParam(
            IntConstants.SWITCH_ID,
            ImmutableByteSequence.copyFrom(
                    Integer.parseInt(deviceId.toString().substring(
                            deviceId.toString().length() - 2))));
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchPi(PiCriterion.builder().matchExact(
                    IntConstants.HDR_INT_IS_VALID, (byte) 0x01)
                     .build())
            .build();
    PiAction transitAction = PiAction.builder()
            .withId(IntConstants.EGRESS_PROCESS_INT_TRANSIT_INIT_METADATA)
            .withParameter(transitIdParam)
            .build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(transitAction)
            .build();

    FlowRule transitFlowRule = DefaultFlowRule.builder()
            .withSelector(selector)
            .withTreatment(treatment)
            .fromApp(appId)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(IntConstants.EGRESS_PROCESS_INT_TRANSIT_TB_INT_INSERT)
            .build();

    flowRuleService.applyFlowRules(transitFlowRule);

    return true;
}
 
Example #28
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setSourcePort(PortNumber port) {
    if (!setupBehaviour()) {
        return false;
    }

    // process_int_source_sink.tb_set_source for each host-facing port
    PiCriterion ingressCriterion = PiCriterion.builder()
            .matchExact(IntConstants.HDR_STANDARD_METADATA_INGRESS_PORT, port.toLong())
            .build();
    TrafficSelector srcSelector = DefaultTrafficSelector.builder()
            .matchPi(ingressCriterion)
            .build();
    PiAction setSourceAct = PiAction.builder()
            .withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_INT_SET_SOURCE)
            .build();
    TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(setSourceAct)
            .build();
    FlowRule srcFlowRule = DefaultFlowRule.builder()
            .withSelector(srcSelector)
            .withTreatment(srcTreatment)
            .fromApp(appId)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SOURCE)
            .build();
    flowRuleService.applyFlowRules(srcFlowRule);
    return true;
}
 
Example #29
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setSinkPort(PortNumber port) {
    if (!setupBehaviour()) {
        return false;
    }

    // process_set_source_sink.tb_set_sink
    PiCriterion egressCriterion = PiCriterion.builder()
            .matchExact(IntConstants.HDR_STANDARD_METADATA_EGRESS_SPEC, port.toLong())
            .build();
    TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
            .matchPi(egressCriterion)
            .build();
    PiAction setSinkAct = PiAction.builder()
            .withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_INT_SET_SINK)
            .build();
    TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(setSinkAct)
            .build();
    FlowRule sinkFlowRule = DefaultFlowRule.builder()
            .withSelector(sinkSelector)
            .withTreatment(sinkTreatment)
            .fromApp(appId)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SINK)
            .build();
    flowRuleService.applyFlowRules(sinkFlowRule);
    return true;
}
 
Example #30
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
                                    int matchValue, PiActionId actionId, ApplicationId appId) {
    PiCriterion instCriterion = PiCriterion.builder()
            .matchExact(matchFieldId, matchValue)
            .build();
    TrafficSelector instSelector = DefaultTrafficSelector.builder()
            .matchPi(instCriterion)
            .build();
    PiAction instAction = PiAction.builder()
            .withId(actionId)
            .build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(instAction)
            .build();

    FlowRule instFlowRule = DefaultFlowRule.builder()
            .withSelector(instSelector)
            .withTreatment(instTreatment)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(tableId)
            .fromApp(appId)
            .build();

    flowRuleService.applyFlowRules(instFlowRule);
}