From 2b5094b8ffd0e06dfaad372437e01ff1bd194623 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Thu, 26 Mar 2015 15:27:24 +0100 Subject: [PATCH] Instruction experimenterId fix Change-Id: I19dde700890e9211b37cfef70b35d764391831f0 Signed-off-by: Michal Polkorab --- .../SerializerExtensionProvider.java | 8 ++++---- .../api/keys/ActionSerializerKey.java | 3 ++- .../api/keys/InstructionSerializerKey.java | 2 +- .../src/main/yang/openflow-instruction.yang | 3 +++ .../core/SwitchConnectionProviderImpl.java | 8 ++++---- .../impl/util/TypeKeyMakerFactory.java | 11 ++++------- .../impl/util/TypeKeyMakerFactoryTest.java | 19 ++++++------------- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java index 8729f874..9e73e951 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java @@ -8,10 +8,10 @@ package org.opendaylight.openflowjava.protocol.api.extensibility; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase; @@ -47,7 +47,7 @@ public interface SerializerExtensionProvider { * @param key used for serializer lookup * @param serializer serializer implementation */ - void registerActionSerializer(ExperimenterActionSerializerKey key, + void registerActionSerializer(ActionSerializerKey key, OFGeneralSerializer serializer); /** @@ -55,7 +55,7 @@ public interface SerializerExtensionProvider { * @param key used for serializer lookup * @param serializer serializer implementation */ - void registerInstructionSerializer(ExperimenterInstructionSerializerKey key, + void registerInstructionSerializer(InstructionSerializerKey key, OFGeneralSerializer serializer); /** diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ActionSerializerKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ActionSerializerKey.java index f23c01c6..7d096f84 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ActionSerializerKey.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ActionSerializerKey.java @@ -15,7 +15,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 * @author michal.polkorab * @param action type */ -public class ActionSerializerKey extends MessageTypeKey { +public class ActionSerializerKey extends MessageTypeKey + implements ExperimenterSerializerKey { private Class actionType; private Long experimenterId; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/InstructionSerializerKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/InstructionSerializerKey.java index 6f9a299b..89f5cbfe 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/InstructionSerializerKey.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/InstructionSerializerKey.java @@ -16,7 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction * @param instruction type */ public class InstructionSerializerKey - extends MessageTypeKey{ + extends MessageTypeKey implements ExperimenterSerializerKey { private Class instructionType; private Long experimenterId; diff --git a/openflow-protocol-api/src/main/yang/openflow-instruction.yang b/openflow-protocol-api/src/main/yang/openflow-instruction.yang index 293e3803..a58fc349 100644 --- a/openflow-protocol-api/src/main/yang/openflow-instruction.yang +++ b/openflow-protocol-api/src/main/yang/openflow-instruction.yang @@ -25,6 +25,9 @@ list instruction { config false; uses instruction-grouping; + leaf experimenter-id { + type oft:experimenter-id; + } } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java index 852ce64f..51b802e3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java @@ -19,14 +19,14 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeseria import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterDeserializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey; @@ -181,7 +181,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C } @Override - public void registerActionSerializer(ExperimenterActionSerializerKey key, + public void registerActionSerializer(ActionSerializerKey key, OFGeneralSerializer serializer) { serializerRegistry.registerSerializer(key, serializer); } @@ -193,7 +193,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C } @Override - public void registerInstructionSerializer(ExperimenterInstructionSerializerKey key, + public void registerInstructionSerializer(InstructionSerializerKey key, OFGeneralSerializer serializer) { serializerRegistry.registerSerializer(key, serializer); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactory.java index e954a436..7fef029c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactory.java @@ -9,7 +9,6 @@ package org.opendaylight.openflowjava.protocol.impl.util; import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; @@ -83,12 +82,10 @@ public abstract class TypeKeyMakerFactory { return new AbstractTypeKeyMaker(version) { @Override public MessageTypeKey make(Instruction entry) { - if (entry.getInstructionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow - .augments.rev150225.instruction.container.instruction.choice.ExperimenterIdCase) { - return new ExperimenterInstructionSerializerKey(getVersion(), - ((org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.instruction - .container.instruction.choice.ExperimenterIdCase) entry.getInstructionChoice()) - .getExperimenter().getExperimenterId().getValue()); + if (entry.getExperimenterId() != null) { + return new InstructionSerializerKey<>(getVersion(), + (Class) entry.getInstructionChoice().getImplementedInterface(), + entry.getExperimenterId().getValue()); } return new InstructionSerializerKey<>(getVersion(), (Class) entry.getInstructionChoice().getImplementedInterface(), null); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java index c6278285..0cfb0940 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java @@ -11,7 +11,6 @@ package org.opendaylight.openflowjava.protocol.impl.util; import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; @@ -25,6 +24,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; @@ -107,22 +108,14 @@ public class TypeKeyMakerFactoryTest { Assert.assertNotNull("Null keyMaker", keyMaker); InstructionBuilder builder = new InstructionBuilder(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.instruction.container - .instruction.choice.ExperimenterIdCaseBuilder caseBuilder = new org.opendaylight.yang.gen.v1.urn - .opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice.ExperimenterIdCaseBuilder(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.instruction.container - .instruction.choice.experimenter.id._case.ExperimenterBuilder expIdBuilder = new org.opendaylight.yang.gen - .v1.urn.opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice.experimenter.id - ._case.ExperimenterBuilder(); - expIdBuilder.setExperimenterId(new ExperimenterId(42L)); - caseBuilder.setExperimenter(expIdBuilder.build()); - builder.setInstructionChoice(caseBuilder.build()); + builder.setExperimenterId(new ExperimenterId(42L)); + builder.setInstructionChoice(new ClearActionsCaseBuilder().build()); Instruction instruction = builder.build(); MessageTypeKey key = keyMaker.make(instruction); Assert.assertNotNull("Null key", key); - Assert.assertEquals("Wrong key", new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, - 42L), key); + Assert.assertEquals("Wrong key", new InstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, + ClearActionsCase.class, 42L), key); } /** -- 2.36.6