Search in sources :

Example 6 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder 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 7 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class MessageListenerWrapperTest method test.

/**
 * Test MessageListenerWrapper creation.
 */
@Test
public void test() {
    HelloInputBuilder builder = new HelloInputBuilder();
    HelloInput hello = builder.build();
    SimpleRpcListener listener = new SimpleRpcListener(hello, "Error");
    MessageListenerWrapper wrapper = new MessageListenerWrapper(hello, listener);
    Assert.assertEquals("Wrong message", hello, wrapper.getMsg());
    Assert.assertEquals("Wrong listener", listener, wrapper.getListener());
}
Also used : HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder) Test(org.junit.Test)

Example 8 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class OFDatagramPacketEncoderTest method startUp.

/**
 * Initializes mocks and other objects.
 *
 * @param version openflow protocol wire version
 */
public void startUp(Short version) {
    MockitoAnnotations.initMocks(this);
    out = new ArrayList<>();
    HelloInputBuilder builder = new HelloInputBuilder();
    builder.setVersion(version);
    HelloInput hello = builder.build();
    wrapper = new UdpMessageListenerWrapper(hello, listener, address);
}
Also used : HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) UdpMessageListenerWrapper(org.opendaylight.openflowjava.protocol.impl.core.connection.UdpMessageListenerWrapper) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)

Example 9 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder 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 10 with HelloInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder in project openflowplugin by opendaylight.

the class HelloInputMessageFactoryTest method testWithoutElementsSet.

/**
 * Testing of {@link HelloInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testWithoutElementsSet() throws Exception {
    HelloInputBuilder hib = new HelloInputBuilder();
    BufferHelper.setupHeader(hib, EncodeConstants.OF13_VERSION_ID);
    HelloInput hi = hib.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    helloFactory.serialize(hi, out);
    BufferHelper.checkHeaderV13(out, (byte) 0, EncodeConstants.OFHEADER_SIZE);
}
Also used : HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) ByteBuf(io.netty.buffer.ByteBuf) HelloInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder) Test(org.junit.Test)

Aggregations

HelloInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)11 Test (org.junit.Test)8 ByteBuf (io.netty.buffer.ByteBuf)7 HelloInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput)7 Elements (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements)3 SerializerRegistry (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry)2 ArrayList (java.util.ArrayList)1 UdpMessageListenerWrapper (org.opendaylight.openflowjava.protocol.impl.core.connection.UdpMessageListenerWrapper)1 ElementsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)1