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