Search in sources :

Example 6 with Elements

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

Example 7 with Elements

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

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

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

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