Search in sources :

Example 81 with MessageCodeKey

use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testExperimenterActionKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createActionsKeyMaker(short)}.
 */
@Test
public void testExperimenterActionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 08 00 00 00 01");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 65535, 1L), codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ByteBuf(io.netty.buffer.ByteBuf) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey) Test(org.junit.Test)

Example 82 with MessageCodeKey

use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testExperimenterInstructionKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createInstructionsKeyMaker(short)}.
 */
@Test
public void testExperimenterInstructionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 08 00 00 00 01");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new InstructionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 65535, 1L), codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ByteBuf(io.netty.buffer.ByteBuf) InstructionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey) Test(org.junit.Test)

Example 83 with MessageCodeKey

use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testInstructionKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createInstructionsKeyMaker(short)}.
 */
@Test
public void testInstructionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("00 00 00 08");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new InstructionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0, null), codeKey);
    Assert.assertEquals("Buffer index modified", 4, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ByteBuf(io.netty.buffer.ByteBuf) InstructionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey) Test(org.junit.Test)

Example 84 with MessageCodeKey

use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testMatchEntriesKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createMatchEntriesKeyMaker(short)}.
 */
@Test
public void testMatchEntriesKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 00 04 00 00 00 01");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 32768, 0), codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) MatchEntryDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 85 with MessageCodeKey

use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.

the class ActionUtil method readActionHeader.

/**
 * Deserialize OpenFlow action header, using extension converter if available.
 * TODO: Remove also extension converters
 *
 * @param version  OpenFlow version
 * @param message  OpenFlow buffered message
 * @param registry deserializer registry
 * @param path     Action path
 */
public static Action readActionHeader(short version, ByteBuf message, DeserializerRegistry registry, ActionPath path) {
    int type = message.getUnsignedShort(message.readerIndex());
    Long expId = null;
    if (type == EncodeConstants.EXPERIMENTER_VALUE) {
        expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    }
    try {
        final MessageCodeExperimenterKey key = new MessageCodeExperimenterKey(version, type, Action.class, expId);
        final HeaderDeserializer<Action> deserializer = registry.getDeserializer(key);
        return deserializer.deserializeHeader(message);
    } catch (ClassCastException | IllegalStateException e) {
        final MessageCodeKey key = Objects.nonNull(expId) ? new ExperimenterActionDeserializerKey(version, expId) : new ActionDeserializerKey(version, type, expId);
        final HeaderDeserializer<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> deserializer = registry.getDeserializer(key);
        return ActionExtensionHelper.processAlienAction(deserializer.deserializeHeader(message), OpenflowVersion.get(version), path);
    }
}
Also used : ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action) HeaderDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer) MessageCodeExperimenterKey(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)

Aggregations

MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)85 Before (org.junit.Before)52 DeserializerRegistryImpl (org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl)52 DeserializerRegistry (org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry)51 Test (org.junit.Test)16 ByteBuf (io.netty.buffer.ByteBuf)10 BigInteger (java.math.BigInteger)8 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)7 MatchV10 (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 ArrayList (java.util.ArrayList)4 ActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)4 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)4 ExperimenterActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey)3 MatchEntryDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey)3 ExperimenterIdDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey)2 InstructionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey)2 TypeToClassKey (org.opendaylight.openflowjava.protocol.api.keys.TypeToClassKey)2 DefaultDeserializerFactoryTest (org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest)2 MessageCodeExperimenterKey (org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey)2