Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.core.web.serializers; |
| 2 | import java.io.IOException; |
| 3 | import java.util.List; |
| 4 | |
| 5 | import net.floodlightcontroller.core.web.OFGroupStatsEntryMod; |
| 6 | |
| 7 | import org.codehaus.jackson.JsonGenerationException; |
| 8 | import org.codehaus.jackson.JsonGenerator; |
| 9 | import org.codehaus.jackson.map.SerializerProvider; |
| 10 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 11 | import org.projectfloodlight.openflow.protocol.OFBucketCounter; |
| 12 | import org.projectfloodlight.openflow.protocol.OFGroupStatsEntry; |
| 13 | |
| 14 | public class OFGroupStatsEntryModSerializer extends SerializerBase<OFGroupStatsEntryMod>{ |
| 15 | |
| 16 | protected OFGroupStatsEntryModSerializer(){ |
| 17 | super(OFGroupStatsEntryMod.class); |
| 18 | } |
| 19 | |
| 20 | @Override |
| 21 | public void serialize(OFGroupStatsEntryMod groupStatsEntryMod, JsonGenerator jGen, |
| 22 | SerializerProvider sp) throws IOException, |
| 23 | JsonGenerationException { |
| 24 | OFGroupStatsEntry groupStatsModEntry = groupStatsEntryMod.getGroupStatsEntry(); |
| 25 | List<OFBucketCounter> bucketCounters = groupStatsModEntry.getBucketStats(); |
| 26 | jGen.writeStartObject(); |
| 27 | jGen.writeNumberField("groupId", groupStatsModEntry.getGroup().getGroupNumber()); |
| 28 | jGen.writeNumberField("packetCount", groupStatsModEntry.getPacketCount().getValue()); |
| 29 | jGen.writeNumberField("byteCount", groupStatsModEntry.getByteCount().getValue()); |
| 30 | jGen.writeNumberField("durationNsec", groupStatsModEntry.getDurationNsec()); |
| 31 | jGen.writeNumberField("durationSec", groupStatsModEntry.getDurationSec()); |
| 32 | jGen.writeArrayFieldStart("bucketStats"); |
| 33 | for (OFBucketCounter bucketCouter : bucketCounters){ |
| 34 | jGen.writeStartObject(); |
| 35 | jGen.writeNumberField("pktCount", bucketCouter.getPacketCount().getValue()); |
| 36 | jGen.writeNumberField("byteCount", bucketCouter.getByteCount().getValue()); |
| 37 | jGen.writeEndObject(); |
| 38 | } |
| 39 | jGen.writeEndArray(); |
| 40 | jGen.writeEndObject(); |
| 41 | } |
| 42 | |
| 43 | } |