Search in sources :

Example 11 with Elements

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;
}
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 12 with Elements

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

Example 13 with Elements

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());
}
Also used : HelloMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 14 with Elements

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;
}
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 15 with Elements

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);
    }
}
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)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)8 ElementsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)8 ByteBuf (io.netty.buffer.ByteBuf)6 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)4 UnknownVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps)4 HelloMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)4 HelloInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput)3 HelloInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)3 BigInteger (java.math.BigInteger)2 DefaultDeserializerFactoryTest (org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)2 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)2 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets)2 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1