use of org.opendaylight.yangtools.yang.binding.DataObject in project openflowplugin by opendaylight.
the class ListDeserializerTest method test2.
/**
* Tests {@link ListDeserializer#deserializeHeaders(short, int, ByteBuf, CodeKeyMaker, DeserializerRegistry)}.
*/
@Test
public void test2() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
List<DataObject> list = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, 42, buffer, keyMaker, registry);
Assert.assertNull("List is not null", list);
}
use of org.opendaylight.yangtools.yang.binding.DataObject in project openflowplugin by opendaylight.
the class ConnectionAdapterImplTest method testConsume.
/**
* Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications.
*/
@Test
public void testConsume() {
DataObject message = new EchoRequestMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
message = new ErrorMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onErrorMessage((ErrorMessage) message);
message = new ExperimenterMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onExperimenterMessage((ExperimenterMessage) message);
message = new FlowRemovedMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onFlowRemovedMessage((FlowRemovedMessage) message);
message = new HelloMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onHelloMessage((HelloMessage) message);
message = new MultipartReplyMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onMultipartReplyMessage((MultipartReplyMessage) message);
message = new PacketInMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onPacketInMessage((PacketInMessage) message);
message = new PortStatusMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onPortStatusMessage((PortStatusMessage) message);
message = new SwitchIdleEventBuilder().build();
adapter.consume(message);
verify(systemListener, times(1)).onSwitchIdleEvent((SwitchIdleEvent) message);
message = new DisconnectEventBuilder().build();
adapter.consume(message);
verify(systemListener, times(1)).onDisconnectEvent((DisconnectEvent) message);
message = new EchoRequestMessageBuilder().build();
adapter.consume(message);
verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
}
use of org.opendaylight.yangtools.yang.binding.DataObject 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.yangtools.yang.binding.DataObject in project openflowplugin by opendaylight.
the class OFDatagramPacketDecoder method channelRead0.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void channelRead0(final ChannelHandlerContext ctx, final VersionMessageUdpWrapper msg) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("UdpVersionMessageWrapper received");
LOG.debug("<< {}", ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));
}
try {
final DataObject dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(), msg.getVersion());
if (dataObject == null) {
LOG.warn("Translated POJO is null");
} else {
MessageConsumer consumer = UdpConnectionMap.getMessageConsumer(msg.getAddress());
consumer.consume(dataObject);
}
} catch (RuntimeException e) {
LOG.warn("Message deserialization failed", e);
// TODO: delegate exception to allow easier deserialization
// debugging / deserialization problem awareness
} finally {
msg.getMessageBuffer().release();
}
}
use of org.opendaylight.yangtools.yang.binding.DataObject in project genius by opendaylight.
the class DataStoreCache method get.
public static <T extends DataObject> Object get(String cacheName, InstanceIdentifier<T> identifier, String key, DataBroker broker, boolean isConfig) throws ReadFailedException {
Object dataObject = getCache(cacheName).get(key);
if (dataObject == null) {
Optional<T> datastoreObject = SingleTransactionDataBroker.syncReadOptional(broker, isConfig ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL, identifier);
if (datastoreObject.isPresent()) {
dataObject = datastoreObject.get();
add(cacheName, key, dataObject);
}
}
return dataObject;
}
Aggregations