1 // Copyright (c) 2018 Maen Artimy
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
16 // Main code to handle flow tables
18 var tabsObj = new Tabs('switches');
19 var tablesObj = new Tables('flow');
21 // Flow fields supported by OF1.3
23 "priority": ["Priority", "number"],
24 "match": ["Match Fields", "alphanum"],
25 "cookie": ["Cookie", "number"],
26 "duration_sec": ["Duration", "number"],
27 "idle_timeout": ["Idle\nTimeout", "number"],
28 "hard_timeout": ["Hard\nTimeout", "number"],
29 "actions": ["Instructions", "alphanum"],
30 "packet_count": ["Packet\nCount", "number"],
31 "byte_count": ["Byte\nCount", "number"],
32 "flags": ["Flags", "number"]
35 // Table Header Mapping Function
36 function headerMapping(orgstr) {
37 var map = header_of13;
38 var newstr = map[orgstr] != null ? map[orgstr][0] : hc(orgstr);
39 var newtype = map[orgstr] != null ? map[orgstr][1] : "number";
40 return [newstr, newtype];
43 // Create Flow Table database
44 function buildFlowTables(dpid, flwlist) {
45 var thelist = JSON.parse(fix_compatibility(JSON.stringify(flwlist)));
47 var fields = Object.keys(header_of13);
50 thelist.forEach(function (flow) {
51 var table_id = flow['table_id'];
52 if (!dp_tables[table_id]) {
53 dp_tables[table_id] = new DPTable(table_id, "flows", "Flow Table", fields, [], dpid);
55 dp_tables[table_id].data.push(flow);
58 //console.log(db_tables)
59 var $envelope = $('<div></div>');
60 for (var i in dp_tables) {
61 var dp_table = dp_tables[i]
62 tablesObj.makeRows(dpid, dp_table, headerMapping, cellFormating);
63 var $card = tablesObj.buildTableCard(dp_table);
64 $envelope.append($card);
69 // Get flows data from swicthes
70 function loadFlows() {
74 tabsObj.buildTabs("#main", sw_list, "Not flows to show!");
76 function (all_flows) {
77 for (var i in all_flows) {
78 var sw = Object.keys(all_flows[i])[0] // the first key is the datapath id
79 var flows = all_flows[i][sw]
80 if (flows.length > 0) {
81 var $envelope = buildFlowTables(sw, flows);
82 tabsObj.buildContent(sw, $envelope);
90 // When the refresh button is clicked, clear the page and start over
91 $("[name='refresh']").on('click', function () {
98 function startRefresh() {
99 setTimeout(startRefresh,30000);
105 // function autoRefreshPage() {
108 // setInterval(loadFlows, 5000);