Stats Improvement
diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/OFFlowStatsEntryModSerializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/OFFlowStatsEntryModSerializer.java
index 4f71dc9..4a83230 100644
--- a/src/main/java/net/floodlightcontroller/core/web/serializers/OFFlowStatsEntryModSerializer.java
+++ b/src/main/java/net/floodlightcontroller/core/web/serializers/OFFlowStatsEntryModSerializer.java
@@ -6,9 +6,9 @@
 import java.util.Set;
 
 import net.floodlightcontroller.core.web.OFFlowStatsEntryMod;
+import net.onrc.onos.core.packet.IPv4;
 
 import org.projectfloodlight.openflow.protocol.action.*;
-import org.apache.commons.codec.binary.Hex;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.JsonGenerator;
 import org.codehaus.jackson.map.SerializerProvider;
@@ -23,7 +23,6 @@
 import org.projectfloodlight.openflow.protocol.instruction.*;
 import org.projectfloodlight.openflow.protocol.match.MatchFields;
 import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
-import org.projectfloodlight.openflow.protocol.ver13.OFInstructionTypeSerializerVer13;
 
 public class OFFlowStatsEntryModSerializer extends SerializerBase<OFFlowStatsEntryMod> {
     
@@ -41,18 +40,14 @@
         List<OFInstruction> instructions = flowStatsEntry.getInstructions();
         Set<OFFlowModFlags> flags = flowStatsEntry.getFlags();
         jGen.writeStartObject();
-        
+        //System.out.println("flowstats:\n\n\n"+ flowStatsEntry);
         jGen.writeNumberField("byteCount", flowStatsEntry.getByteCount().getValue());
         jGen.writeNumberField("packetCount", flowStatsEntry.getPacketCount().getValue());
         jGen.writeNumberField("priority", flowStatsEntry.getPriority());
         jGen.writeNumberField("cookie", flowStatsEntry.getCookie().getValue());
         jGen.writeNumberField("durationNsec", flowStatsEntry.getDurationNsec());
         jGen.writeNumberField("durationSec", flowStatsEntry.getDurationSec());
-        jGen.writeArrayFieldStart("flags");
-        for (OFFlowModFlags flag: flags){
-            jGen.writeNullField(flag.name());;
-        }
-        jGen.writeEndArray();
+        jGen.writeObjectField("flags", flowStatsEntry.getFlags());
         jGen.writeNumberField("hardTimeout", flowStatsEntry.getHardTimeout());
         jGen.writeNumberField("idleTimeout", flowStatsEntry.getIdleTimeout());
         jGen.writeArrayFieldStart("match");
@@ -60,12 +55,21 @@
         Iterator<OFOxm<?>> match= matches.iterator();
         while(match.hasNext()){
             OFOxm<?> matchGeneric = match.next();
-            //jGen.writeObjectField(matchGeneric.getMatchField().id.toString(), matchGeneric.getValue().toString());
             if (matchGeneric.getMatchField().id == MatchFields.IPV4_DST){
-                jGen.writeStringField("networkDestination", matchGeneric.getValue().toString());
+                jGen.writeStringField("networkDestination", matchGeneric.getValue().toString()
+                        +"/"
+                        +(matchGeneric.isMasked() ?
+                                OFFlowStatsEntryModSerializer.covertToMask(
+                                        IPv4.toIPv4Address(
+                                                matchGeneric.getMask().toString())):"0"));
             }
             else if (matchGeneric.getMatchField().id == MatchFields.IPV4_SRC){
-                jGen.writeStringField("networkSource", matchGeneric.getValue().toString());
+                jGen.writeStringField("networkSource", matchGeneric.getValue().toString()
+                        +"/"
+                        +(matchGeneric.isMasked() ?
+                                OFFlowStatsEntryModSerializer.covertToMask(
+                                        IPv4.toIPv4Address(
+                                                matchGeneric.getMask().toString())):"0"));
             }
             else if (matchGeneric.getMatchField().id == MatchFields.ETH_DST){
                 jGen.writeStringField("dataLayerDestination", matchGeneric.getValue().toString());
@@ -74,80 +78,99 @@
                 jGen.writeStringField("dataLayerSource", matchGeneric.getValue().toString());
             }
             else if (matchGeneric.getMatchField().id == MatchFields.ETH_TYPE){
-                jGen.writeNumberField("dataLayerType", Integer.decode("0x"+matchGeneric.getValue().toString()));
+                jGen.writeNumberField("dataLayerType", Integer.decode(matchGeneric.getValue().toString()));
             }
             else if (matchGeneric.getMatchField().id == MatchFields.IN_PORT){
                 jGen.writeNumberField("inputPort", Integer.parseInt(matchGeneric.getValue().toString()));
             }
             else if (matchGeneric.getMatchField().id == MatchFields.MPLS_TC){
-                jGen.writeNumberField("mplsTc", Integer.parseInt(matchGeneric.getValue().toString()));
+                jGen.writeNumberField("mplsTc", Integer.decode(matchGeneric.getValue().toString()));
             }
             else if (matchGeneric.getMatchField().id == MatchFields.MPLS_LABEL){
-                jGen.writeNumberField("mplsLabel", Integer.parseInt(matchGeneric.getValue().toString()));
+                jGen.writeNumberField("mplsLabel", Integer.decode(matchGeneric.getValue().toString()));
             }
             else if (matchGeneric.getMatchField().id == MatchFields.IP_PROTO){
                 jGen.writeNumberField("networkProtocol", Integer.parseInt(matchGeneric.getValue().toString())); 
             }
             //TODO: Ask Saurav about the implementation of tcp and udp.
-            else if (matchGeneric.getMatchField().id == MatchFields.TCP_DST || matchGeneric.getMatchField().id == MatchFields.UDP_DST){
+            else if (matchGeneric.getMatchField().id == MatchFields.TCP_DST
+                    || matchGeneric.getMatchField().id == MatchFields.UDP_DST){
                 jGen.writeNumberField("transportDestination", Integer.parseInt(matchGeneric.getValue().toString()));
             }
-            else if (matchGeneric.getMatchField().id == MatchFields.TCP_SRC || matchGeneric.getMatchField().id == MatchFields.UDP_SRC){
+            else if (matchGeneric.getMatchField().id == MatchFields.TCP_SRC
+                    || matchGeneric.getMatchField().id == MatchFields.UDP_SRC){
                 jGen.writeNumberField("transportSource", Integer.parseInt(matchGeneric.getValue().toString()));
             }
         }
         jGen.writeEndObject();
         jGen.writeEndArray();
-
-        /*\jGen.writeArrayFieldStart("instructions");
-        jGen.writeStartObject();
+        jGen.writeFieldName("instructions");
+        jGen.writeStartArray();
+        List<OFAction> actions = null;
         for (OFInstruction instruction: instructions){
-            jGen.writeObjectField("instructionType", instruction.getType().name());
-            jGen.writeArrayFieldStart("actions");
-            jGen.writeStartObject();
-            //OFInstructionApplyActions newInstruction = instruction.getClass().cast(instruction);
-            //instruction = ;
-            //instruction.g
-            if (instruction.getType().equals(OFInstructionType.APPLY_ACTIONS)){
-                //import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions
-                List<OFAction> actions = ((OFInstructionApplyActions) instruction).getActions();
-                for (OFAction action : actions){
-                    a
-                }
+            if(instruction.getType().equals(OFInstructionType.APPLY_ACTIONS)){
+                actions = ((OFInstructionApplyActions)instruction).getActions();
             }
-            else if (instruction.getType().equals(OFInstructionType.APPLY_ACTIONS)){
-                List<OFAction> actions = ((OFInstructionApplyActions) instruction).getActions();
+            else if(instruction.getType().equals(OFInstructionType.WRITE_ACTIONS)){
+                actions = ((OFInstructionWriteActions)instruction).getActions();
+            }
+            else{
+                continue;
+            }
+            jGen.writeStartObject();
+            jGen.writeFieldName(instruction.getType().name());
+            jGen.writeStartObject();
+            for (OFAction action : actions){
+                if (action.getType().equals(OFActionType.GROUP)){
+                    jGen.writeNumberField("group", ((OFActionGroup)action).getGroup().getGroupNumber());
+                }
+                else if (action.getType().equals(OFActionType.OUTPUT)){
+                    jGen.writeNumberField("group", ((OFActionOutput)action).getPort().getPortNumber());
+                }
+                else if(action.getType().compareTo(OFActionType.POP_MPLS) == 0
+                        || action.getType().compareTo(OFActionType.COPY_TTL_IN) == 0
+                        || action.getType().compareTo(OFActionType.COPY_TTL_OUT) == 0
+                        || action.getType().compareTo(OFActionType.DEC_MPLS_TTL) == 0
+                        || action.getType().compareTo(OFActionType.DEC_NW_TTL) == 0
+                        || action.getType().compareTo(OFActionType.POP_PBB) == 0
+                        || action.getType().compareTo(OFActionType.POP_VLAN) == 0){
+                    jGen.writeStringField(action.getType().name(), "True");
+                }
+                else if(action.getType().compareTo(OFActionType.COPY_TTL_IN) == 0){
+                    jGen.writeStringField("POP_MPLS", "True");
+                }
+                else if (action.getType().equals(OFActionType.SET_FIELD)){
+                    //TODO Support for more setFields
+                    if (((OFActionSetField)action).getField().toString().contains("OFOxmEthSrcVer13")){
+                        jGen.writeStringField("SET_DL_SRC", ((OFActionSetField)action).getField().getValue().toString());
+                    }
+                    else if (((OFActionSetField)action).getField().toString().contains("OFOxmEthDstVer13")){
+                        jGen.writeStringField("SET_DL_DST", ((OFActionSetField)action).getField().getValue().toString());
+                    }
+                    else if (((OFActionSetField)action).getField().toString().contains("OFOxmNwDstVer13")){
+                        jGen.writeStringField("SET_NW_SRC", ((OFActionSetField)action).getField().getValue().toString());
+                    }
+                    else if (((OFActionSetField)action).getField().toString().contains("OFOxmNwDstVer13")){
+                        jGen.writeStringField("SET_NW_DST", ((OFActionSetField)action).getField().getValue().toString());
+                    }
+                    else if (((OFActionSetField)action).getField().toString().contains("OFOxmMplsLabelVer13")){
+                        jGen.writeStringField("PUSH_MPLS", ((OFActionSetField)action).getField().getValue().toString());
+                    }
+                }
             }
             jGen.writeEndObject();
-            jGen.writeEndArray();
         }
         jGen.writeEndObject();
-        jGen.writeEndArray();*/
+        jGen.writeEndArray();
         jGen.writeEndObject();
-
-        
-        //for (OFAction action : actions){
-            /*if(action.getType().compareTo(OFActionType.SET_FIELD) == 0){
-                /*
-                 * TODO: 1-Need better if condition.
-                 * TODO: 2-Complete REST response. (Right now we are only sending what 
-                 * SegmentRouter CLI needs).
-                 */
-                /*if (((OFActionSetField)action).getField().toString().contains("OFOxmEthSrcVer13")){
-                    jGen.writeStringField("SET_DL_SRC", ((OFActionSetField)action).getField().getValue().toString());
-                }
-                else if (((OFActionSetField)action).getField().toString().contains("OFOxmEthDstVer13")){
-                    jGen.writeStringField("SET_DL_DST", ((OFActionSetField)action).getField().getValue().toString());
-                }
-                System.out
-            }
-            else if(action.getType().compareTo(OFActionType.OUTPUT) == 0){
-                jGen.writeNumberField("OUTPPUT", ((OFActionOutput)action).getPort().getPortNumber());
-            }*/
-        //}
-        //jGen.writeEndObject();
-
     }
-    
+    public static int covertToMask(int x) {
+        x = x - ((x >>> 1) & 0x55555555); 
+        x = (x & 0x33333333) + ((x >>> 2) & 0x33333333); 
+        x = (x + (x >>> 4)) & 0x0F0F0F0F; 
+        x = x + (x >>> 8); 
+        x = x + (x >>> 16); 
+        return x & 0x0000003F; 
+    } 
 
 }