2 * Copyright (C) 2014 SDN Hub
4 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.
5 * You may not use this file except in compliance with this License.
6 * You may obtain a copy of the License at
8 * http://www.gnu.org/licenses/gpl-3.0.txt
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16 var url = "http://" + location.hostname + ":8080";
18 function updatePortStats() {
19 var statsTableBody = document.getElementById('port-stats-data');
20 while (statsTableBody.firstChild) {
21 statsTableBody.removeChild(statsTableBody.firstChild);
24 $.getJSON(url.concat("/stats/switches"), function(switches){
25 $.each(switches, function(index, dpid){
26 var hex_dpid = parseInt(dpid).toString(16);
28 $.getJSON(url.concat("/stats/port/").concat(dpid), function(ports) {
29 var portStats = ports[dpid];
31 var tr = document.createElement('TR');
32 var physicalPorts = 0;
33 var switchColTd = document.createElement('TD');
34 switchColTd.appendChild(document.createTextNode(hex_dpid));
35 tr.appendChild(switchColTd);
37 $.each(portStats, function(index, obj) {
38 if (obj.port_no < 65280) {
40 var statsArray = new Array(obj.port_no, obj.rx_packets, obj.rx_bytes, obj.rx_dropped, obj.rx_errors, obj.tx_packets, obj.tx_bytes, obj.tx_dropped, obj.tx_errors);
42 $.each(statsArray, function(index, value) {
43 var td = document.createElement('TD');
44 td.appendChild(document.createTextNode(value));
47 statsTableBody.appendChild(tr);
48 tr = document.createElement('TR');
52 switchColTd.rowSpan = physicalPorts;
60 var portStatsIntervalID = setInterval(function(){updatePortStats()}, 5000);
62 function stopPortStatsTableRefresh() {
63 clearInterval(portStatsIntervalID);