From: michal.polkorab Date: Mon, 23 Sep 2013 15:17:35 +0000 (+0200) Subject: "Added more deserialization factories & their unit tests" X-Git-Tag: jenkins-openflowjava-bulk-release-prepare-only-1~109 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=48ee6cd8d5d60689ecd161a8b420f68a255a2384;p=openflowjava.git "Added more deserialization factories & their unit tests" Renamed factory dependent local variables (builders) in deserialization factories Added control check in SwitchConnectionProviderImpl startup() Removed setChannel method from MessageConsumer interface Quickfixed - correct usage of enums in deserialization factories Updated logging and javadoc Signed-off-by: michal.polkorab Change-Id: I1a71c1d0aef03f8052c9d4e1b256a1fdf6b0d438 --- diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java index d07b5887..c6e9e230 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java @@ -112,7 +112,6 @@ public class ConnectionAdapterImpl implements ConnectionFacade { /** * @param channel the channel to be set - used for communication */ - @Override public void setChannel(Channel channel) { this.channel = channel; } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java index 3f1bf2d8..88a3c747 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java @@ -8,8 +8,6 @@ package org.opendaylight.openflowjava.protocol.impl.connection; -import io.netty.channel.Channel; - import org.opendaylight.yangtools.yang.binding.DataObject; /** @@ -22,9 +20,5 @@ public interface MessageConsumer { * @param message to process */ public void consume(DataObject message); - - /** - * @param channel sets processing channel - */ - public void setChannel(Channel channel); + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java index 3a540449..e0c36e62 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java @@ -29,7 +29,7 @@ import com.google.common.util.concurrent.SettableFuture; /** * @author mirehak - * + * @author michal.polkorab */ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { @@ -40,7 +40,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { @Override public void configure(Collection connConfigs) { - LOG.debug("configurating .."); + LOG.debug("Configurating .."); //TODO - add and configure servers according to configuration serverLot = new HashSet<>(); @@ -58,7 +58,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { @Override public Future> shutdown() { - LOG.debug("shutdown summoned"); + LOG.debug("Shutdown summoned"); ListenableFuture> result = SettableFuture.create(); try { List> shutdownChain = new ArrayList<>(); @@ -66,11 +66,10 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { ListenableFuture shutdownFuture = server.shutdown(); shutdownChain.add(shutdownFuture); } - if (!shutdownChain.isEmpty()) { result = Futures.allAsList(shutdownChain); } else { - throw new IllegalStateException("no servers configured"); + throw new IllegalStateException("No servers configured"); } } catch (Exception e) { SettableFuture> exFuture = SettableFuture.create(); @@ -85,23 +84,27 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { LOG.debug("startup summoned"); ListenableFuture> result = SettableFuture.create(); try { - //TODO - check config, status of servers + if (serverLot.isEmpty()) { + throw new IllegalStateException("No servers configured"); + } + for (ServerFacade server : serverLot) { + if (server.getIsOnlineFuture().isDone()) { + throw new IllegalStateException("Servers already running"); + } + } if (switchConnectionHandler == null) { throw new IllegalStateException("switchConnectionHandler is not set"); } - - // starting List> starterChain = new ArrayList<>(); for (ServerFacade server : serverLot) { new Thread(server).start(); ListenableFuture isOnlineFuture = server.getIsOnlineFuture(); starterChain.add(isOnlineFuture); } - if (!starterChain.isEmpty()) { result = Futures.allAsList(starterChain); } else { - throw new IllegalStateException("no servers configured"); + throw new IllegalStateException("No servers configured"); } } catch (Exception e) { SettableFuture> exFuture = SettableFuture.create(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java index c6c496a4..7f2d2c8b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java @@ -12,7 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Transforms OpenFlow Protocol messages to POJOs and reverse + * Transforms OpenFlow Protocol messages to POJOs * * @author michal.polkorab */ @@ -24,7 +24,7 @@ public class OF13Decoder extends MessageToMessageDecoder * Constructor of class */ public OF13Decoder() { - LOGGER.info("Creating OF 1.3 Codec"); + LOGGER.info("Creating OF 1.3 Decoder"); } @Override diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java index 8e56cc40..fb5dfb80 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java @@ -3,17 +3,26 @@ package org.opendaylight.openflowjava.protocol.impl.core; import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; /** + * Transforms OpenFlow Protocol messages to POJOs + * * @author michal.polkorab - * */ public class OF13Encoder extends MessageToByteEncoder { + private static final Logger LOGGER = LoggerFactory.getLogger(OF13Encoder.class); + + /** Constructor of class */ + public OF13Encoder() { + LOGGER.info("Creating OF13Encoder"); + } @Override protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out) throws Exception { diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java index a126e6a4..be2bbdd8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java @@ -20,8 +20,6 @@ public abstract class DeserializationFactory { public static DataObject bufferToMessage(ByteBuf rawMessage, short version) { DataObject dataObject = null; short type = rawMessage.readUnsignedByte(); - - // TODO - check if no change happened, so that skipping length would cause problems rawMessage.skipBytes(Short.SIZE / Byte.SIZE); MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java index 3ec39752..bc60d23d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java @@ -32,10 +32,10 @@ public class BarrierReplyMessageFactory implements @Override public BarrierOutput bufferToMessage(ByteBuf rawMessage, short version) { - BarrierOutputBuilder bob = new BarrierOutputBuilder(); - bob.setVersion(version); - bob.setXid(rawMessage.readUnsignedInt()); - return bob.build(); + BarrierOutputBuilder builder = new BarrierOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + return builder.build(); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java index 3b5fcc6c..059ae0e3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java @@ -29,17 +29,13 @@ public class EchoReplyMessageFactory implements OFDeserializer { return instance; } - /* (non-Javadoc) - * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short) - */ @Override public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) { - EchoOutputBuilder eob = new EchoOutputBuilder(); - eob.setVersion(version); - eob.setXid(rawMessage.readUnsignedInt()); - // read the rest of EchoReply message - eob.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); - return eob.build(); + EchoOutputBuilder builder = new EchoOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + return builder.build(); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java index 11807db1..263b4d14 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java @@ -32,11 +32,10 @@ public class EchoRequestMessageFactory implements OFDeserializer { @Override public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { - HelloMessageBuilder hmb = new HelloMessageBuilder(); - hmb.setVersion(version); - hmb.setXid(rawMessage.readUnsignedInt()); - return hmb.build(); + HelloMessageBuilder builder = new HelloMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + // TODO - implement setElements() + return builder.build(); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java index e13f230f..76e13619 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java @@ -5,6 +5,7 @@ import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; @@ -26,27 +27,21 @@ public class MultipartReplyMessageFactory implements OFDeserializer 0)); + MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setType(MultipartType.forValue(rawMessage.readUnsignedShort())); + builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) > 0)); rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER); + // TODO - implement body //mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array()); - - return mrmb.build(); + return builder.build(); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java index a8733aff..e997becc 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java @@ -29,28 +29,24 @@ public class PacketInMessageFactory implements OFDeserializer { if(instance == null){ instance = new PacketInMessageFactory(); } - return instance; } @Override public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) { - PacketInMessageBuilder pimb = new PacketInMessageBuilder(); - pimb.setVersion(version); - pimb.setXid(rawMessage.readUnsignedInt()); - pimb.setBufferId(rawMessage.readUnsignedInt()); - pimb.setTotalLen(rawMessage.readUnsignedShort()); - pimb.setReason(rawMessage.readUnsignedByte()); - pimb.setTableId(new TableId((long)rawMessage.readUnsignedByte())); - - byte[] cookie = new byte[8]; + PacketInMessageBuilder builder = new PacketInMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setBufferId(rawMessage.readUnsignedInt()); + builder.setTotalLen(rawMessage.readUnsignedShort()); + builder.setReason(rawMessage.readUnsignedByte()); + builder.setTableId(new TableId((long)rawMessage.readUnsignedByte())); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; rawMessage.readBytes(cookie); - pimb.setCookie(new BigInteger(cookie)); + builder.setCookie(new BigInteger(cookie)); // TODO - implement match factories to finish this factory rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); - - pimb.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); - - return pimb.build(); + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + return builder.build(); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java index 79183330..7c391175 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java @@ -3,6 +3,11 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; @@ -13,7 +18,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class PortStatusMessageFactory implements OFDeserializer { private static PortStatusMessageFactory instance; - private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 7; + private static final byte PADDING_IN_PORT_STATUS_HEADER = 7; + private static final byte PADDING_IN_OFP_PORT_HEADER_1 = 4; + private static final byte PADDING_IN_OFP_PORT_HEADER_2 = 2; + private static final int macAddressLength = 6; private PortStatusMessageFactory() { // Singleton @@ -24,27 +32,73 @@ public class PortStatusMessageFactory implements OFDeserializer 0; + final Boolean _10mbFd = ((input) & 0x02) > 0; + final Boolean _100mbHd = ((input) & 0x04) > 0; + final Boolean _100mbFd = ((input) & 0x08) > 0; + final Boolean _1gbHd = ((input) & 0x10) > 0; + final Boolean _1gbFd = ((input) & 0x20) > 0; + final Boolean _10gbFd = ((input) & 0x40) > 0; + final Boolean _40gbFd = ((input) & 0x80) > 0; + final Boolean _100gbFd = ((input) & 0x100) > 0; + final Boolean _1tbFd = ((input) & 0x200) > 0; + final Boolean _other = ((input) & 0x400) > 0; + final Boolean _copper = ((input) & 0x800) > 0; + final Boolean _fiber = ((input) & 0x1000) > 0; + final Boolean _autoneg = ((input) & 0x2000) > 0; + final Boolean _pause = ((input) & 0x4000) > 0; + final Boolean _pauseAsym = ((input) & 0x8000) > 0; + return new PortFeatures(_10mbHd, _10mbFd, _100mbHd, _100mbFd, _1gbHd, _1gbFd, _10gbFd, + _40gbFd, _100gbFd, _1tbFd, _other, _copper, _fiber, _autoneg, _pause, _pauseAsym); + } + private static PortState createPortState(long input){ + final Boolean _linkDown = ((input) & 0x01) > 0; + final Boolean _blocked = ((input) & 0x02) > 0; + final Boolean _live = ((input) & 0x04) > 0; + return new PortState(_linkDown, _blocked,_live); + } + + private static PortConfig createPortConfig(long input){ + final Boolean _portDown = ((input) & 0x01) > 0; + final Boolean _noRecv = ((input) & 0x02) > 0; + final Boolean _noFwd = ((input) & 0x04) > 0; + final Boolean _noPacketIn = ((input) & 0x08) > 0; + return new PortConfig(_portDown, _noRecv, _noFwd, _noPacketIn); + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java new file mode 100644 index 00000000..aa73fdb0 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java @@ -0,0 +1,82 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import java.util.ArrayList; +import java.util.List; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.Properties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.PropertiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class QueueGetConfigReplyMessageFactory implements OFDeserializer { + + private static QueueGetConfigReplyMessageFactory instance; + private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 4; + private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 6; + private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; + + private QueueGetConfigReplyMessageFactory() { + // singleton + } + + /** + * + * @return singleton factory + */ + public static QueueGetConfigReplyMessageFactory getInstance(){ + + if(instance == null){ + instance = new QueueGetConfigReplyMessageFactory(); + } + return instance; + } + + @Override + public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder(); + builder.setVersion(version); + builder.setXid((rawMessage.readUnsignedInt())); + builder.setPort(new PortNumber(rawMessage.readUnsignedInt())); + rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER); + builder.setQueues(createQueuesList(rawMessage)); + return builder.build(); + } + + private static List createQueuesList(ByteBuf input){ + List queuesList = new ArrayList(); + QueuesBuilder queueBuilder = new QueuesBuilder(); + while (input.readableBytes() > 0) { + queueBuilder.setQueueId(new QueueId(input.readUnsignedInt())); + queueBuilder.setPort(new PortNumber(input.readUnsignedInt())); + input.skipBytes(2); + input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER); + queueBuilder.setProperties(createPropertiesList(input)); + queuesList.add(queueBuilder.build()); + } + return queuesList; + } + + private static List createPropertiesList(ByteBuf propertiesInput){ + List propertiesList = new ArrayList(); + PropertiesBuilder propertiesBuilder = new PropertiesBuilder(); + propertiesBuilder.setProperty(QueueProperty.forValue(propertiesInput.readUnsignedShort())); + propertiesInput.skipBytes(2); + propertiesInput.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); + propertiesList.add(propertiesBuilder.build()); + return propertiesList; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java new file mode 100644 index 00000000..cbdfe48e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java @@ -0,0 +1,51 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class RoleReplyMessageFactory implements OFDeserializer{ + + private static RoleReplyMessageFactory instance; + private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4; + + private RoleReplyMessageFactory() { + // singleton + } + + /** + * + * @return singleton factory + */ + public static RoleReplyMessageFactory getInstance(){ + if(instance == null){ + instance = new RoleReplyMessageFactory(); + } + return instance; + } + + @Override + public RoleRequestOutput bufferToMessage(ByteBuf rawMessage, short version) { + RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + byte[] role = new byte[Integer.SIZE/Byte.SIZE]; + rawMessage.readBytes(role); + builder.setRole(ControllerRole.forValue(new BigInteger(role).intValue())); + rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER); + byte[] generationID = new byte[8]; + rawMessage.readBytes(generationID); + builder.setGenerationId(new BigInteger(generationID)); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java index c1ea5d4a..ea03326d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java @@ -40,8 +40,4 @@ public class HelloInputMessageFactory implements OFSerializer{ // TODO - fill list of elements into ByteBuf, check length too } - - - - } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java index 8789d7a5..cdea17c1 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java @@ -40,8 +40,7 @@ public class RoleRequestInputMessageFactory implements OFSerializer { out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER); out.writeInt(message.getXid().intValue()); // TODO - finish implementation after enums provide needed funcionality - out.writeInt(message.getMissSendLen()); + out.writeShort(message.getFlags().getIntValue()); + out.writeShort(message.getMissSendLen()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java index d828c852..5572342f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java @@ -9,7 +9,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * @author michal.polkorab - * + * @author timotej.kubas */ public class BarrierReplyMessageFactoryTest { diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java index 5338ed03..08d42b5e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java @@ -11,7 +11,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * @author michal.polkorab - * + * @author timotej.kubas */ public class EchoReplyMessageFactoryTest { @@ -38,7 +38,7 @@ public class EchoReplyMessageFactoryTest { EchoReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals(builtByFactory.getData(), data); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java index e136f5ad..5f882dbb 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java @@ -11,7 +11,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * @author michal.polkorab - * + * @author timotej.kubas */ public class EchoRequestMessageFactoryTest { @@ -38,7 +38,7 @@ public class EchoRequestMessageFactoryTest { EchoRequestMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals(builtByFactory.getData(), data); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java new file mode 100644 index 00000000..71172fff --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java @@ -0,0 +1,29 @@ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class ErrorMessageFactoryTest { + + /** + * Test of {@link ErrorMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 04 00 03 01 02 03 04"); + ErrorMessage builtByFactory = BufferHelper.decodeV13(ErrorMessageFactory.getInstance(), bb); + BufferHelper.checkHeaderV13(builtByFactory); + + Assert.assertEquals("Wrong reason", 0x04, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong code", 3, builtByFactory.getCode().intValue()); + Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getData()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java index 091e6a52..0c080a13 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java @@ -24,8 +24,8 @@ public class ExperimenterMessageFactoryTest { ExperimenterMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals(builtByFactory.getExperimenter().longValue(), 0x01020304L); - Assert.assertEquals(builtByFactory.getExpType().longValue(), 0x01020304L); + Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); + Assert.assertEquals("Wrong expType", 0x01020304L, builtByFactory.getExpType().longValue()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java index 44cd9664..8665bad4 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java @@ -10,7 +10,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * @author michal.polkorab - * + * @author timotej.kubas */ public class FeaturesReplyMessageFactoryTest { @@ -31,7 +31,5 @@ public class FeaturesReplyMessageFactoryTest { Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue()); Assert.assertEquals("Wrong capabilities", 0x00010203L, builtByFactory.getCapabilities().longValue()); Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue()); - } - } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java index 7f1aa2e0..e0c830a3 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java @@ -20,7 +20,7 @@ public class FlowRemovedMessageFactoryTest { */ @Test public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 00 04 00 00 00 02" + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 02 04 00 00 00 02" + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07"); FlowRemovedMessage builtByFactory = BufferHelper.decodeV13(FlowRemovedMessageFactory.getInstance(), bb); @@ -28,9 +28,7 @@ public class FlowRemovedMessageFactoryTest { Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L); Assert.assertTrue(builtByFactory.getPriority() == 0x03); - - // TODO enum type! - // builtByFactory.getReason() + Assert.assertEquals("Wrong reason", 0x02, builtByFactory.getReason().getIntValue()); Assert.assertEquals("Wrong tableId", new TableId((long) 4), builtByFactory.getTableId()); Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue()); Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java index 06ef8b5b..8a8717dd 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java @@ -14,7 +14,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetConfigReplyMessageFactoryTest { - /** * Testing {@link GetConfigReplyMessageFactory} for correct translation into POJO */ @@ -25,10 +24,8 @@ public class GetConfigReplyMessageFactoryTest { GetConfigReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - // TODO - enum problem ! -// Assert.assertEquals(builtByFactory.getFlags().toString(),"OFPCFRAGDROP"); - Assert.assertEquals("Wrong missSendLen", 0x01, builtByFactory.getMissSendLen().intValue()); - + Assert.assertEquals("Wrong switchConfigFlag", 0x01, builtByFactory.getFlags().getIntValue()); + Assert.assertEquals("Wrong missSendLen", 0x03, builtByFactory.getMissSendLen().intValue()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java index 04af39d4..5be0dc59 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java @@ -9,7 +9,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * @author michal.polkorab - * + * @author timotej.kubas */ public class HelloMessageFactoryTest { diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java index e4e12eb2..470d944a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java @@ -19,11 +19,12 @@ public class MultipartReplyMessageFactoryTest { */ @Test public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 01 02 03 04"); + ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 01 02 03 04"); MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x07, builtByFactory.getType().getIntValue()); Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); //Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody()); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java index 2100a5a4..39a12076 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java @@ -4,8 +4,13 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; +import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; /** @@ -19,11 +24,43 @@ public class PortStatusMessageFactoryTest { */ @Test public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("01 00 00 00 00 00 00 00"); + ByteBuf bb = BufferHelper.buildBuffer("01 " + //reason + "00 00 00 00 00 00 00 " + //padding + "00 01 02 03 " + //port no + "00 00 00 00 " + //padding in ofp_port1 + "08 00 27 00 B0 EB " + //mac address + "00 00 " + //padding in ofp_port2 + "00 00 00 0a " + //port config + "00 00 00 05 " + //port state + "00 00 00 81 " + //current features + "00 00 00 81 " + //advertised features + "00 00 00 81 " + //supported features + "00 00 00 81 " + //peer features + "00 00 00 81 " + //curr speed + "00 00 00 80" //max speed + ); PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - //Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason()); + Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); + Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue()); + Assert.assertEquals("Wrong macAddress", new MacAddress("08002700B0EB"), builtByFactory.getHwAddr()); + Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig()); + Assert.assertEquals("Wrong portState", new PortState(true, false, true), builtByFactory.getState()); + Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getCurrentFeatures()); + Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getAdvertisedFeatures()); + Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getSupportedFeatures()); + Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getSupportedFeatures()); + Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue()); + Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java new file mode 100644 index 00000000..3fbd8e86 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java @@ -0,0 +1,110 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.Properties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.PropertiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class QueueGetConfigReplyMessageFactoryMultiTest { + + /** + * Testing of {@link QueueGetConfigReplyMessageFactory} for correct + * translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port + "00 00 00 00 " + // padding + "00 00 00 01 " + // queueId + "00 00 00 01 " + // port + "00 00 00 00 00 00 00 00 " + // pad + "00 01 " + // property + "00 00 00 00 00 00 " + // pad + "00 00 00 02 " + // queueId + "00 00 00 02 " + // port + "00 00 00 00 00 00 00 00 " + // pad + "00 01 " + // property + "00 00 00 00 00 00 " + // pad + "00 00 00 03 " + // queueId + "00 00 00 03 " + // port + "00 00 00 00 00 00 00 00 " + // pad + "00 01 " + // property + "00 00 00 00 00 00" // pad + ); + + GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13( + QueueGetConfigReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertTrue("Wrong port", 66051L == builtByFactory.getPort().getValue()); + Assert.assertTrue("Wrong queues", true == compareLists(builtByFactory.getQueues(), + createQueuesList())); + } + + private static List createQueuesList() { + List queuesList = new ArrayList(); + QueuesBuilder qb = new QueuesBuilder(); + for (int i = 1; i <= 3; i++) { + qb.setQueueId(new QueueId((long) i)); + qb.setPort(new PortNumber((long) i)); + qb.setProperties(createPropertiesList()); + queuesList.add(qb.build()); + } + return queuesList; + } + + private static List createPropertiesList() { + List propertiesList = new ArrayList(); + PropertiesBuilder pb = new PropertiesBuilder(); + pb.setProperty(QueueProperty.values()[1]); + propertiesList.add(pb.build()); + return propertiesList; + } + + private static boolean compareLists(List originalList, + List testList) { + boolean result = false; + int originalListLength = originalList.size(); + for (int i = 0; i < originalListLength; i++) { + if (originalList.get(i).getPort().equals(testList.get(i).getPort())) { + result = true; + } else { + result = false; + break; + } + if (originalList.get(i).getQueueId() + .equals(testList.get(i).getQueueId())) { + result = true; + } else { + result = false; + break; + } + if (originalList.get(i).getProperties().get(0).getProperty() + .equals(testList.get(i).getProperties().get(0).getProperty())) { + result = true; + } else { + result = false; + break; + } + } + return result; + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java new file mode 100644 index 00000000..e24af652 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java @@ -0,0 +1,30 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class RoleReplyMessageFactoryTest { + + /** + * Testing of {@link RoleReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 00 00 00 00 00 01 02 03 04 05 06 07"); + RoleRequestOutput builtByFactory = BufferHelper.decodeV13(RoleReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + + Assert.assertEquals("Wrong role", 0x02, builtByFactory.getRole().getIntValue()); + Assert.assertEquals("Wrong generationId", 0x01020304050607L, builtByFactory.getGenerationId().longValue()); + } +}