Removed enumeration ALL from FlowWildCardsV10
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / OF10MatchSerializer.java
index 84023e24087659af25365e6a1ab38a2ae245f640..33f31971e89d7ae40c17adc47f9bd6cb8b3168c4 100644 (file)
@@ -1,76 +1,78 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\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
- * Serializes ofp_match (OpenFlow v1.0) structure\r
- * @author michal.polkorab\r
- */\r
-public abstract class OF10MatchSerializer {\r
-\r
-    private static final byte PADDING_IN_MATCH = 1;\r
-    private static final byte PADDING_IN_MATCH_2 = 2;\r
-    private static final byte NW_SRC_SHIFT = 8;\r
-    private static final byte NW_DST_SHIFT = 14;\r
-    private static final int ALL = ((1 << 22) - 1);\r
-    \r
-    /**\r
-     * Encodes ofp_match (OpenFlow v1.0)\r
-     * @param out output ByteBuf that match will be written into\r
-     * @param match match to be encoded\r
-     */\r
-    public static void encodeMatchV10(ByteBuf out, MatchV10 match) {\r
-        out.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask()));\r
-        out.writeShort(match.getInPort());\r
-        out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue()));\r
-        out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue()));\r
-        out.writeShort(match.getDlVlan());\r
-        out.writeByte(match.getDlVlanPcp());\r
-        ByteBufUtils.padBuffer(PADDING_IN_MATCH, out);\r
-        out.writeShort(match.getDlType());\r
-        out.writeByte(match.getNwTos());\r
-        out.writeByte(match.getNwProto());\r
-        ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, out);\r
-        String[] srcGroups = match.getNwSrc().getValue().split("\\.");\r
-        for (int i = 0; i < srcGroups.length; i++) {\r
-            out.writeByte(Integer.parseInt(srcGroups[i]));\r
-        }\r
-        String[] dstGroups = match.getNwDst().getValue().split("\\.");\r
-        for (int i = 0; i < dstGroups.length; i++) {\r
-            out.writeByte(Integer.parseInt(dstGroups[i]));\r
-        }\r
-        out.writeShort(match.getTpSrc());\r
-        out.writeShort(match.getTpDst());\r
-    }\r
-    \r
-    private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) {\r
-        int bitmask = 0;\r
-        if (wildcards.isALL()) {\r
-            bitmask |= ALL;\r
-        } else {\r
-            Map<Integer, Boolean> wildcardsMap = new HashMap<>();\r
-            wildcardsMap.put(0, wildcards.isINPORT());\r
-            wildcardsMap.put(1, wildcards.isDLVLAN());\r
-            wildcardsMap.put(2, wildcards.isDLSRC());\r
-            wildcardsMap.put(3, wildcards.isDLDST());\r
-            wildcardsMap.put(4, wildcards.isDLTYPE());\r
-            wildcardsMap.put(5, wildcards.isNWPROTO());\r
-            wildcardsMap.put(6, wildcards.isTPSRC());\r
-            wildcardsMap.put(7, wildcards.isTPDST());\r
-            wildcardsMap.put(20, wildcards.isDLVLANPCP());\r
-            wildcardsMap.put(21, wildcards.isNWTOS());\r
-            bitmask = ByteBufUtils.fillBitMaskFromMap(wildcardsMap);\r
-            bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);\r
-            bitmask |= ((32 - dstMask) << NW_DST_SHIFT);\r
-        }\r
-        return bitmask;\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 java.util.HashMap;
+import java.util.Map;
+
+import io.netty.buffer.ByteBuf;
+
+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;
+
+/**
+ * Serializes ofp_match (OpenFlow v1.0) structure
+ * @author michal.polkorab
+ */
+public abstract class OF10MatchSerializer {
+
+    private static final byte PADDING_IN_MATCH = 1;
+    private static final byte PADDING_IN_MATCH_2 = 2;
+    private static final byte NW_SRC_SHIFT = 8;
+    private static final byte NW_DST_SHIFT = 14;
+    
+    /**
+     * Encodes ofp_match (OpenFlow v1.0)
+     * @param out output ByteBuf that match will be written into
+     * @param match match to be encoded
+     */
+    public static void encodeMatchV10(ByteBuf out, MatchV10 match) {
+        out.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask()));
+        out.writeShort(match.getInPort());
+        out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue()));
+        out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue()));
+        out.writeShort(match.getDlVlan());
+        out.writeByte(match.getDlVlanPcp());
+        ByteBufUtils.padBuffer(PADDING_IN_MATCH, out);
+        out.writeShort(match.getDlType());
+        out.writeByte(match.getNwTos());
+        out.writeByte(match.getNwProto());
+        ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, out);
+        String[] srcGroups = match.getNwSrc().getValue().split("\\.");
+        for (int i = 0; i < srcGroups.length; i++) {
+            out.writeByte(Integer.parseInt(srcGroups[i]));
+        }
+        String[] dstGroups = match.getNwDst().getValue().split("\\.");
+        for (int i = 0; i < dstGroups.length; i++) {
+            out.writeByte(Integer.parseInt(dstGroups[i]));
+        }
+        out.writeShort(match.getTpSrc());
+        out.writeShort(match.getTpDst());
+    }
+    
+    private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) {
+        int bitmask = 0;
+        Map<Integer, Boolean> wildcardsMap = new HashMap<>();
+        wildcardsMap.put(0, wildcards.isINPORT());
+        wildcardsMap.put(1, wildcards.isDLVLAN());
+        wildcardsMap.put(2, wildcards.isDLSRC());
+        wildcardsMap.put(3, wildcards.isDLDST());
+        wildcardsMap.put(4, wildcards.isDLTYPE());
+        wildcardsMap.put(5, wildcards.isNWPROTO());
+        wildcardsMap.put(6, wildcards.isTPSRC());
+        wildcardsMap.put(7, wildcards.isTPDST());
+        wildcardsMap.put(20, wildcards.isDLVLANPCP());
+        wildcardsMap.put(21, wildcards.isNWTOS());
+        bitmask = ByteBufUtils.fillBitMaskFromMap(wildcardsMap);
+        bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);
+        bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
+        return bitmask;
+    }
+    
+}