From c4b4dfc4b6d85753b4b3ff5ddef0f1c0595211fc Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 21 Nov 2016 13:59:54 +0100 Subject: [PATCH] Add Action serializers Inject action serializers into OFJ. These serializers will serialize these actions to raw bytes: - CopyTtlIn - CopyTtlOut - DecMplsTtl - DecNwTtl - GroupAction - OutputAction - PopMplsAction - PopPbbAction - PopVlanAction - PushMplsAction - PushPbbAction - PushVlanAction - SetMplsTtlAction - SetNwTtlAction - SetQueueAction - SetFieldAction - DropAction - SetVlanIdAction - SetVlanPcpAction - StripVlanAction - SetDlSrcAction - SetDlDstAction - SetNwSrcAction - SetNwDstAction - SetTpSrcAction - SetTpDstAction - SetNwTosAction See also: bug 7138 Change-Id: I5b42b0b2d2afd3468768e28bd11bfdcfcbbbc142 Signed-off-by: Tomas Slusny --- .../ActionSerializerInjector.java | 84 ++++++++++++++++++- .../AbstractSetFieldActionSerializer.java | 3 +- .../actions/CopyTtlInActionSerializer.java | 31 +++++++ .../actions/CopyTtlOutActionSerializer.java | 31 +++++++ .../actions/DecMplsTtlActionSerializer.java | 31 +++++++ .../actions/DecNwTtlActionSerializer.java | 31 +++++++ .../actions/DropActionSerializer.java | 35 ++++++++ .../actions/GroupActionSerializer.java | 34 ++++++++ .../actions/OutputActionSerializer.java | 40 +++++++++ .../actions/PopMplsActionSerializer.java | 35 ++++++++ .../actions/PopPbbActionSerializer.java | 31 +++++++ .../actions/PopVlanActionSerializer.java | 31 +++++++ .../actions/PushMplsActionSerializer.java | 35 ++++++++ .../actions/PushPbbActionSerializer.java | 35 ++++++++ .../actions/PushVlanActionSerializer.java | 35 ++++++++ .../actions/SetDlDstActionSerializer.java | 34 ++++++++ .../actions/SetDlSrcActionSerializer.java | 34 ++++++++ .../actions/SetFieldActionSerializer.java | 62 ++++++++++++++ .../actions/SetMplsTtlActionSerializer.java | 35 ++++++++ .../actions/SetNwDstActionSerializer.java | 42 ++++++++++ .../actions/SetNwSrcActionSerializer.java | 42 ++++++++++ .../actions/SetNwTosActionSerializer.java | 35 ++++++++ .../actions/SetNwTtlActionSerializer.java | 35 ++++++++ .../actions/SetQueueActionSerializer.java | 34 ++++++++ .../actions/SetTpDstActionSerializer.java | 65 ++++++++++++++ .../actions/SetTpSrcActionSerializer.java | 65 ++++++++++++++ .../actions/SetVlanIdActionSerializer.java | 35 ++++++++ .../actions/SetVlanPcpActionSerializer.java | 31 +++++++ .../actions/StripVlanActionSerializer.java | 35 ++++++++ .../CopyTtlInActionSerializerTest.java | 45 ++++++++++ .../CopyTtlOutActionSerializerTest.java | 45 ++++++++++ .../DecMplsTtlActionSerializerTest.java | 45 ++++++++++ .../actions/DecNwTtlActionSerializerTest.java | 45 ++++++++++ .../actions/GroupActionSerializerTest.java | 50 +++++++++++ .../actions/OutputActionSerializerTest.java | 60 +++++++++++++ .../actions/PopMplsActionSerializerTest.java | 53 ++++++++++++ .../actions/PopPbbActionSerializerTest.java | 45 ++++++++++ .../actions/PopVlanActionSerializerTest.java | 45 ++++++++++ .../actions/PushMplsActionSerializerTest.java | 53 ++++++++++++ .../actions/PushPbbActionSerializerTest.java | 53 ++++++++++++ .../actions/PushVlanActionSerializerTest.java | 53 ++++++++++++ .../actions/SetDlDstActionSerializerTest.java | 45 ++++++++++ .../actions/SetDlSrcActionSerializerTest.java | 45 ++++++++++ .../SetMplsTtlActionSerializerTest.java | 52 ++++++++++++ .../actions/SetNwDstActionSerializerTest.java | 48 +++++++++++ .../actions/SetNwSrcActionSerializerTest.java | 48 +++++++++++ .../actions/SetNwTosActionSerializerTest.java | 40 +++++++++ .../actions/SetNwTtlActionSerializerTest.java | 53 ++++++++++++ .../actions/SetQueueActionSerializerTest.java | 50 +++++++++++ .../actions/SetTpDstActionSerializerTest.java | 42 ++++++++++ .../actions/SetTpSrcActionSerializerTest.java | 42 ++++++++++ .../SetVlanIdActionSerializerTest.java | 40 +++++++++ .../SetVlanPcpActionSerializerTest.java | 40 +++++++++ .../StripVlanActionSerializerTest.java | 42 ++++++++++ 54 files changed, 2282 insertions(+), 3 deletions(-) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DropActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetFieldActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializer.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializer.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializerTest.java diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/ActionSerializerInjector.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/ActionSerializerInjector.java index b0d5d52a9c..08cfcaaf16 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/ActionSerializerInjector.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/ActionSerializerInjector.java @@ -15,7 +15,61 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider; import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.CopyTtlInActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.CopyTtlOutActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.DecMplsTtlActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.DecNwTtlActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.DropActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.GroupActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.OutputActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.PopMplsActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.PopPbbActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.PopVlanActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.PushMplsActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.PushPbbActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.PushVlanActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetDlDstActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetDlSrcActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetFieldActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetMplsTtlActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetNwDstActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetNwSrcActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetNwTosActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetNwTtlActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetQueueActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetTpDstActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetTpSrcActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetVlanIdActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.SetVlanPcpActionSerializer; +import org.opendaylight.openflowplugin.impl.protocol.serialization.actions.StripVlanActionSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase; /** * Util class for injecting new action serializers into OpenflowJava @@ -30,6 +84,34 @@ class ActionSerializerInjector { // Inject new action serializers here using injector created by createInjector method final Function, Consumer>> injector = createInjector(provider, EncodeConstants.OF13_VERSION_ID); + + injector.apply(SetFieldCase.class).accept(new SetFieldActionSerializer()); + injector.apply(CopyTtlInCase.class).accept(new CopyTtlInActionSerializer()); + injector.apply(CopyTtlOutCase.class).accept(new CopyTtlOutActionSerializer()); + injector.apply(DecMplsTtlCase.class).accept(new DecMplsTtlActionSerializer()); + injector.apply(DecNwTtlCase.class).accept(new DecNwTtlActionSerializer()); + injector.apply(GroupActionCase.class).accept(new GroupActionSerializer()); + injector.apply(OutputActionCase.class).accept(new OutputActionSerializer()); + injector.apply(PopMplsActionCase.class).accept(new PopMplsActionSerializer()); + injector.apply(PopPbbActionCase.class).accept(new PopPbbActionSerializer()); + injector.apply(PopVlanActionCase.class).accept(new PopVlanActionSerializer()); + injector.apply(PushMplsActionCase.class).accept(new PushMplsActionSerializer()); + injector.apply(PushPbbActionCase.class).accept(new PushPbbActionSerializer()); + injector.apply(PushVlanActionCase.class).accept(new PushVlanActionSerializer()); + injector.apply(SetMplsTtlActionCase.class).accept(new SetMplsTtlActionSerializer()); + injector.apply(SetNwTtlActionCase.class).accept(new SetNwTtlActionSerializer()); + injector.apply(SetQueueActionCase.class).accept(new SetQueueActionSerializer()); + injector.apply(DropActionCase.class).accept(new DropActionSerializer()); + injector.apply(SetVlanIdActionCase.class).accept(new SetVlanIdActionSerializer()); + injector.apply(SetVlanPcpActionCase.class).accept(new SetVlanPcpActionSerializer()); + injector.apply(StripVlanActionCase.class).accept(new StripVlanActionSerializer()); + injector.apply(SetDlSrcActionCase.class).accept(new SetDlSrcActionSerializer()); + injector.apply(SetDlDstActionCase.class).accept(new SetDlDstActionSerializer()); + injector.apply(SetNwSrcActionCase.class).accept(new SetNwSrcActionSerializer()); + injector.apply(SetNwDstActionCase.class).accept(new SetNwDstActionSerializer()); + injector.apply(SetTpSrcActionCase.class).accept(new SetTpSrcActionSerializer()); + injector.apply(SetTpDstActionCase.class).accept(new SetTpDstActionSerializer()); + injector.apply(SetNwTosActionCase.class).accept(new SetNwTosActionSerializer()); } /** @@ -47,4 +129,4 @@ class ActionSerializerInjector { new MessageTypeKey<>(version, type), serializer); } -} \ No newline at end of file +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/AbstractSetFieldActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/AbstractSetFieldActionSerializer.java index 06289bda0c..17cdd527a0 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/AbstractSetFieldActionSerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/AbstractSetFieldActionSerializer.java @@ -17,7 +17,6 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldAction; public abstract class AbstractSetFieldActionSerializer extends AbstractActionSerializer implements SerializerRegistryInjector { @@ -26,7 +25,7 @@ public abstract class AbstractSetFieldActionSerializer extends AbstractActionSer @Override public void serialize(Action input, ByteBuf outBuffer) { final OFSerializer serializer = registry - .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetFieldAction.class)); + .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetFieldCase.class)); serializer.serialize(buildAction(input), outBuffer); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializer.java new file mode 100644 index 0000000000..9ea760c538 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class CopyTtlInActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + outBuffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.COPY_TTL_IN_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializer.java new file mode 100644 index 0000000000..c9114d2015 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class CopyTtlOutActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + outBuffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.COPY_TTL_OUT_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializer.java new file mode 100644 index 0000000000..fb624215b0 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class DecMplsTtlActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + outBuffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.DEC_MPLS_TTL_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializer.java new file mode 100644 index 0000000000..e758ab18f0 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class DecNwTtlActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + outBuffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.DEC_NW_TTL_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DropActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DropActionSerializer.java new file mode 100644 index 0000000000..22d3e717e4 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DropActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class DropActionSerializer extends AbstractActionSerializer { + + @Override + public void serialize(Action action, ByteBuf outBuffer) { + // NOOP + } + + @Override + public void serializeHeader(Action action, ByteBuf outBuffer) { + // NOOP + } + + @Override + protected int getLength() { + return 0; + } + + @Override + protected int getType() { + return 0; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializer.java new file mode 100644 index 0000000000..e52f2afffe --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction; + +public class GroupActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final GroupAction groupAction = GroupActionCase.class.cast(action).getGroupAction(); + outBuffer.writeInt(groupAction.getGroupId().intValue()); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.GROUP_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializer.java new file mode 100644 index 0000000000..8c8cabac66 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializer.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction; + +public class OutputActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final OutputAction outputAction = OutputActionCase.class.cast(action).getOutputAction(); + outBuffer.writeInt(InventoryDataServiceUtil.portNumberfromNodeConnectorId( + OpenflowVersion.OF13, + outputAction.getOutputNodeConnector().getValue()).intValue()); + outBuffer.writeShort(outputAction.getMaxLength()); + outBuffer.writeZero(ActionConstants.OUTPUT_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.LARGER_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.OUTPUT_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializer.java new file mode 100644 index 0000000000..952e077c74 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsAction; + +public class PopMplsActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final PopMplsAction popMplsAction = PopMplsActionCase.class.cast(action).getPopMplsAction(); + outBuffer.writeShort(popMplsAction.getEthernetType()); + outBuffer.writeZero(ActionConstants.ETHERTYPE_ACTION_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.POP_MPLS_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializer.java new file mode 100644 index 0000000000..5142dc6737 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class PopPbbActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + outBuffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.POP_PBB_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializer.java new file mode 100644 index 0000000000..87f5a56605 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; + +public class PopVlanActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + outBuffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.POP_VLAN_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializer.java new file mode 100644 index 0000000000..84baee876a --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsAction; + +public class PushMplsActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final PushMplsAction pushMplsAction = PushMplsActionCase.class.cast(action).getPushMplsAction(); + outBuffer.writeShort(pushMplsAction.getEthernetType()); + outBuffer.writeZero(ActionConstants.ETHERTYPE_ACTION_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.PUSH_MPLS_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializer.java new file mode 100644 index 0000000000..9c04c9b2ea --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbAction; + +public class PushPbbActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final PushPbbAction pushPbbAction = PushPbbActionCase.class.cast(action).getPushPbbAction(); + outBuffer.writeShort(pushPbbAction.getEthernetType()); + outBuffer.writeZero(ActionConstants.ETHERTYPE_ACTION_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.PUSH_PBB_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializer.java new file mode 100644 index 0000000000..4318fcdbe1 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction; + +public class PushVlanActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final PushVlanAction pushVlanAction = PushVlanActionCase.class.cast(action).getPushVlanAction(); + outBuffer.writeShort(pushVlanAction.getEthernetType()); + outBuffer.writeZero(ActionConstants.ETHERTYPE_ACTION_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.PUSH_VLAN_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializer.java new file mode 100644 index 0000000000..471118bfd9 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder; + +public class SetDlDstActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + return new SetFieldCaseBuilder() + .setSetField(new SetFieldBuilder() + .setEthernetMatch(new EthernetMatchBuilder() + .setEthernetDestination(new EthernetDestinationBuilder() + .setAddress(SetDlDstActionCase.class.cast(input).getSetDlDstAction().getAddress()) + .build()) + .build()) + .build()) + .build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializer.java new file mode 100644 index 0000000000..b2431f9944 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder; + +public class SetDlSrcActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + return new SetFieldCaseBuilder() + .setSetField(new SetFieldBuilder() + .setEthernetMatch(new EthernetMatchBuilder() + .setEthernetSource(new EthernetSourceBuilder() + .setAddress(SetDlSrcActionCase.class.cast(input).getSetDlSrcAction().getAddress()) + .build()) + .build()) + .build()) + .build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetFieldActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetFieldActionSerializer.java new file mode 100644 index 0000000000..297e200ce2 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetFieldActionSerializer.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match; + +public class SetFieldActionSerializer extends AbstractActionSerializer implements SerializerRegistryInjector { + private SerializerRegistry registry; + + @Override + public void serialize(Action action, ByteBuf outBuffer) { + // Serialize field type and save position + int startIndex = outBuffer.writerIndex(); + outBuffer.writeShort(getType()); + int lengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + + // Serialize match (using small workaround with serializeHeader method to serialize only match entries) + final SetField setField = SetFieldCase.class.cast(action).getSetField(); + final HeaderSerializer serializer = registry + .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class)); + serializer.serializeHeader(setField, outBuffer); + + // Serialize padding based on match length + int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder); + } + outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.SET_FIELD_CODE; + } + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + registry = serializerRegistry; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializer.java new file mode 100644 index 0000000000..17769d2dbb --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction; + +public class SetMplsTtlActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final SetMplsTtlAction setMplsTtlAction = SetMplsTtlActionCase.class.cast(action).getSetMplsTtlAction(); + outBuffer.writeByte(setMplsTtlAction.getMplsTtl()); + outBuffer.writeZero(ActionConstants.SET_MPLS_TTL_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.SET_MPLS_TTL_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializer.java new file mode 100644 index 0000000000..19e1af2033 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializer.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder; + +public class SetNwDstActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + final Address address = SetNwDstActionCase.class.cast(input).getSetNwDstAction().getAddress(); + final SetFieldBuilder builder = new SetFieldBuilder(); + + if (Ipv4.class.isInstance(address)) { + builder.setLayer3Match(new Ipv4MatchBuilder() + .setIpv4Destination(Ipv4.class.cast(address).getIpv4Address()) + .build()); + } else if (Ipv6.class.isInstance(address)) { + builder.setLayer3Match(new Ipv6MatchBuilder() + .setIpv6Destination(Ipv6.class.cast(address).getIpv6Address()) + .build()); + } + + return new SetFieldCaseBuilder().setSetField(builder.build()).build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializer.java new file mode 100644 index 0000000000..bafcf4d15c --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializer.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder; + +public class SetNwSrcActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + final Address address = SetNwSrcActionCase.class.cast(input).getSetNwSrcAction().getAddress(); + final SetFieldBuilder builder = new SetFieldBuilder(); + + if (Ipv4.class.isInstance(address)) { + builder.setLayer3Match(new Ipv4MatchBuilder() + .setIpv4Source(Ipv4.class.cast(address).getIpv4Address()) + .build()); + } else if (Ipv6.class.isInstance(address)) { + builder.setLayer3Match(new Ipv6MatchBuilder() + .setIpv6Source(Ipv6.class.cast(address).getIpv6Address()) + .build()); + } + + return new SetFieldCaseBuilder().setSetField(builder.build()).build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializer.java new file mode 100644 index 0000000000..edce954f14 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder; + +public class SetNwTosActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + return new SetFieldCaseBuilder() + .setSetField(new SetFieldBuilder() + .setIpMatch(new IpMatchBuilder() + .setIpDscp(new Dscp( + ActionUtil.tosToDscp(SetNwTosActionCase.class.cast(input) + .getSetNwTosAction().getTos().shortValue()))) + .build()) + .build()) + .build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializer.java new file mode 100644 index 0000000000..db93e8ed54 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlAction; + +public class SetNwTtlActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final SetNwTtlAction setNwTtlAction = SetNwTtlActionCase.class.cast(action).getSetNwTtlAction(); + outBuffer.writeByte(setNwTtlAction.getNwTtl()); + outBuffer.writeZero(ActionConstants.SET_NW_TTL_PADDING); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.SET_NW_TTL_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializer.java new file mode 100644 index 0000000000..4b0f6681ef --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueAction; + +public class SetQueueActionSerializer extends AbstractActionSerializer { + @Override + public void serialize(Action action, ByteBuf outBuffer) { + super.serialize(action, outBuffer); + final SetQueueAction setQueueAction = SetQueueActionCase.class.cast(action).getSetQueueAction(); + outBuffer.writeByte(setQueueAction.getQueueId().intValue()); + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + + @Override + protected int getType() { + return ActionConstants.SET_QUEUE_CODE; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializer.java new file mode 100644 index 0000000000..31b828ba86 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializer.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import java.util.Optional; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder; + +public class SetTpDstActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + final SetTpDstAction setTpDstAction = SetTpDstActionCase.class.cast(input).getSetTpDstAction(); + final PortNumber port = setTpDstAction.getPort(); + final SetFieldBuilder builder = new SetFieldBuilder(); + + Optional.ofNullable(IPProtocols.fromProtocolNum(setTpDstAction.getIpProtocol())).ifPresent(proto -> { + switch (proto) { + case ICMP: { + builder.setIcmpv4Match(new Icmpv4MatchBuilder() + .setIcmpv4Code((short) (0xFF & port.getValue())) + .build()); + break; + } + case ICMPV6: { + builder.setIcmpv6Match(new Icmpv6MatchBuilder() + .setIcmpv6Code((short) (0xFF & port.getValue())) + .build()); + break; + } + case TCP: { + builder.setLayer4Match(new TcpMatchBuilder() + .setTcpDestinationPort(port) + .build()); + break; + } + case UDP: { + builder.setLayer4Match(new UdpMatchBuilder() + .setUdpDestinationPort(port) + .build()); + break; + } + } + }); + + return new SetFieldCaseBuilder().setSetField(builder.build()).build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializer.java new file mode 100644 index 0000000000..b2cf4fa1b3 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializer.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import java.util.Optional; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder; + +public class SetTpSrcActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + final SetTpSrcAction setTpSrcAction = SetTpSrcActionCase.class.cast(input).getSetTpSrcAction(); + final PortNumber port = setTpSrcAction.getPort(); + final SetFieldBuilder builder = new SetFieldBuilder(); + + Optional.ofNullable(IPProtocols.fromProtocolNum(setTpSrcAction.getIpProtocol())).ifPresent(proto -> { + switch (proto) { + case ICMP: { + builder.setIcmpv4Match(new Icmpv4MatchBuilder() + .setIcmpv4Type((short) (0xFF & port.getValue())) + .build()); + break; + } + case ICMPV6: { + builder.setIcmpv6Match(new Icmpv6MatchBuilder() + .setIcmpv6Type((short) (0xFF & port.getValue())) + .build()); + break; + } + case TCP: { + builder.setLayer4Match(new TcpMatchBuilder() + .setTcpSourcePort(port) + .build()); + break; + } + case UDP: { + builder.setLayer4Match(new UdpMatchBuilder() + .setUdpSourcePort(port) + .build()); + break; + } + } + }); + + return new SetFieldCaseBuilder().setSetField(builder.build()).build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializer.java new file mode 100644 index 0000000000..f6ffd7568e --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; + +public class SetVlanIdActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + return new SetFieldCaseBuilder() + .setSetField(new SetFieldBuilder() + .setVlanMatch(new VlanMatchBuilder() + .setVlanId(new VlanIdBuilder() + .setVlanIdPresent(true) + .setVlanId(SetVlanIdActionCase.class.cast(input).getSetVlanIdAction().getVlanId()) + .build()) + .build()) + .build()) + .build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializer.java new file mode 100644 index 0000000000..a99d7bb575 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; + +public class SetVlanPcpActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + return new SetFieldCaseBuilder() + .setSetField(new SetFieldBuilder() + .setVlanMatch(new VlanMatchBuilder() + .setVlanPcp((SetVlanPcpActionCase.class.cast(input).getSetVlanPcpAction().getVlanPcp())) + .build()) + .build()) + .build(); + } + +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializer.java new file mode 100644 index 0000000000..e1dc956ef5 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; + +public class StripVlanActionSerializer extends AbstractSetFieldActionSerializer { + + @Override + protected SetFieldCase buildAction(Action input) { + return new SetFieldCaseBuilder() + .setSetField(new SetFieldBuilder() + .setVlanMatch(new VlanMatchBuilder() + .setVlanId(new VlanIdBuilder() + .setVlanIdPresent(true) + .setVlanId(new VlanId(0x0000)) + .build()) + .build()) + .build()) + .build(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializerTest.java new file mode 100644 index 0000000000..667f387633 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlInActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder; + +public class CopyTtlInActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new CopyTtlInCaseBuilder() + .setCopyTtlIn(new CopyTtlInBuilder() + .build()) + .build(); + + assertAction(action, out -> out.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER)); + } + + @Override + protected Class getClazz() { + return CopyTtlInCase.class; + } + + @Override + protected int getType() { + return ActionConstants.COPY_TTL_IN_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializerTest.java new file mode 100644 index 0000000000..14f90b2ed4 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/CopyTtlOutActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder; + +public class CopyTtlOutActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new CopyTtlOutCaseBuilder() + .setCopyTtlOut(new CopyTtlOutBuilder() + .build()) + .build(); + + assertAction(action, out -> out.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER)); + } + + @Override + protected Class getClazz() { + return CopyTtlOutCase.class; + } + + @Override + protected int getType() { + return ActionConstants.COPY_TTL_OUT_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializerTest.java new file mode 100644 index 0000000000..415c7e5b67 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecMplsTtlActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder; + +public class DecMplsTtlActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new DecMplsTtlCaseBuilder() + .setDecMplsTtl(new DecMplsTtlBuilder() + .build()) + .build(); + + assertAction(action, out -> out.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER)); + } + + @Override + protected Class getClazz() { + return DecMplsTtlCase.class; + } + + @Override + protected int getType() { + return ActionConstants.DEC_MPLS_TTL_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializerTest.java new file mode 100644 index 0000000000..6d3fa185f8 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/DecNwTtlActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder; + +public class DecNwTtlActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new DecNwTtlCaseBuilder() + .setDecNwTtl(new DecNwTtlBuilder() + .build()) + .build(); + + assertAction(action, out -> out.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER)); + } + + @Override + protected Class getClazz() { + return DecNwTtlCase.class; + } + + @Override + protected int getType() { + return ActionConstants.DEC_NW_TTL_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializerTest.java new file mode 100644 index 0000000000..47fcf4b33c --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/GroupActionSerializerTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder; + +public class GroupActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final long group = 10L; + + final Action action = new GroupActionCaseBuilder() + .setGroupAction(new GroupActionBuilder() + .setGroupId(group) + .build()) + .build(); + + assertAction(action, out -> assertEquals(out.readUnsignedInt(), group)); + } + + @Override + protected Class getClazz() { + return GroupActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.GROUP_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializerTest.java new file mode 100644 index 0000000000..1e114c2dbd --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/OutputActionSerializerTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.BinContent; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValues; + +public class OutputActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int length = 10; + final String port = OutputPortValues.LOCAL.toString(); + + final Action action = new OutputActionCaseBuilder() + .setOutputAction(new OutputActionBuilder() + .setOutputNodeConnector(new Uri("openflow:1:" + port)) + .setMaxLength(length) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedInt(), BinContent.intToUnsignedLong(PortNumberValues.LOCAL.getIntValue())); + assertEquals(out.readUnsignedShort(), length); + out.skipBytes(ActionConstants.OUTPUT_PADDING); + }); + } + + @Override + protected Class getClazz() { + return OutputActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.OUTPUT_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.LARGER_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializerTest.java new file mode 100644 index 0000000000..253054d5e9 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopMplsActionSerializerTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder; + +public class PopMplsActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int ethType = 10; + + final Action action = new PopMplsActionCaseBuilder() + .setPopMplsAction(new PopMplsActionBuilder() + .setEthernetType(ethType) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedShort(), ethType); + out.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING); + }); + } + + @Override + protected Class getClazz() { + return PopMplsActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.POP_MPLS_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializerTest.java new file mode 100644 index 0000000000..4461580f74 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopPbbActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder; + +public class PopPbbActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new PopPbbActionCaseBuilder() + .setPopPbbAction(new PopPbbActionBuilder() + .build()) + .build(); + + assertAction(action, out -> out.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER)); + } + + @Override + protected Class getClazz() { + return PopPbbActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.POP_PBB_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializerTest.java new file mode 100644 index 0000000000..302e1bad38 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PopVlanActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder; + +public class PopVlanActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new PopVlanActionCaseBuilder() + .setPopVlanAction(new PopVlanActionBuilder() + .build()) + .build(); + + assertAction(action, out -> out.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER)); + } + + @Override + protected Class getClazz() { + return PopVlanActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.POP_VLAN_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializerTest.java new file mode 100644 index 0000000000..24dfa5f860 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushMplsActionSerializerTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder; + +public class PushMplsActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int ethType = 10; + + final Action action = new PushMplsActionCaseBuilder() + .setPushMplsAction(new PushMplsActionBuilder() + .setEthernetType(ethType) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedShort(), ethType); + out.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING); + }); + } + + @Override + protected Class getClazz() { + return PushMplsActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.PUSH_MPLS_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializerTest.java new file mode 100644 index 0000000000..9ac7fa80e9 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushPbbActionSerializerTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder; + +public class PushPbbActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int ethType = 10; + + final Action action = new PushPbbActionCaseBuilder() + .setPushPbbAction(new PushPbbActionBuilder() + .setEthernetType(ethType) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedShort(), ethType); + out.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING); + }); + } + + @Override + protected Class getClazz() { + return PushPbbActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.PUSH_PBB_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializerTest.java new file mode 100644 index 0000000000..731ce1d8b8 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/PushVlanActionSerializerTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder; + +public class PushVlanActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int ethType = 10; + + final Action action = new PushVlanActionCaseBuilder() + .setPushVlanAction(new PushVlanActionBuilder() + .setEthernetType(ethType) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedShort(), ethType); + out.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING); + }); + } + + @Override + protected Class getClazz() { + return PushVlanActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.PUSH_VLAN_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializerTest.java new file mode 100644 index 0000000000..7f09a69489 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlDstActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder; + +public class SetDlDstActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final MacAddress address = new MacAddress("00:01:02:03:04:05"); + + final Action action = new SetDlDstActionCaseBuilder() + .setSetDlDstAction(new SetDlDstActionBuilder() + .setAddress(address) + .build()) + .build(); + + assertAction(action, out -> { + byte[] addressBytes = new byte[6]; + out.readBytes(addressBytes); + assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue()); + }); + } + + @Override + protected Class getClazz() { + return SetDlDstActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializerTest.java new file mode 100644 index 0000000000..03249df81a --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetDlSrcActionSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder; + +public class SetDlSrcActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final MacAddress address = new MacAddress("00:01:02:03:04:05"); + + final Action action = new SetDlSrcActionCaseBuilder() + .setSetDlSrcAction(new SetDlSrcActionBuilder() + .setAddress(address) + .build()) + .build(); + + assertAction(action, out -> { + byte[] addressBytes = new byte[6]; + out.readBytes(addressBytes); + assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue()); + }); + } + + @Override + protected Class getClazz() { + return SetDlSrcActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializerTest.java new file mode 100644 index 0000000000..36bec2f1b8 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetMplsTtlActionSerializerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder; + +public class SetMplsTtlActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final short mpls = (short) 10; + + final Action action = new SetMplsTtlActionCaseBuilder() + .setSetMplsTtlAction(new SetMplsTtlActionBuilder() + .setMplsTtl(mpls) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedByte(), mpls); + out.skipBytes(ActionConstants.SET_MPLS_TTL_PADDING); + }); + } + + @Override + protected Class getClazz() { + return SetMplsTtlActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.SET_MPLS_TTL_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializerTest.java new file mode 100644 index 0000000000..25b25dc1a4 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwDstActionSerializerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; + +public class SetNwDstActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Ipv4 address = new Ipv4Builder() + .setIpv4Address(new Ipv4Prefix("192.168.76.2/32")) + .build(); + + final Action action = new SetNwDstActionCaseBuilder() + .setSetNwDstAction(new SetNwDstActionBuilder() + .setAddress(address) + .build()) + .build(); + + assertAction(action, out -> { + byte[] addressBytes = new byte[4]; + out.readBytes(addressBytes); + assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 2 }); + }); + } + + @Override + protected Class getClazz() { + return SetNwDstActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializerTest.java new file mode 100644 index 0000000000..974d831ff2 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwSrcActionSerializerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; + +public class SetNwSrcActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Ipv4 address = new Ipv4Builder() + .setIpv4Address(new Ipv4Prefix("192.168.76.2/32")) + .build(); + + final Action action = new SetNwSrcActionCaseBuilder() + .setSetNwSrcAction(new SetNwSrcActionBuilder() + .setAddress(address) + .build()) + .build(); + + assertAction(action, out -> { + byte[] addressBytes = new byte[4]; + out.readBytes(addressBytes); + assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 2 }); + }); + } + + @Override + protected Class getClazz() { + return SetNwSrcActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializerTest.java new file mode 100644 index 0000000000..6953018c0c --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTosActionSerializerTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder; + +public class SetNwTosActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int tos = 10; + + final Action action = new SetNwTosActionCaseBuilder() + .setSetNwTosAction(new SetNwTosActionBuilder() + .setTos(10) + .build()) + .build(); + + assertAction(action, out -> assertEquals(out.readUnsignedByte(), (short) ActionUtil.tosToDscp((short) tos))); + } + + @Override + protected Class getClazz() { + return SetNwTosActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializerTest.java new file mode 100644 index 0000000000..7eadf5c6b5 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetNwTtlActionSerializerTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder; + +public class SetNwTtlActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final short ttl = 10; + + final Action action = new SetNwTtlActionCaseBuilder() + .setSetNwTtlAction(new SetNwTtlActionBuilder() + .setNwTtl(ttl) + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedByte(), ttl); + out.skipBytes(ActionConstants.SET_NW_TTL_PADDING); + }); + } + + @Override + protected Class getClazz() { + return SetNwTtlActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.SET_NW_TTL_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializerTest.java new file mode 100644 index 0000000000..6e8c9f419f --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetQueueActionSerializerTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder; + +public class SetQueueActionSerializerTest extends AbstractActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final long queue = 10; + + final Action action = new SetQueueActionCaseBuilder() + .setSetQueueAction(new SetQueueActionBuilder() + .setQueueId(queue) + .build()) + .build(); + + assertAction(action, out -> assertEquals(out.readUnsignedByte(), queue)); + } + + @Override + protected Class getClazz() { + return SetQueueActionCase.class; + } + + @Override + protected int getType() { + return ActionConstants.SET_QUEUE_CODE; + } + + @Override + protected int getLength() { + return ActionConstants.GENERAL_ACTION_LENGTH; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializerTest.java new file mode 100644 index 0000000000..65e1a842f5 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpDstActionSerializerTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder; + +public class SetTpDstActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final PortNumber port = new PortNumber(20); + final short protocol = 6; // TCP + + final Action action = new SetTpDstActionCaseBuilder() + .setSetTpDstAction(new SetTpDstActionBuilder() + .setPort(port) + .setIpProtocol(protocol) + .build()) + .build(); + + assertAction(action, out -> assertEquals(Integer.valueOf(out.readUnsignedShort()), port.getValue())); + } + + @Override + protected Class getClazz() { + return SetTpDstActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializerTest.java new file mode 100644 index 0000000000..95e2827898 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetTpSrcActionSerializerTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder; + +public class SetTpSrcActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final PortNumber port = new PortNumber(20); + final short protocol = 6; // TCP + + final Action action = new SetTpSrcActionCaseBuilder() + .setSetTpSrcAction(new SetTpSrcActionBuilder() + .setPort(port) + .setIpProtocol(protocol) + .build()) + .build(); + + assertAction(action, out -> assertEquals(Integer.valueOf(out.readUnsignedShort()), port.getValue())); + } + + @Override + protected Class getClazz() { + return SetTpSrcActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializerTest.java new file mode 100644 index 0000000000..cf8fab3828 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanIdActionSerializerTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; + +public class SetVlanIdActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final int vlan = 1; + + final Action action = new SetVlanIdActionCaseBuilder() + .setSetVlanIdAction(new SetVlanIdActionBuilder() + .setVlanId(new VlanId(vlan)) + .build()) + .build(); + + assertAction(action, out -> assertEquals(out.readShort(), vlan | (1 << 12))); + } + + @Override + protected Class getClazz() { + return SetVlanIdActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializerTest.java new file mode 100644 index 0000000000..c03de2bcea --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/SetVlanPcpActionSerializerTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp; + +public class SetVlanPcpActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final short vlan = 1; + + final Action action = new SetVlanPcpActionCaseBuilder() + .setSetVlanPcpAction(new SetVlanPcpActionBuilder() + .setVlanPcp(new VlanPcp(vlan)) + .build()) + .build(); + + assertAction(action, out -> assertEquals(out.readUnsignedByte(), vlan)); + } + + @Override + protected Class getClazz() { + return SetVlanPcpActionCase.class; + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializerTest.java new file mode 100644 index 0000000000..14b8e04bd3 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/actions/StripVlanActionSerializerTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.protocol.serialization.actions; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder; + +public class StripVlanActionSerializerTest extends AbstractSetFieldActionSerializerTest { + + @Test + public void testSerialize() throws Exception { + final Action action = new StripVlanActionCaseBuilder() + .setStripVlanAction(new StripVlanActionBuilder() + .build()) + .build(); + + assertAction(action, out -> { + assertEquals(out.readUnsignedShort(), (1 << 12)); + byte[] mask = new byte[2]; + out.readBytes(mask); + assertArrayEquals(mask, new byte[] { 16, 0 }); + }); + } + + @Override + protected Class getClazz() { + return StripVlanActionCase.class; + } + +} -- 2.36.6