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 clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer);
123 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/flowStats?nodeId=" + nodeId, function(content) {
124 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
125 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Flows");
126 one.lib.dashlet.empty($rightBottomDashlet);
127 $rightBottomDashlet.append(one.lib.dashlet.header("Flow Details"));
129 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.flowsDataGrid, {
133 flexibleRowsPerPage: true
134 }, "table-striped table-condensed");
135 $rightBottomDashlet.append($gridHTML);
136 var dataSource = one.f.troubleshooting.existingNodes.data.flowsGrid(content);
137 $("#" + one.f.troubleshooting.existingNodes.id.flowsDataGrid).datagrid({dataSource: dataSource});
139 var numberOfFlows = content.nodeData.length;
140 var refreshRate = one.f.troubleshooting.existingNodes.autoRefreshInterval.flows;
141 if (numberOfFlows > 0) {
142 refreshRate += Math.floor(numberOfFlows / 500) *
143 one.f.troubleshooting.existingNodes.autoRefreshInterval.refreshRateInterval;
145 one.f.troubleshooting.existingNodes.registry.refreshTimer = setTimeout(
146 one.f.troubleshooting.existingNodes.load.flows,
147 refreshRate, nodeId);
151 ports: function(nodeId) {
153 clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer);
154 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/portStats?nodeId=" + nodeId, function(content) {
155 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
156 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Ports");
157 one.lib.dashlet.empty($rightBottomDashlet);
158 $rightBottomDashlet.append(one.lib.dashlet.header("Port Details"));
160 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.portsDataGrid, {
164 flexibleRowsPerPage: true
165 }, "table-striped table-condensed");
166 $rightBottomDashlet.append($gridHTML);
167 var dataSource = one.f.troubleshooting.existingNodes.data.portsGrid(content);
168 $("#" + one.f.troubleshooting.existingNodes.id.portsDataGrid).datagrid({dataSource: dataSource});
170 var numberOfPorts = content.nodeData.length;
171 var refreshRate = one.f.troubleshooting.existingNodes.autoRefreshInterval.ports;
172 if (numberOfPorts > 0) {
173 refreshRate += Math.floor(numberOfPorts / 500) *
174 one.f.troubleshooting.existingNodes.autoRefreshInterval.refreshRateInterval;
176 one.f.troubleshooting.existingNodes.registry.refreshTimer = setTimeout(
177 one.f.troubleshooting.existingNodes.load.ports,
178 refreshRate, nodeId);
183 ajax : function(url, callback) {
184 $.getJSON(url, function(data) {
192 existingNodesGrid: function(data) {
193 var source = new StaticDataSource({
196 property: 'nodeName',
202 label: 'Static Route',
206 property: 'statistics',
212 formatter: function(items) {
213 $.each(items, function(index, item) {
214 item["statistics"] = "<a href=\"javascript:one.f.troubleshooting.existingNodes.load.flows('" + item["nodeId"] + "');\">Flows</a>" +
215 " <a href=\"javascript:one.f.troubleshooting.existingNodes.load.ports('" + item["nodeId"] + "');\">Ports</a>";
223 portsGrid: function(data) {
224 var source = new StaticDataSource({
227 property: 'nodeConnector',
228 label: 'Node Connector',
262 property: 'rxErrors',
267 property: 'txErrors',
272 property: 'rxFrameErrors',
273 label: 'Rx Frame Errs',
277 property: 'rxOverRunErrors',
278 label: 'Rx OverRun Errs',
282 property: 'rxCRCErrors',
283 label: 'Rx CRC Errs',
287 property: 'collisions',
297 ports: function(data) {
299 $.each(data.nodeData, function(key, value) {
302 entry.push(value["nodeConnector"]);
303 entry.push(value["rxPkts"]);
304 entry.push(value["txPkts"]);
305 entry.push(value["rxBytes"]);
306 entry.push(value["txBytes"]);
307 entry.push(value["rxDrops"]);
308 entry.push(value["txDrops"]);
309 entry.push(value["rxErrors"]);
310 entry.push(value["txErrors"]);
311 entry.push(value["rxFrameErrors"]);
312 entry.push(value["rxOverRunErrors"]);
313 entry.push(value["rxCRCErrors"]);
314 entry.push(value["collisions"]);
320 flowsGrid: function(data) {
321 var source = new StaticDataSource({
324 property: 'nodeName',
384 property: 'byteCount',
389 property: 'packetCount',
390 label: 'Packet Count',
394 property: 'durationSeconds',
395 label: 'Duration Seconds',
399 property: 'idleTimeout',
400 label: 'Idle Timeout',
404 property: 'priority',
414 flows: function(data) {
416 $.each(data.nodeData, function(key, value) {
419 entry.push(value["nodeName"]);
420 entry.push(value["inPort"]);
421 entry.push(value["dlSrc"]);
422 entry.push(value["dlDst"]);
423 entry.push(value["dlType"]);
424 entry.push(value["dlVlan"]);
425 entry.push(value["nwSrc"]);
426 entry.push(value["nwDst"]);
427 entry.push(value["nwProto"]);
428 entry.push(value["tpSrc"]);
429 entry.push(value["tpDst"]);
430 entry.push(value["actions"]);
431 entry.push(value["byteCount"]);
432 entry.push(value["packetCount"]);
433 entry.push(value["durationSeconds"]);
434 entry.push(value["idleTimeout"]);
435 entry.push(value["priority"]);
444 one.f.troubleshooting.uptime = {
446 popout: "one_f_troubleshooting_uptime_id_popout",
447 modal: "one_f_troubleshooting_uptime_id_modal",
448 datagrid: "one_f_troubleshooting_uptime_id_datagrid"
451 dashlet: function($dashlet) {
452 one.lib.dashlet.empty($dashlet);
453 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
454 var url = one.f.troubleshooting.rootUrl + "/uptime";
455 one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
456 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.uptime.id.datagrid, {
460 flexibleRowsPerPage: true
461 }, "table-striped table-condensed");
462 $dashlet.append($gridHTML);
463 var dataSource = one.f.troubleshooting.uptime.data.uptimeDataGrid(content);
464 $("#" + one.f.troubleshooting.uptime.id.datagrid).datagrid({dataSource: dataSource});
469 main : function(url, requestData, callback) {
470 $.getJSON(url, requestData, function(data) {
477 uptimeDataGrid: function(data) {
478 var source = new StaticDataSource({
481 property: 'nodeName',
491 property: 'connectedSince',
501 uptime: function(data) {
503 $.each(data.nodeData, function(key, value) {
506 entry.push(value["nodeName"]);
507 entry.push(value["nodeId"]);
508 entry.push(value["connectedSince"]);
517 one.f.troubleshooting.statistics = {
518 dashlet : function($dashlet) {
519 var $h4 = one.lib.dashlet.header("Statistics");
520 $dashlet.append($h4);
522 var $none = $(document.createElement('div'));
523 $none.addClass('none');
524 var $p = $(document.createElement('p'));
525 $p.text('Please select a Flow or Ports statistics');
526 $p.addClass('text-center').addClass('text-info');
528 $dashlet.append($none)
534 $('.dash .nav a', '#main').click(function() {
536 var $li = $(this).parent();
537 var $ul = $li.parent();
538 one.lib.nav.unfocus($ul);
539 $li.addClass('active');
540 // clear respective dashlet
541 var $dashlet = $ul.parent().find('.dashlet');
542 one.lib.dashlet.empty($dashlet);
543 // callback based on menu
544 var id = $(this).attr('id');
545 var menu = one.f.dashlet;
547 case menu.existingNodes.id:
548 one.f.troubleshooting.existingNodes.load.main($dashlet);
551 one.f.troubleshooting.uptime.dashlet($dashlet);
553 case menu.flowsOrPorts.id:
554 one.f.troubleshooting.statistics.dashlet($dashlet);
559 // activate first tab on each dashlet
560 $('.dash .nav').each(function(index, value) {
561 $($(value).find('li')[0]).find('a').click();