Search in sources :

Example 1 with ElementsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder 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;
}
Also used : ArrayList(java.util.ArrayList) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements) ElementsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)

Example 2 with ElementsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder 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;
}
Also used : ArrayList(java.util.ArrayList) ElementsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements)

Example 3 with ElementsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder 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;
}
Also used : ArrayList(java.util.ArrayList) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements) ElementsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)

Example 4 with ElementsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder 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;
}
Also used : ArrayList(java.util.ArrayList) ElementsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements)

Example 5 with ElementsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder 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);
    }
}
Also used : ElementsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements) Test(org.junit.Test)

Aggregations

Elements (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements)8 ElementsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)1 HelloInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)1