Java Code Examples for org.onlab.util.ImmutableByteSequence#ByteSequenceTrimException

The following examples show how to use org.onlab.util.ImmutableByteSequence#ByteSequenceTrimException . 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: InterpreterImpl.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a pipeconf-specific packet-out instance with the given payload and
 * egress port.
 *
 * @param pktData    packet payload
 * @param portNumber egress port
 * @return packet-out
 * @throws PiInterpreterException if packet-out cannot be built
 */
private PiPacketOperation buildPacketOut(ByteBuffer pktData, long portNumber)
        throws PiInterpreterException {

    // Make sure port number can fit in v1model port metadata bitwidth.
    final ImmutableByteSequence portBytes;
    try {
        portBytes = copyFrom(portNumber).fit(V1MODEL_PORT_BITWIDTH);
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number %d too big, %s", portNumber, e.getMessage()));
    }

    // Create metadata instance for egress port.
    // TODO EXERCISE 3: modify metadata names to match P4 program
    // ---- START SOLUTION ----
    final String outPortMetadataName = "egress_port";
    // ---- END SOLUTION ----
    final PiPacketMetadata outPortMetadata = PiPacketMetadata.builder()
            .withId(PiPacketMetadataId.of(outPortMetadataName))
            .withValue(portBytes)
            .build();

    // Build packet out.
    return PiPacketOperation.builder()
            .withType(PACKET_OUT)
            .withData(copyFrom(pktData))
            .withMetadata(outPortMetadata)
            .build();
}
 
Example 2
Source File: InterpreterImpl.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a pipeconf-specific packet-out instance with the given payload and
 * egress port.
 *
 * @param pktData    packet payload
 * @param portNumber egress port
 * @return packet-out
 * @throws PiInterpreterException if packet-out cannot be built
 */
private PiPacketOperation buildPacketOut(ByteBuffer pktData, long portNumber)
        throws PiInterpreterException {

    // Make sure port number can fit in v1model port metadata bitwidth.
    final ImmutableByteSequence portBytes;
    try {
        portBytes = copyFrom(portNumber).fit(V1MODEL_PORT_BITWIDTH);
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number %d too big, %s", portNumber, e.getMessage()));
    }

    // Create metadata instance for egress port.
    // *** TODO EXERCISE 3: modify metadata names to match P4 program
    // ---- START SOLUTION ----
    final String outPortMetadataName = "<ADD HERE METADATA NAME FOR THE EGRESS PORT>";
    // ---- END SOLUTION ----
    final PiPacketMetadata outPortMetadata = PiPacketMetadata.builder()
            .withId(PiPacketMetadataId.of(outPortMetadataName))
            .withValue(portBytes)
            .build();

    // Build packet out.
    return PiPacketOperation.builder()
            .withType(PACKET_OUT)
            .withData(copyFrom(pktData))
            .withMetadata(outPortMetadata)
            .build();
}
 
Example 3
Source File: InterpreterImpl.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a pipeconf-specific packet-out instance with the given payload and
 * egress port.
 *
 * @param pktData    packet payload
 * @param portNumber egress port
 * @return packet-out
 * @throws PiInterpreterException if packet-out cannot be built
 */
private PiPacketOperation buildPacketOut(ByteBuffer pktData, long portNumber)
        throws PiInterpreterException {

    // Make sure port number can fit in v1model port metadata bitwidth.
    final ImmutableByteSequence portBytes;
    try {
        portBytes = copyFrom(portNumber).fit(V1MODEL_PORT_BITWIDTH);
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number %d too big, %s", portNumber, e.getMessage()));
    }

    // Create metadata instance for egress port.
    // TODO EXERCISE 1: modify metadata names to match P4 program
    // ---- START SOLUTION ----
    final String outPortMetadataName = "egress_port";
    // ---- END SOLUTION ----
    final PiPacketMetadata outPortMetadata = PiPacketMetadata.builder()
            .withId(PiPacketMetadataId.of(outPortMetadataName))
            .withValue(portBytes)
            .build();

    // Build packet out.
    return PiPacketOperation.builder()
            .withType(PACKET_OUT)
            .withData(copyFrom(pktData))
            .withMetadata(outPortMetadata)
            .build();
}
 
Example 4
Source File: InterpreterImpl.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a pipeconf-specific packet-out instance with the given payload and
 * egress port.
 *
 * @param pktData    packet payload
 * @param portNumber egress port
 * @return packet-out
 * @throws PiInterpreterException if packet-out cannot be built
 */
private PiPacketOperation buildPacketOut(ByteBuffer pktData, long portNumber)
        throws PiInterpreterException {

    // Make sure port number can fit in v1model port metadata bitwidth.
    final ImmutableByteSequence portBytes;
    try {
        portBytes = copyFrom(portNumber).fit(V1MODEL_PORT_BITWIDTH);
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number %d too big, %s", portNumber, e.getMessage()));
    }

    // Create metadata instance for egress port.
    // TODO EXERCISE 1: modify metadata names to match P4 program
    // ---- START SOLUTION ----
    final String outPortMetadataName = "MODIFY ME";
    // ---- END SOLUTION ----
    final PiPacketMetadata outPortMetadata = PiPacketMetadata.builder()
            .withId(PiPacketMetadataId.of(outPortMetadataName))
            .withValue(portBytes)
            .build();

    // Build packet out.
    return PiPacketOperation.builder()
            .withType(PACKET_OUT)
            .withData(copyFrom(pktData))
            .withMetadata(outPortMetadata)
            .build();
}
 
Example 5
Source File: PacketInEventTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Setup method for packetOperation and packetOperation2.
 * @throws ImmutableByteSequence.ByteSequenceTrimException if byte sequence cannot be trimmed
 */
@Before
public void setup() throws ImmutableByteSequence.ByteSequenceTrimException {

    packetOperation = PiPacketOperation.builder()
            .withData(ImmutableByteSequence.ofOnes(512))
            .withType(PACKET_OUT)
            .withMetadata(PiPacketMetadata.builder()
                                  .withId(PiPacketMetadataId.of("egress_port"))
                                  .withValue(copyFrom(DEFAULT_ORIGINAL_VALUE).fit(DEFAULT_BIT_WIDTH))
                                  .build())
            .build();

    packetOperation2 = PiPacketOperation.builder()
            .withData(ImmutableByteSequence.ofOnes(512))
            .withType(PACKET_IN)
            .withMetadata(PiPacketMetadata.builder()
                                  .withId(PiPacketMetadataId.of("ingress_port"))
                                  .withValue(copyFrom(DEFAULT_ORIGINAL_VALUE).fit(DEFAULT_BIT_WIDTH))
                                  .build())
            .build();

    packetIn = new org.onosproject.p4runtime.ctl.controller.PacketInEvent(deviceId, packetOperation);
    sameAsPacketIn = new org.onosproject.p4runtime.ctl.controller.PacketInEvent(sameDeviceId, packetOperation);
    packetIn2 = new org.onosproject.p4runtime.ctl.controller.PacketInEvent(deviceId2, packetOperation);
    packetIn3 = new org.onosproject.p4runtime.ctl.controller.PacketInEvent(deviceId, packetOperation2);
}
 
Example 6
Source File: FabricInterpreter.java    From onos with Apache License 2.0 5 votes vote down vote up
private PiPacketMetadata createPacketMetadata(long portNumber)
        throws PiInterpreterException {
    try {
        return PiPacketMetadata.builder()
                .withId(FabricConstants.EGRESS_PORT)
                .withValue(copyFrom(portNumber).fit(PORT_BITWIDTH))
                .build();
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number '%d' too big, %s", portNumber, e.getMessage()));
    }
}
 
Example 7
Source File: BasicInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private PiPacketMetadata createPacketMetadata(long portNumber) throws PiInterpreterException {
    try {
        return PiPacketMetadata.builder()
                .withId(EGRESS_PORT)
                .withValue(copyFrom(portNumber).fit(PORT_BITWIDTH))
                .build();
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number %d too big, %s", portNumber, e.getMessage()));
    }
}
 
Example 8
Source File: PipelineInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private PiPacketMetadata createPacketMetadata(long portNumber)
        throws PiInterpreterException {
    try {
        return PiPacketMetadata.builder()
                .withId(PiPacketMetadataId.of(EGRESS_PORT))
                .withValue(copyFrom(portNumber).fit(PORT_FIELD_BITWIDTH))
                .build();
    } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
        throw new PiInterpreterException(format(
                "Port number %d too big, %s", portNumber, e.getMessage()));
    }
}
 
Example 9
Source File: PiGroupTranslatorImplTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static PiActionProfileMember outputMember(int portNum)
        throws ImmutableByteSequence.ByteSequenceTrimException {
    PiActionParam param = new PiActionParam(PORT, copyFrom(portNum).fit(PORT_BITWIDTH));
    PiAction piAction = PiAction.builder()
            .withId(INGRESS_WCMP_CONTROL_SET_EGRESS_PORT)
            .withParameter(param).build();
    return PiActionProfileMember.builder()
            .forActionProfile(INGRESS_WCMP_CONTROL_WCMP_SELECTOR)
            .withAction(piAction)
            .withId(PiActionProfileMemberId.of(BASE_MEM_ID + portNum))
            .build();
}
 
Example 10
Source File: TableEntryEncoderTest.java    From onos with Apache License 2.0 4 votes vote down vote up
public TableEntryEncoderTest() throws ImmutableByteSequence.ByteSequenceTrimException {
}