|
16 | 16 | import java.util.concurrent.ConcurrentLinkedQueue; |
17 | 17 | import java.util.concurrent.TimeUnit; |
18 | 18 |
|
19 | | -import org.apache.commons.codec.binary.Hex; |
20 | 19 | import org.flowvisor.api.FlowTableCallback; |
21 | 20 | import org.flowvisor.api.TopologyCallback; |
22 | 21 | import org.flowvisor.config.ConfigError; |
23 | 22 | import org.flowvisor.config.ConfigurationEvent; |
24 | 23 | import org.flowvisor.config.FVConfig; |
25 | 24 |
|
26 | 25 | import org.flowvisor.config.FlowMapChangedListener; |
27 | | -import org.flowvisor.config.FlowSpace; |
28 | 26 | import org.flowvisor.config.FlowSpaceImpl; |
29 | 27 | import org.flowvisor.config.FlowvisorChangedListener; |
30 | 28 | import org.flowvisor.config.FlowvisorImpl; |
|
64 | 62 | import org.flowvisor.message.statistics.FVAggregateStatisticsRequest; |
65 | 63 | import org.flowvisor.message.statistics.FVFlowStatisticsReply; |
66 | 64 | import org.flowvisor.message.statistics.FVFlowStatisticsRequest; |
67 | | -import org.flowvisor.ofswitch.TopologyController; |
68 | 65 | import org.flowvisor.openflow.protocol.FVMatch; |
69 | 66 | import org.flowvisor.resources.SlicerLimits; |
70 | 67 | import org.flowvisor.resources.ratelimit.FixedIntervalRefillStrategy; |
|
83 | 80 | import org.openflow.protocol.OFType; |
84 | 81 | import org.openflow.protocol.OFError.OFHelloFailedCode; |
85 | 82 | import org.openflow.protocol.action.*; |
86 | | -import org.openflow.protocol.statistics.OFFlowStatisticsReply; |
87 | 83 | import org.openflow.protocol.statistics.OFStatistics; |
88 | 84 | import org.openflow.protocol.statistics.OFStatisticsType; |
89 | | -import org.openflow.util.HexString; |
90 | | -import org.openflow.util.U16; |
91 | | -import org.openflow.util.U8; |
92 | 85 |
|
93 | 86 | /** |
94 | 87 | * Map OF messages from the switch to the appropriate slice |
@@ -1114,210 +1107,16 @@ public void sendFlowStatsResp(FVSlicer fvSlicer, FVStatisticsRequest original) { |
1114 | 1107 | } |
1115 | 1108 |
|
1116 | 1109 |
|
1117 | | - public synchronized void classifyFlowStats(FVStatisticsReply fvStatisticsReply) { |
| 1110 | + public synchronized void classifyFlowStats(FVStatisticsReply fvStatisticsReply, HashMap<String,Object> cache) { |
1118 | 1111 | flowStats.clear(); |
1119 | 1112 | List<OFStatistics> stats = fvStatisticsReply.getStatistics(); |
1120 | | - FVLog.log(LogLevel.DEBUG, this, " Inside classifyFlowStats, stats is: ",stats); |
1121 | | - |
1122 | | - List<Object> params = new ArrayList<Object>(); |
1123 | | - //Serialize the stats to send it via JSON |
1124 | | - |
1125 | | - for (int i=0; i<stats.size(); i++){ |
1126 | | - OFFlowStatisticsReply reply = (OFFlowStatisticsReply) stats.get(i); |
1127 | | - |
1128 | | - HashMap <String,Object> cache = new HashMap<String,Object>(); |
1129 | | - |
1130 | | - cache.put(FlowSpace.PRIO, String.valueOf(reply.getPriority())); |
1131 | | - |
1132 | | - //Put all the individual action fields into the cache |
1133 | | - //cache.put(FlowSpace.ACTION, reply.getActions().toString()); |
1134 | | - for (OFAction act : reply.getActions()) { |
1135 | | - switch (act.getType()) { |
1136 | | - case OUTPUT: |
1137 | | - OFActionOutput out = (OFActionOutput) act; |
1138 | | - cache.put("OFPAT_OUTPUT type", out.getType().toString()); |
1139 | | - cache.put("OFPAT_OUTPUT len", U16.f(out.getLength())); |
1140 | | - cache.put("OFPAT_OUTPUT port", U16.f(out.getPort())); |
1141 | | - cache.put("OFPAT_OUTPUT max_len", U16.f(out.getMaxLength())); |
1142 | | - break; |
1143 | | - |
1144 | | - case OPAQUE_ENQUEUE: |
1145 | | - OFActionEnqueue enq = (OFActionEnqueue) act; |
1146 | | - cache.put("OFPAT_ENQUEUE type", enq.getType().toString()); |
1147 | | - cache.put("OFPAT_ENQUEUE len", U16.f(enq.getLength())); |
1148 | | - cache.put("OFPAT_ENQUEUE port", U16.f(enq.getPort())); |
1149 | | - cache.put("OFPAT_ENQUEUE queue_id", enq.getQueueId()); |
1150 | | - break; |
1151 | | - |
1152 | | - case SET_VLAN_VID: |
1153 | | - OFActionVirtualLanIdentifier vid = (OFActionVirtualLanIdentifier)act; |
1154 | | - cache.put("OFPAT_SET_VLAN_VID type", vid.getType().toString()); |
1155 | | - cache.put("OFPAT_SET_VLAN_VID len", U16.f(vid.getLength())); |
1156 | | - cache.put("OFPAT_SET_VLAN_VID vlan_vid", U16.f(vid.getVirtualLanIdentifier())); |
1157 | | - break; |
1158 | | - |
1159 | | - case SET_VLAN_PCP: |
1160 | | - OFActionVirtualLanPriorityCodePoint vpcp = (OFActionVirtualLanPriorityCodePoint) act; |
1161 | | - cache.put("OFPAT_SET_VLAN_PCP type", vpcp.getType().toString()); |
1162 | | - cache.put("OFPAT_SET_VLAN_PCP len", U16.f(vpcp.getLength())); |
1163 | | - cache.put("OFPAT_SET_VLAN_PCP vlan_pcp", U8.f(vpcp.getVirtualLanPriorityCodePoint())); |
1164 | | - break; |
1165 | | - |
1166 | | - case STRIP_VLAN: |
1167 | | - OFActionStripVirtualLan svlan = (OFActionStripVirtualLan) act; |
1168 | | - cache.put("OFPAT_STRIP_VLAN type", svlan.getType().toString()); |
1169 | | - break; |
1170 | | - |
1171 | | - case SET_DL_DST: |
1172 | | - OFActionDataLayerDestination dl_dst = (OFActionDataLayerDestination) act; |
1173 | | - cache.put("OFPAT_SET_DL_DST type",dl_dst.getType().toString()); |
1174 | | - cache.put("OFPAT_SET_DL_DST len",U16.f(dl_dst.getLength())); |
1175 | | - cache.put("OFPAT_SET_DL_DST dl_addr", HexString.toHexString(dl_dst.getDataLayerAddress())); |
1176 | | - break; |
1177 | | - |
1178 | | - case SET_DL_SRC: |
1179 | | - OFActionDataLayerSource dl_src = (OFActionDataLayerSource) act; |
1180 | | - cache.put("OFPAT_SET_DL_SRC type",dl_src.getType().toString()); |
1181 | | - cache.put("OFPAT_SET_DL_SRC len",U16.f(dl_src.getLength())); |
1182 | | - cache.put("OFPAT_SET_DL_SRC dl_addr", HexString.toHexString(dl_src.getDataLayerAddress())); |
1183 | | - break; |
1184 | | - |
1185 | | - case SET_NW_DST: |
1186 | | - OFActionNetworkLayerDestination nw_dst = (OFActionNetworkLayerDestination) act; |
1187 | | - cache.put("OFPAT_SET_NW_DST type", nw_dst.getType().toString()); |
1188 | | - cache.put("OFPAT_SET_NW_DST len", U16.f(nw_dst.getLength())); |
1189 | | - cache.put("OFPAT_SET_NW_DST nw_addr", FlowSpaceUtil.intToIp(nw_dst.getNetworkAddress())); |
1190 | | - break; |
1191 | 1113 |
|
1192 | | - case SET_NW_SRC: |
1193 | | - OFActionNetworkLayerSource nw_src = (OFActionNetworkLayerSource) act; |
1194 | | - cache.put("OFPAT_SET_NW_SRC type", nw_src.getType().toString()); |
1195 | | - cache.put("OFPAT_SET_NW_SRC len", U16.f(nw_src.getLength())); |
1196 | | - cache.put("OFPAT_SET_NW_SRC nw_addr", FlowSpaceUtil.intToIp(nw_src.getNetworkAddress())); |
1197 | | - break; |
1198 | | - |
1199 | | - case SET_NW_TOS: |
1200 | | - OFActionNetworkTypeOfService nw_tos = (OFActionNetworkTypeOfService) act; |
1201 | | - cache.put("OFPAT_SET_NW_TOS type", nw_tos.getType().toString()); |
1202 | | - cache.put("OFPAT_SET_NW_TOS len", U16.f(nw_tos.getLength())); |
1203 | | - cache.put("OFPAT_SET_NW_TOS nw_tos", U8.f(nw_tos.getNetworkTypeOfService())); |
1204 | | - break; |
1205 | | - |
1206 | | - case SET_TP_DST: |
1207 | | - OFActionTransportLayerDestination tp_dst = (OFActionTransportLayerDestination) act; |
1208 | | - cache.put("OFPAT_SET_TP_DST type", tp_dst.getType().toString()); |
1209 | | - cache.put("OFPAT_SET_TP_DST len", U16.f(tp_dst.getLength())); |
1210 | | - cache.put("OFPAT_SET_TP_DST tp_port", U16.f(tp_dst.getTransportPort())); |
1211 | | - break; |
1212 | | - |
1213 | | - case SET_TP_SRC: |
1214 | | - OFActionTransportLayerSource tp_src = (OFActionTransportLayerSource) act; |
1215 | | - cache.put("OFPAT_SET_TP_SRC type", tp_src.getType().toString()); |
1216 | | - cache.put("OFPAT_SET_TP_SRC len", U16.f(tp_src.getLength())); |
1217 | | - cache.put("OFPAT_SET_TP_SRC tp_port", U16.f(tp_src.getTransportPort())); |
1218 | | - break; |
1219 | | - |
1220 | | - case VENDOR: |
1221 | | - OFActionVendor ven = (OFActionVendor) act; |
1222 | | - cache.put("OFPAT_VENDOR type", ven.getType().toString()); |
1223 | | - cache.put("OFPAT_VENDOR len", U16.f(ven.getLength())); |
1224 | | - cache.put("OFPAT_VENDOR vendor", ven.getVendor()); |
1225 | | - break; |
1226 | | - |
1227 | | - default: |
1228 | | - //Error |
1229 | | - FVLog.log(LogLevel.ALERT, this, "Shouldn't have come here- No default ActionType "); |
1230 | | - break; |
1231 | | - } |
1232 | | - } |
1233 | | - |
1234 | | - //Put all the individual match fields into the cache |
1235 | | - //cache.put("OFMatch", reply.getMatch().toString()); |
1236 | | - int wildcards = reply.getMatch().getWildcards(); |
1237 | | - if((wildcards & OFMatch.OFPFW_IN_PORT) == 0) |
1238 | | - cache.put(FlowSpace.INPORT, U16.f(reply.getMatch().getInputPort())); |
1239 | | - if((wildcards & OFMatch.OFPFW_DL_DST) == 0) |
1240 | | - cache.put(FlowSpace.DLDST, HexString.toHexString(reply.getMatch().getDataLayerDestination())); |
1241 | | - if((wildcards & OFMatch.OFPFW_DL_SRC) == 0) |
1242 | | - cache.put(FlowSpace.DLSRC, HexString.toHexString(reply.getMatch().getDataLayerSource())); |
1243 | | - if((wildcards & OFMatch.OFPFW_DL_TYPE) == 0) |
1244 | | - cache.put(FlowSpace.DLTYPE, Integer.toHexString(U16.f(reply.getMatch().getDataLayerType()))); |
1245 | | - if((wildcards & OFMatch.OFPFW_DL_VLAN) == 0) |
1246 | | - cache.put(FlowSpace.VLAN, U16.f(reply.getMatch().getDataLayerVirtualLan())); |
1247 | | - if((wildcards & OFMatch.OFPFW_DL_VLAN_PCP) == 0) |
1248 | | - cache.put(FlowSpace.VPCP, U8.f(reply.getMatch().getDataLayerVirtualLanPriorityCodePoint())); |
1249 | | - if(reply.getMatch().getNetworkDestinationMaskLen() > 0) |
1250 | | - cache.put(FlowSpace.NWDST, cidrToString(reply.getMatch().getNetworkDestination(),reply.getMatch().getNetworkDestinationMaskLen())); |
1251 | | - if(reply.getMatch().getNetworkSourceMaskLen() > 0) |
1252 | | - cache.put(FlowSpace.NWSRC, cidrToString(reply.getMatch().getNetworkSource(),reply.getMatch().getNetworkSourceMaskLen())); |
1253 | | - if((wildcards & OFMatch.OFPFW_NW_PROTO) == 0) |
1254 | | - cache.put(FlowSpace.NWPROTO, reply.getMatch().getNetworkProtocol()); |
1255 | | - if((wildcards & OFMatch.OFPFW_NW_TOS) == 0) |
1256 | | - cache.put(FlowSpace.NWTOS,reply.getMatch().getNetworkTypeOfService()); |
1257 | | - if((wildcards & OFMatch.OFPFW_TP_DST) == 0) |
1258 | | - cache.put(FlowSpace.TPDST,reply.getMatch().getTransportDestination()); |
1259 | | - if((wildcards & OFMatch.OFPFW_TP_SRC) == 0) |
1260 | | - cache.put(FlowSpace.TPSRC,reply.getMatch().getTransportSource()); |
1261 | | - |
1262 | | - cache.put(FlowSpace.DPID, getDPID()); |
1263 | | - cache.put("tableId ", HexString.toHexString(reply.getTableId())); |
1264 | | - cache.put("nanoSecondDuration ", reply.getDurationNanoseconds()); |
1265 | | - cache.put("durationInSeconds ",reply.getDurationSeconds()); |
1266 | | - cache.put("hardTimeOut ",reply.getHardTimeout()); |
1267 | | - cache.put("idleTimeOut ", reply.getIdleTimeout()); |
1268 | | - cache.put("cookie ",reply.getCookie()); |
1269 | | - cache.put("packetCount ", reply.getPacketCount()); |
1270 | | - cache.put("byteCount ",reply.getByteCount()); |
1271 | | - cache.put("length ", reply.getLength()); |
1272 | | - |
1273 | | - //cache.put(FlowSpace.DLDST, HexString.toHexString(reply.getMatch().getDataLayerDestination())); |
1274 | | - //cache.put(FlowSpace.DLSRC, HexString.toHexString(reply.getMatch().getDataLayerSource())); |
1275 | | - //cache.put(FlowSpace.DLTYPE, reply.getMatch().getDataLayerType()); |
1276 | | - //cache.put(FlowSpace.INPORT, reply.getMatch().getInputPort()); |
1277 | | - //cache.put(FlowSpace.NWDST, reply.getMatch().getNetworkDestination()); |
1278 | | - //cache.put(FlowSpace.NWPROTO, reply.getMatch().getNetworkProtocol()); |
1279 | | - //cache.put(FlowSpace.NWSRC, reply.getMatch().getNetworkSource()); |
1280 | | - //cache.put(FlowSpace.NWTOS, reply.getMatch().getNetworkTypeOfService()); |
1281 | | - //cache.put(FlowSpace.TPDST, reply.getMatch().getTransportDestination()); |
1282 | | - //cache.put(FlowSpace.TPSRC, reply.getMatch().getTransportSource()); |
1283 | | - //cache.put(FlowSpace.VLAN, reply.getMatch().getDataLayerVirtualLan()); |
1284 | | - //cache.put(FlowSpace.VPCP, reply.getMatch().getDataLayerVirtualLanPriorityCodePoint()); |
1285 | | - //cache.put(FlowSpace.WILDCARDS, reply.getMatch().getWildcards()); |
1286 | | - |
1287 | | - params.add(cache); |
1288 | | - } |
1289 | | - //Probably not the most efficient way of doing but for now - |
1290 | | - /*HashMap <String,Object> cache = new HashMap<String,Object>(); |
1291 | | - int initOffset=0; |
1292 | | - int finalOffset=0; |
1293 | | -
|
1294 | | - for (int i=0; i<stats.size(); i++){ |
1295 | | - String st = stats.toString(); |
1296 | | -
|
1297 | | - String temp = new String(); |
1298 | | - |
1299 | | - initOffset = stats.indexOf("=", stats.indexOf("length") + "length".length()); |
1300 | | - finalOffset = stats.indexOf(",",initOffset); |
1301 | | - temp = stats.substring(initOffset+1, finalOffset); |
1302 | | - System.out.println("Length is: "+temp); |
1303 | | - cache.put("length", temp); |
1304 | | - |
1305 | | - initOffset = stats.indexOf("=", stats.indexOf("tableId") + "tableId".length()); |
1306 | | - finalOffset = stats.indexOf(",",initOffset); |
1307 | | - System.out.println("initOffset : "+initOffset+"finalOffset: "+finalOffset); |
1308 | | - temp = stats.substring(initOffset+1, finalOffset); |
1309 | | - System.out.println("Temp is: "+temp); |
1310 | | - cache.put("tableId", temp); |
1311 | | - |
1312 | | - System.out.println("Cache is: "+cache); |
1313 | | - |
1314 | | - }*/ |
1315 | 1114 | //Adding for registering a FlowTable |
1316 | 1115 | if (this.registeredForFlowTable == true && !this.flowTableList.isEmpty()){ |
1317 | 1116 | FVLog.log(LogLevel.DEBUG, this, "Inside registeredForFlowTable ",this.registeredForFlowTable); |
1318 | 1117 | for (FlowTableCallback fcb : this.flowTableList) { |
1319 | 1118 | fcb.clearParams(); |
1320 | | - fcb.setParams(params); |
| 1119 | + fcb.setParams(cache); |
1321 | 1120 | fcb.spawn(); // Is this ok to use run, there will be only one thread of fcb per classifier? |
1322 | 1121 |
|
1323 | 1122 | } |
@@ -1391,19 +1190,5 @@ public void deRegisterCallBack(String userName, String method,String cookie, Top |
1391 | 1190 | it.remove(); |
1392 | 1191 | } |
1393 | 1192 | } |
1394 | | - |
1395 | | - private String cidrToString(int ip, int prefix) { |
1396 | | - String str; |
1397 | | - if (prefix >= 32) { |
1398 | | - str = OFMatch.ipToString(ip);; |
1399 | | - |
1400 | | - } else { |
1401 | | - // use the negation of mask to fake endian magic |
1402 | | - int mask = ~((1 << (32 - prefix)) - 1); |
1403 | | - str = OFMatch.ipToString(ip & mask) + "/" + prefix; |
1404 | | - } |
1405 | | - |
1406 | | - return str; |
1407 | | - } |
1408 | 1193 |
|
1409 | 1194 | } |
0 commit comments