3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
14 // specify dashlets and layouts
18 name : 'Existing Nodes'
33 one.f.dashlet.existingNodes
42 one.f.dashlet.flowsOrPorts
49 $(one.f.menu.left.top).each(function(index, value) {
50 var $nav = $(".nav", "#left-top");
51 one.main.page.dashlet($nav, value);
54 $(one.f.menu.left.bottom).each(function(index, value) {
55 var $nav = $(".nav", "#left-bottom");
56 one.main.page.dashlet($nav, value);
59 $(one.f.menu.right.bottom).each(function(index, value) {
60 var $nav = $(".nav", "#right-bottom");
61 one.main.page.dashlet($nav, value);
64 /**Troubleshoot modules*/
65 one.f.troubleshooting = {
66 rootUrl: "/one/troubleshoot",
69 var $rightBottomDashlet = $("#right-bottom").find(".dashlet");
70 return $rightBottomDashlet;
72 setDashletHeader: function(label) {
73 $("#right-bottom li a")[0].innerHTML = label;
76 createTable: function(columnNames, body) {
77 var tableAttributes = ["table-striped", "table-bordered", "table-condensed"];
78 var $table = one.lib.dashlet.table.table(tableAttributes);
79 var tableHeaders = columnNames;
80 var $thead = one.lib.dashlet.table.header(tableHeaders);
81 var $tbody = one.lib.dashlet.table.body(body, tableHeaders);
88 one.f.troubleshooting.existingNodes = {
90 popout: "one_f_troubleshooting_existingNodes_id_popout",
91 modal: "one_f_troubleshooting_existingNodes_id_modal"
94 main: function($dashlet) {
95 one.lib.dashlet.empty($dashlet);
96 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.existingNodes.name));
98 // TODO(l): Add a generic auto expand function to one.lib and replace custom height setting.
99 //$('#left-top').height('100%');
100 one.f.troubleshooting.existingNodes.ajax(one.f.troubleshooting.rootUrl + "/existingNodes" , function(content) {
101 var body = one.f.troubleshooting.existingNodes.data.existingNodes(content);
102 var $table = one.f.troubleshooting.createTable(content.columnNames, body);
103 $dashlet.append($table);
106 flows: function(nodeId) {
108 clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer);
109 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/flowStats?nodeId=" + nodeId, function(content) {
110 var body = one.f.troubleshooting.existingNodes.data.flows(content);
111 var $table = one.f.troubleshooting.createTable(content.columnNames, body);
112 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
113 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Flows");
114 one.lib.dashlet.empty($rightBottomDashlet);
115 $rightBottomDashlet.append(one.lib.dashlet.header("Flow Details"));
116 $rightBottomDashlet.append($table);
117 one.f.troubleshooting.existingNodes.registry.refreshTimer = setTimeout(
118 one.f.troubleshooting.existingNodes.load.flows, 5000, nodeId);
122 ports: function(nodeId) {
124 clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer);
125 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/portStats?nodeId=" + nodeId, function(content) {
126 var body = one.f.troubleshooting.existingNodes.data.ports(content);
127 var $table = one.f.troubleshooting.createTable(content.columnNames, body);
128 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
129 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Ports");
130 one.lib.dashlet.empty($rightBottomDashlet);
131 $rightBottomDashlet.append(one.lib.dashlet.header("Port Details"));
132 $rightBottomDashlet.append($table);
133 one.f.troubleshooting.existingNodes.registry.refreshTimer = setTimeout(
134 one.f.troubleshooting.existingNodes.load.ports, 5000, nodeId);
139 ajax : function(url, callback) {
140 $.getJSON(url, function(data) {
148 existingNodes : function(data) {
150 $.each(data.nodeData, function(key, value) {
153 entry.push(value["nodeName"]);
154 entry.push(value["nodeId"]);
155 var nodeIdvalue = value["nodeId"];
156 entry.push("<a href=\"javascript:one.f.troubleshooting.existingNodes.load.flows('" + value["nodeId"] + "');\">Flows</a>" +
157 " <a href=\"javascript:one.f.troubleshooting.existingNodes.load.ports('" + value["nodeId"] + "');\">Ports</a>");
163 ports: function(data) {
165 $.each(data.nodeData, function(key, value) {
168 entry.push(value["nodeConnector"]);
169 entry.push(value["rxPkts"]);
170 entry.push(value["txPkts"]);
171 entry.push(value["rxBytes"]);
172 entry.push(value["txBytes"]);
173 entry.push(value["rxDrops"]);
174 entry.push(value["txDrops"]);
175 entry.push(value["rxErrors"]);
176 entry.push(value["txErrors"]);
177 entry.push(value["rxFrameErrors"]);
178 entry.push(value["rxOverRunErrors"]);
179 entry.push(value["rxCRCErrors"]);
180 entry.push(value["collisions"]);
186 flows: function(data) {
188 $.each(data.nodeData, function(key, value) {
191 entry.push(value["nodeName"]);
192 entry.push(value["inPort"]);
193 entry.push(value["dlSrc"]);
194 entry.push(value["dlDst"]);
195 entry.push(value["dlType"]);
196 entry.push(value["dlVlan"]);
197 entry.push(value["nwSrc"]);
198 entry.push(value["nwDst"]);
199 entry.push(value["nwProto"]);
200 entry.push(value["tpSrc"]);
201 entry.push(value["tpDst"]);
202 entry.push(value["actions"]);
203 entry.push(value["byteCount"]);
204 entry.push(value["packetCount"]);
205 entry.push(value["durationSeconds"]);
206 entry.push(value["idleTimeout"]);
207 entry.push(value["outPorts"]);
208 entry.push(value["outVlanId"]);
209 entry.push(value["priority"]);
218 one.f.troubleshooting.uptime = {
220 popout: "one_f_troubleshooting_existingNodes_id_popout",
221 modal: "one_f_troubleshooting_existingNodes_id_modal"
224 dashlet: function($dashlet) {
225 one.lib.dashlet.empty($dashlet);
226 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
227 var url = one.f.troubleshooting.rootUrl + "/uptime";
228 one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
229 var body = one.f.troubleshooting.uptime.data.uptime(content);
230 var $table = one.f.troubleshooting.createTable(content.columnNames, body);
231 $dashlet.append($table);
236 main : function(url, requestData, callback) {
237 $.getJSON(url, requestData, function(data) {
244 uptime: function(data) {
246 $.each(data.nodeData, function(key, value) {
249 entry.push(value["nodeName"]);
250 entry.push(value["nodeId"]);
251 entry.push(value["connectedSince"]);
260 one.f.troubleshooting.statistics = {
261 dashlet : function($dashlet) {
262 var $h4 = one.lib.dashlet.header("Statistics");
263 $dashlet.append($h4);
265 var $none = $(document.createElement('div'));
266 $none.addClass('none');
267 var $p = $(document.createElement('p'));
268 $p.text('Please select a Flow or Ports statistics');
269 $p.addClass('text-center').addClass('text-info');
271 $dashlet.append($none)
277 $('.dash .nav a', '#main').click(function() {
279 var $li = $(this).parent();
280 var $ul = $li.parent();
281 one.lib.nav.unfocus($ul);
282 $li.addClass('active');
283 // clear respective dashlet
284 var $dashlet = $ul.parent().find('.dashlet');
285 one.lib.dashlet.empty($dashlet);
286 // callback based on menu
287 var id = $(this).attr('id');
288 var menu = one.f.dashlet;
290 case menu.existingNodes.id:
291 one.f.troubleshooting.existingNodes.load.main($dashlet);
294 one.f.troubleshooting.uptime.dashlet($dashlet);
296 case menu.flowsOrPorts.id:
297 one.f.troubleshooting.statistics.dashlet($dashlet);
302 // activate first tab on each dashlet
303 $('.dash .nav').each(function(index, value) {
304 $($(value).find('li')[0]).find('a').click();