Search in sources :

Example 21 with DataObject

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);
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 22 with DataObject

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);
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) DisconnectEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder) ExperimenterMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SwitchIdleEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder) PortStatusMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) EchoRequestMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder) Test(org.junit.Test)

Example 23 with DataObject

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;
}
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 24 with 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();
    }
}
Also used : MessageConsumer(org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 25 with DataObject

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;
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Aggregations

DataObject (org.opendaylight.yangtools.yang.binding.DataObject)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)24 Test (org.junit.Test)14 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)10 Optional (com.google.common.base.Optional)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 AbstractDataChangeListenerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)6 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)6 Collection (java.util.Collection)5 Nonnull (javax.annotation.Nonnull)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey)5 DataObjectModification (org.opendaylight.controller.md.sal.binding.api.DataObjectModification)4