blob: e04487dce0ac417d5079bf4ec85f36b9b17c8923 [file] [log] [blame]
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -07001package net.floodlightcontroller.core.web.serializers;
2
3import java.io.IOException;
Fahad Naeem Khand89448d2014-10-06 18:40:45 -07004import java.util.Iterator;
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -07005import java.util.List;
Fahad Naeem Khand89448d2014-10-06 18:40:45 -07006import java.util.Set;
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -07007
8import net.floodlightcontroller.core.web.OFFlowStatsEntryMod;
9
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070010import org.projectfloodlight.openflow.protocol.action.*;
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -070011import org.codehaus.jackson.JsonGenerationException;
12import org.codehaus.jackson.JsonGenerator;
13import org.codehaus.jackson.map.SerializerProvider;
14import org.codehaus.jackson.map.ser.std.SerializerBase;
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070015import org.projectfloodlight.openflow.protocol.OFActionType;
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070016import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
17import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070018import org.projectfloodlight.openflow.protocol.OFInstructionType;
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070019import org.projectfloodlight.openflow.protocol.OFMatchV3;
20import org.projectfloodlight.openflow.protocol.OFOxmList;
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070021import org.projectfloodlight.openflow.protocol.action.OFAction;
22import org.projectfloodlight.openflow.protocol.instruction.*;
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070023import org.projectfloodlight.openflow.protocol.match.MatchFields;
24import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070025import org.projectfloodlight.openflow.protocol.ver13.OFInstructionTypeSerializerVer13;
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -070026
27public class OFFlowStatsEntryModSerializer extends SerializerBase<OFFlowStatsEntryMod> {
28
29 protected OFFlowStatsEntryModSerializer(){
30 super(OFFlowStatsEntryMod.class);
31 }
32
33 @Override
34 public void serialize(OFFlowStatsEntryMod FlowStatsEntryMod, JsonGenerator jGen,
35 SerializerProvider sp) throws IOException,
36 JsonGenerationException {
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070037 OFFlowStatsEntry flowStatsEntry = FlowStatsEntryMod.getFlowStatsEntry();
38 OFOxmList matches = ((OFMatchV3)flowStatsEntry.getMatch()).getOxmList();
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070039
40 List<OFInstruction> instructions = flowStatsEntry.getInstructions();
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070041 Set<OFFlowModFlags> flags = flowStatsEntry.getFlags();
42 jGen.writeStartObject();
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -070043
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070044 jGen.writeNumberField("byteCount", flowStatsEntry.getByteCount().getValue());
Fahad Naeem Khanf35e4f62014-10-07 16:45:39 -070045 jGen.writeNumberField("packetCount", flowStatsEntry.getPacketCount().getValue());
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070046 jGen.writeNumberField("priority", flowStatsEntry.getPriority());
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070047 jGen.writeNumberField("cookie", flowStatsEntry.getCookie().getValue());
48 jGen.writeNumberField("durationNsec", flowStatsEntry.getDurationNsec());
49 jGen.writeNumberField("durationSec", flowStatsEntry.getDurationSec());
50 jGen.writeArrayFieldStart("flags");
51 for (OFFlowModFlags flag: flags){
52 jGen.writeNullField(flag.name());;
53 }
54 jGen.writeEndArray();
55 jGen.writeNumberField("hardTimeout", flowStatsEntry.getHardTimeout());
56 jGen.writeNumberField("idleTimeout", flowStatsEntry.getIdleTimeout());
57 jGen.writeArrayFieldStart("match");
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070058 jGen.writeStartObject();
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070059 Iterator<OFOxm<?>> match= matches.iterator();
60 while(match.hasNext()){
61 OFOxm<?> matchGeneric = match.next();
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070062 //jGen.writeObjectField(matchGeneric.getMatchField().id.toString(), matchGeneric.getValue().toString());
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070063 if (matchGeneric.getMatchField().id == MatchFields.IPV4_DST){
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070064 jGen.writeStringField("networkDestination", matchGeneric.getValue().toString());
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070065 }
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070066 else if (matchGeneric.getMatchField().id == MatchFields.IPV4_SRC){
67 jGen.writeStringField("networkSource", matchGeneric.getValue().toString());
68 }
69 else if (matchGeneric.getMatchField().id == MatchFields.ETH_DST){
70 jGen.writeStringField("dataLayerDestination", matchGeneric.getValue().toString());
71 }
72 else if (matchGeneric.getMatchField().id == MatchFields.ETH_SRC){
73 jGen.writeStringField("dataLayerSource", matchGeneric.getValue().toString());
74 }
75 else if (matchGeneric.getMatchField().id == MatchFields.ETH_TYPE){
76 jGen.writeStringField("dataLayerType", "0x"+matchGeneric.getValue().toString());
77 }
78 else if (matchGeneric.getMatchField().id == MatchFields.IN_PORT){
79 jGen.writeNumberField("inputPort", Integer.parseInt(matchGeneric.getValue().toString()));
80 }
81 else if (matchGeneric.getMatchField().id == MatchFields.MPLS_TC){
82 jGen.writeNumberField("mplsTc", Integer.parseInt(matchGeneric.getValue().toString()));
83 }
84 else if (matchGeneric.getMatchField().id == MatchFields.MPLS_LABEL){
85 jGen.writeNumberField("mplsLabel", Integer.parseInt(matchGeneric.getValue().toString()));
86 }
87 else if (matchGeneric.getMatchField().id == MatchFields.IP_PROTO){
88 jGen.writeNumberField("networkProtocol", Integer.parseInt(matchGeneric.getValue().toString()));
89 }
90 //TODO: Ask Saurav about the implementation of tcp and udp.
91 else if (matchGeneric.getMatchField().id == MatchFields.TCP_DST || matchGeneric.getMatchField().id == MatchFields.UDP_DST){
92 jGen.writeNumberField("transportDestination", Integer.parseInt(matchGeneric.getValue().toString()));
93 }
94 else if (matchGeneric.getMatchField().id == MatchFields.TCP_SRC || matchGeneric.getMatchField().id == MatchFields.UDP_SRC){
95 jGen.writeNumberField("transportSource", Integer.parseInt(matchGeneric.getValue().toString()));
96 }
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070097 }
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -070098 jGen.writeEndObject();
Fahad Naeem Khand89448d2014-10-06 18:40:45 -070099 jGen.writeEndArray();
100
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -0700101 /*\jGen.writeArrayFieldStart("instructions");
102 jGen.writeStartObject();
103 for (OFInstruction instruction: instructions){
104 jGen.writeObjectField("instructionType", instruction.getType().name());
105 jGen.writeArrayFieldStart("actions");
106 jGen.writeStartObject();
107 //OFInstructionApplyActions newInstruction = instruction.getClass().cast(instruction);
108 //instruction = ;
109 //instruction.g
110 if (instruction.getType().equals(OFInstructionType.APPLY_ACTIONS)){
111 //import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions
112 List<OFAction> actions = ((OFInstructionApplyActions) instruction).getActions();
113 for (OFAction action : actions){
114 a
115 }
116 }
117 else if (instruction.getType().equals(OFInstructionType.APPLY_ACTIONS)){
118 List<OFAction> actions = ((OFInstructionApplyActions) instruction).getActions();
119 }
120 jGen.writeEndObject();
121 jGen.writeEndArray();
122 }
Fahad Naeem Khand89448d2014-10-06 18:40:45 -0700123 jGen.writeEndObject();
Fahad Naeem Khan0c1c7b32014-10-07 16:22:23 -0700124 jGen.writeEndArray();*/
125 jGen.writeEndObject();
126
127
128 //for (OFAction action : actions){
129 /*if(action.getType().compareTo(OFActionType.SET_FIELD) == 0){
130 /*
131 * TODO: 1-Need better if condition.
132 * TODO: 2-Complete REST response. (Right now we are only sending what
133 * SegmentRouter CLI needs).
134 */
135 /*if (((OFActionSetField)action).getField().toString().contains("OFOxmEthSrcVer13")){
136 jGen.writeStringField("SET_DL_SRC", ((OFActionSetField)action).getField().getValue().toString());
137 }
138 else if (((OFActionSetField)action).getField().toString().contains("OFOxmEthDstVer13")){
139 jGen.writeStringField("SET_DL_DST", ((OFActionSetField)action).getField().getValue().toString());
140 }
141 System.out
142 }
143 else if(action.getType().compareTo(OFActionType.OUTPUT) == 0){
144 jGen.writeNumberField("OUTPPUT", ((OFActionOutput)action).getPort().getPortNumber());
145 }*/
146 //}
147 //jGen.writeEndObject();
148
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -0700149 }
Fahad Naeem Khand89448d2014-10-06 18:40:45 -0700150
Fahad Naeem Khan8a8daf22014-10-06 14:07:43 -0700151
152}