Search in sources :

Example 76 with MessageCodeKey

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

the class OF10FeaturesReplyMessageFactoryTest method startUp.

/**
 * Initializes deserializer registry and lookups correct deserializer.
 */
@Before
public void startUp() {
    DeserializerRegistry registry = new DeserializerRegistryImpl();
    registry.init();
    featuresFactory = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, GetFeaturesOutput.class));
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) DeserializerRegistryImpl(org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl) DeserializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry) Before(org.junit.Before)

Example 77 with MessageCodeKey

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

the class GetAsyncRequestMessageFactoryTest method startUp.

@Before
public void startUp() {
    DeserializerRegistry desRegistry = new DeserializerRegistryImpl();
    desRegistry.init();
    factory = desRegistry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 26, GetAsyncInput.class));
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) DeserializerRegistryImpl(org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl) DeserializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry) Before(org.junit.Before)

Example 78 with MessageCodeKey

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

the class BarrierInputMessageFactoryTest method testVersions.

/**
 * Testing of {@link BarrierInputMessageFactory} for correct header version.
 */
@Test
public void testVersions() {
    List<Byte> versions = new ArrayList<>(Arrays.asList(EncodeConstants.OF13_VERSION_ID, EncodeConstants.OF14_VERSION_ID, EncodeConstants.OF15_VERSION_ID));
    ByteBuf bb = BufferHelper.buildBuffer();
    testHeaderVersions(versions, bb);
    // OFP v1.0 need to be tested separately cause of different message type value
    messageCodeKey = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 18, BarrierInput.class);
    testHeaderVersions(Collections.singletonList(EncodeConstants.OF10_VERSION_ID), bb);
}
Also used : BarrierInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) DefaultDeserializerFactoryTest(org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest) Test(org.junit.Test)

Example 79 with MessageCodeKey

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

the class ListDeserializer method deserializeHeaders.

/**
 * Deserializes headers of items into list (used in MultipartReplyMessage - Table features).
 *
 * @param version openflow wire version
 * @param length length of list in ByteBuf (bytes)
 * @param input input buffer
 * @param keyMaker creates keys for deserializer lookup
 * @param registry stores deserializers
 * @return list of items
 */
public static <E extends DataObject> List<E> deserializeHeaders(short version, int length, ByteBuf input, CodeKeyMaker keyMaker, DeserializerRegistry registry) {
    List<E> items = null;
    if (input.readableBytes() > 0) {
        items = new ArrayList<>();
        int startIndex = input.readerIndex();
        boolean exceptionLogged = false;
        while (input.readerIndex() - startIndex < length) {
            HeaderDeserializer<E> deserializer;
            MessageCodeKey key = keyMaker.make(input);
            try {
                deserializer = registry.getDeserializer(key);
            } catch (ClassCastException | IllegalStateException e) {
                // TODO - simplify to correctly report exception during deserialization
                if (!exceptionLogged) {
                    LOG.warn("Problem during reading table feature property. Skipping unknown feature property: {}." + "If more information is needed, set org.opendaylight.openflowjava do DEBUG log level.", key, e.getMessage());
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Detailed exception: {}", e);
                        LOG.debug("This exception is logged only once for each multipart reply (table features) to " + "prevent log flooding. There might be more of table features related exceptions.");
                    }
                    exceptionLogged = true;
                }
                input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
                continue;
            }
            E item = deserializer.deserializeHeader(input);
            items.add(item);
        }
    }
    return items;
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)

Example 80 with MessageCodeKey

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

the class CodeKeyMakerFactoryTest method testActionKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createActionsKeyMaker(short)}.
 */
@Test
public void testActionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00");
    // 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, 0, null), codeKey);
    Assert.assertEquals("Buffer index modified", 16, 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)

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