Search in sources :

Example 26 with MessageCodeKey

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

the class DeserializationFactory method deserialize.

/**
 * Transforms ByteBuf into correct POJO message.
 *
 * @param rawMessage the message
 * @param version
 *            version decoded from OpenFlow protocol message
 * @return correct POJO as DataObject
 */
public DataObject deserialize(final ByteBuf rawMessage, final short version) {
    DataObject dataObject = null;
    int type = rawMessage.readUnsignedByte();
    Class<?> clazz = messageClassMap.get(new TypeToClassKey(version, type));
    rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    OFDeserializer<DataObject> deserializer = registry.getDeserializer(new MessageCodeKey(version, type, clazz));
    dataObject = deserializer.deserialize(rawMessage);
    return dataObject;
}
Also used : TypeToClassKey(org.opendaylight.openflowjava.protocol.api.keys.TypeToClassKey) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)

Example 27 with MessageCodeKey

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

the class MessageCodeKeyTest method test.

/**
 * Test MessageCodeKey equals and hashCode.
 */
@Test
public void test() {
    MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
    MessageCodeKey key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
    Assert.assertTrue("Wrong equals", key1.equals(key2));
    Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
    key2 = new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 4, BarrierInput.class);
    Assert.assertFalse("Wrong equals", key1.equals(key2));
    Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
    key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
    Assert.assertFalse("Wrong equals", key1.equals(key2));
    Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
    key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierOutput.class);
    Assert.assertFalse("Wrong equals", key1.equals(key2));
    Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
    key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, BarrierInput.class);
    Assert.assertFalse("Wrong equals", key1.equals(key2));
    Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
}
Also used : BarrierInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) BarrierOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput) Test(org.junit.Test)

Example 28 with MessageCodeKey

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

the class OF10FlowRemovedMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
    builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookie);
    builder.setCookie(new BigInteger(1, cookie));
    builder.setPriority(rawMessage.readUnsignedShort());
    builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
    rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
    builder.setDurationSec(rawMessage.readUnsignedInt());
    builder.setDurationNsec(rawMessage.readUnsignedInt());
    builder.setIdleTimeout(rawMessage.readUnsignedShort());
    rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
    byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(packetCount);
    builder.setPacketCount(new BigInteger(1, packetCount));
    byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(byteCount);
    builder.setByteCount(new BigInteger(1, byteCount));
    return builder.build();
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) BigInteger(java.math.BigInteger) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) MatchV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 29 with MessageCodeKey

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

the class OF10MatchDeserializerTest method startUp.

/**
 * Initializes deserializer registry and lookups correct deserializer.
 */
@Before
public void startUp() {
    DeserializerRegistry registry = new DeserializerRegistryImpl();
    registry.init();
    matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.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 30 with MessageCodeKey

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

the class MessageDeserializerInjectorTest method injectDeserializers.

@Test
public void injectDeserializers() throws Exception {
    injector.apply(10).apply(OfHeader.class).accept(ofDeserializer);
    verify(switchConnectionProvider).unregisterDeserializerMapping(new TypeToClassKey(EncodeConstants.OF13_VERSION_ID, 10));
    verify(switchConnectionProvider).registerDeserializerMapping(new TypeToClassKey(EncodeConstants.OF13_VERSION_ID, 10), OfHeader.class);
    verify(switchConnectionProvider).registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 10, OfHeader.class), ofDeserializer);
}
Also used : TypeToClassKey(org.opendaylight.openflowjava.protocol.api.keys.TypeToClassKey) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) 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