Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.core.web.serializers; |
| 2 | |
| 3 | import java.io.IOException; |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 4 | import java.util.Iterator; |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 5 | import java.util.List; |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 6 | import java.util.Set; |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 7 | |
| 8 | import net.floodlightcontroller.core.web.OFFlowStatsEntryMod; |
| 9 | |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 10 | import org.projectfloodlight.openflow.protocol.action.*; |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 11 | import org.codehaus.jackson.JsonGenerationException; |
| 12 | import org.codehaus.jackson.JsonGenerator; |
| 13 | import org.codehaus.jackson.map.SerializerProvider; |
| 14 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 15 | import org.projectfloodlight.openflow.protocol.OFActionType; |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 16 | import org.projectfloodlight.openflow.protocol.OFFlowModFlags; |
| 17 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 18 | import org.projectfloodlight.openflow.protocol.OFInstructionType; |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 19 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
| 20 | import org.projectfloodlight.openflow.protocol.OFOxmList; |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 21 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 22 | import org.projectfloodlight.openflow.protocol.instruction.*; |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 23 | import org.projectfloodlight.openflow.protocol.match.MatchFields; |
| 24 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 25 | import org.projectfloodlight.openflow.protocol.ver13.OFInstructionTypeSerializerVer13; |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 26 | |
| 27 | public 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 Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 37 | OFFlowStatsEntry flowStatsEntry = FlowStatsEntryMod.getFlowStatsEntry(); |
| 38 | OFOxmList matches = ((OFMatchV3)flowStatsEntry.getMatch()).getOxmList(); |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 39 | |
| 40 | List<OFInstruction> instructions = flowStatsEntry.getInstructions(); |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 41 | Set<OFFlowModFlags> flags = flowStatsEntry.getFlags(); |
| 42 | jGen.writeStartObject(); |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 43 | |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 44 | jGen.writeNumberField("byteCount", flowStatsEntry.getByteCount().getValue()); |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 45 | jGen.writeNumberField("pktCount", flowStatsEntry.getPacketCount().getValue()); |
| 46 | jGen.writeNumberField("priority", flowStatsEntry.getPriority()); |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 47 | 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 Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 58 | jGen.writeStartObject(); |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 59 | Iterator<OFOxm<?>> match= matches.iterator(); |
| 60 | while(match.hasNext()){ |
| 61 | OFOxm<?> matchGeneric = match.next(); |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 62 | //jGen.writeObjectField(matchGeneric.getMatchField().id.toString(), matchGeneric.getValue().toString()); |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 63 | if (matchGeneric.getMatchField().id == MatchFields.IPV4_DST){ |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 64 | jGen.writeStringField("networkDestination", matchGeneric.getValue().toString()); |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 65 | } |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 66 | 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 Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 97 | } |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 98 | jGen.writeEndObject(); |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 99 | jGen.writeEndArray(); |
| 100 | |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 101 | /*\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 Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 123 | jGen.writeEndObject(); |
Fahad Naeem Khan | 0c1c7b3 | 2014-10-07 16:22:23 -0700 | [diff] [blame^] | 124 | 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 Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 149 | } |
Fahad Naeem Khan | d89448d | 2014-10-06 18:40:45 -0700 | [diff] [blame] | 150 | |
Fahad Naeem Khan | 8a8daf2 | 2014-10-06 14:07:43 -0700 | [diff] [blame] | 151 | |
| 152 | } |