use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput in project openflowplugin by opendaylight.
the class HandshakeManagerImpl method sendHelloMessage.
/**
* send hello reply without versionBitmap.
*
* @param helloVersion initial hello version for openflow connection negotiation
* @param helloXid transaction id
*/
private ListenableFuture<Void> sendHelloMessage(Short helloVersion, final Long helloXid) throws Exception {
HelloInput helloInput = MessageFactory.createHelloInput(helloVersion, helloXid, versionOrder);
final SettableFuture<Void> resultFtr = SettableFuture.create();
LOG.debug("sending hello message: version{}, xid={}, version bitmap={}", helloVersion, helloXid, MessageFactory.digVersions(helloInput.getElements()));
Future<RpcResult<Void>> helloResult = connectionAdapter.hello(helloInput);
ListenableFuture<RpcResult<Void>> rpcResultListenableFuture = JdkFutureAdapters.listenInPoolThread(helloResult);
Futures.addCallback(rpcResultListenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.debug("hello successfully sent, xid={}, addr={}", helloXid, connectionAdapter.getRemoteAddress());
resultFtr.set(null);
} else {
for (RpcError error : result.getErrors()) {
LOG.debug("hello sending failed [{}]: i:{} s:{} m:{}, addr:{}", helloXid, error.getInfo(), error.getSeverity(), error.getMessage(), connectionAdapter.getRemoteAddress());
if (error.getCause() != null) {
LOG.trace("DETAIL of sending hello failure", error.getCause());
}
}
resultFtr.cancel(false);
handshakeListener.onHandshakeFailure();
}
}
@Override
public void onFailure(Throwable throwable) {
LOG.warn("sending of hello failed seriously [{}, addr:{}]: {}", helloXid, connectionAdapter.getRemoteAddress(), throwable.getMessage());
LOG.trace("DETAIL of sending of hello failure:", throwable);
resultFtr.cancel(false);
handshakeListener.onHandshakeFailure();
}
}, MoreExecutors.directExecutor());
LOG.trace("sending hello message [{}] - result hooked ..", helloXid);
return resultFtr;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput in project openflowplugin by opendaylight.
the class ByteBufUtilsTest method testWriteHeader.
/**
* Write OF header test.
*/
@Test
public void testWriteHeader() {
HelloInputBuilder helloBuilder = new HelloInputBuilder();
helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
helloBuilder.setXid(12345L);
helloBuilder.setElements(null);
HelloInput helloInput = helloBuilder.build();
ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
ByteBufUtils.writeOFHeader((byte) 0, helloInput, buf, EncodeConstants.OFHEADER_SIZE);
Assert.assertEquals("Wrong version", EncodeConstants.OF13_VERSION_ID, buf.readUnsignedByte());
Assert.assertEquals("Wrong type", 0, buf.readUnsignedByte());
Assert.assertEquals("Wrong length", EncodeConstants.OFHEADER_SIZE, buf.readUnsignedShort());
Assert.assertEquals("Wrong xid", 12345, buf.readUnsignedInt());
Assert.assertTrue("Unexpected data", buf.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput 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);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput 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();
}
Aggregations