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

The following examples show how to use org.onosproject.net.pi.model.PiPacketMetadataId. 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: PacketMetadataCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected PiPacketMetadata decode(
        P4RuntimeOuterClass.PacketMetadata message,
        P4InfoOuterClass.Preamble ctrlPktMetaPreamble,
        PiPipeconf pipeconf, P4InfoBrowser browser)
        throws P4InfoBrowser.NotFoundException {
    final String packetMetadataName = browser
            .packetMetadatas(ctrlPktMetaPreamble.getId())
            .getById(message.getMetadataId()).getName();
    final PiPacketMetadataId metadataId = PiPacketMetadataId
            .of(packetMetadataName);
    return PiPacketMetadata.builder()
            .withId(metadataId)
            .withValue(copyFrom(message.getValue().asReadOnlyByteBuffer()))
            .build();
}
 
Example #2
Source File: P4InfoParser.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Map<PiPacketOperationType, PiPacketOperationModel> parseCtrlPktMetadatas(P4Info p4info)
        throws P4InfoParserException {
    final Map<PiPacketOperationType, PiPacketOperationModel> packetOpMap = Maps.newHashMap();
    for (ControllerPacketMetadata ctrlPktMetaMsg : p4info.getControllerPacketMetadataList()) {
        final ImmutableList.Builder<PiPacketMetadataModel> metadataListBuilder =
                ImmutableList.builder();
        ctrlPktMetaMsg.getMetadataList().forEach(metadataMsg -> metadataListBuilder.add(
                new P4PacketMetadataModel(PiPacketMetadataId.of(metadataMsg.getName()),
                                           metadataMsg.getBitwidth())));
        packetOpMap.put(
                mapPacketOpType(ctrlPktMetaMsg.getPreamble().getName()),
                new P4PacketOperationModel(mapPacketOpType(ctrlPktMetaMsg.getPreamble().getName()),
                                           metadataListBuilder.build()));

    }
    return packetOpMap;
}
 
Example #3
Source File: PiPacketOperationTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the methods of PiPacketOperation.
 */
@Test
public void testMethods() {

    final PiPacketOperation piPacketOperation = PiPacketOperation.builder()
            .withData(ImmutableByteSequence.ofOnes(512))
            .withType(PACKET_OUT)
            .withMetadata(PiPacketMetadata.builder()
                                  .withId(PiPacketMetadataId.of(EGRESS_PORT))
                                  .withValue(copyFrom((short) 10))
                                  .build())
            .build();

    assertThat(piPacketOperation, is(notNullValue()));
    assertThat(piPacketOperation.type(), is(PACKET_OUT));
    assertThat(piPacketOperation.data(), is(ImmutableByteSequence.ofOnes(512)));
    assertThat("Incorrect metadatas value",
               CollectionUtils.isEqualCollection(piPacketOperation.metadatas(),
                                                 ImmutableList.of(PiPacketMetadata.builder()
                                                                          .withId(PiPacketMetadataId
                                                                                          .of(EGRESS_PORT))
                                                                          .withValue(copyFrom((short) 10))
                                                                          .build())));
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: PiPacketMetadataTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the methods of PiPacketMetadata.
 */
@Test
public void testMethods() {

    assertThat(piPacketMetadata1, is(notNullValue()));
    assertThat(piPacketMetadata1.id(), is(PiPacketMetadataId.of(EGRESS_PORT)));
    assertThat(piPacketMetadata1.value(), is(copyFrom(0x10)));
}
 
Example #11
Source File: P4ControlMetadataModel.java    From onos with Apache License 2.0 4 votes vote down vote up
P4PacketMetadataModel(PiPacketMetadataId id, int bitWidth) {
    this.id = id;
    this.bitWidth = bitWidth;
}
 
Example #12
Source File: P4ControlMetadataModel.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public PiPacketMetadataId id() {
    return id;
}
 
Example #13
Source File: PiPacketMetadataIdTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Checks that the PiPacketMetadataId class is immutable.
 */
@Test
public void testImmutability() {

    assertThatClassIsImmutable(PiPacketMetadataId.class);
}
 
Example #14
Source File: PiPacketMetadata.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new packet metadata instance for the given identifier and
 * value.
 *
 * @param id    packet metadata identifier
 * @param value value for this metadata
 */
private PiPacketMetadata(PiPacketMetadataId id, ImmutableByteSequence value) {
    this.id = id;
    this.value = value;
}
 
Example #15
Source File: PiPacketMetadata.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Return the identifier of this packet metadata.
 *
 * @return packet metadata identifier
 */
public PiPacketMetadataId id() {
    return id;
}
 
Example #16
Source File: PiPacketMetadata.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the identifier of this packet metadata.
 *
 * @param id packet metadata identifier
 * @return this
 */
public Builder withId(PiPacketMetadataId id) {
    this.id = id;
    return this;
}