Commit 14af801ffe17160d695da9996abef44e4b70105e

Authored by adumas
1 parent 5b31688f

new flow message with dynamic port

src/main/java/net/floodlightcontroller/pelstats/PELStats.java
... ... @@ -44,6 +44,8 @@ import org.openflow.protocol.Pel.statistics.VideoMetricDevice;
44 44 import org.openflow.protocol.Pel.threshold.PelVendorExtension;
45 45 import org.openflow.protocol.Pel.statistics.StatisticVoIP;
46 46 import org.openflow.protocol.Pel.statistics.StatisticVoIP_CAC;
  47 +import org.openflow.protocol.action.OFAction;
  48 +import org.openflow.protocol.action.OFActionEnqueue;
47 49 import org.openflow.protocol.statistics.OFStatistics;
48 50 import org.openflow.protocol.statistics.OFVendorStatistics;
49 51 import org.openflow.util.U16;
... ... @@ -68,6 +70,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
68 70 public static ConcurrentHashMap<Integer, List<double[]>> callStatsMap;
69 71 public static ConcurrentHashMap<IOFSwitch,List<double[][]>> statsMap;
70 72  
  73 + public static ConcurrentHashMap<IOFSwitch, List<Integer>> queueInfos;
71 74 public static ConcurrentHashMap<IOFSwitch, List<Integer>> portsCallsMap;
72 75  
73 76 private double previousMos=-1;
... ... @@ -128,23 +131,77 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
128 131  
129 132 }*/
130 133 if (srb.getStatistic().getType()==5){
131   - //System.out.println("Getting stat5");
132   - double[][] stats= ((StatisticVoIP)srb.getStatistic()).getStats();
133   - //System.out.println("stats received: "+stats[0][0]);
134 134 List<double[][]> calls=new ArrayList<double[][]>();
135   - //System.out.println("calls memory attibution");
136 135 if (statsMap.get(sw)!=null) {
137   - //System.out.println("statsmap.get not null");
138 136 calls=new ArrayList<double[][]>(statsMap.get(sw));
139   - //System.out.println("Stats found");
140 137 }
141   - //System.out.println("calls created");
142   - calls.add(stats);
143   - //System.out.println("Stats added to call");
  138 + calls.add(((StatisticVoIP)srb.getStatistic()).getStats());
144 139 statsMap.put(sw, calls);
145   - //System.out.println("Stats added to map");
146 140  
147 141 }
  142 + if (srb.getStatistic().getType()==6){ //If we received a SIP message
  143 + System.out.println("@PELStats: SIP message received");
  144 + if(enabledStatistics.containsKey(sw)){
  145 + System.out.println("@PELStats: enabledStatistics contains sw:"+sw);
  146 + if(enabledStatistics.get(sw).contains(new Integer(8))){ //And the switch have a queue metric enabled
  147 + System.out.println("@PELStats: enabledStatistics sw containts the 8th metric:");
  148 + int[] SwitchRTPPorts = ((StatisticVoIP_SIP)srb.getStatistic()).getRTPPorts();
  149 +
  150 + System.out.println("@PELStats: queueInfos:"+queueInfos.get(sw).get(0)+" "+queueInfos.get(sw).get(1)+" "+queueInfos.get(sw).get(2)+" ");
  151 + if(queueInfos.get(sw).get(2)==1 || queueInfos.get(sw).get(2)==3){ //if we want to delete or modify existing queue
  152 + System.out.println("@PELStats: Modification or deletion");
  153 + for (int port : portsCallsMap.get(sw))
  154 + {
  155 + System.out.println("@PELStats: port modification or deletion: "+port);
  156 + sendOFFlowMod(sw,port);
  157 + }
  158 + if(queueInfos.get(sw).get(2)==3){ //If we deleted the queue
  159 + portsCallsMap.put(sw, new ArrayList<Integer>());
  160 + }
  161 +
  162 +
  163 + }
  164 + System.out.println("@PELStats: intermission");
  165 + if (queueInfos.get(sw).get(2)!=3 && SwitchRTPPorts!=null) {
  166 + System.out.println("@PELStats: Modification or addition");
  167 + for (int port:SwitchRTPPorts){ //For each calls of the switch
  168 + System.out.println("@PELStats: Modification or addition for port: "+port);
  169 +
  170 + if (portsCallsMap.get(sw)!=null){
  171 + List<Integer> portsCalls =new ArrayList<Integer>(portsCallsMap.get(sw));
  172 +
  173 + System.out.println("@PELStats: portsCalls created: "+portsCalls);
  174 + if (!portsCalls.contains(new Integer(port))){ //if the call isn't already assigned to a queue and we want to add new calls to queue
  175 + System.out.println("@PELStats: port add: "+port);
  176 + sendOFFlowMod(sw,port);
  177 +
  178 + //Updating the ports calls map
  179 + portsCalls.add(port);
  180 + portsCallsMap.put(sw, portsCalls);
  181 +
  182 + }
  183 + }
  184 + else{
  185 + System.out.println("@PELStats portsCalls==null");
  186 + List<Integer> portsCalls =new ArrayList<Integer>();
  187 + sendOFFlowMod(sw,port);
  188 +
  189 + portsCalls.add(port);
  190 + portsCallsMap.put(sw, portsCalls);
  191 + }
  192 + }
  193 + }
  194 +
  195 + //Set and send OFMessage
  196 +
  197 +
  198 + }
  199 + }
  200 +
  201 +
  202 +
  203 +
  204 + }
148 205 if (srb.getStatistic().getType()==7){
149 206 double mos= ((StatisticVoIP_CAC)srb.getStatistic()).getMos();
150 207 sendThreshold(sw,mos,cntx);
... ... @@ -162,7 +219,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
162 219 }
163 220  
164 221 } catch (Exception e) {
165   - System.out.println("we have a problem:" + e.toString());
  222 + System.out.println("@PELStats: We have a problem:" + e.toString());
166 223 // e.printStackTrace();
167 224 }
168 225 }
... ... @@ -172,7 +229,47 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
172 229 }
173 230 return Command.CONTINUE;
174 231 }
  232 + private void sendOFFlowMod(IOFSwitch sw,int port){
  233 + System.out.println("@PELStats,sendOFFlowMod: trying to craft message");
  234 + //OpenFlow message for flow tables modifications
  235 + //
  236 + OFFlowMod OFmessage= new OFFlowMod();
  237 + OFMatch OFmatch= new OFMatch();
  238 + OFActionEnqueue enqueue= new OFActionEnqueue();
  239 +
  240 + OFmessage.setCommand((short)0);
  241 + OFmessage.setCookie(0);
  242 + OFmessage.setIdleTimeout((short) 0);
  243 + OFmessage.setHardTimeout((short)0);
  244 + OFmessage.setPriority((short)queueInfos.get(sw).get(1).shortValue());
  245 + OFmessage.setBufferId(0);
  246 + OFmessage.setOutPort((short)0xffff);
  247 + OFmessage.setFlags((short) 0);
  248 +
  249 + OFmatch.setTransportDestination((short)port);
  250 + OFmatch.setTransportSource((short)port);
  251 +
175 252  
  253 + OFmatch.setWildcards(OFMatch.OFPFW_ALL - OFMatch.OFPFW_IN_PORT
  254 + - OFMatch.OFPFW_TP_SRC - OFmatch.OFPFW_TP_DST );
  255 + OFmatch.setInputPort((short)1);
  256 + OFmessage.setMatch(OFmatch);
  257 +
  258 + List<OFAction> actions= new ArrayList<OFAction>(1);
  259 + enqueue=new OFActionEnqueue((short)2,queueInfos.get(sw).get(0));
  260 + actions.add(enqueue);
  261 +
  262 + OFmessage.setActions(actions);
  263 + OFmessage.setLength((short)(OFFlowMod.MINIMUM_LENGTH +OFActionEnqueue.MINIMUM_LENGTH));
  264 + System.out.println("@PELStats,sendOFFlowMod: trying to send message");
  265 + try {
  266 + sw.write(OFmessage, null);
  267 + sw.flush();
  268 + System.out.println("@PELStats,sendOFFlowMod: message sent: "+OFmessage);
  269 + } catch (IOException e) {
  270 + e.printStackTrace();
  271 + }
  272 + }
176 273 private void sendThreshold(IOFSwitch sw, double mos, FloodlightContext cntx) {
177 274  
178 275 //System.out.println("Pelstats: mos: " +mos);
... ... @@ -246,6 +343,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
246 343 PelVendorExtension.initialize();
247 344 PELStats.enabledStatistics = new ConcurrentHashMap<IOFSwitch, List<Integer>>();
248 345 PELStats.portsCallsMap=new ConcurrentHashMap<IOFSwitch, List<Integer>>();
  346 + PELStats.queueInfos=new ConcurrentHashMap<IOFSwitch, List<Integer>>();
249 347 PELStats.callStatsMap=new ConcurrentHashMap<Integer, List<double[]>>() ;
250 348 PELStats.statsMap=new ConcurrentHashMap<IOFSwitch, List<double[][]>>() ;
251 349 requestThread.start();
... ...
src/main/java/net/floodlightcontroller/pelstats/rest/RESTExportStats.java
... ... @@ -54,9 +54,6 @@ public class RESTExportStats extends ServerResource{
54 54 System.out.println(" Switch : " + switchId);
55 55 System.out.println(" call ID : " + sIdVoip);
56 56  
57   -
58   - SetConfigurationMessage setConfigMsg = new SetConfigurationMessage();
59   -
60 57  
61 58 try {
62 59 idVoip = Integer.parseInt(sIdVoip);
... ... @@ -106,7 +103,7 @@ public class RESTExportStats extends ServerResource{
106 103  
107 104 }
108 105  
109   - if (idVoip==0){
  106 + if (idVoip==0){//If we want to export all the switch calls stats
110 107 for (Map.Entry<Double, List<double[]>> entry : callsStatsMap.entrySet()){
111 108 out.println("Call:\t"+entry.getKey());
112 109 out.println("Elapsed Time (s)\tSSRC0\tiMOS0\tLoss0 (%)\tJitter0 (ms)\tDelay0 (ms)\tSSRC1\tiMOS1\tLoss1 (%)\tJitter1 (ms)\tDelay1 (ms)");
... ... @@ -121,7 +118,7 @@ public class RESTExportStats extends ServerResource{
121 118 out.println("\n");
122 119 }
123 120 }
124   - else{
  121 + else{//If we want to export only the stats for a call
125 122 out.println("Call:\t"+idVoip);
126 123 out.println("Elapsed Time (s)\tSSRC0\tiMOS0\tLoss0 (%)\tJitter0 (ms)\tDelay0 (ms)\tSSRC1\tiMOS1\tLoss1 (%)\tJitter1 (ms)\tDelay1 (ms)");
127 124 for (double[] statLine : callsStatsMap.get(new Double(idVoip))){
... ... @@ -135,8 +132,8 @@ public class RESTExportStats extends ServerResource{
135 132  
136 133  
137 134 }
138   - //out.println(PELStats.statsMap.get(mySwitch).get(0)[0][0]);
139 135 System.out.println("-> stats export successful");
  136 +
140 137 }catch (FileNotFoundException e) {
141 138 System.out.println("Error during the stats export");
142 139 e.printStackTrace();
... ...
src/main/java/net/floodlightcontroller/pelstats/rest/RESTQueue.java
... ... @@ -194,8 +194,7 @@ public class RESTQueue extends ServerResource{
194 194 } catch (IOException e) {
195 195 e.printStackTrace();
196 196 }
197   -
198   -
  197 +
199 198 //Vendor message to implement the metric on switch
200 199 //
201 200 if (enableBit){
... ... @@ -203,7 +202,6 @@ public class RESTQueue extends ServerResource{
203 202 "0.0.0.0", "0.0.0.0", 0, action, idQueue, priority, protocol);
204 203 mySwitch.write(setConfigMsg, null);
205 204 }
206   -
207 205 // Vendor message for queue action
208 206 //
209 207 int nb= 2*16777216+8*65536+action*4096+idQueue*256+priority*16+protocol;
... ... @@ -215,64 +213,70 @@ public class RESTQueue extends ServerResource{
215 213 e.printStackTrace();
216 214 }//*/
217 215  
218   - //OpenFlow message for flow tables modifications
219   - //
220   - OFFlowMod OFmessage= new OFFlowMod();
221   - OFMatch OFmatch= new OFMatch();
222   - OFActionEnqueue enqueue= new OFActionEnqueue();
223   -
224   - OFmessage.setCommand((short)action);
225   - OFmessage.setCookie(0);
226   - OFmessage.setIdleTimeout((short) 0);
227   - OFmessage.setHardTimeout((short)0);
228   - OFmessage.setPriority((short)priority);
229   - OFmessage.setBufferId(0);
230   - OFmessage.setOutPort((short)0xffff);
231   - OFmessage.setFlags((short) 0);
232   -
233 216  
234   - switch(protocol){//TODO change the ports to have them dynamically
235   - case 1://VoIP
236   - OFmatch.setTransportDestination((short)7078);
237   - OFmatch.setTransportSource((short)7078);
238   - break;
239   -
240   - case 2://Web
241   - OFmatch.setTransportDestination((short)80);
242   - OFmatch.setTransportSource((short)80);
243   - break;
244   -
245   - case 3://Mail
246   - OFmatch.setTransportDestination((short)433);
247   - OFmatch.setTransportSource((short)433);
248   - break;
249   -
250   -
251   - default:
252   - break;
253   - }
254   - OFmatch.setWildcards(OFMatch.OFPFW_ALL - OFMatch.OFPFW_IN_PORT
255   - - OFMatch.OFPFW_TP_SRC - OFmatch.OFPFW_DL_DST );
256   - OFmatch.setInputPort((short)1);
257   - OFmessage.setMatch(OFmatch);
258 217  
259   - List<OFAction> actions= new ArrayList<OFAction>(1);
260   - enqueue=new OFActionEnqueue((short)2,idQueue);
261   - actions.add(enqueue);
  218 + List<Integer> queueInfos =new ArrayList<Integer>();
  219 + queueInfos.add(new Integer(idQueue));
  220 + queueInfos.add(new Integer(priority));
  221 + queueInfos.add(new Integer(action));
262 222  
263   - OFmessage.setActions(actions);
264   - OFmessage.setLength((short)(OFFlowMod.MINIMUM_LENGTH +OFActionEnqueue.MINIMUM_LENGTH));
  223 + PELStats.queueInfos.put(mySwitch, queueInfos);
265 224  
266   - try {
267   - Thread.sleep(1000);
268   - mySwitch.write(OFmessage, null);
269   - mySwitch.flush();
270   - System.out.println("@RESTQueue message sent: "+OFmessage);
271   - } catch (IOException e) {
272   - e.printStackTrace();
273   - }catch(InterruptedException ex) {
274   - Thread.currentThread().interrupt();
275   - }//*/
  225 + if (protocol!=1){
  226 + //OpenFlow message for flow tables modifications
  227 + //
  228 + OFFlowMod OFmessage= new OFFlowMod();
  229 + OFMatch OFmatch= new OFMatch();
  230 + OFActionEnqueue enqueue= new OFActionEnqueue();
  231 +
  232 + OFmessage.setCommand((short)action);
  233 + OFmessage.setCookie(0);
  234 + OFmessage.setIdleTimeout((short) 0);
  235 + OFmessage.setHardTimeout((short)0);
  236 + OFmessage.setPriority((short)priority);
  237 + OFmessage.setBufferId(0);
  238 + OFmessage.setOutPort((short)0xffff);
  239 + OFmessage.setFlags((short) 0);
  240 +
  241 +
  242 + switch(protocol){//TODO change the ports to have them dynamically
  243 +
  244 + case 2://Web
  245 + OFmatch.setTransportDestination((short)80);
  246 + OFmatch.setTransportSource((short)80);
  247 + break;
  248 +
  249 + case 3://Mail
  250 + OFmatch.setTransportDestination((short)433);
  251 + OFmatch.setTransportSource((short)433);
  252 + break;
  253 +
  254 +
  255 + default:return "{\"resultCode\" : 0, \"error, invalid protocol : \"}";
  256 + }
  257 + OFmatch.setWildcards(OFMatch.OFPFW_ALL - OFMatch.OFPFW_IN_PORT
  258 + - OFMatch.OFPFW_TP_SRC - OFmatch.OFPFW_TP_DST );
  259 + OFmatch.setInputPort((short)1);
  260 + OFmessage.setMatch(OFmatch);
  261 +
  262 + List<OFAction> actions= new ArrayList<OFAction>(1);
  263 + enqueue=new OFActionEnqueue((short)2,idQueue);
  264 + actions.add(enqueue);
  265 +
  266 + OFmessage.setActions(actions);
  267 + OFmessage.setLength((short)(OFFlowMod.MINIMUM_LENGTH +OFActionEnqueue.MINIMUM_LENGTH));
  268 +
  269 + try {
  270 + Thread.sleep(1000);
  271 + mySwitch.write(OFmessage, null);
  272 + mySwitch.flush();
  273 + System.out.println("@RESTQueue message sent: "+OFmessage);
  274 + } catch (IOException e) {
  275 + e.printStackTrace();
  276 + }catch(InterruptedException ex) {
  277 + Thread.currentThread().interrupt();
  278 + }//*/
  279 + }
276 280  
277 281  
278 282 } catch (Exception e) {
... ...