summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-babeld/root/www/luci-static/resources/babeld.js
blob: 864010ef6c8de306d4d0bd7c0e1070a5ed75d5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
function ubus_call(command, argument, params) {
    var request_data = {};
    request_data.jsonrpc = "2.0";
    request_data.method = "call";
    request_data.params = [data.ubus_rpc_session, command, argument, params]
    var request_json = JSON.stringify(request_data);
    var request = new XMLHttpRequest();
    request.open("POST", ubus_url, false);
    request.setRequestHeader("Content-type", "application/json");
    request.send(request_json);
    if (request.status === 200) {
        var response = JSON.parse(request.responseText)
        if (!("error" in response) && "result" in response) {
            if (response.result.length === 2) {
                return response.result[1];
            }
        } else {
            console.err("Failed query ubus!");
        }
    }
}

function renderTableXRoutes(data, target_id) {
    for (var protocol in data) {
        var target = document.getElementById(target_id);

        var title = document.createElement('h3');
        title.appendChild(document.createTextNode('X-Routes ' + protocol));
        target.appendChild(title);

        var table = document.createElement('div');
        table.setAttribute('class', 'table');
        table.setAttribute('id', 'babel_overview_xroutes_' + protocol);

        var headerRow = document.createElement('div');
        headerRow.setAttribute('class', 'tr table-titles');
        var headerContent = '<div class="th" style="font-weight: 700;">' + protocol + ' Prefix</div>\
                             <div class="th" style="font-weight: 700;">Metric</div>\
                             <div class="th" style="font-weight: 700;">Source-Prefix</div>';

        headerRow.innerHTML = headerContent;
        table.appendChild(headerRow);


        for (var prefix in data[protocol]) {
            var prefixRow = document.createElement('div');
            prefixRow.setAttribute('class', 'tr');
            var prefixContent = '<div class="td" data-title="xroutes_' + protocol + '_prefix">' + prefix + '</div>\
                                 <div class="td" data-title="xroutes_' + protocol + '_metric">' + data[protocol][prefix]["metric"] + '</div>\
                                 <div class="td" data-title="xroutes_' + protocol + '_src-prefix">' + data[protocol][prefix]["src-prefix"] + '</div>';

            prefixRow.innerHTML = prefixContent;
            table.appendChild(prefixRow);
        }
        target.appendChild(table);
    }
}

function renderTableRoutes(data, target_id) {
    for (var protocol in data) {
        var target = document.getElementById(target_id);

        var title = document.createElement('h3');
        title.appendChild(document.createTextNode('Routes ' + protocol));
        target.appendChild(title);

        var table = document.createElement('div');
        table.setAttribute('class', 'table');
        table.setAttribute('id', 'babel_overview_routes_' + protocol);

        var headerRow = document.createElement('div');
        headerRow.setAttribute('class', 'tr table-titles');
        var headerContent = '<div class="th" style="font-weight: 700;">' + protocol + ' Prefix</div>\
                             <div class="th" style="font-weight: 700;">Source-Prefix</div>\
                             <div class="th" style="font-weight: 700;">Route-Metric</div>\
                             <div class="th" style="font-weight: 700;">Route Smoothed Metric</div>\
                             <div class="th" style="font-weight: 700;">Refmetric</div>\
                             <div class="th" style="font-weight: 700;">ID</div>\
                             <div class="th" style="font-weight: 700;">Seq. No.</div>\
                             <div class="th" style="font-weight: 700;">Channes</div>\
                             <div class="th" style="font-weight: 700;">Age</div>\
                             <div class="th" style="font-weight: 700;">Via</div>\
                             <div class="th" style="font-weight: 700;">Nexthop</div>\
                             <div class="th" style="font-weight: 700;">Installed</div>\
                             <div class="th" style="font-weight: 700;">Feasible</div>';

        headerRow.innerHTML = headerContent;
        table.appendChild(headerRow);

        for (var prefix in data[protocol]) {
            var prefixRow = document.createElement('div');
            prefixRow.setAttribute('class', 'tr');
            var prefixContent = '<div class="td" data-title="routes_' + protocol + '_prefix">' + prefix + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_src-prefix">' + data[protocol][prefix]["src-prefix"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_metric">' + data[protocol][prefix]["route_metric"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_rout-smoothed-metric">' + data[protocol][prefix]["route_smoothed_metric"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_refmetric">' + data[protocol][prefix]["refmetric"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_id">' + data[protocol][prefix]["id"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_seqno">' + data[protocol][prefix]["seqno"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_channels">' + data[protocol][prefix]["channels"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_age">' + data[protocol][prefix]["age"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_via">' + data[protocol][prefix]["via"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_nexthop">' + data[protocol][prefix]["nexthop"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_installed">' + data[protocol][prefix]["installed"] + '</div>\
                                 <div class="td" data-title="routes_' + protocol + '_feasible">' + data[protocol][prefix]["feasible"] + '</div>';

            prefixRow.innerHTML = prefixContent;
            table.appendChild(prefixRow);
        }
        target.appendChild(table);
    }
}

function renderTableNeighbours(data, target_id) {
    for (var protocol in data) {
        var target = document.getElementById(target_id);

        var title = document.createElement('h3');
        title.appendChild(document.createTextNode('Neighbours ' + protocol));
        target.appendChild(title);

        var table = document.createElement('div');
        table.setAttribute('class', 'table');
        table.setAttribute('id', 'babel_overview_neighbours_' + protocol);

        var headerRow = document.createElement('div');
        headerRow.setAttribute('class', 'tr table-titles');
        var headerContent = '<div class="th" style="font-weight: 700;">' + protocol + ' Neighbour</div>\
                             <div class="th" style="font-weight: 700;">Device</div>\
                             <div class="th" style="font-weight: 700;">Hello-Reach</div>\
                             <div class="th" style="font-weight: 700;">RX cost</div>\
                             <div class="th" style="font-weight: 700;">TX cost</div>\
                             <div class="th" style="font-weight: 700;">RTT</div>\
                             <div class="th" style="font-weight: 700;">Channel</div>\
                             <div class="th" style="font-weight: 700;">Interface up</div>';

        headerRow.innerHTML = headerContent;
        table.appendChild(headerRow);

        for (var neighbour in data[protocol]) {
            var neighbourRow = document.createElement('div');
            neighbourRow.setAttribute('class', 'tr');
            var neighbourContent = '<div class="td" data-title="' + protocol + '_neighbour">' + neighbour + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_dev">' + data[protocol][neighbour]["dev"] + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_hello-reach">' + data[protocol][neighbour]["hello-reach"] + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_rxcost">' + data[protocol][neighbour]["rxcost"] + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_txcost">' + data[protocol][neighbour]["txcost"] + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_rtt">' + data[protocol][neighbour]["rtt"] + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_channel">' + data[protocol][neighbour]["channel"] + '</div>\
                                    <div class="td" data-title="neighbours_' + protocol + '_if_up">' + data[protocol][neighbour]["if_up"] + '</div>';

            neighbourRow.innerHTML = neighbourContent;
            table.appendChild(neighbourRow);
        }
        target.appendChild(table);
    }
}

function renderTableInfo(data, target_id) {
    var target = document.getElementById(target_id);

    var title = document.createElement('h3');
    title.appendChild(document.createTextNode('Info'));
    target.appendChild(title);

    var table = document.createElement('div');
    table.setAttribute('class', 'table');
    table.setAttribute('id', 'babel_overview_info');


    var headerRow = document.createElement('div');
    headerRow.setAttribute('class', 'tr table-titles');
    var headerContent = '<div class="th" style="font-weight: 700;">Babeld Version</div>\
                         <div class="th" style="font-weight: 700;">My-ID</div>\
                         <div class="th" style="font-weight: 700;">Host</div>';

    headerRow.innerHTML = headerContent;
    table.appendChild(headerRow);

    var neighbourRow = document.createElement('div');
    neighbourRow.setAttribute('class', 'tr');
    var neighbourContent = '<div class="td" data-title="info_babeld-version">' + data["babeld-version"] + '</div>\
                            <div class="td" data-title="info_dev">' + data["my-id"] + '</div>\
                            <div class="td" data-title="info_hello-reach">' + data["host"] + '</div>';

    neighbourRow.innerHTML = neighbourContent;
    table.appendChild(neighbourRow);
    target.appendChild(table);
}