-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-import io.netty.buffer.UnpooledByteBufAllocator;\r
-\r
-import java.math.BigInteger;\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.util.BufferHelper;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc;\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.FlowModCommand;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class OF10FlowModInputMessageFactoryTest {\r
-\r
- /**\r
- * @throws Exception \r
- * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO\r
- */\r
- @Test\r
- public void testFlowModInputMessageFactory() throws Exception {\r
- FlowModInputBuilder builder = new FlowModInputBuilder();\r
- BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);\r
- MatchV10Builder matchBuilder = new MatchV10Builder();\r
- matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true, true));\r
- matchBuilder.setNwSrcMask((short) 0);\r
- matchBuilder.setNwDstMask((short) 0);\r
- matchBuilder.setInPort(58);\r
- matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
- matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));\r
- matchBuilder.setDlVlan(18);\r
- matchBuilder.setDlVlanPcp((short) 5);\r
- matchBuilder.setDlType(42);\r
- matchBuilder.setNwTos((short) 4);\r
- matchBuilder.setNwProto((short) 7);\r
- matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));\r
- matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));\r
- matchBuilder.setTpSrc(6653);\r
- matchBuilder.setTpDst(6633);\r
- builder.setMatchV10(matchBuilder.build());\r
- byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01};\r
- builder.setCookie(new BigInteger(cookie));\r
- builder.setCommand(FlowModCommand.forValue(0));\r
- builder.setIdleTimeout(12);\r
- builder.setHardTimeout(16);\r
- builder.setPriority(1);\r
- builder.setBufferId(2L);\r
- builder.setOutPort(new PortNumber(4422L));\r
- builder.setFlagsV10(new FlowModFlagsV10(true, false, true));\r
- List<ActionsList> actions = new ArrayList<>();\r
- ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
- ActionBuilder actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetNwDst.class);\r
- IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder();\r
- ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2"));\r
- actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build());\r
- actionsListBuilder.setAction(actionBuilder.build());\r
- actions.add(actionsListBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(SetTpSrc.class);\r
- PortActionBuilder portBuilder = new PortActionBuilder();\r
- portBuilder.setPort(new PortNumber(42L));\r
- actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
- actionsListBuilder.setAction(actionBuilder.build());\r
- actions.add(actionsListBuilder.build());\r
- builder.setActionsList(actions);\r
- FlowModInput message = builder.build();\r
- \r
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
- \r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message));\r
- Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());\r
- byte[] dlSrc = new byte[6];\r
- out.readBytes(dlSrc);\r
- Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));\r
- byte[] dlDst = new byte[6];\r
- out.readBytes(dlDst);\r
- Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));\r
- Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte());\r
- out.skipBytes(1);\r
- Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte());\r
- out.skipBytes(2);\r
- Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort());\r
- byte[] cookieRead = new byte[8];\r
- out.readBytes(cookieRead);\r
- Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);\r
- Assert.assertEquals("Wrong command", 0, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort());\r
- out.skipBytes(2);\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.UnpooledByteBufAllocator;
+
+import java.math.BigInteger;
+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.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+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.augments.rev131002.IpAddressAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF10FlowModInputMessageFactoryTest {
+
+ /**
+ * @throws Exception
+ * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO
+ */
+ @Test
+ public void testFlowModInputMessageFactory() throws Exception {
+ FlowModInputBuilder builder = new FlowModInputBuilder();
+ BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
+ MatchV10Builder matchBuilder = new MatchV10Builder();
+ matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true, true));
+ matchBuilder.setNwSrcMask((short) 0);
+ matchBuilder.setNwDstMask((short) 0);
+ matchBuilder.setInPort(58);
+ matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
+ matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));
+ matchBuilder.setDlVlan(18);
+ matchBuilder.setDlVlanPcp((short) 5);
+ matchBuilder.setDlType(42);
+ matchBuilder.setNwTos((short) 4);
+ matchBuilder.setNwProto((short) 7);
+ matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));
+ matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));
+ matchBuilder.setTpSrc(6653);
+ matchBuilder.setTpDst(6633);
+ builder.setMatchV10(matchBuilder.build());
+ byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01};
+ builder.setCookie(new BigInteger(cookie));
+ builder.setCommand(FlowModCommand.forValue(0));
+ builder.setIdleTimeout(12);
+ builder.setHardTimeout(16);
+ builder.setPriority(1);
+ builder.setBufferId(2L);
+ builder.setOutPort(new PortNumber(4422L));
+ builder.setFlagsV10(new FlowModFlagsV10(true, false, true));
+ List<ActionsList> actions = new ArrayList<>();
+ ActionsListBuilder actionsListBuilder = new ActionsListBuilder();
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setType(SetNwDst.class);
+ IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder();
+ ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2"));
+ actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build());
+ actionsListBuilder.setAction(actionBuilder.build());
+ actions.add(actionsListBuilder.build());
+ actionBuilder = new ActionBuilder();
+ actionBuilder.setType(SetTpSrc.class);
+ PortActionBuilder portBuilder = new PortActionBuilder();
+ portBuilder.setPort(new PortNumber(42L));
+ actionBuilder.addAugmentation(PortAction.class, portBuilder.build());
+ actionsListBuilder.setAction(actionBuilder.build());
+ actions.add(actionsListBuilder.build());
+ builder.setActionsList(actions);
+ FlowModInput message = builder.build();
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+ OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance();
+ factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+
+ BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message));
+ Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());
+ Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
+ byte[] dlSrc = new byte[6];
+ out.readBytes(dlSrc);
+ Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
+ byte[] dlDst = new byte[6];
+ out.readBytes(dlDst);
+ Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
+ Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort());
+ Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte());
+ out.skipBytes(1);
+ Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort());
+ Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte());
+ Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte());
+ out.skipBytes(2);
+ Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt());
+ Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt());
+ Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort());
+ Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort());
+ byte[] cookieRead = new byte[8];
+ out.readBytes(cookieRead);
+ Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);
+ Assert.assertEquals("Wrong command", 0, out.readUnsignedShort());
+ Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort());
+ Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort());
+ Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort());
+ Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt());
+ Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort());
+ Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt());
+ Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort());
+ out.skipBytes(2);
+ }
+
+}