Updated experimenter model
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / OF10MatchSerializer.java
index d934e4c75e129f47b35cfb24d12cfe626cbeefea..813b60841702063505711fa27fcb2dd7ad5b6037 100644 (file)
@@ -10,10 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.util;
 
 import io.netty.buffer.ByteBuf;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
 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;
 
@@ -34,7 +32,7 @@ public class OF10MatchSerializer implements OFSerializer<MatchV10> {
      * @param match match to be serialized
      */
     @Override
-    public void serialize(MatchV10 match, ByteBuf outBuffer) {
+    public void serialize(final MatchV10 match, final ByteBuf outBuffer) {
         outBuffer.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask()));
         outBuffer.writeShort(match.getInPort());
         outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue()));
@@ -46,32 +44,31 @@ public class OF10MatchSerializer implements OFSerializer<MatchV10> {
         outBuffer.writeByte(match.getNwTos());
         outBuffer.writeByte(match.getNwProto());
         ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, outBuffer);
-        String[] srcGroups = match.getNwSrc().getValue().split("\\.");
-        for (int i = 0; i < srcGroups.length; i++) {
-            outBuffer.writeByte(Integer.parseInt(srcGroups[i]));
+        Iterable<String> srcGroups = ByteBufUtils.DOT_SPLITTER.split(match.getNwSrc().getValue());
+        for (String group : srcGroups) {
+            outBuffer.writeByte(Short.parseShort(group));
         }
-        String[] dstGroups = match.getNwDst().getValue().split("\\.");
-        for (int i = 0; i < dstGroups.length; i++) {
-            outBuffer.writeByte(Integer.parseInt(dstGroups[i]));
+        Iterable<String> dstGroups = ByteBufUtils.DOT_SPLITTER.split(match.getNwDst().getValue());
+        for (String group : dstGroups) {
+            outBuffer.writeByte(Short.parseShort(group));
         }
         outBuffer.writeShort(match.getTpSrc());
         outBuffer.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);
+    private static int encodeWildcards(final FlowWildcardsV10 wildcards, final short srcMask, final short dstMask) {
+        int bitmask = ByteBufUtils.fillBitMask(0,
+                wildcards.isINPORT(),
+                wildcards.isDLVLAN(),
+                wildcards.isDLSRC(),
+                wildcards.isDLDST(),
+                wildcards.isDLTYPE(),
+                wildcards.isNWPROTO(),
+                wildcards.isTPSRC(),
+                wildcards.isTPDST());
+        bitmask |= ByteBufUtils.fillBitMask(20,
+                wildcards.isDLVLANPCP(),
+                wildcards.isNWTOS());
         bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);
         bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
         return bitmask;