org.onosproject.net.pi.model.PiMatchFieldId Java Examples

The following examples show how to use org.onosproject.net.pi.model.PiMatchFieldId. 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: 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 #2
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 #3
Source File: P4TableModel.java    From onos with Apache License 2.0 6 votes vote down vote up
P4TableModel(PiTableId id, PiTableType tableType,
             PiActionProfileModel actionProfile, long maxSize,
             ImmutableMap<PiCounterId, PiCounterModel> counters,
             ImmutableMap<PiMeterId, PiMeterModel> meters, boolean supportAging,
             ImmutableMap<PiMatchFieldId, PiMatchFieldModel> matchFields,
             ImmutableMap<PiActionId, PiActionModel> actions,
             PiActionModel constDefaultAction,
             boolean isConstTable) {
    this.id = id;
    this.tableType = tableType;
    this.actionProfile = actionProfile;
    this.maxSize = maxSize;
    this.counters = counters;
    this.meters = meters;
    this.supportAging = supportAging;
    this.matchFields = matchFields;
    this.actions = actions;
    this.constDefaultAction = constDefaultAction;
    this.isConstTable = isConstTable;
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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);
}
 
Example #9
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 #10
Source File: FieldMatchCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public PiFieldMatch decode(
        P4RuntimeOuterClass.FieldMatch message, P4InfoOuterClass.Preamble tablePreamble,
        PiPipeconf pipeconf, P4InfoBrowser browser)
        throws CodecException, P4InfoBrowser.NotFoundException {

    String fieldMatchName = browser.matchFields(tablePreamble.getId())
            .getById(message.getFieldId()).getName();
    PiMatchFieldId headerFieldId = PiMatchFieldId.of(fieldMatchName);

    P4RuntimeOuterClass.FieldMatch.FieldMatchTypeCase typeCase = message.getFieldMatchTypeCase();

    switch (typeCase) {
        case EXACT:
            P4RuntimeOuterClass.FieldMatch.Exact exactFieldMatch = message.getExact();
            ImmutableByteSequence exactValue = copyFrom(exactFieldMatch.getValue().asReadOnlyByteBuffer());
            return new PiExactFieldMatch(headerFieldId, exactValue);
        case TERNARY:
            P4RuntimeOuterClass.FieldMatch.Ternary ternaryFieldMatch = message.getTernary();
            ImmutableByteSequence ternaryValue = copyFrom(ternaryFieldMatch.getValue().asReadOnlyByteBuffer());
            ImmutableByteSequence ternaryMask = copyFrom(ternaryFieldMatch.getMask().asReadOnlyByteBuffer());
            return new PiTernaryFieldMatch(headerFieldId, ternaryValue, ternaryMask);
        case LPM:
            P4RuntimeOuterClass.FieldMatch.LPM lpmFieldMatch = message.getLpm();
            ImmutableByteSequence lpmValue = copyFrom(lpmFieldMatch.getValue().asReadOnlyByteBuffer());
            int lpmPrefixLen = lpmFieldMatch.getPrefixLen();
            return new PiLpmFieldMatch(headerFieldId, lpmValue, lpmPrefixLen);
        case RANGE:
            P4RuntimeOuterClass.FieldMatch.Range rangeFieldMatch = message.getRange();
            ImmutableByteSequence rangeHighValue = copyFrom(rangeFieldMatch.getHigh().asReadOnlyByteBuffer());
            ImmutableByteSequence rangeLowValue = copyFrom(rangeFieldMatch.getLow().asReadOnlyByteBuffer());
            return new PiRangeFieldMatch(headerFieldId, rangeLowValue, rangeHighValue);
        default:
            throw new CodecException(format(
                    "Decoding of field match type '%s' not implemented", typeCase.name()));
    }
}
 
Example #11
Source File: Srv6Component.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Insert a SRv6 transit insert policy that will inject an SRv6 header for
 * packets destined to destIp.
 *
 * @param deviceId     device ID
 * @param destIp       target IP address for the SRv6 policy
 * @param prefixLength prefix length for the target IP
 * @param segmentList  list of SRv6 SIDs that make up the path
 */
public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength,
                                 List<Ip6Address> segmentList) {
    if (segmentList.size() < 2 || segmentList.size() > 3) {
        throw new RuntimeException("List of " + segmentList.size() + " segments is not supported");
    }

    // TODO EXERCISE 4
    // Fill in the table ID for the SRv6 transit table.
    // ---- START SOLUTION ----
    String tableId = "MODIFY ME";
    // ---- END SOLUTION ----

    // TODO EXERCISE 4
    // Modify match field, action id, and action parameters to match your P4Info.
    // ---- START SOLUTION ----
    PiCriterion match = PiCriterion.builder()
            .matchLpm(PiMatchFieldId.of("MODIFY ME"), destIp.toOctets(), prefixLength)
            .build();

    List<PiActionParam> actionParams = Lists.newArrayList();

    for (int i = 0; i < segmentList.size(); i++) {
        PiActionParamId paramId = PiActionParamId.of("s" + (i + 1));
        PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets());
        actionParams.add(param);
    }

    PiAction action = PiAction.builder()
            .withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size()))
            .withParameters(actionParams)
            .build();
    // ---- END SOLUTION ----

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

    flowRuleService.applyFlowRules(rule);
}
 
Example #12
Source File: Srv6Component.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the My SID table from the network configuration for the
 * specified device.
 *
 * @param deviceId the device Id
 */
private void setUpMySidTable(DeviceId deviceId) {

    Ip6Address mySid = getMySid(deviceId);

    log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid);

    // TODO EXERCISE 4
    // Fill in the table ID for the SRv6 my segment identifier table
    // ---- START SOLUTION ----
    String tableId = "MODIFY ME";
    // ---- END SOLUTION ----

    // TODO EXERCISE 4
    // Modify the field and action id to match your P4Info
    // ---- START SOLUTION ----
    PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("MODIFY ME"),
                    mySid.toOctets(), 128)
            .build();

    PiTableAction action = PiAction.builder()
            .withId(PiActionId.of("MODIFY ME"))
            .build();
    // ---- END SOLUTION ----

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

    flowRuleService.applyFlowRules(myStationRule);
}
 
Example #13
Source File: L2BridgingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Insert flow rules to forward packets to a given host located at the given
 * device and port.
 * <p>
 * This method will be called at component activation for each host known by
 * ONOS, and every time a new host-added event is captured by the
 * InternalHostListener defined below.
 *
 * @param host     host instance
 * @param deviceId device where the host is located
 * @param port     port where the host is attached to
 */
private void learnHost(Host host, DeviceId deviceId, PortNumber port) {

    log.info("Adding L2 unicast rule on {} for host {} (port {})...",
             deviceId, host.id(), port);

    // TODO EXERCISE 2
    // 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";
    // Match exactly on the host MAC address.
    final MacAddress hostMac = host.mac();
    final PiCriterion hostMacCriterion = PiCriterion.builder()
            .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
                        hostMac.toBytes())
            .build();

    // Action: set output port
    final PiAction l2UnicastAction = PiAction.builder()
            .withId(PiActionId.of("IngressPipeImpl.set_output_port"))
            .withParameter(new PiActionParam(
                    PiActionParamId.of("port_num"),
                    port.toLong()))
            .build();

    // Forge flow rule.
    final FlowRule rule = Utils.buildFlowRule(
            deviceId, appId, tableId, hostMacCriterion, l2UnicastAction);
    // ---- END SOLUTION ----

    // Insert.
    flowRuleService.applyFlowRules(rule);
}
 
Example #14
Source File: InterpreterImpl.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type) {
    if (CRITERION_MAP.containsKey(type)) {
        return Optional.of(PiMatchFieldId.of(CRITERION_MAP.get(type)));
    } else {
        return Optional.empty();
    }
}
 
Example #15
Source File: NdpReplyComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId,
                                       MacAddress deviceMac,
                                       Ip6Address targetIp) {
    PiCriterion match = PiCriterion.builder()
            .matchExact(PiMatchFieldId.of("hdr.ndp.target_addr"), targetIp.toOctets())
            .build();

    PiActionParam paramRouterMac = new PiActionParam(
            PiActionParamId.of("target_mac"), deviceMac.toBytes());
    PiAction action = PiAction.builder()
            .withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na"))
            .withParameter(paramRouterMac)
            .build();

    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchPi(match)
            .build();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(action)
            .build();

    return DefaultFlowRule.builder()
            .forDevice(deviceId)
            .forTable(PiTableId.of("IngressPipeImpl.ndp_reply_table"))
            .fromApp(appId)
            .makePermanent()
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(DEFAULT_FLOW_RULE_PRIORITY)
            .build();
}
 
Example #16
Source File: Ipv6RoutingComponent.java    From ngsdn-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 the p4 program, 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.

    final String tableId = "IngressPipeImpl.my_station_table";

    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();

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

    flowRuleService.applyFlowRules(myStationRule);
}
 
Example #17
Source File: InterpreterImpl.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type) {
    if (CRITERION_MAP.containsKey(type)) {
        return Optional.of(PiMatchFieldId.of(CRITERION_MAP.get(type)));
    } else {
        return Optional.empty();
    }
}
 
Example #18
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 #19
Source File: PiLpmFieldMatch.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new LPM field match.
 *
 * @param fieldId      field identifier
 * @param value        value
 * @param prefixLength prefix length
 */
public PiLpmFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence value, int prefixLength) {
    super(fieldId);
    this.value = checkNotNull(value);
    this.prefixLength = prefixLength;
    checkArgument(value.size() > 0, "Value must have non-zero size");
    checkArgument(prefixLength >= 0, "Prefix length must be a non-negative integer");
}
 
Example #20
Source File: PiRangeFieldMatch.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new range field match for the given low and high value.
 *
 * @param fieldId   field identifier
 * @param lowValue  low value
 * @param highValue high value
 */
public PiRangeFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence lowValue,
                         ImmutableByteSequence highValue) {
    super(fieldId);
    this.lowValue = checkNotNull(lowValue);
    this.highValue = checkNotNull(highValue);
    checkArgument(lowValue.size() == highValue.size() && lowValue.size() > 0,
                  "Low and high values must have the same non-zero size.");
}
 
Example #21
Source File: PiTernaryFieldMatch.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ternary field match.
 *
 * @param fieldId field identifier
 * @param value   value
 * @param mask    mask
 */
public PiTernaryFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence value,
                           ImmutableByteSequence mask) {
    super(fieldId);
    this.value = checkNotNull(value);
    this.mask = checkNotNull(mask);
    checkArgument(value.size() == mask.size() && value.size() > 0,
                  "Value and mask must have same non-zero size");
}
 
Example #22
Source File: PiMatchFieldIdTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiMatchFieldId object.
 */
@Test
public void testConstruction() {
    final String name = IPV4_HEADER_NAME  + DOT + DST_ADDR;
    final PiMatchFieldId piMatchFieldId = PiMatchFieldId.of(name);
    assertThat(piMatchFieldId, is(notNullValue()));
    assertThat(piMatchFieldId.id(), is(name));
}
 
Example #23
Source File: PiMatchFieldIdTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiMatchFieldId object with index.
 */
@Test
public void testConstructionWithIndex() {
    final String name = IPV4_HEADER_NAME + DOT + DST_ADDR + "[1]";
    final PiMatchFieldId piMatchFieldId = PiMatchFieldId.of(name);
    assertThat(piMatchFieldId, is(notNullValue()));
    assertThat(piMatchFieldId.id(), is(name));
}
 
Example #24
Source File: PiLpmFieldMatchTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiLpmFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence value = copyFrom(0x0a01010a);
    int prefix = 24;
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(IPV4_HEADER_NAME + DOT + DST_ADDR);
    PiLpmFieldMatch piLpmFieldMatch = new PiLpmFieldMatch(piMatchField, value, prefix);
    assertThat(piLpmFieldMatch, is(notNullValue()));
    assertThat(piLpmFieldMatch.value(), is(value));
    assertThat(piLpmFieldMatch.prefixLength(), is(prefix));
    assertThat(piLpmFieldMatch.type(), is(PiMatchType.LPM));
}
 
Example #25
Source File: PiRangeFieldMatchTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiRangeFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence high = copyFrom(0x50);
    final ImmutableByteSequence low = copyFrom(0x00);
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(VLAN_HEADER_NAME + DOT + VID);
    PiRangeFieldMatch piRangeFieldMatch = new PiRangeFieldMatch(piMatchField, low, high);
    assertThat(piRangeFieldMatch, is(notNullValue()));
    assertThat(piRangeFieldMatch.lowValue(), is(low));
    assertThat(piRangeFieldMatch.highValue(), is(high));
    assertThat(piRangeFieldMatch.type(), is(PiMatchType.RANGE));
}
 
Example #26
Source File: PiTernaryFieldMatchTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiTernaryFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence value = copyFrom(0x0a01010a);
    final ImmutableByteSequence mask = copyFrom(0x00ffffff);
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(IPV4_HEADER_NAME + DOT + DST_ADDR);
    PiTernaryFieldMatch piTernaryFieldMatch = new PiTernaryFieldMatch(piMatchField, value, mask);
    assertThat(piTernaryFieldMatch, is(notNullValue()));
    assertThat(piTernaryFieldMatch.value(), is(value));
    assertThat(piTernaryFieldMatch.mask(), is(mask));
    assertThat(piTernaryFieldMatch.type(), is(PiMatchType.TERNARY));
}
 
Example #27
Source File: PiTableEntryTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests creation of a DefaultFlowRule using a FlowRule constructor.
 */
@Test
public void testBuilder() {

    PiTableId piTableId = PiTableId.of("table10");
    long cookie = 0xfff0323;
    int priority = 100;
    double timeout = 1000;
    PiMatchFieldId piMatchFieldId = PiMatchFieldId.of(IPV4_HEADER_NAME + DOT + DST_ADDR);
    PiFieldMatch piFieldMatch = new PiExactFieldMatch(piMatchFieldId, ImmutableByteSequence.copyFrom(0x0a010101));
    PiAction piAction = PiAction.builder().withId(PiActionId.of(DROP)).build();
    final Map<PiMatchFieldId, PiFieldMatch> fieldMatches = Maps.newHashMap();
    fieldMatches.put(piMatchFieldId, piFieldMatch);
    final PiTableEntry piTableEntry = PiTableEntry.builder()
            .forTable(piTableId)
            .withMatchKey(PiMatchKey.builder()
                                  .addFieldMatches(fieldMatches.values())
                                  .build())
            .withAction(piAction)
            .withCookie(cookie)
            .withPriority(priority)
            .withTimeout(timeout)
            .build();

    assertThat(piTableEntry.table(), is(piTableId));
    assertThat(piTableEntry.cookie(), is(cookie));
    assertThat("Priority must be set", piTableEntry.priority().isPresent());
    assertThat("Timeout must be set", piTableEntry.timeout().isPresent());
    assertThat(piTableEntry.priority().getAsInt(), is(priority));
    assertThat(piTableEntry.timeout().get(), is(timeout));
    assertThat("Incorrect match param value",
               CollectionUtils.isEqualCollection(piTableEntry.matchKey().fieldMatches(), fieldMatches.values()));
    assertThat(piTableEntry.action(), is(piAction));
}
 
Example #28
Source File: PiFieldMatchTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void basics() {
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(ETH_HEADER_NAME + DOT + ETH_TYPE);
    PiFieldMatch piFieldMatch = new PiExactFieldMatch(piMatchField, copyFrom(0x0806));

    assertEquals(piFieldMatch.fieldId(), piMatchField);
    assertEquals(piFieldMatch.type(), PiMatchType.EXACT);
}
 
Example #29
Source File: PiExactFieldMatchTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiExactFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence value = copyFrom(0x0806);
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(ETH_HEADER_NAME + DOT + ETH_TYPE);
    PiExactFieldMatch piExactFieldMatch = new PiExactFieldMatch(piMatchField, value);
    assertThat(piExactFieldMatch, is(notNullValue()));
    assertThat(piExactFieldMatch.value(), is(value));
    assertThat(piExactFieldMatch.type(), is(PiMatchType.EXACT));
}
 
Example #30
Source File: CriterionCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests protocol-independent type criterion encoding.
 */
@Test
public void matchPiTypeEncodingTest() {

    PiMatchFieldId ethMatchFieldId = PiMatchFieldId.of("ethernet_t.etherType");
    byte[] matchExactBytes1 = {0x08, 0x00};
    Criterion exactBytesCriterion = PiCriterion.builder().matchExact(ethMatchFieldId, matchExactBytes1).build();
    ObjectNode exactResult = criterionCodec.encode(exactBytesCriterion, context);
    assertThat(exactResult, matchesCriterion(exactBytesCriterion));

    PiMatchFieldId ipv4MatchFieldId = PiMatchFieldId.of("ipv4_t.dstAddr");
    int mask = 0x00ffffff;
    byte[] matchLpmBytes1 = {0x0a, 0x01, 0x01, 0x01};
    Criterion lpmBytesCriterion = PiCriterion.builder().matchLpm(ipv4MatchFieldId, matchLpmBytes1, mask).build();
    ObjectNode lpmResult = criterionCodec.encode(lpmBytesCriterion, context);
    assertThat(lpmResult, matchesCriterion(lpmBytesCriterion));

    byte[] matchTernaryBytes1 = {0x0a, 0x01, 0x01, 0x01};
    byte[] matchTernaryMaskBytes = {0x7f, 0x7f, 0x7f, 0x00};
    Criterion ternaryBytesCriterion = PiCriterion.builder().matchTernary(ipv4MatchFieldId, matchTernaryBytes1,
                                                                matchTernaryMaskBytes).build();
    ObjectNode ternaryResult = criterionCodec.encode(ternaryBytesCriterion, context);
    assertThat(ternaryResult, matchesCriterion(ternaryBytesCriterion));

    byte[] matchRangeBytes1 = {0x10};
    byte[] matchRangeHighBytes = {0x30};
    Criterion rangeBytesCriterion = PiCriterion.builder()
            .matchRange(ipv4MatchFieldId, matchRangeBytes1, matchRangeHighBytes).build();
    ObjectNode rangeResult = criterionCodec.encode(rangeBytesCriterion, context);
    assertThat(rangeResult, matchesCriterion(rangeBytesCriterion));
}