-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopology.php
More file actions
240 lines (216 loc) · 10.7 KB
/
topology.php
File metadata and controls
240 lines (216 loc) · 10.7 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require './inc/restcontroller/restcontroller.php';
$restcont = new restController($_CONTROLLERURI);
$restcont->refreshData();
$switches = $restcont->getSwitches();
$edges = $restcont->getEdges();
$networks = $restcont->getNetworks($edges);
$nodes = array_merge($switches, $networks);
$routing = $restcont->getRoutingTables();
$reqrouters = $restcont->getRequestRouters();
$cdnrouting = $restcont->getCDNRouting();
?>
<div width="100%">
<h1>Network topology</h1>
</div>
<div width="100%">
<?php $mynetwork_width = '800px'; ?>
<div id="mynetwork" style="border:solid 1px; float:left"></div>
<div style="float:left; width:220px; height:602px">
<h2>Node info</h2>
<div id="nodecontroller"></div>
</div>
</div>
<div style="width:100%; float:left">
<a href="<?php echo $_SITEROOT; ?>">Back</a>
</div>
<script type="text/javascript">
// create an array with nodes
var nodes = <?php echo json_encode($nodes); ?>
// create an array with edges
var edges = <?php echo json_encode($edges); ?>
//Save switches so we know the list of em
var switches = <?php echo json_encode($switches); ?>
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges,
};
var options = {
width: '<?php echo $mynetwork_width ?>',
height: '600px',
smoothCurves: false,
nodes: {fontSize: 10},
edges: {fontSize: 8},
groups: {
FW: {
shape: 'image',
image: './inc/visjs/img/network/switch-blue-hi.png'
}
},
physics: {
barnesHut: {
enabled: false
},
repulsion: {
nodeDistance: 136,
centralGravity: 0.15,
springLength: 101,
springConstant: 0.5,
damping: 0.3}
}
};
var network = new vis.Network(container, data, options);
network.on('select', onSelect);
function onSelect(properties) {
for (i = 0; i < switches.length; i++) {
if (switches[i]['id'] == properties.nodes) {
var nodecon = document.getElementById("nodecontroller");
var routing = <?php echo json_encode($routing); ?>;
var reqrouters = <?php echo json_encode($reqrouters); ?>;
var cdnrouting = <?php echo json_encode($cdnrouting); ?>;
var routingdiv = document.createElement("div");
//Loading routing table in JS
if (properties.nodes in routing) {
if (routing[properties.nodes] != null) {
var rtableh3 = document.createElement('h3');
rtableh3.textContent = "Routing Table:";
var rtable = document.createElement('table');
var thid = document.createElement('th');
thid.textContent = "ID";
var thnetwork = document.createElement('th');
thnetwork.textContent = "Destination network";
var thgw = document.createElement('th');
thgw.textContent = "Gateway";
rtable.appendChild(thid);
rtable.appendChild(thnetwork);
rtable.appendChild(thgw);
for (i = 0; i < routing[properties.nodes].length; i++) {
var row = document.createElement('tr');
var id = document.createElement('td');
id.textContent = routing[properties.nodes][i]['route_id'];
row.appendChild(id);
var destination = document.createElement('td');
destination.textContent = routing[properties.nodes][i]['destination'];
row.appendChild(destination);
var gateway = document.createElement('td');
gateway.textContent = routing[properties.nodes][i]['gateway'];
row.appendChild(gateway);
rtable.appendChild(row);
}
routingdiv.appendChild(rtableh3);
routingdiv.appendChild(rtable);
} else {
var par = document.createElement('p');
par.textContent = "No Routing table information found";
routingdiv.appendChild(par);
}
}
var reqroutersdiv = document.createElement('div');
//loading request routers in JS
if (properties.nodes in reqrouters) {
if (reqrouters[properties.nodes] != null) {
var rrlisth3 = document.createElement('h3');
rrlisth3.textContent = "Request routers defined:";
var rrtable = document.createElement('table');
var thid = document.createElement('th');
thid.textContent = "ID";
var thrr = document.createElement('th');
thrr.textContent = "Request Router";
rrtable.appendChild(thid);
rrtable.appendChild(thrr);
for (i = 0; i < reqrouters[properties.nodes].length; i++) {
var row = document.createElement('tr');
var id = document.createElement('td');
id.textContent = reqrouters[properties.nodes][i]['request_router_id'];
row.appendChild(id);
var reqrouter = document.createElement('td');
reqrouter.textContent = reqrouters[properties.nodes][i]['request_router'];
row.appendChild(reqrouter);
rrtable.appendChild(row);
}
reqroutersdiv.appendChild(rrlisth3);
reqroutersdiv.appendChild(rrtable);
} else {
var par = document.createElement('p');
par.textContent = "Not a CDN router";
var cdnform = document.createElement('form');
cdnform.setAttribute('method', 'get');
cdnform.setAttribute('action', 'index.php');
//Other variables...reserved as reference for later use
// var cdnizeinput = document.createElement('input');
// cdnizeinput.setAttribute('type', 'hidden');
// cdnizeinput.setAttribute('name', 'do');
// cdnizeinput.setAttribute('value', 'cdnize');
var switchid = document.createElement('input');
switchid.setAttribute('type', 'hidden');
switchid.setAttribute('name', 'switchid');
switchid.setAttribute('value', properties.nodes);
var submitbutton = document.createElement('button');
submitbutton.setAttribute('type', 'submit');
submitbutton.setAttribute('name', 'do');
submitbutton.setAttribute('value', 'cdnize');
submitbutton.textContent = "CDNize this switch";
// cdnform.appendChild(cdnizeinput);
cdnform.appendChild(switchid);
cdnform.appendChild(submitbutton);
reqroutersdiv.appendChild(par);
reqroutersdiv.appendChild(cdnform);
}
}
var cdnroutingdiv = document.createElement("div");
//Loading routing table in JS
if (properties.nodes in cdnrouting) {
if (cdnrouting[properties.nodes] != null) {
var rtableh3 = document.createElement('h3');
rtableh3.textContent = "CDN Routing Table:";
var rtable = document.createElement('table');
var thid = document.createElement('th');
thid.textContent = "ID";
var thnetwork = document.createElement('th');
thnetwork.textContent = "Source subnet";
var thgw = document.createElement('th');
thgw.textContent = "Service Engine";
rtable.appendChild(thid);
rtable.appendChild(thnetwork);
rtable.appendChild(thgw);
for (i = 0; i < cdnrouting[properties.nodes].length; i++) {
var row = document.createElement('tr');
var id = document.createElement('td');
id.textContent = cdnrouting[properties.nodes][i]['route_id'];
row.appendChild(id);
var subnet = document.createElement('td');
subnet.textContent = cdnrouting[properties.nodes][i]['address'];
row.appendChild(subnet);
var seip = document.createElement('td');
seip.textContent = cdnrouting[properties.nodes][i]['service_engine'];
row.appendChild(seip);
rtable.appendChild(row);
}
cdnroutingdiv.appendChild(rtableh3);
cdnroutingdiv.appendChild(rtable);
var sessionsurl = document.createElement('a');
var linkText = document.createTextNode("List sessions");
sessionsurl.appendChild(linkText);
sessionsurl.title = "Session list";
sessionsurl.href = "index.php?do=sessions&switchid="+ properties.nodes;
cdnroutingdiv.appendChild(sessionsurl);
}
}
while (nodecon.firstChild) {
nodecon.removeChild(nodecon.firstChild);
}
nodecon.appendChild(routingdiv);
nodecon.appendChild(reqroutersdiv);
nodecon.appendChild(cdnroutingdiv);
return;
}
}
}
</script>