use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HelloMessageFactory 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 - HELLO_ELEMENT_HEADER_SIZE) / 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);
}
} else {
return elementsList;
}
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 HelloInputMessageFactory method serializeElementsList.
private static void serializeElementsList(HelloInput message, ByteBuf output) {
int[] versionBitmap;
if (message.getElements() != null) {
for (Elements currElement : message.getElements()) {
int elementStartIndex = output.writerIndex();
output.writeShort(currElement.getType().getIntValue());
if (currElement.getType().equals(HelloElementType.VERSIONBITMAP)) {
final int elementLengthIndex = output.writerIndex();
output.writeShort(EncodeConstants.EMPTY_LENGTH);
versionBitmap = ByteBufUtils.fillBitMaskFromList(currElement.getVersionBitmap());
for (int element : versionBitmap) {
output.writeInt(element);
}
int length = output.writerIndex() - elementStartIndex;
int padding = length - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE;
output.writeZero(padding);
output.setShort(elementLengthIndex, output.writerIndex() - elementStartIndex);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class OF10HelloMessageFactoryTest method testWithElements.
/**
* Testing {@link OF10HelloMessageFactory} for correct translation into POJO.
*/
@Test
public void testWithElements() {
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(helloFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertNull("Wrong elements", builtByFactory.getElements());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HandshakeManagerImplTest method addVersionBitmap.
/**
* Adds version bitmap.
* @param versionOrder version order
* @param helloBuilder hello builder
* @return builder
*/
private static HelloMessageBuilder addVersionBitmap(List<Short> versionOrder, HelloMessageBuilder helloBuilder) {
short highestVersion = versionOrder.get(0);
int elementsCount = highestVersion / Integer.SIZE;
ElementsBuilder elementsBuilder = new ElementsBuilder();
List<Elements> elementList = new ArrayList<>();
int orderIndex = versionOrder.size();
int value = versionOrder.get(--orderIndex);
for (int index = 0; index <= elementsCount; index++) {
List<Boolean> booleanList = new ArrayList<>();
for (int i = 0; i < Integer.SIZE; i++) {
if (value == index * Integer.SIZE + i) {
booleanList.add(true);
value = orderIndex == 0 ? highestVersion : versionOrder.get(--orderIndex);
} else {
booleanList.add(false);
}
}
elementsBuilder.setType(HelloElementType.forValue(1));
elementsBuilder.setVersionBitmap(booleanList);
elementList.add(elementsBuilder.build());
}
helloBuilder.setElements(elementList);
return helloBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.
the class HandshakeManagerImplTest method testProposeCommonBitmapVersion.
/**
* Test method for
* {@link org.opendaylight.openflowplugin.openflow.md.core
* .HandshakeManagerImpl#proposeCommonBitmapVersion(java.util.List)}.
*/
@Test
public void testProposeCommonBitmapVersion() {
Boolean[][] versions = new Boolean[][] { { true, true, true, false, false, false }, { true, true, true, false, false } };
for (Boolean[] verasionList : versions) {
ElementsBuilder elementsBuilder = new ElementsBuilder();
elementsBuilder.setVersionBitmap(Lists.newArrayList(verasionList));
Elements element = elementsBuilder.build();
List<Elements> elements = Lists.newArrayList(element);
Short proposal = handshakeManager.proposeCommonBitmapVersion(elements);
Assert.assertEquals(Short.valueOf((short) 1), proposal);
}
}
Aggregations