2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
13 // specify dashlets and layouts
17 name : 'Existing Nodes'
32 one.f.dashlet.existingNodes
41 one.f.dashlet.flowsOrPorts
48 $(one.f.menu.left.top).each(function(index, value) {
49 var $nav = $(".nav", "#left-top");
50 one.main.page.dashlet($nav, value);
53 $(one.f.menu.left.bottom).each(function(index, value) {
54 var $nav = $(".nav", "#left-bottom");
55 one.main.page.dashlet($nav, value);
58 $(one.f.menu.right.bottom).each(function(index, value) {
59 var $nav = $(".nav", "#right-bottom");
60 one.main.page.dashlet($nav, value);
63 /**Troubleshoot modules*/
64 one.f.troubleshooting = {
65 rootUrl: "/controller/web/troubleshoot",
68 var $rightBottomDashlet = $("#right-bottom").find(".dashlet");
69 return $rightBottomDashlet;
71 setDashletHeader: function(label) {
72 $("#right-bottom li a")[0].innerHTML = label;
75 createTable: function(columnNames, body) {
76 var tableAttributes = ["table-striped", "table-bordered", "table-condensed"];
77 var $table = one.lib.dashlet.table.table(tableAttributes);
78 var tableHeaders = columnNames;
79 var $thead = one.lib.dashlet.table.header(tableHeaders);
80 var $tbody = one.lib.dashlet.table.body(body, tableHeaders);
87 one.f.troubleshooting.existingNodes = {
89 popout: "one_f_troubleshooting_existingNodes_id_popout",
90 modal: "one_f_troubleshooting_existingNodes_id_modal",
91 existingNodesDataGrid: "one_f_troubleshooting_existingNodes_id_datagrid",
92 portsDataGrid: "one_f_troubleshooting_existingNodes_id_portsDataGrid",
93 flowsDataGrid: "one_f_troubleshooting_existingNodes_id_flowsDataGrid"
95 // TODO: Make these values configurable.
96 autoRefreshInterval: {
99 refreshRateInterval: 5000
102 main: function($dashlet) {
103 one.lib.dashlet.empty($dashlet);
104 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.existingNodes.name));
105 // TODO(l): Add a generic auto expand function to one.lib and replace custom height setting.
106 //$('#left-top').height('100%');
107 one.f.troubleshooting.existingNodes.ajax(one.f.troubleshooting.rootUrl + "/existingNodes" , function(content) {
108 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.existingNodesDataGrid, {
112 flexibleRowsPerPage: true
113 }, "table-striped table-condensed");
114 $dashlet.append($gridHTML);
115 var dataSource = one.f.troubleshooting.existingNodes.data.existingNodesGrid(content);
116 $("#" + one.f.troubleshooting.existingNodes.id.existingNodesDataGrid).datagrid({dataSource: dataSource});
120 flows: function(nodeId) {
122 if(one.f.troubleshooting === undefined){
125 clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer);
126 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/flowStats?nodeId=" + nodeId, function(content) {
127 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
128 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Flows");
129 one.lib.dashlet.empty($rightBottomDashlet);
130 $rightBottomDashlet.append(one.lib.dashlet.header("Flow Details"));
132 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.flowsDataGrid, {
136 flexibleRowsPerPage: true
137 }, "table-striped table-condensed");
138 $rightBottomDashlet.append($gridHTML);
139 var dataSource = one.f.troubleshooting.existingNodes.data.flowsGrid(content);
140 $("#" + one.f.troubleshooting.existingNodes.id.flowsDataGrid).datagrid({dataSource: dataSource});
142 var numberOfFlows = content.nodeData.length;
143 var refreshRate = one.f.troubleshooting.existingNodes.autoRefreshInterval.flows;
144 if (numberOfFlows > 0) {
145 refreshRate += Math.floor(numberOfFlows / 500) *
146 one.f.troubleshooting.existingNodes.autoRefreshInterval.refreshRateInterval;
148 one.f.troubleshooting.existingNodes.registry.refreshTimer = setTimeout(
149 one.f.troubleshooting.existingNodes.load.flows,
150 refreshRate, nodeId);
154 ports: function(nodeId) {
156 if(one.f.troubleshooting === undefined){
159 clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer);
160 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/portStats?nodeId=" + nodeId, function(content) {
161 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
162 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Ports");
163 one.lib.dashlet.empty($rightBottomDashlet);
164 $rightBottomDashlet.append(one.lib.dashlet.header("Port Details"));
166 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.portsDataGrid, {
170 flexibleRowsPerPage: true
171 }, "table-striped table-condensed");
172 $rightBottomDashlet.append($gridHTML);
173 var dataSource = one.f.troubleshooting.existingNodes.data.portsGrid(content);
174 $("#" + one.f.troubleshooting.existingNodes.id.portsDataGrid).datagrid({dataSource: dataSource});
176 var numberOfPorts = content.nodeData.length;
177 var refreshRate = one.f.troubleshooting.existingNodes.autoRefreshInterval.ports;
178 if (numberOfPorts > 0) {
179 refreshRate += Math.floor(numberOfPorts / 500) *
180 one.f.troubleshooting.existingNodes.autoRefreshInterval.refreshRateInterval;
182 one.f.troubleshooting.existingNodes.registry.refreshTimer = setTimeout(
183 one.f.troubleshooting.existingNodes.load.ports,
184 refreshRate, nodeId);
189 ajax : function(url, callback) {
190 $.getJSON(url, function(data) {
198 existingNodesGrid: function(data) {
199 var source = new StaticDataSource({
202 property: 'nodeName',
208 label: 'Static Route',
212 property: 'statistics',
218 formatter: function(items) {
219 $.each(items, function(index, item) {
220 item["statistics"] = "<a href=\"javascript:one.f.troubleshooting.existingNodes.load.flows('" + item["nodeId"] + "');\">Flows</a>" +
221 " <a href=\"javascript:one.f.troubleshooting.existingNodes.load.ports('" + item["nodeId"] + "');\">Ports</a>";
229 portsGrid: function(data) {
230 var source = new StaticDataSource({
233 property: 'nodeConnector',
234 label: 'Node Connector',
268 property: 'rxErrors',
273 property: 'txErrors',
278 property: 'rxFrameErrors',
279 label: 'Rx Frame Errs',
283 property: 'rxOverRunErrors',
284 label: 'Rx OverRun Errs',
288 property: 'rxCRCErrors',
289 label: 'Rx CRC Errs',
293 property: 'collisions',
303 ports: function(data) {
305 $.each(data.nodeData, function(key, value) {
308 entry.push(value["nodeConnector"]);
309 entry.push(value["rxPkts"]);
310 entry.push(value["txPkts"]);
311 entry.push(value["rxBytes"]);
312 entry.push(value["txBytes"]);
313 entry.push(value["rxDrops"]);
314 entry.push(value["txDrops"]);
315 entry.push(value["rxErrors"]);
316 entry.push(value["txErrors"]);
317 entry.push(value["rxFrameErrors"]);
318 entry.push(value["rxOverRunErrors"]);
319 entry.push(value["rxCRCErrors"]);
320 entry.push(value["collisions"]);
326 flowsGrid: function(data) {
327 var source = new StaticDataSource({
330 property: 'nodeName',
390 property: 'byteCount',
395 property: 'packetCount',
396 label: 'Packet Count',
400 property: 'durationSeconds',
401 label: 'Duration Seconds',
405 property: 'idleTimeout',
406 label: 'Idle Timeout',
410 property: 'priority',
420 flows: function(data) {
422 $.each(data.nodeData, function(key, value) {
425 entry.push(value["nodeName"]);
426 entry.push(value["inPort"]);
427 entry.push(value["dlSrc"]);
428 entry.push(value["dlDst"]);
429 entry.push(value["dlType"]);
430 entry.push(value["dlVlan"]);
431 entry.push(value["nwSrc"]);
432 entry.push(value["nwDst"]);
433 entry.push(value["nwProto"]);
434 entry.push(value["tpSrc"]);
435 entry.push(value["tpDst"]);
436 entry.push(value["actions"]);
437 entry.push(value["byteCount"]);
438 entry.push(value["packetCount"]);
439 entry.push(value["durationSeconds"]);
440 entry.push(value["idleTimeout"]);
441 entry.push(value["priority"]);
450 one.f.troubleshooting.uptime = {
452 popout: "one_f_troubleshooting_uptime_id_popout",
453 modal: "one_f_troubleshooting_uptime_id_modal",
454 datagrid: "one_f_troubleshooting_uptime_id_datagrid"
457 dashlet: function($dashlet) {
458 one.lib.dashlet.empty($dashlet);
459 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
460 var url = one.f.troubleshooting.rootUrl + "/uptime";
461 one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
462 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.uptime.id.datagrid, {
466 flexibleRowsPerPage: true
467 }, "table-striped table-condensed");
468 $dashlet.append($gridHTML);
469 var dataSource = one.f.troubleshooting.uptime.data.uptimeDataGrid(content);
470 $("#" + one.f.troubleshooting.uptime.id.datagrid).datagrid({dataSource: dataSource});
475 main : function(url, requestData, callback) {
476 $.getJSON(url, requestData, function(data) {
483 uptimeDataGrid: function(data) {
484 var source = new StaticDataSource({
487 property: 'nodeName',
497 property: 'connectedSince',
507 uptime: function(data) {
509 $.each(data.nodeData, function(key, value) {
512 entry.push(value["nodeName"]);
513 entry.push(value["nodeId"]);
514 entry.push(value["connectedSince"]);
523 one.f.troubleshooting.statistics = {
524 dashlet : function($dashlet) {
525 var $h4 = one.lib.dashlet.header("Statistics");
526 $dashlet.append($h4);
528 var $none = $(document.createElement('div'));
529 $none.addClass('none');
530 var $p = $(document.createElement('p'));
531 $p.text('Please select a Flow or Ports statistics');
532 $p.addClass('text-center').addClass('text-info');
534 $dashlet.append($none)
540 $('.dash .nav a', '#main').click(function() {
542 var $li = $(this).parent();
543 var $ul = $li.parent();
544 one.lib.nav.unfocus($ul);
545 $li.addClass('active');
546 // clear respective dashlet
547 var $dashlet = $ul.parent().find('.dashlet');
548 one.lib.dashlet.empty($dashlet);
549 // callback based on menu
550 var id = $(this).attr('id');
551 var menu = one.f.dashlet;
553 case menu.existingNodes.id:
554 one.f.troubleshooting.existingNodes.load.main($dashlet);
557 one.f.troubleshooting.uptime.dashlet($dashlet);
559 case menu.flowsOrPorts.id:
560 one.f.troubleshooting.statistics.dashlet($dashlet);
565 // activate first tab on each dashlet
566 $('.dash .nav').each(function(index, value) {
567 $($(value).find('li')[0]).find('a').click();