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('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_xroutes_' + protocol);
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '
' + protocol + ' Prefix | \
Metric | \
Source-Prefix | ';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (var prefix in data[protocol]) {
var prefixRow = document.createElement('tr');
prefixRow.setAttribute('class', 'tr');
var prefixContent = '' + prefix + ' | \
' + data[protocol][prefix]["metric"] + ' | \
' + data[protocol][prefix]["src-prefix"] + ' | ';
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('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_routes_' + protocol);
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '' + protocol + ' Prefix | \
Source-Prefix | \
Route-Metric | \
Route Smoothed Metric | \
Refmetric | \
ID | \
Seq. No. | \
Channes | \
Age | \
Via | \
Nexthop | \
Installed | \
Feasible | ';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (var prefix in data[protocol]) {
var prefixRow = document.createElement('tr');
prefixRow.setAttribute('class', 'tr');
var prefixContent = '' + prefix + ' | \
' + data[protocol][prefix]["src-prefix"] + ' | \
' + data[protocol][prefix]["route_metric"] + ' | \
' + data[protocol][prefix]["route_smoothed_metric"] + ' | \
' + data[protocol][prefix]["refmetric"] + ' | \
' + data[protocol][prefix]["id"] + ' | \
' + data[protocol][prefix]["seqno"] + ' | \
' + data[protocol][prefix]["channels"] + ' | \
' + data[protocol][prefix]["age"] + ' | \
' + data[protocol][prefix]["via"] + ' | \
' + data[protocol][prefix]["nexthop"] + ' | \
' + data[protocol][prefix]["installed"] + ' | \
' + data[protocol][prefix]["feasible"] + ' | ';
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('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_neighbours_' + protocol);
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '' + protocol + ' Neighbour | \
Device | \
Hello-Reach | \
RX cost | \
TX cost | \
RTT | \
Channel | \
Interface up | ';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (var neighbour in data[protocol]) {
var neighbourRow = document.createElement('tr');
neighbourRow.setAttribute('class', 'tr');
var neighbourContent = '' + neighbour + ' | \
' + data[protocol][neighbour]["dev"] + ' | \
' + data[protocol][neighbour]["hello-reach"] + ' | \
' + data[protocol][neighbour]["rxcost"] + ' | \
' + data[protocol][neighbour]["txcost"] + ' | \
' + data[protocol][neighbour]["rtt"] + ' | \
' + data[protocol][neighbour]["channel"] + ' | \
' + data[protocol][neighbour]["if_up"] + ' | ';
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('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_info');
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = 'Babeld Version | \
My-ID | \
Host | ';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
var neighbourRow = document.createElement('tr');
neighbourRow.setAttribute('class', 'tr');
var neighbourContent = '' + data["babeld-version"] + ' | \
' + data["my-id"] + ' | \
' + data["host"] + ' | ';
neighbourRow.innerHTML = neighbourContent;
table.appendChild(neighbourRow);
target.appendChild(table);
}