Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / OF10MatchSerializerTest.java
index c077cf8336ab63f875003cd63cd174f8f1d80346..e19ede8ceaf5f8f23e0b96055f441e1f010db7a0 100644 (file)
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import junit.framework.Assert;\r
-import io.netty.buffer.ByteBuf;\r
-import io.netty.buffer.UnpooledByteBufAllocator;\r
-\r
-import org.junit.Test;\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.common.types.rev130731.FlowWildcardsV10;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class OF10MatchSerializerTest {\r
-\r
-    /**\r
-     * Testing correct serialization of ofp_match\r
-     */\r
-    @Test\r
-    public void test() {\r
-        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        MatchV10Builder builder = new MatchV10Builder();\r
-        builder.setWildcards(new FlowWildcardsV10(false, false, false, true, false,\r
-                false, true, false, true, true, true));\r
-        builder.setNwSrcMask((short) 24);\r
-        builder.setNwDstMask((short) 16);\r
-        builder.setInPort(6653);\r
-        builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
-        builder.setDlDst(new MacAddress("02:02:02:02:02:02"));\r
-        builder.setDlVlan(128);\r
-        builder.setDlVlanPcp((short) 2);\r
-        builder.setDlType(15);\r
-        builder.setNwTos((short) 14);\r
-        builder.setNwProto((short) 85);\r
-        builder.setNwSrc(new Ipv4Address("1.1.1.2"));\r
-        builder.setNwDst(new Ipv4Address("32.16.8.1"));\r
-        builder.setTpSrc(2048);\r
-        builder.setTpDst(4096);\r
-        MatchV10 match = builder.build();\r
-        OF10MatchSerializer.encodeMatchV10(out, match);\r
-        \r
-        Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());\r
-        byte[] dlSrc = new byte[6];\r
-        out.readBytes(dlSrc);\r
-        Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));\r
-        byte[] dlDst = new byte[6];\r
-        out.readBytes(dlDst);\r
-        Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));\r
-        Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());\r
-        out.skipBytes(1);\r
-        Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());\r
-        Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());\r
-        out.skipBytes(2);\r
-        Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());\r
-    }\r
-    \r
-    /**\r
-     * Testing correct serialization of ofp_match\r
-     */\r
-    @Test\r
-    public void test2() {\r
-        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        MatchV10Builder builder = new MatchV10Builder();\r
-        builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true,\r
-                true, true, true, true, true, true));\r
-        builder.setNwSrcMask((short) 0);\r
-        builder.setNwDstMask((short) 0);\r
-        builder.setInPort(6653);\r
-        builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
-        builder.setDlDst(new MacAddress("02:02:02:02:02:02"));\r
-        builder.setDlVlan(128);\r
-        builder.setDlVlanPcp((short) 2);\r
-        builder.setDlType(15);\r
-        builder.setNwTos((short) 14);\r
-        builder.setNwProto((short) 85);\r
-        builder.setNwSrc(new Ipv4Address("1.1.1.2"));\r
-        builder.setNwDst(new Ipv4Address("32.16.8.1"));\r
-        builder.setTpSrc(2048);\r
-        builder.setTpDst(4096);\r
-        MatchV10 match = builder.build();\r
-        OF10MatchSerializer.encodeMatchV10(out, match);\r
-        \r
-        Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());\r
-        byte[] dlSrc = new byte[6];\r
-        out.readBytes(dlSrc);\r
-        Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));\r
-        byte[] dlDst = new byte[6];\r
-        out.readBytes(dlDst);\r
-        Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));\r
-        Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());\r
-        out.skipBytes(1);\r
-        Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());\r
-        Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());\r
-        out.skipBytes(2);\r
-        Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());\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.util;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+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.common.types.rev130731.FlowWildcardsV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF10MatchSerializerTest {
+
+    private SerializerRegistry registry;
+    private OFSerializer<MatchV10> matchSerializer;
+
+    /**
+     * Initializes serializer table and stores correct factory in field
+     */
+    @Before
+    public void startUp() {
+        registry = new SerializerRegistryImpl();
+        registry.init();
+        matchSerializer = registry.getSerializer(
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MatchV10.class));
+    }
+
+    /**
+     * Testing correct serialization of ofp_match
+     */
+    @Test
+    public void test() {
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+        MatchV10Builder builder = new MatchV10Builder();
+        builder.setWildcards(new FlowWildcardsV10(false, false, true, false,
+                false, true, false, true, true, true));
+        builder.setNwSrcMask((short) 24);
+        builder.setNwDstMask((short) 16);
+        builder.setInPort(6653);
+        builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
+        builder.setDlDst(new MacAddress("02:02:02:02:02:02"));
+        builder.setDlVlan(128);
+        builder.setDlVlanPcp((short) 2);
+        builder.setDlType(15);
+        builder.setNwTos((short) 14);
+        builder.setNwProto((short) 85);
+        builder.setNwSrc(new Ipv4Address("1.1.1.2"));
+        builder.setNwDst(new Ipv4Address("32.16.8.1"));
+        builder.setTpSrc(2048);
+        builder.setTpDst(4096);
+        MatchV10 match = builder.build();
+        matchSerializer.serialize(match, out);
+
+        Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt());
+        Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
+        byte[] dlSrc = new byte[6];
+        out.readBytes(dlSrc);
+        Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
+        byte[] dlDst = new byte[6];
+        out.readBytes(dlDst);
+        Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));
+        Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());
+        Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());
+        out.skipBytes(1);
+        Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());
+        Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());
+        Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());
+        out.skipBytes(2);
+        Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());
+        Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());
+        Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());
+        Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());
+    }
+
+    /**
+     * Testing correct serialization of ofp_match
+     */
+    @Test
+    public void test2() {
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+        MatchV10Builder builder = new MatchV10Builder();
+        builder.setWildcards(new FlowWildcardsV10(true, true, true, true,
+                true, true, true, true, true, true));
+        builder.setNwSrcMask((short) 0);
+        builder.setNwDstMask((short) 0);
+        builder.setInPort(6653);
+        builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
+        builder.setDlDst(new MacAddress("02:02:02:02:02:02"));
+        builder.setDlVlan(128);
+        builder.setDlVlanPcp((short) 2);
+        builder.setDlType(15);
+        builder.setNwTos((short) 14);
+        builder.setNwProto((short) 85);
+        builder.setNwSrc(new Ipv4Address("1.1.1.2"));
+        builder.setNwDst(new Ipv4Address("32.16.8.1"));
+        builder.setTpSrc(2048);
+        builder.setTpDst(4096);
+        MatchV10 match = builder.build();
+        matchSerializer.serialize(match, out);
+
+        Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
+        Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
+        byte[] dlSrc = new byte[6];
+        out.readBytes(dlSrc);
+        Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
+        byte[] dlDst = new byte[6];
+        out.readBytes(dlDst);
+        Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));
+        Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());
+        Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());
+        out.skipBytes(1);
+        Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());
+        Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());
+        Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());
+        out.skipBytes(2);
+        Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());
+        Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());
+        Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());
+        Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());
+    }
+}