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 | |
Fahad Naeem Khan | c4e7388 | 2014-10-09 14:19:42 -0700 | [diff] [blame] | 7 | import org.apache.commons.codec.binary.Hex; |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 8 | import org.codehaus.jackson.JsonGenerationException; |
| 9 | import org.codehaus.jackson.JsonGenerator; |
| 10 | import org.codehaus.jackson.map.SerializerProvider; |
| 11 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 12 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 13 | import org.projectfloodlight.openflow.protocol.OFBucket; |
| 14 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry; |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 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 | } |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame] | 23 | //TODO:- Java-doc |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 24 | |
| 25 | @Override |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 26 | public void serialize(OFGroupDescStatsEntryMod groupDescStatsModEntry, JsonGenerator jGen, |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 27 | SerializerProvider sp) throws IOException, |
| 28 | JsonGenerationException { |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 29 | OFGroupDescStatsEntry groupDescStatsEntryMod = groupDescStatsModEntry.getGroupDescStatsEntry(); |
| 30 | List<OFBucket> Buckets = groupDescStatsEntryMod.getBuckets(); |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 31 | jGen.writeStartObject(); |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 32 | jGen.writeNumberField("groupId", groupDescStatsEntryMod.getGroup().getGroupNumber()); |
| 33 | jGen.writeStringField("groupType", groupDescStatsEntryMod.getGroupType().name()); |
| 34 | jGen.writeArrayFieldStart("bucketsActions"); |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 35 | for (OFBucket bucket : Buckets){ |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 36 | jGen.writeStartObject(); |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 37 | List<OFAction> actions = bucket.getActions(); |
| 38 | for (OFAction action : actions ){ |
| 39 | if(action.getType().compareTo(OFActionType.SET_FIELD) == 0){ |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame] | 40 | /* |
| 41 | * TODO: 1-Need better if condition. |
| 42 | * TODO: 2-Complete REST response. (Right now we are only sending what |
| 43 | * SegmentRouter CLI needs). |
| 44 | */ |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 45 | if (((OFActionSetField)action).getField().toString().contains("OFOxmEthSrcVer13")){ |
| 46 | jGen.writeStringField("SET_DL_SRC", ((OFActionSetField)action).getField().getValue().toString()); |
| 47 | } |
| 48 | else if (((OFActionSetField)action).getField().toString().contains("OFOxmEthDstVer13")){ |
| 49 | jGen.writeStringField("SET_DL_DST", ((OFActionSetField)action).getField().getValue().toString()); |
| 50 | } |
Fahad Naeem Khan | c4e7388 | 2014-10-09 14:19:42 -0700 | [diff] [blame] | 51 | else if (((OFActionSetField)action).getField().toString().contains("OFOxmMplsLabelVer13")){ |
Fahad Naeem Khan | f59c285 | 2014-10-10 18:52:26 -0700 | [diff] [blame] | 52 | jGen.writeNumberField("PUSH_MPLS", |
| 53 | Integer.decode(((OFActionSetField)action).getField().getValue().toString())); |
Fahad Naeem Khan | c4e7388 | 2014-10-09 14:19:42 -0700 | [diff] [blame] | 54 | } |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 55 | } |
| 56 | else if(action.getType().compareTo(OFActionType.OUTPUT) == 0){ |
| 57 | jGen.writeNumberField("OUTPPUT", ((OFActionOutput)action).getPort().getPortNumber()); |
| 58 | } |
Fahad Naeem Khan | c4e7388 | 2014-10-09 14:19:42 -0700 | [diff] [blame] | 59 | else if(action.getType().compareTo(OFActionType.POP_MPLS) == 0){ |
| 60 | jGen.writeStringField("POP_MPLS", "True"); |
Fahad Naeem Khan | c4e7388 | 2014-10-09 14:19:42 -0700 | [diff] [blame] | 61 | } |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 62 | else if(action.getType().compareTo(OFActionType.GROUP) == 0){ |
| 63 | jGen.writeNumberField("goToGroup", ((OFActionGroup)action).getGroup().getGroupNumber()); |
| 64 | } |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 65 | } |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 66 | jGen.writeEndObject(); |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 67 | } |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 68 | jGen.writeEndArray(); |
Fahad Naeem Khan | 9ae7fa1 | 2014-10-03 14:30:55 -0700 | [diff] [blame] | 69 | jGen.writeEndObject(); |
| 70 | |
| 71 | } |
| 72 | |
| 73 | } |