Search in sources :

Example 1 with PacketOutInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput in project openflowplugin by opendaylight.

the class PacketOutConvertor method convert.

@Override
public PacketOutInput convert(TransmitPacketInput source, PacketOutConvertorData data) {
    LOG.trace("toPacketOutInput for datapathId:{}, xid:{}", data.getDatapathId(), data.getXid());
    // Build Port ID from TransmitPacketInput.Ingress
    PortNumber inPortNr;
    Long bufferId = OFConstants.OFP_NO_BUFFER;
    Iterable<PathArgument> inArgs = null;
    if (source.getIngress() != null) {
        inArgs = source.getIngress().getValue().getPathArguments();
    }
    if (inArgs != null && Iterables.size(inArgs) >= 3) {
        inPortNr = getPortNumber(Iterables.get(inArgs, 2), data.getVersion());
    } else {
        // The packetOut originated from the controller
        inPortNr = new PortNumber(0xfffffffdL);
    }
    // Build Buffer ID to be NO_OFP_NO_BUFFER
    if (source.getBufferId() != null) {
        bufferId = source.getBufferId();
    }
    PortNumber outPort = null;
    NodeConnectorRef outRef = source.getEgress();
    Iterable<PathArgument> outArgs = outRef.getValue().getPathArguments();
    if (Iterables.size(outArgs) >= 3) {
        outPort = getPortNumber(Iterables.get(outArgs, 2), data.getVersion());
    } else {
        // TODO : P4 search for some normal exception
        // new Exception("PORT NR not exist in Egress");
        LOG.error("PORT NR not exist in Egress");
    }
    List<Action> actions = new ArrayList<>();
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> inputActions = source.getAction();
    if (inputActions != null) {
        final ActionConvertorData actionConvertorData = new ActionConvertorData(data.getVersion());
        actionConvertorData.setDatapathId(data.getDatapathId());
        final Optional<List<Action>> convertedActions = getConvertorExecutor().convert(inputActions, actionConvertorData);
        actions = convertedActions.orElse(Collections.emptyList());
    } else {
        // TODO VD P! wait for way to move Actions (e.g. augmentation)
        OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder();
        OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
        outputActionBuilder.setPort(outPort);
        outputActionBuilder.setMaxLength(OFConstants.OFPCML_NO_BUFFER);
        outputActionCaseBuilder.setOutputAction(outputActionBuilder.build());
        ActionBuilder actionBuild = new ActionBuilder();
        actionBuild.setActionChoice(outputActionCaseBuilder.build());
        actions.add(actionBuild.build());
    }
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    builder.setAction(actions);
    builder.setData(source.getPayload());
    builder.setVersion(data.getVersion());
    builder.setXid(data.getXid());
    builder.setInPort(inPortNr);
    builder.setBufferId(bufferId);
    return builder.build();
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) ArrayList(java.util.ArrayList) ActionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData) PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) ArrayList(java.util.ArrayList) List(java.util.List) PathArgument(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)

Example 2 with PacketOutInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput in project openflowplugin by opendaylight.

the class PacketOutInputMessageFactory method deserialize.

@Override
public PacketOutInput deserialize(ByteBuf rawMessage) {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setInPort(new PortNumber(rawMessage.readUnsignedInt()));
    int actionsLen = rawMessage.readShort();
    rawMessage.skipBytes(PADDING);
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actionsLen, rawMessage, keyMaker, registry);
    builder.setAction(actions);
    byte[] data = new byte[rawMessage.readableBytes()];
    rawMessage.readBytes(data);
    builder.setData(data);
    return builder.build();
}
Also used : PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)

Example 3 with PacketOutInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput in project openflowplugin by opendaylight.

the class PacketProcessingServiceImpl method buildRequest.

@Override
protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) throws ServiceException {
    final PacketOutConvertorData data = new PacketOutConvertorData(getVersion());
    data.setDatapathId(getDatapathId());
    data.setXid(xid.getValue());
    final Optional<PacketOutInput> result = convertorExecutor.convert(input, data);
    return result.orElse(PacketOutConvertor.defaultResult(getVersion()));
}
Also used : PacketOutConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput)

Example 4 with PacketOutInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput in project openflowplugin by opendaylight.

the class OF10PacketOutInputMessageFactoryTest method testPacketOutInputWithNoData.

/**
 * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testPacketOutInputWithNoData() throws Exception {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setBufferId(256L);
    builder.setInPort(new PortNumber(257L));
    List<Action> actions = new ArrayList<>();
    builder.setAction(actions);
    builder.setData(null);
    PacketOutInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    packetOutFactory.serialize(message, out);
    BufferHelper.checkHeaderV10(out, (byte) 13, 16);
    // skip packet out message to data index
    out.skipBytes(8);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
Also used : PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) ArrayList(java.util.ArrayList) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) ByteBuf(io.netty.buffer.ByteBuf) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Example 5 with PacketOutInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput in project openflowplugin by opendaylight.

the class PacketOutInputMessageFactoryTest method testPacketOutInputWithNoData.

/**
 * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testPacketOutInputWithNoData() throws Exception {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setBufferId(256L);
    builder.setInPort(new PortNumber(256L));
    List<Action> actions = new ArrayList<>();
    builder.setAction(actions);
    builder.setData(null);
    PacketOutInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    packetOutFactory.serialize(message, out);
    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 24);
    // skip packet out message to data index
    out.skipBytes(16);
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}
Also used : PacketOutInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) ArrayList(java.util.ArrayList) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) ByteBuf(io.netty.buffer.ByteBuf) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Aggregations

PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)10 PacketOutInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput)10 Test (org.junit.Test)9 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)8 PacketOutInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder)7 ByteBuf (io.netty.buffer.ByteBuf)6 ArrayList (java.util.ArrayList)6 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)4 PacketOutConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData)3 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)3 TransmitPacketInput (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput)3 List (java.util.List)2 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)2 ActionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData)2 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)2 NodeConnectorKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)2 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder)2 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder)2 TransmitPacketInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder)2 BigInteger (java.math.BigInteger)1