-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeeringdb.html
146 lines (121 loc) · 3.69 KB
/
peeringdb.html
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
<html>
<head>
<script type="text/javascript" src="https://cdn.rawgit.com/almende/vis/master/dist/vis.js"></script>
<link href="https://cdn.rawgit.com/almende/vis/master/dist/vis.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#mynetwork {
width: 1200px;
height: 800px;
border: 1px solid lightgray;
}
</style>
</head>
<body onload="draw();">
ASN: <input type="text" id="peeringASN" value="">
<p>Click the button to draw their Peering Infra. Please only input one ASN per button click (Will fix soon)</p>
<input type="button" onclick="updateGraph()" value="Draw it!"> <br />
<div id="mynetwork"></div>
<table id="table">
<tr id="row">
<td>Remove ASN</td><td>Highlight</td>
</tr>
</table>
<script type="text/javascript">
var nodes, edges, network, data, container;
var group = 0;
function updateGraph() {
asn = document.getElementById("peeringASN").value
var req = new XMLHttpRequest();
req.open("GET", "https://unicast.network/api/net?depth=2&asn=" + asn, false);
req.send(null);
asnIX = JSON.parse(req.responseText);
var ix_num = asnIX["data"][0]["netixlan_set"];
var node,link;
nodes.add([ {"id": asnIX["data"][0]["asn"], "label": asnIX["data"][0]["name"], "group": group } ]);
for (var i = 0; i < ix_num.length; i++){
name = ix_num[i]["name"];
node = {"id": name, "label": ix_num[i]["name"]};
node_c = {"id": name, "label": ix_num[i]["name"], color: "red"};
link = {"to": name, "from": asnIX["data"][0]["asn"]};
edges.add([link]);
try { nodes.add([node]); } // End try
// Catch logic should detect if there is 2x links from same ASN, or links to different ASN here.
catch(err){
console.log("updating " + name );
nodes.update([{ id: name, color: "red" }]);
} // End catch
}
var btn = document.createElement("button")
var t = document.createTextNode("Remove " + asnIX["data"][0]["asn"])
btn.setAttribute("id", asn)
btn.setAttribute("onclick", "removeNode(this.id)")
btn.appendChild(t);
var element = document.getElementById("table");
element.appendChild(btn);
group++;
network = new vis.Network(container, data, options);
}
function draw() {
// create an array with nodes
nodes = new vis.DataSet();
// create an array with edges
edges = new vis.DataSet();
// create a network
var container = document.getElementById('network');
data = {
nodes: nodes,
edges: edges
};
var options = {};
network = new vis.Network(container, data, options);
}
function removeNode(nodeId) {
// Need to loop over nodes, detect only has edges towards the node we remove, and remove those nodes also.
// Foreach edge, filter node group by ID. Re-draw on these only.
nodes.remove({nodeId});
var fromID = edges.get({
filter: function (item) {
return (item.from == nodeId);
}
});
edges.remove(fromID)
// Redraw!
network = new vis.Network(container, data, options);
}
// create a network
var container = document.getElementById("mynetwork");
// provide the data in the vis format
var options = {
nodes: {
shape: 'dot',
scaling: {
min: 10,
max: 30,
label: {
min: 8,
max: 30,
drawThreshold: 12,
maxVisible: 20
}
},
font: {
size: 12,
face: 'Tahoma'
}
},
edges: {
width: 0.15,
color: {inherit: 'from'},
smooth: {
type: 'continuous'
}
},
physics: false,
interaction: {
tooltipDelay: 200,
hideEdgesOnDrag: true
}
};
</script>
</body>
</html>