Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / OF10MatchDeserializerTest.java
index 06b78e3487455d00ee5c8bb127d579fd6a98b51a..0201f609feef90c97c55ad22de9bd3c4b6300653 100644 (file)
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.junit.Assert;\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
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class OF10MatchDeserializerTest {\r
-\r
-    /**\r
-     * Testing correct deserialization of ofp_match\r
-     */\r
-    @Test\r
-    public void test() {\r
-        ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF "\r
-                + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "\r
-                + "50 50 20 20");\r
-        message.skipBytes(4); // skip XID\r
-        MatchV10 match = OF10MatchDeserializer.createMatchV10(message);\r
-        Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, true, false,\r
-                false, true, false, true, true, false), match.getWildcards());\r
-        Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());\r
-        Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());\r
-        Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());\r
-        Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());\r
-        Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());\r
-        Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());\r
-        Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());\r
-        Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());\r
-        Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());\r
-        Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());\r
-        Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());\r
-        Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());\r
-        Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());\r
-        Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());\r
-    }\r
-    \r
-    /**\r
-     * Testing correct deserialization of ofp_match\r
-     */\r
-    @Test\r
-    public void test2() {\r
-        ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF "\r
-                + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "\r
-                + "50 50 20 20");\r
-        message.skipBytes(4); // skip XID\r
-        MatchV10 match = OF10MatchDeserializer.createMatchV10(message);\r
-        Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true, true,\r
-                true, true, true, true, true, true), match.getWildcards());\r
-        Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());\r
-        Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());\r
-        Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());\r
-        Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());\r
-        Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());\r
-        Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());\r
-        Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());\r
-        Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());\r
-        Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());\r
-        Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());\r
-        Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());\r
-        Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());\r
-        Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());\r
-        Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());\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.util;
+
+import io.netty.buffer.ByteBuf;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
+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;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF10MatchDeserializerTest {
+
+    private OFDeserializer<MatchV10> matchDeserializer;
+
+    /**
+     * Initializes deserializer registry and lookups correct deserializer
+     */
+    @Before
+    public void startUp() {
+        DeserializerRegistry registry = new DeserializerRegistryImpl();
+        registry.init();
+        matchDeserializer = registry.getDeserializer(
+                new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
+    }
+
+    /**
+     * Testing correct deserialization of ofp_match
+     */
+    @Test
+    public void test() {
+        ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF "
+                + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
+                + "50 50 20 20");
+        message.skipBytes(4); // skip XID
+        MatchV10 match = matchDeserializer.deserialize(message);
+        Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, true, false,
+                false, true, false, true, true, false), match.getWildcards());
+        Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());
+        Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());
+        Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
+        Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());
+        Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());
+        Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
+        Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
+        Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
+        Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
+        Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
+        Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
+        Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
+        Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
+        Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());
+    }
+
+    /**
+     * Testing correct deserialization of ofp_match
+     */
+    @Test
+    public void test2() {
+        ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF "
+                + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
+                + "50 50 20 20");
+        message.skipBytes(4); // skip XID
+        MatchV10 match = matchDeserializer.deserialize(message);
+        Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true,
+                true, true, true, true, true, true), match.getWildcards());
+        Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());
+        Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());
+        Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
+        Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());
+        Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());
+        Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
+        Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
+        Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
+        Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
+        Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
+        Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
+        Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
+        Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
+        Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());
+    }
+
+}