\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
-import junit.framework.Assert;\r
\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.Assert;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder;\r
*/\r
public class PacketOutInputMessageFactoryTest {\r
private static final byte MESSAGE_TYPE = 13;\r
- private static final int MESSAGE_LENGTH = 24;\r
private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;\r
+ private static final int PADDING_IN_ACTION_HEADER = 4;\r
\r
/**\r
* Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO\r
BufferHelper.setupHeader(builder);\r
builder.setBufferId(256L);\r
builder.setInPort(new PortNumber(256L));\r
+ List<ActionsList> actions = new ArrayList<>();\r
+ ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
+ actionBuilder.setType(PushVlan.class);\r
+ EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder();\r
+ ethertypeBuilder.setEthertype(new EtherType(25));\r
+ actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build());\r
+ actionsListBuilder.setAction(actionBuilder.build());\r
+ actions.add(actionsListBuilder.build());\r
+ actionBuilder = new ActionBuilder();\r
+ actionBuilder.setType(PopVlan.class);\r
+ actionsListBuilder.setAction(actionBuilder.build());\r
+ actions.add(actionsListBuilder.build());\r
+ builder.setActionsList(actions);\r
+ builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"));\r
PacketOutInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance();\r
factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
\r
- BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);\r
+ BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56);\r
Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt());\r
Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt());\r
- // TODO make test for actions after its implementation in factory \r
- // TODO data\r
+ Assert.assertEquals("Wrong ActionsLength", 16, out.readUnsignedShort());\r
out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE);\r
+ Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong ethertype", 25, out.readUnsignedShort());\r
+ out.skipBytes(Short.SIZE / Byte.SIZE);\r
+ Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
+ out.skipBytes(PADDING_IN_ACTION_HEADER);\r
+ Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array());\r
}\r
}\r