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;
}
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());
}
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();
}
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));
}
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);
}
Aggregations