use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class MessageFactory method createHelloInput.
/**
* Creates hello input.
*
* @param helloVersion openflow version for hello message to send to switch
* @param helloXid transaction id for hello message
* @param versionOrder list of openflow version in order
* @return HelloInput with elements (version bitmap)
*/
public static HelloInput createHelloInput(short helloVersion, long helloXid, List<Short> versionOrder) {
HelloInputBuilder helloInputbuilder = prepareHelloInputBuilder(helloVersion, helloXid);
if (versionOrder != null) {
ElementsBuilder elementsBuilder = new ElementsBuilder();
elementsBuilder.setType(HelloElementType.VERSIONBITMAP);
int resultVersionListSize = 0;
if (!versionOrder.isEmpty()) {
resultVersionListSize = versionOrder.get(0) + 1;
}
List<Boolean> booleanList = new ArrayList<>(resultVersionListSize);
int versionOrderIndex = versionOrder.size() - 1;
while (versionOrderIndex >= 0) {
short version = versionOrder.get(versionOrderIndex);
if (version == booleanList.size()) {
booleanList.add(true);
versionOrderIndex--;
} else {
booleanList.add(false);
}
}
elementsBuilder.setVersionBitmap(booleanList);
List<Elements> elementList = Collections.singletonList(elementsBuilder.build());
helloInputbuilder.setElements(elementList);
}
return helloInputbuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HelloMessageFactoryTest method createElement.
private static List<Elements> createElement(int lengthInByte, int type) {
final ElementsBuilder elementsBuilder = new ElementsBuilder();
final List<Elements> elementsList = new ArrayList<>();
List<Boolean> booleanList = new ArrayList<>();
booleanList.add(true);
booleanList.add(false);
booleanList.add(false);
booleanList.add(false);
booleanList.add(true);
int inSize = booleanList.size();
for (int i = 1; i < lengthInByte * 8 - inSize + 1; i++) {
booleanList.add(false);
}
elementsBuilder.setType(HelloElementType.forValue(type));
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 HelloMessageFactoryTest method testWithPadding.
/**
* Testing {@link HelloMessageFactory} for correct length with padding.
*/
@Test
public void testWithPadding() {
ByteBuf bb = BufferHelper.buildBuffer(// type
"00 01 " + // length
"00 0c " + // bitmap 1
"00 00 00 11 " + // bitmap 2
"00 00 00 00 " + // padding
"00 00 00 00");
HelloMessage builtByFactory = BufferHelper.deserialize(factory, bb);
List<Elements> element = createElement(8, 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 testWith4BitVersionBitmap.
/**
* Testing of {@link HelloInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testWith4BitVersionBitmap() throws Exception {
int lengthOfBitmap = 4;
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, 16);
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 HelloInputMessageFactoryTest method createElement.
private static List<Elements> createElement(int lengthOfBitmap) {
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);
}
elementsBuilder.setType(HelloElementType.forValue(1));
elementsBuilder.setVersionBitmap(booleanList);
elementsList.add(elementsBuilder.build());
return elementsList;
}
Aggregations