Commit 98f24711c81b08dd94a85831ba747e2de3be28da

Authored by adumas
1 parent 641daa18

average mos export

src/main/java/net/floodlightcontroller/pelstats/PELStats.java
... ... @@ -68,8 +68,10 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
68 68 public static ConcurrentHashMap<IOFSwitch, List<ThresholdMessage>> thresholdMap;
69 69  
70 70 public static ConcurrentHashMap<Integer, List<double[]>> callStatsMap;
71   - public static ConcurrentHashMap<IOFSwitch,List<double[][]>> statsMap;
  71 + public static ConcurrentHashMap<IOFSwitch,List<double[][]>> voipStatsMap;
72 72  
  73 + public static ConcurrentHashMap<IOFSwitch,List<double[]>> cacStatsMap;
  74 +
73 75 public static ConcurrentHashMap<IOFSwitch, List<Integer>> queueInfos;
74 76 public static ConcurrentHashMap<IOFSwitch, List<Integer>> portsCallsMap;
75 77  
... ... @@ -119,11 +121,11 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
119 121  
120 122 if (srb.getStatistic().getType()==5){
121 123 List<double[][]> calls=new ArrayList<double[][]>();
122   - if (statsMap.get(sw)!=null) {
123   - calls=new ArrayList<double[][]>(statsMap.get(sw));
  124 + if (voipStatsMap.get(sw)!=null) {
  125 + calls=new ArrayList<double[][]>(voipStatsMap.get(sw));
124 126 }
125 127 calls.add(((StatisticVoIP)srb.getStatistic()).getStats());
126   - statsMap.put(sw, calls);
  128 + voipStatsMap.put(sw, calls);
127 129  
128 130 }
129 131 if (srb.getStatistic().getType()==6){ //If we received a SIP message
... ... @@ -192,6 +194,16 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
192 194 if (srb.getStatistic().getType()==7){
193 195 double mos= ((StatisticVoIP_CAC)srb.getStatistic()).getMos();
194 196 sendThreshold(sw,mos,cntx);
  197 +
  198 + List<double[]> cacStats = new ArrayList<double[]>();
  199 + double[] stats = ((StatisticVoIP_CAC)srb.getStatistic()).getStats();
  200 + if(cacStatsMap.get(sw)!=null){
  201 + cacStats =new ArrayList<double[]>(cacStatsMap.get(sw));
  202 + }
  203 + cacStats.add(stats);
  204 + cacStatsMap.put(sw,cacStats);
  205 +
  206 +
195 207 }
196 208  
197 209 if(enabledStatistics.containsKey(sw)){
... ... @@ -370,7 +382,8 @@ public class PELStats implements IFloodlightModule, IOFMessageListener, RestAPIP
370 382 PELStats.portsCallsMap=new ConcurrentHashMap<IOFSwitch, List<Integer>>();
371 383 PELStats.queueInfos=new ConcurrentHashMap<IOFSwitch, List<Integer>>();
372 384 PELStats.callStatsMap=new ConcurrentHashMap<Integer, List<double[]>>() ;
373   - PELStats.statsMap=new ConcurrentHashMap<IOFSwitch, List<double[][]>>() ;
  385 + PELStats.voipStatsMap=new ConcurrentHashMap<IOFSwitch, List<double[][]>>() ;
  386 + PELStats.cacStatsMap=new ConcurrentHashMap<IOFSwitch, List<double[]>>() ;
374 387 requestThread.start();
375 388 }
376 389  
... ...
src/main/java/net/floodlightcontroller/pelstats/rest/RESTExportStats.java
... ... @@ -45,7 +45,9 @@ public class RESTExportStats extends ServerResource{
45 45  
46 46 String switchId = (String) getRequestAttributes().get("idSwitch");
47 47 String sIdVoip = (String) getRequestAttributes().get("idVoip");
  48 + String sType = (String) getRequestAttributes().get("metricType");
48 49 int idVoip;
  50 + int type=-1;
49 51  
50 52  
51 53  
... ... @@ -53,9 +55,16 @@ public class RESTExportStats extends ServerResource{
53 55 System.out.println("Exporting stats(REST):");
54 56 System.out.println(" Switch : " + switchId);
55 57 System.out.println(" call ID : " + sIdVoip);
  58 + System.out.println(" type : " + sType);
56 59  
57 60  
58 61 try {
  62 + type = Integer.parseInt(sType);
  63 + if(type<0)return "{\"resultCode\" : 0, \"error\" : \"Invalid metric type value \"}";
  64 + } catch (Exception e) {
  65 + return "{\"resultCode\" : 0, \"error\" : \"Invalid metric type value \"}";
  66 + }
  67 + try {
59 68 idVoip = Integer.parseInt(sIdVoip);
60 69 if(idVoip<0)return "{\"resultCode\" : 0, \"error\" : \"Invalid idVoip value \"}";
61 70 } catch (Exception e) {
... ... @@ -82,57 +91,88 @@ public class RESTExportStats extends ServerResource{
82 91  
83 92 PrintWriter out=null;
84 93 try{
85   - out = new PrintWriter("statsExport.txt");
86   -
87   - //Retrieving all stats
88   - ConcurrentHashMap<Double, List<double[]>> callsStatsMap = new ConcurrentHashMap<Double, List<double[]>>();
89   - List<double[]> callsStats=new ArrayList<double[]>();
90   - double callID;
91   -
92   - for (double[][] list:PELStats.statsMap.get(mySwitch)){
  94 + if(type==5){
  95 + out = new PrintWriter("VoIPstatsExport.txt");
93 96  
94   - for (int i=0;i<list.length;i++){
95   - callID=new Double(list[i][0]);
96   - if (callsStatsMap.get(callID)!=null) {
  97 + //Retrieving all stats
  98 + ConcurrentHashMap<Double, List<double[]>> callsStatsMap = new ConcurrentHashMap<Double, List<double[]>>();
  99 + List<double[]> callsStats=new ArrayList<double[]>();
  100 + double callID;
  101 +
  102 + for (double[][] list:PELStats.voipStatsMap.get(mySwitch)){
97 103  
98   - callsStats=new ArrayList<double[]>(callsStatsMap.get(callID));
  104 + for (int i=0;i<list.length;i++){
  105 + callID=new Double(list[i][0]);
  106 + if (callsStatsMap.get(callID)!=null) {
  107 +
  108 + callsStats=new ArrayList<double[]>(callsStatsMap.get(callID));
  109 + }
  110 + callsStats.add(list[i]);
  111 + callsStatsMap.put(callID, callsStats);
  112 + }
  113 +
  114 + }
  115 +
  116 + if (idVoip==0){//If we want to export all the switch calls stats
  117 + for (Map.Entry<Double, List<double[]>> entry : callsStatsMap.entrySet()){
  118 + out.println("Call:\t"+entry.getKey());
  119 + out.println("Elapsed Time (s)\tSSRC0\tiMOS0\tLoss0 (%)\tJitter0 (ms)\tDelay0 (ms)\tSSRC1\tiMOS1\tLoss1 (%)\tJitter1 (ms)\tDelay1 (ms)");
  120 + for (double[] statLine : entry.getValue()){
  121 + String line=new String();
  122 + for (int i=1;i<12;i++){
  123 + line+=statLine[i]+"\t";
  124 + }
  125 + out.println(line);
  126 + System.out.println(line);
  127 + }
  128 + out.println("\n");
99 129 }
100   - callsStats.add(list[i]);
101   - callsStatsMap.put(callID, callsStats);
102 130 }
103   -
104   - }
105   -
106   - if (idVoip==0){//If we want to export all the switch calls stats
107   - for (Map.Entry<Double, List<double[]>> entry : callsStatsMap.entrySet()){
108   - out.println("Call:\t"+entry.getKey());
  131 + else{//If we want to export only the stats for a call
  132 + out.println("Call:\t"+idVoip);
109 133 out.println("Elapsed Time (s)\tSSRC0\tiMOS0\tLoss0 (%)\tJitter0 (ms)\tDelay0 (ms)\tSSRC1\tiMOS1\tLoss1 (%)\tJitter1 (ms)\tDelay1 (ms)");
110   - for (double[] statLine : entry.getValue()){
  134 + for (double[] statLine : callsStatsMap.get(new Double(idVoip))){
111 135 String line=new String();
112   - for (int i=1;i<12;i++){
  136 + for (int i=0;i<12;i++){
113 137 line+=statLine[i]+"\t";
114 138 }
115 139 out.println(line);
116 140 System.out.println(line);
117 141 }
118   - out.println("\n");
  142 +
  143 +
119 144 }
  145 + System.out.println("-> stats export successful");
120 146 }
121   - else{//If we want to export only the stats for a call
122   - out.println("Call:\t"+idVoip);
123   - out.println("Elapsed Time (s)\tSSRC0\tiMOS0\tLoss0 (%)\tJitter0 (ms)\tDelay0 (ms)\tSSRC1\tiMOS1\tLoss1 (%)\tJitter1 (ms)\tDelay1 (ms)");
124   - for (double[] statLine : callsStatsMap.get(new Double(idVoip))){
125   - String line=new String();
126   - for (int i=0;i<12;i++){
127   - line+=statLine[i]+"\t";
128   - }
129   - out.println(line);
130   - System.out.println(line);
131   - }
132   -
  147 + else if(type==7){
  148 + out = new PrintWriter("CACstatsExport.txt");
  149 + System.out.println("type7");
  150 + if (idVoip==0){//export stats for all switches
  151 + System.out.println("voip0");
  152 + for (Map.Entry<IOFSwitch, List<double[]>> entry : PELStats.cacStatsMap.entrySet()){
  153 + out.println("Switch:\t"+entry.getKey());
  154 + out.println("Number of calls\tAverage iMOS");
  155 + for (double[] list:PELStats.cacStatsMap.get(entry.getKey())){
  156 + out.println(list[0]+"\t"+list[1]);
  157 + }
  158 + out.println("\n");
  159 + }
  160 + }
  161 + else if (idVoip==1){//export stats for this switch only
  162 + System.out.println("voip1");
  163 + out.println("Switch:\t"+mySwitch);
  164 + out.println("Number of calls\tAverage iMOS");
  165 + for (double[] list:PELStats.cacStatsMap.get(mySwitch)){
  166 + out.println(list[0]+"\t"+list[1]);
  167 + }
  168 + }
  169 +
  170 +
  171 +
  172 +
133 173  
  174 + System.out.println("-> stats export successful");
134 175 }
135   - System.out.println("-> stats export successful");
136 176  
137 177 }catch (FileNotFoundException e) {
138 178 System.out.println("Error during the stats export");
... ...
src/main/java/net/floodlightcontroller/pelstats/rest/StatsRoutable.java
... ... @@ -37,7 +37,7 @@ public class StatsRoutable implements RestletRoutable{
37 37 router.attach("/switch/{idSwitch}/{enable}/type/{metricType}/opt/{ipSrc}/{ipDst}/{threshold}/{idVoip}/json",RESTVoip.class);
38 38 router.attach("/switch/{idSwitch}/{enable}/type/{metricType}/cac/{nominalNbOfCalls}/{lowMos}/{highMos}/{meanMos}/{cir}/{maxBurst}/json",RESTCallAdmissionControl.class);
39 39 router.attach("/switch/{idSwitch}/{enable}/type/{metricType}/queue/{action}/{idQueue}/{priority}/{protocol}/json",RESTQueue.class);
40   - router.attach("/switch/{idSwitch}/export/{idVoip}/json",RESTExportStats.class);
  40 + router.attach("/switch/{idSwitch}/export/{metricType}/{idVoip}/json",RESTExportStats.class);
41 41  
42 42 return router;
43 43 }
... ...
src/main/java/org/openflow/protocol/Pel/statistics/StatisticVoIP_CAC.java
... ... @@ -37,6 +37,12 @@ public class StatisticVoIP_CAC extends Statistic{
37 37  
38 38  
39 39 }
  40 + public double[] getStats(){
  41 + double stats[]=new double[2];
  42 + stats[0]=nbCalls;
  43 + stats[1]=averageMos;
  44 + return stats;
  45 + }
40 46  
41 47 private double getDoubleBytes(ByteBuffer b, int nbBytes){
42 48 byte[] bytes=new byte[4];
... ...
src/main/python/debugserver$py.class
No preview for this file type
src/main/resources/web/js/main.js
... ... @@ -131,6 +131,7 @@ var vsl = new VoIPSwitchCollection();
131 131 var v = new VoIP();
132 132 var allStats = new allStatsCollection();
133 133  
  134 +var views=[];
134 135 var updating = true;
135 136 var allSipMetrics=false;
136 137  
... ... @@ -164,17 +165,31 @@ tpl.loadTemplates([&#39;home&#39;, &#39;status&#39;, &#39;topology&#39;, &#39;header&#39;, &#39;switch&#39;, &#39;switch-lis
164 165 swl.fetch();
165 166 hl.fetch();
166 167 vl.fetch();
167   - vsl.fetch();
  168 + //vsl.fetch();
168 169 allStats.fetch();
169 170  
170 171 setInterval(function () {
171 172 if(updating) {
172 173 swl.fetch();
173 174 hl.fetch();
174   - vsl.fetch();
  175 + //vsl.fetch();
175 176 vl.fetch();
176 177 v.fetch();
177 178 allStats.fetch();
  179 +
  180 + /*while (views.length>30){
  181 + var vi=views.shift();
  182 + // COMPLETELY UNBIND THE VIEW
  183 + vi.undelegateEvents();
  184 +
  185 + vi.$el.removeData().unbind();
  186 +
  187 + // Remove view from DOM
  188 + vi.remove();
  189 + Backbone.View.prototype.remove.call(vi);
  190 +
  191 + };*/
  192 +
178 193 }
179 194 }, 1000);
180 195 });
... ...
src/main/resources/web/js/models/switchmodel.js
... ... @@ -27,7 +27,6 @@ window.Switch = Backbone.Model.extend({
27 27 flowCount: ' ',
28 28 packetCount: ' ',
29 29 byteCount: ' ',
30   - sipSent:'false',
31 30 },
32 31  
33 32 initialize:function () {
... ... @@ -282,14 +281,23 @@ window.SwitchCollection = Backbone.Collection.extend({
282 281 old_ids = _.without(old_ids, sw['dpid']);
283 282 self.add({id: sw['dpid'], inetAddress: sw.inetAddress,
284 283 connectedSince: new Date(sw.connectedSince).toLocaleString()});
285   - });
286   -
  284 +
  285 +
  286 + vsl.add({id: sw['dpid'], inetAddress: sw.inetAddress,
  287 + connectedSince: new Date(sw.connectedSince).toLocaleString()});
  288 +
  289 + sscm = new switchStatsCollectionModel(); //We add the switch to the stats
  290 + sscm.id=sw['dpid']; //If we don't, we wouldn't be able to start metrics
  291 + allStats.add(sscm);
  292 + });
287 293  
288 294 // old_ids now holds switches that no longer exist; remove them
289 295 //console.log("old_ids" + old_ids);
290 296 _.each(old_ids, function(sw) {
291 297 //console.log("removing switch " + sw);
292 298 self.remove({id:sw});
  299 + vsl.remove({id:sw});
  300 + allStats.remove({id:sw});
293 301 });
294 302 },
295 303 });
... ...
src/main/resources/web/js/views/voip.js
... ... @@ -15,6 +15,7 @@ window.VoIPGraphView = Backbone.View.extend({
15 15  
16 16 console.log("VoIPGraphView init" );
17 17 this.template = _.template(tpl.get('voip-graph'));
  18 + views[views.length]=this;
18 19  
19 20 Chart.defaults.global = {
20 21 animation: false, // Boolean - Whether to animate the chart
... ... @@ -133,7 +134,7 @@ window.VoIPView = Backbone.View.extend({
133 134 model: VoIP,
134 135  
135 136 events: {
136   - "click input[name=export]" : "Export",
  137 + "click input[name=exportVoIP]" : "ExportVoIP",
137 138 "click img" : "clicked",
138 139 },
139 140  
... ... @@ -147,7 +148,9 @@ window.VoIPView = Backbone.View.extend({
147 148  
148 149 initialize:function () {
149 150 //console.log("VoIPView init" )
  151 + //this.eraseView();view=this;
150 152 this.template = _.template(tpl.get('voip'));
  153 + views[views.length]=this;
151 154 this.model.bind("add", this.render, this);
152 155  
153 156 },
... ... @@ -158,11 +161,18 @@ window.VoIPView = Backbone.View.extend({
158 161 return this;
159 162 },
160 163  
  164 + /*eraseView:function(){
  165 + //////view.undelegateEvents();
  166 + view$el.removeData().unbind();
  167 + view.remove();
  168 + Backbone.View.prototype.remove.call(view);
  169 + },*/
  170 +
161 171 Export:function(e){
162 172 var self=this;
163 173 console.log("Export on "+self.model.idswitch);
164 174 $.ajax({
165   - url:hackBase + '/wm/iptv/switch/'+self.model.idswitch+'/export/'+v.id+'/json',
  175 + url:hackBase + '/wm/iptv/switch/'+self.model.idswitch+'/export/5/'+v.id+'/json',
166 176 dataType:"json",
167 177 success:function (data) {
168 178  
... ... @@ -199,7 +209,8 @@ window.VoIPListView = Backbone.View.extend({
199 209  
200 210 events: {
201 211 "click img" : "clicked",
202   - "click input[name=export]" : "Export",
  212 + "click input[name=exportVoIP]" : "ExportVoIP",
  213 + "click input[name=exportCAC]" : "ExportCAC",
203 214 },
204 215 clicked:function(e){
205 216 if( $(e.currentTarget).attr("alt") == "update" ){
... ... @@ -210,8 +221,10 @@ window.VoIPListView = Backbone.View.extend({
210 221 },
211 222 initialize:function () {
212 223 //console.log("VoIPListView init" );
  224 + //this.eraseView();view=this;
213 225 var self = this;
214 226 this.template = _.template(tpl.get('voip-list'));
  227 + views[views.length]=this;
215 228 vl.bind("change", this.render, this);
216 229 vl.bind("add", this.render, this);
217 230 vl.bind("remove", this.render, this);
... ... @@ -233,17 +246,39 @@ window.VoIPListView = Backbone.View.extend({
233 246  
234 247 return self;
235 248 },
236   - Export:function(e){
  249 + /*eraseView:function(){
  250 + //view.undelegateEvents();
  251 + view$el.removeData().unbind();
  252 + view.remove();
  253 + Backbone.View.prototype.remove.call(view);
  254 + },*/
  255 + ExportVoIP:function(e){
237 256 var self=this;
238 257 console.log("Export on "+self.model.idswitch);
239 258 $.ajax({
240   - url:hackBase + '/wm/iptv/switch/'+self.model.idswitch+'/export/0/json',
  259 + url:hackBase + '/wm/iptv/switch/'+self.model.idswitch+'/export/5/0/json',
241 260 dataType:"json",
242 261 success:function (data) {
243 262  
244 263 if ( data.resultCode == 0 ) alert(data.error);
245 264 else {
246   - console.log("Export started for "+self.model.idswitch);
  265 + console.log("Export VoIP started for "+self.model.idswitch);
  266 + }
  267 + },
  268 + });
  269 +
  270 + },
  271 + ExportCAC:function(e){
  272 + var self=this;
  273 + console.log("Export on "+self.model.idswitch);
  274 + $.ajax({
  275 + url:hackBase + '/wm/iptv/switch/'+self.model.idswitch+'/export/7/1/json',
  276 + dataType:"json",
  277 + success:function (data) {
  278 +
  279 + if ( data.resultCode == 0 ) alert(data.error);
  280 + else {
  281 + console.log("Export CAC started for "+self.model.idswitch);
247 282 }
248 283 },
249 284 });
... ... @@ -260,6 +295,7 @@ window.VoIPListItemView = Backbone.View.extend({
260 295 },
261 296 initialize:function () {
262 297 this.template = _.template(tpl.get('voip-list-item'));
  298 + views[views.length]=this;
263 299 this.model.bind("change", this.render, this);
264 300 this.model.bind("add", this.render, this);
265 301 this.model.bind("destroy", this.close, this);
... ... @@ -353,6 +389,7 @@ window.VoIPSwitchQueueListItemView = Backbone.View.extend({
353 389 initialize:function () {
354 390 //console.log("VSQLVI init" );
355 391 this.template = _.template(tpl.get('voip-switch-queue-list-item'));
  392 + //views[views.length]=this;
356 393 this.bind("change", this.render, this);
357 394 },
358 395 render:function (eventName) {
... ... @@ -390,7 +427,10 @@ window.VoIPSwitchListView = Backbone.View.extend({
390 427 },
391 428 initialize:function () {
392 429 //console.log("SLV init" );
  430 + //this.eraseView();
  431 + //view=this;console.log("view: "+view);
393 432 this.template = _.template(tpl.get('voip-switch-list'));
  433 + views[views.length]=this;
394 434 this.model.bind("change", this.render, this);
395 435 this.model.bind("remove", this.render, this);
396 436  
... ... @@ -414,6 +454,12 @@ window.VoIPSwitchListView = Backbone.View.extend({
414 454 }, this);
415 455 return this;
416 456 },
  457 + /*eraseView:function(){
  458 + view.undelegateEvents();
  459 + view$el.removeData().unbind();
  460 + view.remove();
  461 + Backbone.View.prototype.remove.call(view);
  462 + },*/
417 463 addAllSIP:function(){
418 464 var self=this;
419 465 $(this.el).parent().find(".popupStats").each(function( i ) {
... ... @@ -473,8 +519,8 @@ window.VoIPSwitchListItemView = Backbone.View.extend({
473 519 },
474 520 initialize:function () {
475 521 //console.log("VSLVI init" );
476   -
477 522 this.template = _.template(tpl.get('voip-switch-list-item'));
  523 + //views[views.length]=this;
478 524 this.model.bind("change", this.render, this);
479 525  
480 526  
... ...
src/main/resources/web/tpl/voip-list.html
... ... @@ -13,8 +13,9 @@
13 13 <table style="width: 770px;">
14 14 <tbody>
15 15 <tr>
16   - <td><h1>Calls (<%= nvoip %>)</h1></td>
17   - <td style="text-align: center;"><input value="Export" name="export" type="button"></td>
  16 + <td style="width: 450px;"><h1>Calls (0)</h1></td>
  17 + <td style="width: 150px;"><input value="Export VoIP" name="exportVoIP" type="button"></td>
  18 + <td><input value="Export CAC" name="exportCAC" type="button"></td>
18 19 </tr>
19 20 </tbody>
20 21 </table>
... ...