Search in sources :

Example 16 with OutputActionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase in project openflowplugin by opendaylight.

the class OF10ActionsDeserializerTest method test.

/**
 * Testing correct deserialization of actions (OF v1.0).
 */
@Test
public void test() {
    ByteBuf message = BufferHelper.buildBuffer("00 00 00 08 00 10 20 00 " + "00 01 00 08 10 10 00 00 " + "00 02 00 08 25 00 00 00 " + "00 03 00 08 00 00 00 00 " + "00 04 00 10 01 02 03 04 05 06 00 00 00 00 00 00 " + "00 05 00 10 02 03 04 05 06 07 00 00 00 00 00 00 " + "00 06 00 08 0A 00 00 01 " + "00 07 00 08 0B 00 00 02 " + "00 08 00 08 01 00 00 00 " + "00 09 00 08 00 02 00 00 " + "00 0A 00 08 00 03 00 00 " + "00 0B 00 10 00 04 00 00 00 00 00 00 00 00 00 30");
    // skip XID
    message.skipBytes(4);
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
    List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, message.readableBytes(), message, keyMaker, registry);
    Assert.assertEquals("Wrong number of actions", 12, actions.size());
    Action action1 = actions.get(0);
    Assert.assertTrue("Wrong action type", action1.getActionChoice() instanceof OutputActionCase);
    Assert.assertEquals("Wrong port", 16, ((OutputActionCase) action1.getActionChoice()).getOutputAction().getPort().getValue().intValue());
    Assert.assertEquals("Wrong max-length", 8192, ((OutputActionCase) action1.getActionChoice()).getOutputAction().getMaxLength().intValue());
    Action action2 = actions.get(1);
    Assert.assertTrue("Wrong action type", action2.getActionChoice() instanceof SetVlanVidCase);
    Assert.assertEquals("Wrong vlan-vid", 4112, ((SetVlanVidCase) action2.getActionChoice()).getSetVlanVidAction().getVlanVid().intValue());
    Action action3 = actions.get(2);
    Assert.assertTrue("Wrong action type", action3.getActionChoice() instanceof SetVlanPcpCase);
    Assert.assertEquals("Wrong vlan-pcp", 37, ((SetVlanPcpCase) action3.getActionChoice()).getSetVlanPcpAction().getVlanPcp().intValue());
    Action action4 = actions.get(3);
    Assert.assertTrue("Wrong action type", action4.getActionChoice() instanceof StripVlanCase);
    Action action5 = actions.get(4);
    Assert.assertTrue("Wrong action type", action5.getActionChoice() instanceof SetDlSrcCase);
    Assert.assertEquals("Wrong dl-src", "01:02:03:04:05:06", ((SetDlSrcCase) action5.getActionChoice()).getSetDlSrcAction().getDlSrcAddress().getValue());
    Action action6 = actions.get(5);
    Assert.assertTrue("Wrong action type", action6.getActionChoice() instanceof SetDlDstCase);
    Assert.assertEquals("Wrong dl-dst", "02:03:04:05:06:07", ((SetDlDstCase) action6.getActionChoice()).getSetDlDstAction().getDlDstAddress().getValue());
    Action action7 = actions.get(6);
    Assert.assertTrue("Wrong action type", action7.getActionChoice() instanceof SetNwSrcCase);
    Assert.assertEquals("Wrong nw-src", new Ipv4Address("10.0.0.1"), ((SetNwSrcCase) action7.getActionChoice()).getSetNwSrcAction().getIpAddress());
    Action action8 = actions.get(7);
    Assert.assertTrue("Wrong action type", action8.getActionChoice() instanceof SetNwDstCase);
    Assert.assertEquals("Wrong nw-dst", new Ipv4Address("11.0.0.2"), ((SetNwDstCase) action8.getActionChoice()).getSetNwDstAction().getIpAddress());
    Action action9 = actions.get(8);
    Assert.assertTrue("Wrong action type", action9.getActionChoice() instanceof SetNwTosCase);
    Assert.assertEquals("Wrong nw-tos", 1, ((SetNwTosCase) action9.getActionChoice()).getSetNwTosAction().getNwTos().intValue());
    Action action10 = actions.get(9);
    Assert.assertTrue("Wrong action type", action10.getActionChoice() instanceof SetTpSrcCase);
    Assert.assertEquals("Wrong port", 2, ((SetTpSrcCase) action10.getActionChoice()).getSetTpSrcAction().getPort().getValue().intValue());
    Action action11 = actions.get(10);
    Assert.assertTrue("Wrong action type", action11.getActionChoice() instanceof SetTpDstCase);
    Assert.assertEquals("Wrong port", 3, ((SetTpDstCase) action11.getActionChoice()).getSetTpDstAction().getPort().getValue().intValue());
    Action action12 = actions.get(11);
    Assert.assertTrue("Wrong action type", action12.getActionChoice() instanceof EnqueueCase);
    Assert.assertEquals("Wrong port", 4, ((EnqueueCase) action12.getActionChoice()).getEnqueueAction().getPort().getValue().intValue());
    Assert.assertEquals("Wrong queue-id", 48, ((EnqueueCase) action12.getActionChoice()).getEnqueueAction().getQueueId().getValue().intValue());
}
Also used : SetVlanVidCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanVidCase) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) EnqueueCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.EnqueueCase) SetDlDstCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlDstCase) SetTpSrcCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCase) SetNwSrcCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCase) ByteBuf(io.netty.buffer.ByteBuf) SetVlanPcpCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanPcpCase) SetDlSrcCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlSrcCase) SetNwDstCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCase) SetTpDstCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpDstCase) StripVlanCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCase) SetNwTosCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTosCase) OutputActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 17 with OutputActionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase in project openflowplugin by opendaylight.

the class OfToSalOutputActionCase method process.

@Override
public Optional<Action> process(@Nonnull final OutputActionCase source, final ActionResponseConvertorData data, ConvertorExecutor convertorExecutor) {
    final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
    OutputActionBuilder outputAction = new OutputActionBuilder();
    OutputAction outputActionFromOF = source.getOutputAction();
    if (outputActionFromOF.getPort() != null) {
        PortNumberUni protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion, outputActionFromOF.getPort().getValue());
        String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
        outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
    } else {
        LOG.error("Provided action is not OF Output action, no associated port found!");
    }
    Integer maxLength = outputActionFromOF.getMaxLength();
    if (maxLength != null) {
        outputAction.setMaxLength(maxLength);
    } else {
        LOG.error("Provided action is not OF Output action, no associated length found!");
    }
    OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder();
    outputActionCaseBuilder.setOutputAction(outputAction.build());
    return Optional.of(outputActionCaseBuilder.build());
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) OutputAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction) PortNumberUni(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)

Example 18 with OutputActionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase in project openflowplugin by opendaylight.

the class ActionConvertorV10Test method testToMDSalActions.

/**
 * Test {@link ActionResponseConvertor#convert(List, ActionResponseConvertorData)}}.
 */
@Test
public void testToMDSalActions() {
    OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
    OutputActionBuilder outputBuilder = new OutputActionBuilder();
    outputBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(14L));
    outputBuilder.setMaxLength(555);
    caseBuilder.setOutputAction(outputBuilder.build());
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
    actionBuilder.setActionChoice(caseBuilder.build());
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> actions = new ArrayList<>();
    actions.add(actionBuilder.build());
    ActionResponseConvertorData data = new ActionResponseConvertorData(OFConstants.OFP_VERSION_1_0);
    data.setActionPath(ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
    Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> mdSalActionsOptional = convertorManager.convert(actions, data);
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> mdSalActions = mdSalActionsOptional.orElse(Collections.emptyList());
    Assert.assertEquals("Wrong number of output actions", 1, mdSalActions.size());
    org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = mdSalActions.get(0);
    Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types" + ".rev131112.action.action.OutputActionCase", action.getImplementedInterface().getName());
    OutputActionCase outputAction = (OutputActionCase) action;
    Assert.assertEquals("Wrong output port", "14", outputAction.getOutputAction().getOutputNodeConnector().getValue());
    Assert.assertEquals("Wrong max length", 555, outputAction.getOutputAction().getMaxLength().intValue());
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) SetTpDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder) SetVlanIdActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder) SetNwTosActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder) SetTpSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder) SetNwDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder) SetDlDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder) StripVlanActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder) SetVlanPcpActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder) SetDlSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) ArrayList(java.util.ArrayList) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) List(java.util.List) ArrayList(java.util.ArrayList) OutputActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase) ActionResponseConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 OutputActionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase)8 OutputActionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)7 ByteBuf (io.netty.buffer.ByteBuf)6 ArrayList (java.util.ArrayList)5 PushVlanActionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase)4 SetFieldCase (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase)4 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder)4 CopyTtlInCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase)3 CopyTtlOutCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase)3 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Nonnull (javax.annotation.Nonnull)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)2 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)2 ActionOutput (org.opendaylight.genius.mdsalutil.actions.ActionOutput)2 ActionPushVlan (org.opendaylight.genius.mdsalutil.actions.ActionPushVlan)2 ActionRegLoad (org.opendaylight.genius.mdsalutil.actions.ActionRegLoad)2