Skip to content

Commit

Permalink
add-topology-options (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
NogyJ0D authored Nov 28, 2023
1 parent d435e9d commit a12c99f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
30 changes: 27 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ <h3>Bash file preview:</h3>

<div id="controls" style="border: 1px solid lightgray; width: 100%; margin-top: 1em;">
<div class="row" style="margin: 0 !important;">
<div class="col-md-offset-4 col-md-2">
<div class="col-md-offset-3 col-md-2">
<h3 class="margin-bottom: 5px;">Edges smoothness</h3>

<div class="form-group">
Expand Down Expand Up @@ -634,7 +634,7 @@ <h3 class="margin-bottom: 5px;">Physics</h3>
<div class="form-group">
<input class="form-check-input" type="checkbox" value="" id="physicsEnabled"
onclick="setNetworkOptions()">
<label class="form-check-label" for="smoothEnabled">
<label class="form-check-label" for="physicsEnabled">
Enabled
</label>
</div>
Expand All @@ -647,10 +647,34 @@ <h3 class="margin-bottom: 5px;">Physics</h3>
value='-1200' id='physicsGravitationalConstantValue' readonly='true'>
</div>
</div>
<div class="col-md-2">
<h3 class="margin-bottom: 5px;">Miscellaneous</h3>

<div class="form-group">
<input class="form-check-input" type="checkbox" value="" id="ifNameAt">
<label class="form-check-label" for="ifNameAt">
Replace interface name with "@"
</label>
</div>

<div class="form-group">
<input class="form-check-input" type="checkbox" value="" id="ifOspfCost">
<label class="form-check-label" for="ifOspfCost">
Show OSPF interface cost
</label>
</div>

<div class="form-group">
<input class="form-check-input" type="checkbox" value="" id="routingLabel">
<label class="form-check-label" for="routingLabel">
Show OSPF/RIP/BGP label on router
</label>
</div>
</div>
</div>

<div class="row" style="margin: 0 !important; margin-top: 10px;">
<div class="col-md-offset-4 col-md-4">
<div class="col-md-offset-3 col-md-6">
<div class="form-group">
<button class="btn btn-danger btn-block" data-ng-click="makeGraph(netkit)">Reset</button>
</div>
Expand Down
32 changes: 25 additions & 7 deletions src/lab-generator/make_draw_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ function generate_nodes_edges(lab) {
let nodes = [];
let edges = [];

let ifNameAt = document.getElementById("ifNameAt");
let ifOspfCost = document.getElementById("ifOspfCost");
let routingLabel = document.getElementById("routingLabel");

let pendingDomainNodes = [];

for (let m in lab) {
Expand All @@ -114,7 +118,7 @@ function generate_nodes_edges(lab) {

if (machine.type == "router") {
if (machine.routing.rip.en) {
if (!containsNodeWithID("label-rip-" + machine.name, nodes)) {
if (!containsNodeWithID("label-rip-" + machine.name, nodes) && routingLabel.checked) {
nodes.push({
id: "label-rip-" + machine.name,
label: "RIP",
Expand All @@ -131,7 +135,7 @@ function generate_nodes_edges(lab) {
}
}
if (machine.routing.ospf.en) {
if (!containsNodeWithID("label-ospf-" + machine.name, nodes)) {
if (!containsNodeWithID("label-ospf-" + machine.name, nodes) && routingLabel.checked) {
nodes.push({
id: "label-ospf-" + machine.name,
label: "OSPF",
Expand All @@ -148,7 +152,7 @@ function generate_nodes_edges(lab) {
}
}
if (machine.routing.bgp.en) {
if (!containsNodeWithID("label-bgp-" + machine.name, nodes)) {
if (!containsNodeWithID("label-bgp-" + machine.name, nodes) && routingLabel.checked) {
nodes.push({
id: "label-bgp-" + machine.name,
label: "AS " + machine.routing.bgp.as + "\n" + machine.routing.bgp.network,
Expand All @@ -170,14 +174,22 @@ function generate_nodes_edges(lab) {
let domain_name = interface.eth.domain;
if (!domain_name || domain_name == "") continue;

let if_name = "eth" + interface.eth.number;
let if_name = (ifNameAt.checked ? "@" : "eth") + interface.eth.number;
let domain_id = "domain-" + domain_name;
let app_to = "iplabel-" + domain_name + "-domain_ip";
let domain_ip, if_ip;
if(interface.ip){
domain_ip = get_network_from_ip_net(interface.ip);
if_ip = get_eth_ip_difference(domain_ip, interface.ip);
}
}

let ifCost = "";
if (machine.type == "router") {
if (machine.routing.ospf.en && ifOspfCost.checked) {
let cost = machine.routing.ospf.if.filter(ifn => ifn.interface == interface.eth.number)[0];
ifCost = cost ? cost.cost : "";
}
}

// the domain is a new node. beware of duplicates.
// domain should have a child node with the ip description
Expand Down Expand Up @@ -210,9 +222,15 @@ function generate_nodes_edges(lab) {
}
}
//each eth is a new node, linked to its domain and its machine. can't be duplicated
nodes.push({
let ifLabel = if_ip ? if_ip + (ifNameAt.checked ? "" : "\n") + if_name : if_name;

if (ifCost) {
ifLabel += "\nCost: " + ifCost;
}

nodes.push({
id: "eth-" + id + "-" + if_name + "-" + m,
label: if_ip ? (if_ip + "\n" + if_name) : if_name,
label: ifLabel,
group: "eth",
value: 2
});
Expand Down

0 comments on commit a12c99f

Please sign in to comment.