Search in sources :

Example 1 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class ByteBufUtilsTest method testWriteHeader.

/**
 * Write OF header test.
 */
@Test
public void testWriteHeader() {
    HelloInputBuilder helloBuilder = new HelloInputBuilder();
    helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    helloBuilder.setXid(12345L);
    helloBuilder.setElements(null);
    HelloInput helloInput = helloBuilder.build();
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
    ByteBufUtils.writeOFHeader((byte) 0, helloInput, buf, EncodeConstants.OFHEADER_SIZE);
    Assert.assertEquals("Wrong version", EncodeConstants.OF13_VERSION_ID, buf.readUnsignedByte());
    Assert.assertEquals("Wrong type", 0, buf.readUnsignedByte());
    Assert.assertEquals("Wrong length", EncodeConstants.OFHEADER_SIZE, buf.readUnsignedShort());
    Assert.assertEquals("Wrong xid", 12345, buf.readUnsignedInt());
    Assert.assertTrue("Unexpected data", buf.readableBytes() == 0);
}
Also used : HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) ByteBuf(io.netty.buffer.ByteBuf) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder) Test(org.junit.Test)

Example 2 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class HelloInputMessageFactoryTest method testWith64BitVersionBitmap.

/**
 * Testing of {@link HelloInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testWith64BitVersionBitmap() throws Exception {
    int lengthOfBitmap = 64;
    HelloInputBuilder builder = new HelloInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    List<Elements> expectedElement = createElement(lengthOfBitmap);
    builder.setElements(expectedElement);
    HelloInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    helloFactory.serialize(message, out);
    if (LOG.isDebugEnabled()) {
        LOG.debug("bytebuf: ", ByteBufUtils.byteBufToHexString(out));
    }
    BufferHelper.checkHeaderV13(out, (byte) 0, 24);
    Elements element = readElement(out).get(0);
    Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
    Elements comparation = createComparationElement(lengthOfBitmap).get(0);
    Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray());
}
Also used : HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements) ByteBuf(io.netty.buffer.ByteBuf) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder) Test(org.junit.Test)

Example 3 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class SerializationFactoryTest method test.

/**
 * Test serializer lookup & serialization.
 */
@Test
public void test() {
    SerializerRegistry registry = new SerializerRegistryImpl();
    registry.init();
    final SerializationFactory factory = new SerializationFactory(registry);
    final ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    HelloInputBuilder helloBuilder = new HelloInputBuilder();
    helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    helloBuilder.setXid(123456L);
    helloBuilder.setElements(null);
    factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, buffer, helloBuilder.build());
    assertEquals("Serialization failed", EncodeConstants.OFHEADER_SIZE, buffer.readableBytes());
}
Also used : SerializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry) ByteBuf(io.netty.buffer.ByteBuf) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder) Test(org.junit.Test)

Example 4 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class SerializationFactoryTest method testNotExistingSerializer.

/**
 * Test serializer not found scenario.
 */
@Test(expected = IllegalStateException.class)
public void testNotExistingSerializer() {
    SerializerRegistry registry = new SerializerRegistryImpl();
    registry.init();
    final SerializationFactory factory = new SerializationFactory(registry);
    final ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    HelloInputBuilder helloBuilder = new HelloInputBuilder();
    helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    helloBuilder.setXid(123456L);
    helloBuilder.setElements(null);
    factory.messageToBuffer((short) 0, buffer, helloBuilder.build());
}
Also used : SerializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry) ByteBuf(io.netty.buffer.ByteBuf) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder) Test(org.junit.Test)

Example 5 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class MessageFactory method prepareHelloInputBuilder.

/**
 * Builder.
 *
 * @param highestVersion highest openflow version
 * @param xid            transaction id
 * @return builder with prepared header
 */
private static HelloInputBuilder prepareHelloInputBuilder(short highestVersion, long xid) {
    HelloInputBuilder helloInputbuilder = new HelloInputBuilder();
    helloInputbuilder.setVersion(highestVersion);
    helloInputbuilder.setXid(xid);
    return helloInputbuilder;
}
Also used : HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)

Aggregations

HelloInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)11 Test (org.junit.Test)8 ByteBuf (io.netty.buffer.ByteBuf)7 HelloInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput)7 Elements (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements)3 SerializerRegistry (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry)2 ArrayList (java.util.ArrayList)1 UdpMessageListenerWrapper (org.opendaylight.openflowjava.protocol.impl.core.connection.UdpMessageListenerWrapper)1 ElementsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)1