Java Code Examples for org.onosproject.net.pi.model.PiActionId#of()

The following examples show how to use org.onosproject.net.pi.model.PiActionId#of() . 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: PiActionTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the construction of a PiAction object with parameters.
 */
@Test
public void testMethodWithParameters() {
    PiActionId piActionId = PiActionId.of(MOD_NW_DST);
    Collection<PiActionParam> runtimeParams = Lists.newArrayList();
    PiActionParam piActionParam = new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101));

    runtimeParams.add(piActionParam);
    final PiAction piAction = PiAction.builder().withId(piActionId)
            .withParameters(runtimeParams)
            .build();
    assertThat(piAction, is(notNullValue()));
    assertThat(piAction.id(), is(piActionId));
    assertThat(piAction.parameters(), is(runtimeParams));
    assertThat(piAction.type(), is(PiTableAction.Type.ACTION));
}
 
Example 2
Source File: InstructionCodecTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the encoding of protocol-independent instructions.
 */
@Test
public void piInstructionEncodingTest() {
    PiActionId actionId = PiActionId.of("set_egress_port");
    PiActionParamId actionParamId = PiActionParamId.of("port");
    PiActionParam actionParam = new PiActionParam(actionParamId, ImmutableByteSequence.copyFrom(10));
    PiTableAction action = PiAction.builder().withId(actionId).withParameter(actionParam).build();
    final PiInstruction actionInstruction = Instructions.piTableAction(action);
    final ObjectNode actionInstructionJson =
            instructionCodec.encode(actionInstruction, context);
    assertThat(actionInstructionJson, matchesInstruction(actionInstruction));

    PiTableAction actionGroupId = PiActionProfileGroupId.of(10);
    final PiInstruction actionGroupIdInstruction = Instructions.piTableAction(actionGroupId);
    final ObjectNode actionGroupIdInstructionJson =
            instructionCodec.encode(actionGroupIdInstruction, context);
    assertThat(actionGroupIdInstructionJson, matchesInstruction(actionGroupIdInstruction));

    PiTableAction actionProfileMemberId = PiActionProfileMemberId.of(10);
    final PiInstruction actionProfileMemberIdInstruction = Instructions.piTableAction(actionProfileMemberId);
    final ObjectNode actionProfileMemberIdInstructionJson =
            instructionCodec.encode(actionProfileMemberIdInstruction, context);
    assertThat(actionProfileMemberIdInstructionJson, matchesInstruction(actionProfileMemberIdInstruction));
}
 
Example 3
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 4
Source File: PiActionTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiAction object with parameter.
 */
@Test
public void testMethodWithParameter() {
    PiActionId piActionId = PiActionId.of(MOD_NW_DST);
    PiActionParam piActionParam = new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101));
    final PiAction piAction = PiAction.builder().withId(piActionId)
            .withParameter(piActionParam)
            .build();
    assertThat(piAction, is(notNullValue()));
    assertThat(piAction.id(), is(piActionId));
    assertThat(piAction.type(), is(PiTableAction.Type.ACTION));
}
 
Example 5
Source File: PiActionIdTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the construction of a PiActionId object.
 */
@Test
public void testConstruction() {
    final PiActionId actionId = PiActionId.of(DEC_TTL);
    assertThat(actionId, is(notNullValue()));
    assertThat(actionId.id(), is(DEC_TTL));
}
 
Example 6
Source File: MyTunnelApp.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Generates and insert a flow rule to perform the tunnel FORWARD/EGRESS
 * function for the given switch, output port address and tunnel ID.
 *
 * @param switchId switch ID
 * @param outPort  output port where to forward tunneled packets
 * @param tunId    tunnel ID
 * @param isEgress if true, perform tunnel egress action, otherwise forward
 *                 packet as is to port
 */
private void insertTunnelForwardRule(DeviceId switchId,
                                     PortNumber outPort,
                                     int tunId,
                                     boolean isEgress) {

    PiTableId tunnelForwardTableId = PiTableId.of("c_ingress.t_tunnel_fwd");

    // Exact match on tun_id
    PiMatchFieldId tunIdMatchFieldId = PiMatchFieldId.of("hdr.my_tunnel.tun_id");
    PiCriterion match = PiCriterion.builder()
            .matchExact(tunIdMatchFieldId, tunId)
            .build();

    // Action depend on isEgress parameter.
    // if true, perform tunnel egress action on the given outPort, otherwise
    // simply forward packet as is (set_out_port action).
    PiActionParamId portParamId = PiActionParamId.of("port");
    PiActionParam portParam = new PiActionParam(portParamId, (short) outPort.toLong());

    final PiAction action;
    if (isEgress) {
        // Tunnel egress action.
        // Remove MyTunnel header and forward to outPort.
        PiActionId egressActionId = PiActionId.of("c_ingress.my_tunnel_egress");
        action = PiAction.builder()
                .withId(egressActionId)
                .withParameter(portParam)
                .build();
    } else {
        // Tunnel transit action.
        // Forward the packet as is to outPort.
        /*
         * TODO EXERCISE: create action object for the transit case.
         * Look at the t_tunnel_fwd table in the P4 program. Which of the 3
         * actions can be used to simply set the output port? Get the full
         * action name from the P4Info file, and use that when creating the
         * PiActionId object. When creating the PiAction object, remember to
         * add all action parameters as defined in the P4 program.
         *
         * Hint: the code will be similar to the case when isEgress is true.
         */
        action = null; // Replace null with your solution.
    }

    log.info("Inserting {} rule on switch {}: table={}, match={}, action={}",
             isEgress ? "EGRESS" : "TRANSIT",
             switchId, tunnelForwardTableId, match, action);

    insertPiFlowRule(switchId, tunnelForwardTableId, match, action);
}