Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -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.OFGroupDescStatsEntryMod; |
| 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.OFActionType; |
| 12 | import org.projectfloodlight.openflow.protocol.OFBucket; |
| 13 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry; |
| 14 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 15 | import org.projectfloodlight.openflow.protocol.action.*; |
| 16 | public class OFGroupDescStatsEntryModSerializer extends SerializerBase<OFGroupDescStatsEntryMod>{ |
| 17 | |
| 18 | |
| 19 | |
| 20 | protected OFGroupDescStatsEntryModSerializer(){ |
| 21 | super(OFGroupDescStatsEntryMod.class); |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public void serialize(OFGroupDescStatsEntryMod GroupDescStatsModEntry, JsonGenerator jGen, |
| 26 | SerializerProvider sp) throws IOException, |
| 27 | JsonGenerationException { |
| 28 | OFGroupDescStatsEntry GroupStatsEntryMod = GroupDescStatsModEntry.getGroupDescStatsEntry(); |
| 29 | List<OFBucket> Buckets = GroupStatsEntryMod.getBuckets(); |
| 30 | jGen.writeStartObject(); |
| 31 | jGen.writeNumberField("groupId", GroupStatsEntryMod.getGroup().getGroupNumber()); |
| 32 | jGen.writeStringField("groupType", GroupStatsEntryMod.getGroupType().name()); |
| 33 | for (OFBucket bucket : Buckets){ |
| 34 | List<OFAction> actions = bucket.getActions(); |
| 35 | for (OFAction action : actions ){ |
| 36 | if(action.getType().compareTo(OFActionType.SET_FIELD) == 0){ |
| 37 | //TODO: Need better if condition. |
| 38 | if (((OFActionSetField)action).getField().toString().contains("OFOxmEthSrcVer13")){ |
| 39 | jGen.writeStringField("SET_DL_SRC", ((OFActionSetField)action).getField().getValue().toString()); |
| 40 | } |
| 41 | else if (((OFActionSetField)action).getField().toString().contains("OFOxmEthDstVer13")){ |
| 42 | jGen.writeStringField("SET_DL_DST", ((OFActionSetField)action).getField().getValue().toString()); |
| 43 | } |
| 44 | } |
| 45 | else if(action.getType().compareTo(OFActionType.OUTPUT) == 0){ |
| 46 | jGen.writeNumberField("OUTPPUT", ((OFActionOutput)action).getPort().getPortNumber()); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | jGen.writeEndObject(); |
| 51 | |
| 52 | } |
| 53 | |
| 54 | } |