use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HelloMessageFactoryTest method testWithoutPadding.
/**
* Testing {@link HelloMessageFactory} for correct length without padding.
*/
@Test
public void testWithoutPadding() {
ByteBuf bb = BufferHelper.buildBuffer(// type
"00 01 " + // length
"00 08 " + // bitmap 1
"00 00 00 11");
HelloMessage builtByFactory = BufferHelper.deserialize(factory, bb);
List<Elements> element = createElement(4, HelloElementType.VERSIONBITMAP.getIntValue());
Assert.assertEquals("Wrong type", element.get(0).getType(), builtByFactory.getElements().get(0).getType());
Assert.assertEquals("Wrong versionBitmap", element.get(0).getVersionBitmap(), builtByFactory.getElements().get(0).getVersionBitmap());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HelloInputMessageFactoryTest method readElement.
private static List<Elements> readElement(ByteBuf input) {
List<Elements> elementsList = new ArrayList<>();
while (input.readableBytes() > 0) {
ElementsBuilder elementsBuilder = new ElementsBuilder();
int type = input.readUnsignedShort();
int elementLength = input.readUnsignedShort();
if (type == HelloElementType.VERSIONBITMAP.getIntValue()) {
elementsBuilder.setType(HelloElementType.forValue(type));
int[] versionBitmap = new int[(elementLength - 4) / 4];
for (int i = 0; i < versionBitmap.length; i++) {
versionBitmap[i] = (int) input.readUnsignedInt();
}
elementsBuilder.setVersionBitmap(readVersionBitmap(versionBitmap));
int paddingRemainder = elementLength % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
input.readBytes(EncodeConstants.PADDING - paddingRemainder);
}
}
elementsList.add(elementsBuilder.build());
}
return elementsList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HelloInputMessageFactoryTest method createComparationElement.
private static List<Elements> createComparationElement(int lengthOfBitmap) {
final ElementsBuilder elementsBuilder = new ElementsBuilder();
final List<Elements> elementsList = new ArrayList<>();
List<Boolean> booleanList = new ArrayList<>();
for (int i = 0; i < lengthOfBitmap; i++) {
booleanList.add(true);
}
if (lengthOfBitmap % Integer.SIZE != 0) {
for (int i = 0; i < Integer.SIZE - lengthOfBitmap % Integer.SIZE; i++) {
booleanList.add(false);
}
}
LOG.debug("boolsize {}", booleanList.size());
elementsBuilder.setType(HelloElementType.forValue(1));
elementsBuilder.setVersionBitmap(booleanList);
elementsList.add(elementsBuilder.build());
return elementsList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements 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.hello.Elements in project openflowplugin by opendaylight.
the class OF10HelloMessageFactoryTest method testWithoutElements.
/**
* Testing {@link OF10HelloMessageFactory} for correct translation into POJO.
*/
@Test
public void testWithoutElements() {
ByteBuf bb = BufferHelper.buildBuffer();
HelloMessage builtByFactory = BufferHelper.deserialize(helloFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertNull("Wrong elements", builtByFactory.getElements());
}
Aggregations