Skip to content

Commit dade5c1

Browse files
authored
webapp: fix asviz.js (#184)
The json returned by the /getastopo endpoint has changed; it directly marshals the return value of the sciond API requests and these types have been changed (a rather long time ago). The service IDs used as keys here have also changed. Adapt the JS code to deal with the new (simpler) data format. Remove various unused helper function.
1 parent 35f60e3 commit dade5c1

File tree

1 file changed

+30
-131
lines changed

1 file changed

+30
-131
lines changed

webapp/web/static/js/asviz.js

Lines changed: 30 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ var sv_r = 11; // service node radius
3131
var as_st = 6; // AS node stroke
3232
var sv_st = 2; // service node stroke
3333

34-
/*
35-
* Focuses the active tab to the tab label.
36-
*/
37-
function activateTab(tab) {
38-
$('.tab-pane a[href="#' + tab + '"]').tab('show');
39-
};
40-
41-
/*
42-
* Returns the tab label of the active tab
43-
*/
44-
function getTab() {
45-
return $("ul#sampleTabs li.active")
46-
}
47-
4834
/*
4935
* Creates on-click handler that will draw/hide selected path arcs.
5036
*/
@@ -399,26 +385,20 @@ function updateNodeSelected(isSelected, selected) {
399385

400386
var svc_pre = {
401387
0 : "unset", // Not set
402-
1 : "bs", // Beacon service
403-
2 : "ps", // Path service
404-
3 : "cs", // Certificate service
405-
4 : "sb", // SIBRA service
406-
5 : "ds", // Discovery service
407-
6 : "br", // Border router
408-
7 : "sig", // SCION-IP gateway
409-
8 : "hps", // Hidden Path service
388+
1 : "ds",
389+
2 : "cs",
390+
3 : "sb",
391+
4 : "sig",
392+
5 : "hps",
410393
};
411394

412395
var svc_service = {
413396
0 : "unset",
414-
1 : "BEACON",
415-
2 : "PATH",
416-
3 : "CERTIFICATE",
417-
4 : "SIBRA",
418-
5 : "GATEWAY",
419-
6 : "DISCOVERY",
420-
7 : "SIG",
421-
8 : "HIDDEN PATH",
397+
1 : "Discovery Service",
398+
2 : "Control Service",
399+
3 : "SIBRA",
400+
4 : "SIG",
401+
5 : "Hidden Path Service",
422402
};
423403

424404
function get_json_as_topo(data, width, height) {
@@ -431,16 +411,14 @@ function get_json_as_topo(data, width, height) {
431411
"links" : []
432412
};
433413
}
434-
var a = data.as_info.Entries[0];
435-
var ia = iaRaw2Read(a.RawIsdas);
436-
var iaf = iaRaw2File(a.RawIsdas);
414+
var a = data.as_info
415+
var iaf = a.IA.replace(/:/g, "_")
437416

438417
// asinfo: add AS root node
439418
var asnode = {};
440-
asnode.name = ia;
419+
asnode.name = a.IA;
441420
asnode.service = "ISD-AS";
442-
asnode.mtu = a.Mtu;
443-
asnode.is_core_as = a.IsCore;
421+
asnode.mtu = a.MTU;
444422
asnode.type = "root";
445423
asnode.group = gidx;
446424
// fix root in center
@@ -449,34 +427,23 @@ function get_json_as_topo(data, width, height) {
449427
asnode.fixed = true;
450428
nodes.push(asnode);
451429

452-
var sinfos = data.svc_info.Entries;
430+
var sinfos = data.svc_info;
453431
for (s in sinfos) {
454-
var st = sinfos[s].ServiceType;
455432
gidx += 1;
456-
var hinfos = sinfos[s].HostInfos;
457-
for (h in hinfos) {
458-
// svcinfo: add all service nodes
459-
var snode = {};
460-
snode.name = svc_pre[st] + iaf + "-" + (parseInt(h) + 1);
461-
snode.service = svc_service[st];
462-
snode.ttl = sinfos[s].Ttl;
463-
if (hinfos[h].Addrs.IPv4) {
464-
snode.ipv4 = ipv4Raw2Read(hinfos[h].Addrs.IPv4);
465-
}
466-
if (hinfos[h].Addrs.IPv6) {
467-
snode.ipv6 = ipv6Raw2Read(hinfos[h].Addrs.IPv6);
468-
}
469-
snode.port = hinfos[h].Port;
470-
snode.type = "service";
471-
snode.group = gidx;
472-
nodes.push(snode);
473-
// svcinfo: add internal links to service nodes
474-
var slink = {};
475-
slink.source = asnode.name;
476-
slink.target = snode.name;
477-
slink.type = "as-in";
478-
links.push(slink);
479-
}
433+
// svcinfo: add all service nodes
434+
var snode = {};
435+
snode.name = svc_pre[s] + iaf
436+
snode.service = svc_service[s];
437+
snode.addr = sinfos[s]
438+
snode.type = "service";
439+
snode.group = gidx;
440+
nodes.push(snode);
441+
// svcinfo: add internal links to service nodes
442+
var slink = {};
443+
slink.source = asnode.name;
444+
slink.target = snode.name;
445+
slink.type = "as-in";
446+
links.push(slink);
480447
}
481448

482449
// consider each unique ip/port as a single border router, which may
@@ -495,10 +462,9 @@ function get_json_as_topo(data, width, height) {
495462
var snode = {};
496463
brs[brkey] = "br" + iaf + "-" + (Object.keys(brs).length + 1);
497464
snode.name = brs[brkey];
498-
snode.service = "BORDER";
465+
snode.service = "Border Router";
499466
snode.ipv4 = ipv4;
500467
snode.port = port;
501-
snode.if_id = ""; // no longer in if_info in sciond
502468
snode.zone = zone;
503469
snode.type = "router";
504470
snode.group = gidx;
@@ -564,70 +530,3 @@ function showError(err) {
564530
$("#as-error").empty();
565531
}
566532
}
567-
568-
function htmlDecode(htmlIn) {
569-
var e = document.createElement('div');
570-
e.innerHTML = htmlIn;
571-
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
572-
}
573-
574-
function ab2str(ab) {
575-
return String.fromCharCode.apply(null, new Uint8Array(ab));
576-
}
577-
578-
function str2ab(str) {
579-
var buf = new ArrayBuffer(str.length);
580-
var bufView = new Uint8Array(buf);
581-
for (var i = 0; i < str.length; i++) {
582-
bufView[i] = str.charCodeAt(i);
583-
}
584-
return buf;
585-
}
586-
587-
function toBytesUInt32(num) {
588-
var ab = new ArrayBuffer(4);
589-
var view = new DataView(ab);
590-
view.setInt32(0, num, false);
591-
return ab;
592-
}
593-
594-
function fromBytesUInt32(ab) {
595-
var view = new DataView(ab);
596-
return view.getInt32(0, false);
597-
}
598-
599-
function reduceHex(hex) {
600-
return parseInt(hex, 16).toString(16);
601-
}
602-
603-
function iaRawCompose(rawIa) {
604-
var parts = [];
605-
var hex = rawIa.toString(16);
606-
var isd = parseInt(hex.slice(0, -12), 16);
607-
var as1 = reduceHex(hex.slice(-12, -8));
608-
var as2 = reduceHex(hex.slice(-8, -4));
609-
var as3 = reduceHex(hex.slice(-4));
610-
return [ isd, as1, as2, as3 ];
611-
}
612-
613-
function iaRaw2Read(rawIa) {
614-
var parts = iaRawCompose(rawIa);
615-
return parts[0] + '-' + parts.slice(1, 4).join(':');
616-
}
617-
618-
function iaRaw2File(rawIa) {
619-
var parts = iaRawCompose(rawIa);
620-
return parts[0] + '-' + parts.slice(1, 4).join('_');
621-
}
622-
623-
function ipv4Raw2Read(rawIpv4) {
624-
var b = atob(rawIpv4); // decode
625-
var a = new Uint8Array(str2ab(b));
626-
var ipv4 = a.join('.');
627-
return ipv4;
628-
}
629-
630-
// TODO: needs decoding
631-
function ipv6Raw2Read(rawIpv6) {
632-
return rawIpv6;
633-
}

0 commit comments

Comments
 (0)