Search in sources :

Example 71 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project openflowplugin by opendaylight.

the class PacketOutInputMessageFactoryTest method test.

@Test
public void test() {
    ByteBuf bb = BufferHelper.buildBuffer("00 00 01 00 00 00 01 00 00 28 00 00 00 00 00 00 00 11 00 08 00 19 00 00 00 12 00 08 00 00 00 00 00 12 " + "00 08 00 00 00 00 00 12 00 08 00 00 00 00 00 12 00 08 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 10 " + "11 12 13 14");
    PacketOutInput deserializedMessage = BufferHelper.deserialize(factory, bb);
    BufferHelper.checkHeaderV13(deserializedMessage);
    Assert.assertEquals("Wrong buffer Id", 256L, deserializedMessage.getBufferId().longValue());
    Assert.assertEquals("Wrong In Port", new PortNumber(256L), deserializedMessage.getInPort());
    Assert.assertEquals("Wrong Numbers of actions", createAction(), deserializedMessage.getAction());
    byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14");
    Assert.assertArrayEquals("Wrong data", data, deserializedMessage.getData());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Example 72 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project openflowplugin by opendaylight.

the class ActionsDeserializerTest method test.

/**
 * Testing actions deserialization.
 */
@Test
public void test() {
    ByteBuf message = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00 " + "00 0B 00 08 00 00 00 00 " + "00 0C 00 08 00 00 00 00 " + "00 0F 00 08 03 00 00 00 " + "00 10 00 08 00 00 00 00 " + "00 11 00 08 00 04 00 00 " + "00 12 00 08 00 00 00 00 " + "00 13 00 08 00 05 00 00 " + "00 14 00 08 00 06 00 00 " + "00 15 00 08 00 00 00 07 " + "00 16 00 08 00 00 00 08 " + "00 17 00 08 09 00 00 00 " + "00 18 00 08 00 00 00 00 " + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 " + "00 1A 00 08 00 0A 00 00 " + "00 1B 00 08 00 00 00 00");
    // skip XID
    message.skipBytes(4);
    LOG.info("bytes: {}", message.readableBytes());
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, message.readableBytes(), message, keyMaker, registry);
    Assert.assertTrue("Wrong action type", actions.get(0).getActionChoice() instanceof OutputActionCase);
    Assert.assertEquals("Wrong action port", 1, ((OutputActionCase) actions.get(0).getActionChoice()).getOutputAction().getPort().getValue().intValue());
    Assert.assertEquals("Wrong action max-length", 2, ((OutputActionCase) actions.get(0).getActionChoice()).getOutputAction().getMaxLength().intValue());
    Assert.assertTrue("Wrong action type", actions.get(1).getActionChoice() instanceof CopyTtlOutCase);
    Assert.assertTrue("Wrong action type", actions.get(2).getActionChoice() instanceof CopyTtlInCase);
    Assert.assertTrue("Wrong action type", actions.get(3).getActionChoice() instanceof SetMplsTtlCase);
    Assert.assertEquals("Wrong action value", 3, ((SetMplsTtlCase) actions.get(3).getActionChoice()).getSetMplsTtlAction().getMplsTtl().shortValue());
    Assert.assertTrue("Wrong action type", actions.get(4).getActionChoice() instanceof DecMplsTtlCase);
    Assert.assertTrue("Wrong action type", actions.get(5).getActionChoice() instanceof PushVlanCase);
    Assert.assertEquals("Wrong action value", 4, ((PushVlanCase) actions.get(5).getActionChoice()).getPushVlanAction().getEthertype().getValue().intValue());
    Assert.assertTrue("Wrong action type", actions.get(6).getActionChoice() instanceof PopVlanCase);
    Assert.assertTrue("Wrong action type", actions.get(7).getActionChoice() instanceof PushMplsCase);
    Assert.assertEquals("Wrong action value", 5, ((PushMplsCase) actions.get(7).getActionChoice()).getPushMplsAction().getEthertype().getValue().intValue());
    Assert.assertTrue("Wrong action type", actions.get(8).getActionChoice() instanceof PopMplsCase);
    Assert.assertEquals("Wrong action value", 6, ((PopMplsCase) actions.get(8).getActionChoice()).getPopMplsAction().getEthertype().getValue().intValue());
    Assert.assertTrue("Wrong action type", actions.get(9).getActionChoice() instanceof SetQueueCase);
    Assert.assertEquals("Wrong action value", 7, ((SetQueueCase) actions.get(9).getActionChoice()).getSetQueueAction().getQueueId().intValue());
    Assert.assertTrue("Wrong action type", actions.get(10).getActionChoice() instanceof GroupCase);
    Assert.assertEquals("Wrong action value", 8, ((GroupCase) actions.get(10).getActionChoice()).getGroupAction().getGroupId().intValue());
    Assert.assertTrue("Wrong action type", actions.get(11).getActionChoice() instanceof SetNwTtlCase);
    Assert.assertEquals("Wrong action value", 9, ((SetNwTtlCase) actions.get(11).getActionChoice()).getSetNwTtlAction().getNwTtl().intValue());
    Assert.assertTrue("Wrong action type", actions.get(12).getActionChoice() instanceof DecNwTtlCase);
    Assert.assertTrue("Wrong action type", actions.get(13).getActionChoice() instanceof SetFieldCase);
    List<MatchEntry> entries = ((SetFieldCase) actions.get(13).getActionChoice()).getSetFieldAction().getMatchEntry();
    Assert.assertEquals("Wrong number of fields", 1, entries.size());
    Assert.assertEquals("Wrong match entry class", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow." + "oxm.rev150225.OpenflowBasicClass", entries.get(0).getOxmClass().getName());
    Assert.assertEquals("Wrong match entry field", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow." + "oxm.rev150225.InPhyPort", entries.get(0).getOxmMatchField().getName());
    Assert.assertEquals("Wrong match entry mask", false, entries.get(0).isHasMask());
    Assert.assertEquals("Wrong match entry value", 11, ((InPhyPortCase) entries.get(0).getMatchEntryValue()).getInPhyPort().getPortNumber().getValue().intValue());
    Assert.assertTrue("Wrong action type", actions.get(14).getActionChoice() instanceof PushPbbCase);
    Assert.assertEquals("Wrong action value", 10, ((PushPbbCase) actions.get(14).getActionChoice()).getPushPbbAction().getEthertype().getValue().intValue());
    Assert.assertTrue("Wrong action type", actions.get(15).getActionChoice() instanceof PopPbbCase);
    Assert.assertTrue("Unread data in message", message.readableBytes() == 0);
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) PushVlanCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) SetFieldCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) SetMplsTtlCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase) SetQueueCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase) GroupCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase) ByteBuf(io.netty.buffer.ByteBuf) PushPbbCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase) DecNwTtlCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCase) InPhyPortCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCase) PopPbbCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCase) CopyTtlOutCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase) PushMplsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase) OutputActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase) DecMplsTtlCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCase) PopVlanCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase) SetNwTtlCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase) CopyTtlInCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase) PopMplsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase) Test(org.junit.Test)

Example 73 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project openflowplugin by opendaylight.

the class ActionResponseConvertor method convert.

@Override
public List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convert(List<Action> source, ActionResponseConvertorData data) {
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> result = new ArrayList<>();
    final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
    // Iterate over Openflow actions, run them through tokenizer and then add them to list of converted actions
    if (source != null) {
        for (final Action action : source) {
            final Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convertedAction = PROCESSOR.process(action.getActionChoice(), data, getConvertorExecutor());
            if (convertedAction.isPresent()) {
                result.add(convertedAction.get());
            } else {
                /**
                 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
                 * - we might also need a way on how to identify exact type of augmentation to be
                 *   used as match can be bound to multiple models
                 */
                org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction = ActionExtensionHelper.processAlienAction(action, ofVersion, data.getActionPath());
                if (processedAction != null) {
                    result.add(processedAction);
                }
            }
        }
    }
    return result;
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) ArrayList(java.util.ArrayList)

Example 74 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project openflowplugin by opendaylight.

the class PacketOutConvertorTest method buildActionForNullTransmitPacketInputAction.

private static List<Action> buildActionForNullTransmitPacketInputAction(final NodeConnectorKey nodeConKey, final short version) {
    PortNumber outPort = getPortNumber(nodeConKey, version);
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder outputActionCaseBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder();
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder outputActionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder();
    outputActionBuilder.setPort(outPort);
    outputActionBuilder.setMaxLength(0xffff);
    outputActionCaseBuilder.setOutputAction(outputActionBuilder.build());
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(outputActionCaseBuilder.build());
    List<Action> actions = new ArrayList<>();
    actions.add(actionBuilder.build());
    return actions;
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) ArrayList(java.util.ArrayList) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)

Example 75 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project openflowplugin by opendaylight.

the class PacketOutConvertorTest method toPacketOutInputAllParmTest.

/**
 * Test for PacketOutConvertor.
 */
@Test
public void toPacketOutInputAllParmTest() {
    org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder ab = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
    OutputActionBuilder output = new OutputActionBuilder();
    output.setMaxLength(OFConstants.OFPCML_NO_BUFFER);
    Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
    output.setOutputNodeConnector(value);
    ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = new ArrayList<>();
    actionList.add(ab.build());
    Long bufferId = 0xfL;
    Long valueForCookie = 0xeL;
    ConnectionCookie connCook = new ConnectionCookie(valueForCookie);
    String nodeId = "node:1";
    NodeRef ref = createNodeRef(nodeId);
    String portO = "0xfffffffd";
    NodeConnectorKey egrConKey = PacketOutConvertorTest.createNodeConnKey(nodeId, portO);
    NodeConnectorRef egressConfRef = new NodeConnectorRef(createNodeConnRef(nodeId, egrConKey));
    String inPort = "2";
    NodeConnectorKey ingrConKey = PacketOutConvertorTest.createNodeConnKey(nodeId, inPort);
    NodeConnectorRef ingressConRef = new NodeConnectorRef(createNodeConnRef(nodeId, ingrConKey));
    String string = new String("sendOutputMsg_TEST");
    byte[] msg = string.getBytes();
    byte[] payload = msg;
    TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
    transmitPacketInputBuilder.setAction(actionList);
    transmitPacketInputBuilder.setBufferId(bufferId);
    transmitPacketInputBuilder.setConnectionCookie(connCook);
    transmitPacketInputBuilder.setEgress(egressConfRef);
    transmitPacketInputBuilder.setIngress(ingressConRef);
    transmitPacketInputBuilder.setNode(ref);
    transmitPacketInputBuilder.setPayload(payload);
    final TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
    Short version = (short) 0x04;
    byte[] datapathIdByte = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    for (int i = 0; i < datapathIdByte.length; i++) {
        datapathIdByte[i] = 1;
    }
    BigInteger datapathId = new BigInteger(1, datapathIdByte);
    Long xid = 0xfffffL;
    PacketOutConvertorData data = new PacketOutConvertorData(version);
    data.setXid(xid);
    data.setDatapathId(datapathId);
    PacketOutInput message = convert(transmitPacketInput, data);
    Assert.assertEquals(transmitPacketInput.getBufferId(), message.getBufferId());
    Assert.assertEquals(Long.valueOf(inPort), message.getInPort().getValue());
    Assert.assertEquals(version, message.getVersion());
    Assert.assertEquals(xid, message.getXid());
    ActionConvertorData actionConvertorData = new ActionConvertorData(version);
    actionConvertorData.setDatapathId(datapathId);
    Optional<List<Action>> actionsOptional = convertorManager.convert(actionList, actionConvertorData);
    List<Action> actions = actionsOptional.orElse(Collections.emptyList());
    Assert.assertEquals(actions, message.getAction());
    Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) ArrayList(java.util.ArrayList) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) PacketOutConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ArrayList(java.util.ArrayList) List(java.util.List) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) ActionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) BigInteger(java.math.BigInteger) ConnectionCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.ConnectionCookie) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)112 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)67 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)45 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)42 Test (org.junit.Test)38 PushVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder)33 GroupActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder)32 PopMplsActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder)32 PopPbbActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder)32 PopVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder)32 PushMplsActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder)32 PushPbbActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder)32 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)29 ByteBuf (io.netty.buffer.ByteBuf)28 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)26 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder)24 SetMplsTtlActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder)22 SetNwTtlActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder)22 SetQueueActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder)22 BigInteger (java.math.BigInteger)21