Jonathan Hart | b32b24c | 2014-08-19 15:02:01 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.core.web.serializers; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import net.floodlightcontroller.core.IOFSwitch; |
| 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.OFDescStatsReply; |
| 12 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 13 | |
| 14 | public class IOFSwitchSerializer extends SerializerBase<IOFSwitch> { |
| 15 | |
| 16 | protected IOFSwitchSerializer() { |
| 17 | super(IOFSwitch.class); |
| 18 | } |
| 19 | |
| 20 | @Override |
| 21 | public void serialize(IOFSwitch sw, JsonGenerator jGen, SerializerProvider sp) |
| 22 | throws IOException, JsonGenerationException { |
| 23 | |
| 24 | jGen.writeStartObject(); |
| 25 | jGen.writeStringField("dpid", sw.getStringId()); |
| 26 | |
| 27 | jGen.writeArrayFieldStart("ports"); |
| 28 | for (OFPortDesc port : sw.getPorts()) { |
| 29 | jGen.writeStartObject(); |
| 30 | jGen.writeNumberField("number", port.getPortNo().getPortNumber()); |
| 31 | jGen.writeStringField("macAddress", port.getHwAddr().toString()); |
| 32 | jGen.writeStringField("name", port.getName()); |
| 33 | jGen.writeEndObject(); |
| 34 | } |
| 35 | jGen.writeEndArray(); |
| 36 | |
| 37 | jGen.writeStringField("version", sw.getOFVersion().toString()); |
| 38 | |
| 39 | // Description from OFDescStatsReply |
| 40 | OFDescStatsReply desc = sw.getSwitchDescription(); |
| 41 | jGen.writeObjectFieldStart("description"); |
| 42 | jGen.writeStringField("manufacturer", desc.getMfrDesc()); |
| 43 | jGen.writeStringField("hardware", desc.getHwDesc()); |
| 44 | jGen.writeStringField("switch", desc.getSwDesc()); |
| 45 | jGen.writeStringField("serialNum", desc.getSerialNum()); |
| 46 | jGen.writeStringField("datapath", desc.getDpDesc()); |
| 47 | jGen.writeEndObject(); |
| 48 | |
| 49 | jGen.writeStringField("connectedSince", sw.getConnectedSince().toString()); |
| 50 | jGen.writeObjectField("role", sw.getRole()); |
| 51 | |
| 52 | jGen.writeEndObject(); |
| 53 | } |
| 54 | |
| 55 | } |