Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.core.web.serializers; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
Fahad Naeem Khan | f52d92e | 2014-11-04 16:22:10 -0800 | [diff] [blame^] | 5 | import net.floodlightcontroller.core.IOFSwitch; |
| 6 | import net.floodlightcontroller.core.internal.OFSwitchImplBase; |
Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 7 | import net.floodlightcontroller.core.web.OFPortStatsEntryMod; |
| 8 | |
| 9 | import org.codehaus.jackson.JsonGenerationException; |
| 10 | import org.codehaus.jackson.JsonGenerator; |
| 11 | import org.codehaus.jackson.map.SerializerProvider; |
| 12 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 13 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
| 14 | |
| 15 | public class OFPortStatsEntrySerializer extends SerializerBase<OFPortStatsEntryMod> { |
| 16 | |
| 17 | protected OFPortStatsEntrySerializer() { |
| 18 | super(OFPortStatsEntryMod.class); |
| 19 | } |
| 20 | |
| 21 | @Override |
| 22 | public void serialize(OFPortStatsEntryMod portStatModEntry, JsonGenerator jGen, |
Srikanth Vavilapalli | f25c7b0 | 2014-10-01 14:30:43 -0700 | [diff] [blame] | 23 | SerializerProvider sp) throws IOException, JsonGenerationException { |
Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 24 | |
Fahad Naeem Khan | f52d92e | 2014-11-04 16:22:10 -0800 | [diff] [blame^] | 25 | IOFSwitch sw = portStatModEntry.getSwitch(); |
Srikanth Vavilapalli | f25c7b0 | 2014-10-01 14:30:43 -0700 | [diff] [blame] | 26 | OFPortStatsEntry portStatEntry = portStatModEntry.getPortStatsEntry(); |
Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 27 | jGen.writeStartObject(); |
| 28 | jGen.writeNumberField("portNumber", portStatEntry.getPortNo().getPortNumber()); |
Fahad Naeem Khan | f52d92e | 2014-11-04 16:22:10 -0800 | [diff] [blame^] | 29 | jGen.writeStringField("portStatus", ((OFSwitchImplBase) sw).portEnabled( |
| 30 | portStatEntry.getPortNo().getPortNumber()) ? "up" : "down"); |
Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 31 | jGen.writeNumberField("receivePackets", portStatEntry.getRxPackets().getValue()); |
| 32 | jGen.writeNumberField("transmitPackets", portStatEntry.getTxPackets().getValue()); |
| 33 | jGen.writeNumberField("receiveBytes", portStatEntry.getRxBytes().getValue()); |
| 34 | jGen.writeNumberField("transmitBytes", portStatEntry.getTxBytes().getValue()); |
| 35 | jGen.writeNumberField("receiveDropped", portStatEntry.getRxDropped().getValue()); |
| 36 | jGen.writeNumberField("transmitDropped", portStatEntry.getTxDropped().getValue()); |
| 37 | jGen.writeNumberField("receiveErrors", portStatEntry.getRxErrors().getValue()); |
| 38 | jGen.writeNumberField("transmitErrors", portStatEntry.getTxErrors().getValue()); |
Srikanth Vavilapalli | f25c7b0 | 2014-10-01 14:30:43 -0700 | [diff] [blame] | 39 | jGen.writeNumberField("receiveFrameErrors", portStatEntry.getRxFrameErr() |
| 40 | .getValue()); |
| 41 | jGen.writeNumberField("receiveOverrunErrors", portStatEntry.getRxOverErr() |
| 42 | .getValue()); |
Srikanth Vavilapalli | b725851 | 2014-09-29 13:24:11 -0700 | [diff] [blame] | 43 | jGen.writeNumberField("receiveCRCErrors", portStatEntry.getRxCrcErr().getValue()); |
| 44 | jGen.writeNumberField("collisions", portStatEntry.getCollisions().getValue()); |
| 45 | |
| 46 | jGen.writeEndObject(); |
| 47 | } |
| 48 | |
| 49 | } |