blob: 259f7f21b66d25b1a978785bab36fc1eb3d5490d [file] [log] [blame]
Srikanth Vavilapallib7258512014-09-29 13:24:11 -07001package net.floodlightcontroller.core.web.serializers;
2
3import java.io.IOException;
4
Fahad Naeem Khanf52d92e2014-11-04 16:22:10 -08005import net.floodlightcontroller.core.IOFSwitch;
6import net.floodlightcontroller.core.internal.OFSwitchImplBase;
Srikanth Vavilapallib7258512014-09-29 13:24:11 -07007import net.floodlightcontroller.core.web.OFPortStatsEntryMod;
8
9import org.codehaus.jackson.JsonGenerationException;
10import org.codehaus.jackson.JsonGenerator;
11import org.codehaus.jackson.map.SerializerProvider;
12import org.codehaus.jackson.map.ser.std.SerializerBase;
13import org.projectfloodlight.openflow.protocol.OFPortStatsEntry;
14
15public 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 Vavilapallif25c7b02014-10-01 14:30:43 -070023 SerializerProvider sp) throws IOException, JsonGenerationException {
Srikanth Vavilapallib7258512014-09-29 13:24:11 -070024
Fahad Naeem Khanf52d92e2014-11-04 16:22:10 -080025 IOFSwitch sw = portStatModEntry.getSwitch();
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -070026 OFPortStatsEntry portStatEntry = portStatModEntry.getPortStatsEntry();
Srikanth Vavilapallib7258512014-09-29 13:24:11 -070027 jGen.writeStartObject();
28 jGen.writeNumberField("portNumber", portStatEntry.getPortNo().getPortNumber());
Fahad Naeem Khanf52d92e2014-11-04 16:22:10 -080029 jGen.writeStringField("portStatus", ((OFSwitchImplBase) sw).portEnabled(
30 portStatEntry.getPortNo().getPortNumber()) ? "up" : "down");
Srikanth Vavilapallib7258512014-09-29 13:24:11 -070031 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 Vavilapallif25c7b02014-10-01 14:30:43 -070039 jGen.writeNumberField("receiveFrameErrors", portStatEntry.getRxFrameErr()
40 .getValue());
41 jGen.writeNumberField("receiveOverrunErrors", portStatEntry.getRxOverErr()
42 .getValue());
Srikanth Vavilapallib7258512014-09-29 13:24:11 -070043 jGen.writeNumberField("receiveCRCErrors", portStatEntry.getRxCrcErr().getValue());
44 jGen.writeNumberField("collisions", portStatEntry.getCollisions().getValue());
45
46 jGen.writeEndObject();
47 }
48
49}