Commit 641daa1824e2499836425a024f682399815dd8ad

Authored by adumas
1 parent 14af801f

Flow message for both way of the flows and display of the voip bandwidth on switch

src/main/java/net/floodlightcontroller/pelstats/PELStats.java
... ... @@ -116,20 +116,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
116 116  
117 117 receivedStatistics.addStatistic(sw, srb.getIPsrc(), srb.getIPdst(), srb.getStatistic());
118 118  
119   - /*if (srb.getStatistic().getType()==6){
120   - List<Integer> SwitchPorts=new ArrayList<Integer>(portsCallsMap.get(sw));
121   - int[] RTPPorts = ((StatisticVoIP_SIP)srb.getStatistic()).getRTPPorts();
122   -
123   - if (enabledStatistics.get(sw).contains(new Integer(8))){//If the queue management is enabled on this switch
124   - for (Object obj : RTPPorts){ //For each call on the switch
125   - if (!SwitchPorts.contains(obj)){ //if the call isn't already assigned to a queue
126   -
127   - }
128   - }
129   - }
130 119  
131   -
132   - }*/
133 120 if (srb.getStatistic().getType()==5){
134 121 List<double[][]> calls=new ArrayList<double[][]>();
135 122 if (statsMap.get(sw)!=null) {
... ... @@ -140,19 +127,19 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
140 127  
141 128 }
142 129 if (srb.getStatistic().getType()==6){ //If we received a SIP message
143   - System.out.println("@PELStats: SIP message received");
  130 + //System.out.println("@PELStats: SIP message received");
144 131 if(enabledStatistics.containsKey(sw)){
145   - System.out.println("@PELStats: enabledStatistics contains sw:"+sw);
  132 + //System.out.println("@PELStats: enabledStatistics contains sw:"+sw);
146 133 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:");
  134 + //System.out.println("@PELStats: enabledStatistics sw containts the 8th metric:");
148 135 int[] SwitchRTPPorts = ((StatisticVoIP_SIP)srb.getStatistic()).getRTPPorts();
149 136  
150   - System.out.println("@PELStats: queueInfos:"+queueInfos.get(sw).get(0)+" "+queueInfos.get(sw).get(1)+" "+queueInfos.get(sw).get(2)+" ");
  137 + //System.out.println("@PELStats: queueInfos:"+queueInfos.get(sw).get(0)+" "+queueInfos.get(sw).get(1)+" "+queueInfos.get(sw).get(2)+" ");
151 138 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");
  139 + //System.out.println("@PELStats: Modification or deletion");
153 140 for (int port : portsCallsMap.get(sw))
154 141 {
155   - System.out.println("@PELStats: port modification or deletion: "+port);
  142 + //System.out.println("@PELStats: port modification or deletion: "+port);
156 143 sendOFFlowMod(sw,port);
157 144 }
158 145 if(queueInfos.get(sw).get(2)==3){ //If we deleted the queue
... ... @@ -161,18 +148,18 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
161 148  
162 149  
163 150 }
164   - System.out.println("@PELStats: intermission");
  151 + //System.out.println("@PELStats: intermission");
165 152 if (queueInfos.get(sw).get(2)!=3 && SwitchRTPPorts!=null) {
166   - System.out.println("@PELStats: Modification or addition");
  153 + //System.out.println("@PELStats: Modification or addition");
167 154 for (int port:SwitchRTPPorts){ //For each calls of the switch
168   - System.out.println("@PELStats: Modification or addition for port: "+port);
  155 + //System.out.println("@PELStats: Modification or addition for port: "+port);
169 156  
170 157 if (portsCallsMap.get(sw)!=null){
171 158 List<Integer> portsCalls =new ArrayList<Integer>(portsCallsMap.get(sw));
172 159  
173   - System.out.println("@PELStats: portsCalls created: "+portsCalls);
  160 + //System.out.println("@PELStats: portsCalls created: "+portsCalls);
174 161 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);
  162 + //System.out.println("@PELStats: port add: "+port);
176 163 sendOFFlowMod(sw,port);
177 164  
178 165 //Updating the ports calls map
... ... @@ -182,7 +169,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
182 169 }
183 170 }
184 171 else{
185   - System.out.println("@PELStats portsCalls==null");
  172 + //System.out.println("@PELStats portsCalls==null");
186 173 List<Integer> portsCalls =new ArrayList<Integer>();
187 174 sendOFFlowMod(sw,port);
188 175  
... ... @@ -220,7 +207,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
220 207  
221 208 } catch (Exception e) {
222 209 System.out.println("@PELStats: We have a problem:" + e.toString());
223   -// e.printStackTrace();
  210 + e.printStackTrace();
224 211 }
225 212 }
226 213 }
... ... @@ -230,7 +217,7 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
230 217 return Command.CONTINUE;
231 218 }
232 219 private void sendOFFlowMod(IOFSwitch sw,int port){
233   - System.out.println("@PELStats,sendOFFlowMod: trying to craft message");
  220 + //System.out.println("@PELStats,sendOFFlowMod: trying to craft message");
234 221 //OpenFlow message for flow tables modifications
235 222 //
236 223 OFFlowMod OFmessage= new OFFlowMod();
... ... @@ -261,11 +248,49 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
261 248  
262 249 OFmessage.setActions(actions);
263 250 OFmessage.setLength((short)(OFFlowMod.MINIMUM_LENGTH +OFActionEnqueue.MINIMUM_LENGTH));
264   - System.out.println("@PELStats,sendOFFlowMod: trying to send message");
  251 + //System.out.println("@PELStats,sendOFFlowMod: trying to send message");
  252 + try {
  253 + sw.write(OFmessage, null);
  254 + sw.flush();
  255 + //System.out.println("@PELStats,sendOFFlowMod: message sent: "+OFmessage);
  256 + } catch (IOException e) {
  257 + e.printStackTrace();
  258 + }
  259 + //OpenFlow message for flow tables modifications
  260 + //The same as before, only the input and output ports are inverted
  261 + OFmessage= new OFFlowMod();
  262 + OFmatch= new OFMatch();
  263 + enqueue= new OFActionEnqueue();
  264 +
  265 + OFmessage.setCommand((short)0);
  266 + OFmessage.setCookie(0);
  267 + OFmessage.setIdleTimeout((short) 0);
  268 + OFmessage.setHardTimeout((short)0);
  269 + OFmessage.setPriority((short)queueInfos.get(sw).get(1).shortValue());
  270 + OFmessage.setBufferId(0);
  271 + OFmessage.setOutPort((short)0xffff);
  272 + OFmessage.setFlags((short) 0);
  273 +
  274 + OFmatch.setTransportDestination((short)port);
  275 + OFmatch.setTransportSource((short)port);
  276 +
  277 +
  278 + OFmatch.setWildcards(OFMatch.OFPFW_ALL - OFMatch.OFPFW_IN_PORT
  279 + - OFMatch.OFPFW_TP_SRC - OFmatch.OFPFW_TP_DST );
  280 + OFmatch.setInputPort((short)2);
  281 + OFmessage.setMatch(OFmatch);
  282 +
  283 + actions= new ArrayList<OFAction>(1);
  284 + enqueue=new OFActionEnqueue((short)1,queueInfos.get(sw).get(0));
  285 + actions.add(enqueue);
  286 +
  287 + OFmessage.setActions(actions);
  288 + OFmessage.setLength((short)(OFFlowMod.MINIMUM_LENGTH +OFActionEnqueue.MINIMUM_LENGTH));
  289 + //System.out.println("@PELStats,sendOFFlowMod: trying to send message");
265 290 try {
266 291 sw.write(OFmessage, null);
267 292 sw.flush();
268   - System.out.println("@PELStats,sendOFFlowMod: message sent: "+OFmessage);
  293 + //System.out.println("@PELStats,sendOFFlowMod: message sent: "+OFmessage);
269 294 } catch (IOException e) {
270 295 e.printStackTrace();
271 296 }
... ...
src/main/java/net/floodlightcontroller/pelstats/rest/RESTQueue.java
... ... @@ -239,7 +239,7 @@ public class RESTQueue extends ServerResource{
239 239 OFmessage.setFlags((short) 0);
240 240  
241 241  
242   - switch(protocol){//TODO change the ports to have them dynamically
  242 + switch(protocol){
243 243  
244 244 case 2://Web
245 245 OFmatch.setTransportDestination((short)80);
... ... @@ -270,12 +270,68 @@ public class RESTQueue extends ServerResource{
270 270 Thread.sleep(1000);
271 271 mySwitch.write(OFmessage, null);
272 272 mySwitch.flush();
273   - System.out.println("@RESTQueue message sent: "+OFmessage);
  273 + //System.out.println("@RESTQueue message sent: "+OFmessage);
274 274 } catch (IOException e) {
275 275 e.printStackTrace();
276 276 }catch(InterruptedException ex) {
277 277 Thread.currentThread().interrupt();
278 278 }//*/
  279 +
  280 +
  281 + //OpenFlow message for flow tables modifications
  282 + //The same as before, only the input and output ports are inverted
  283 + OFmessage= new OFFlowMod();
  284 + OFmatch= new OFMatch();
  285 + enqueue= new OFActionEnqueue();
  286 +
  287 + OFmessage.setCommand((short)action);
  288 + OFmessage.setCookie(0);
  289 + OFmessage.setIdleTimeout((short) 0);
  290 + OFmessage.setHardTimeout((short)0);
  291 + OFmessage.setPriority((short)priority);
  292 + OFmessage.setBufferId(0);
  293 + OFmessage.setOutPort((short)0xffff);
  294 + OFmessage.setFlags((short) 0);
  295 +
  296 +
  297 + switch(protocol){
  298 +
  299 + case 2://Web
  300 + OFmatch.setTransportDestination((short)80);
  301 + OFmatch.setTransportSource((short)80);
  302 + break;
  303 +
  304 + case 3://Mail
  305 + OFmatch.setTransportDestination((short)433);
  306 + OFmatch.setTransportSource((short)433);
  307 + break;
  308 +
  309 +
  310 + default:return "{\"resultCode\" : 0, \"error, invalid protocol : \"}";
  311 + }
  312 + OFmatch.setWildcards(OFMatch.OFPFW_ALL - OFMatch.OFPFW_IN_PORT
  313 + - OFMatch.OFPFW_TP_SRC - OFmatch.OFPFW_TP_DST );
  314 + OFmatch.setInputPort((short)2);
  315 + OFmessage.setMatch(OFmatch);
  316 +
  317 + actions= new ArrayList<OFAction>(1);
  318 + enqueue=new OFActionEnqueue((short)1,idQueue);
  319 + actions.add(enqueue);
  320 +
  321 + OFmessage.setActions(actions);
  322 + OFmessage.setLength((short)(OFFlowMod.MINIMUM_LENGTH +OFActionEnqueue.MINIMUM_LENGTH));
  323 +
  324 + try {
  325 + Thread.sleep(1000);
  326 + mySwitch.write(OFmessage, null);
  327 + mySwitch.flush();
  328 + //System.out.println("@RESTQueue message sent: "+OFmessage);
  329 + } catch (IOException e) {
  330 + e.printStackTrace();
  331 + }catch(InterruptedException ex) {
  332 + Thread.currentThread().interrupt();
  333 + }//*/
  334 +
279 335 }
280 336  
281 337  
... ...
src/main/java/org/openflow/protocol/Pel/statistics/StatisticVoIP_Queue.java
... ... @@ -103,7 +103,6 @@ public class StatisticVoIP_Queue extends Statistic{
103 103 if (i<nbQueues-1) toJson+=",";
104 104 }
105 105 toJson+="]";
106   - System.out.println("@Json8 :" +toJson);
107 106 return toJson;
108 107 }
109 108 public String protocolIntToString(int i){
... ...
src/main/resources/web/js/models/voipmodel.js
... ... @@ -152,6 +152,7 @@ window.VoIP = Backbone.Model.extend({
152 152 callRequest: null,
153 153 elapsedTime: null,
154 154 RTPPort: null,
  155 + voipBandwidth:null,
155 156  
156 157 id0: null,
157 158 src0: null,
... ... @@ -263,7 +264,24 @@ window.VoIP = Backbone.Model.extend({
263 264 });
264 265 });
265 266 },
266   - }); //*/
  267 + }); //*/voipBandwidth
  268 + $.ajax({
  269 +
  270 + url:hackBase + "/wm/iptv/switch/"+vl.idswitch+"/stats/8/json",
  271 + dataType:"json",
  272 + success:function (data) {
  273 + //console.log("Json9 success for "+vl.idswitch);
  274 + _.each(data['stats'], function(t) {
  275 + _.each(t.enabled, function(s) {
  276 + _.each(s.values, function(q) {
  277 + if (q.protocol=="VoIP"){
  278 + v.voipBandwidth+= q.bandwidth;
  279 + }
  280 + });
  281 + });
  282 + });
  283 + },
  284 + }); //*/voipBandwidth
267 285  
268 286  
269 287 self.trigger('add');
... ...
src/main/resources/web/js/views/voip.js
... ... @@ -219,16 +219,19 @@ window.VoIPListView = Backbone.View.extend({
219 219  
220 220 render:function (eventName) {
221 221 //console.log("VoIPListView render" );
222   - var self=this;
  222 + var self=this;
223 223  
224   - $(this.el).html(this.template({nvoip:vl.length, idswitch:this.id, bandwidth:v.bandwidth,
225   - averageMos:v.averageMos, cpu:v.cpu, cacStatus:v.cacStatus, memory:v.memory}));
  224 + $(self.el).html(self.template({nvoip:vl.length, idswitch:self.id, bandwidth:v.bandwidth,
  225 + voipBandwidth:v.voipBandwidth, averageMos:v.averageMos,
  226 + cpu:v.cpu, cacStatus:v.cacStatus, memory:v.memory}));
226 227 _.each(vl.models, function (v) {
227 228 v.idswitch=self.id;
228   - $(this.el).find('table.voipList-table > tbody')
  229 + $(self.el).find('table.voipList-table > tbody')
229 230 .append(new VoIPListItemView({model:v,idswitch:self.id}).render().el);
230   - }, this);
231   - return this;
  231 + }, self);
  232 +
  233 +
  234 + return self;
232 235 },
233 236 Export:function(e){
234 237 var self=this;
... ... @@ -348,12 +351,12 @@ window.VoIPSwitchQueueListItemView = Backbone.View.extend({
348 351 "click input[name=removeQueue]":"removeQueue",
349 352 },
350 353 initialize:function () {
351   - console.log("VSQLVI init" );
  354 + //console.log("VSQLVI init" );
352 355 this.template = _.template(tpl.get('voip-switch-queue-list-item'));
353 356 this.bind("change", this.render, this);
354 357 },
355 358 render:function (eventName) {
356   - console.log("VSQLVI render ");
  359 + //console.log("VSQLVI render ");
357 360 $(this.el).html(this.template({idQueue:this.model.idQueue,protocol:this.model.protocol,priority:this.model.priority,bandwidth:this.model.bandwidth}));
358 361 return this;
359 362 },
... ... @@ -362,7 +365,7 @@ window.VoIPSwitchQueueListItemView = Backbone.View.extend({
362 365 },
363 366 removeQueue:function (e) {
364 367 var self=this;
365   - console.log("protocol: "+self.model.protocol+ " "+self.model.idQueue+" "+self.model.priority+ " "+self.model.idswitch);
  368 + //console.log("protocol: "+self.model.protocol+ " "+self.model.idQueue+" "+self.model.priority+ " "+self.model.idswitch);
366 369 $.ajax({
367 370 url:hackBase + '/wm/iptv/switch/'+self.model.idswitch+'/disable/type/8/queue/3/'+self.model.idQueue+'/'+self.model.priority+'/'+self.model.protocol+'/json',
368 371 dataType:"json",
... ...
src/main/resources/web/tpl/voip-list.html
... ... @@ -4,9 +4,9 @@
4 4 <h1>VoIP Calls on switch <%= idswitch %> <a href="javascript:history.back()"><img alt="prec" src="/ui/img/previous.png" /></a><img alt="update" src="/ui/img/update.png" /></h1>
5 5 </div>
6 6 <table class="status-table">
7   - <tr><td class="status-head">Bandwidth (kbits/s):</td><td><%= bandwidth %></td><td style="width:220px"></td><td class="status-head">Average iMOS:<td><%= averageMos %></td></tr>
8   - <tr><td class="status-head">CPU (%):</td><td><%= cpu %></td><td></td><td class="status-head">CAC status:</td ><td id="CACStatus"><%= cacStatus %></td></tr>
9   - <tr><td class="status-head">Memory (%):</td><td><%= memory %></td></tr>
  7 + <tr><td class="status-head">Bandwidth (kbits/s):</td><td><%= bandwidth %></td><td style="width:220px"></td><td class="status-head">VoIP bandwidth (kbits/s):<td><%= voipBandwidth %></td></tr>
  8 + <tr><td class="status-head">CPU (%):</td><td><%= cpu %></td><td></td><td class="status-head">Average iMOS:<td><%= averageMos %></td></tr>
  9 + <tr><td class="status-head">Memory (%):</td><td><%= memory %></td><td></td><td class="status-head">CAC status:</td ><td id="CACStatus"><%= cacStatus %></td></tr>
10 10 </table>
11 11  
12 12 <div class="page-header">
... ...