Search in sources :

Example 16 with Elements

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();
}
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) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)

Example 17 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 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;
}
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 18 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 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());
}
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 19 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 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());
}
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 20 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 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;
}
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)

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