Skip to content

Commit ec9a8ac

Browse files
committed
improved malicious selection and visualization
1 parent 3808420 commit ec9a8ac

4 files changed

Lines changed: 42 additions & 21 deletions

File tree

nebula/frontend/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,12 @@ async def nebula_dashboard_monitor(scenario_name: str, request: Request, session
639639
[x[10] for x in nodes_list], # Round
640640
[x[11] for x in nodes_list], # Scenario name
641641
[x[12] for x in nodes_list], # Run hash
642+
[x[13] for x in nodes_list], # Malicious
642643
nodes_status,
643644
strict=False, # Status
644645
)
646+
647+
logging.info(f"[FER] malicious { [x[13] for x in nodes_list]}")
645648

646649
topology_path = FileUtils.check_path(settings.config_dir, os.path.join(scenario_name, "topology.png"))
647650
if os.path.exists(topology_path):
@@ -766,6 +769,7 @@ async def nebula_update_node(scenario_name: str, request: Request):
766769
str(config["federation_args"]["round"]),
767770
str(config["scenario_args"]["name"]),
768771
str(config["tracking_args"]["run_hash"]),
772+
str(config["device_args"]["malicious"]),
769773
)
770774

771775
neighbors_distance = config["mobility_args"]["neighbors_distance"]
@@ -778,6 +782,7 @@ async def nebula_update_node(scenario_name: str, request: Request):
778782
"ip": config["network_args"]["ip"],
779783
"port": str(config["network_args"]["port"]),
780784
"role": config["device_args"]["role"],
785+
"malicious": config["device_args"]["malicious"],
781786
"neighbors": config["network_args"]["neighbors"],
782787
"latitude": config["mobility_args"]["latitude"],
783788
"longitude": config["mobility_args"]["longitude"],

nebula/frontend/database.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async def initialize_databases():
7272
ip TEXT,
7373
port TEXT,
7474
role TEXT,
75+
malicious TEXT,
7576
neighbors TEXT,
7677
latitude TEXT,
7778
longitude TEXT,
@@ -89,6 +90,7 @@ async def initialize_databases():
8990
"ip": "TEXT",
9091
"port": "TEXT",
9192
"role": "TEXT",
93+
"malicious": "TEXT",
9294
"neighbors": "TEXT",
9395
"latitude": "TEXT",
9496
"longitude": "TEXT",
@@ -282,6 +284,7 @@ async def update_node_record(
282284
federation_round,
283285
scenario,
284286
run_hash,
287+
malicious,
285288
):
286289
# Check if the node record with node_uid and scenario already exists in the database
287290
# If it does, update the record
@@ -298,8 +301,9 @@ async def update_node_record(
298301

299302
if result is None:
300303
# Create a new record
304+
logging.info(f"[FER] node_uid {node_uid}")
301305
await _c.execute(
302-
"INSERT INTO nodes VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
306+
"INSERT INTO nodes VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
303307
(
304308
node_uid,
305309
idx,
@@ -314,18 +318,20 @@ async def update_node_record(
314318
federation_round,
315319
scenario,
316320
run_hash,
321+
malicious,
317322
),
318323
)
319324
else:
320325
# Update the record
321-
command = "UPDATE nodes SET idx = ?, ip = ?, port = ?, role = ?, neighbors = ?, latitude = ?, longitude = ?, timestamp = ?, federation = ?, round = ?, hash = ? WHERE uid = ? AND scenario = ?;"
326+
command = "UPDATE nodes SET idx = ?, ip = ?, port = ?, role = ?, malicious = ?, neighbors = ?, latitude = ?, longitude = ?, timestamp = ?, federation = ?, round = ?, hash = ? WHERE uid = ? AND scenario = ?;"
322327
await _c.execute(
323328
command,
324329
(
325330
idx,
326331
ip,
327332
port,
328333
role,
334+
malicious,
329335
neighbors,
330336
latitude,
331337
longitude,

nebula/frontend/templates/deployment.html

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,17 +2749,12 @@ <h5 class="step-title">Schema of deployment</h5>
27492749

27502750
<script>
27512751
// Update attacks configuration
2752-
2753-
var manualMalicious = false
2754-
27552752
document.getElementById("malicious-nodes-select").addEventListener("change", function(){
27562753
if(this.value == "Manual"){
27572754
document.getElementById("poisoned-node-percent").value = 0;
27582755
document.getElementById("poisoned-node-percent").disabled = true;
2759-
manualMalicious = true;
27602756
}else{
27612757
document.getElementById("poisoned-node-percent").disabled = false;
2762-
manualMalicious = false;
27632758
}
27642759
});
27652760

@@ -3503,21 +3498,14 @@ <h5 class="step-title">Schema of deployment</h5>
35033498
const changeMalicious = document.createElement("a");
35043499
changeMalicious.innerHTML = "<i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> Change malicious";
35053500
changeMalicious.style.display = "block";
3506-
if(!manualMalicious){
3507-
changeMalicious.style.opacity = "0.5";
3508-
changeMalicious.style.cursor = "not-allowed";
3509-
}
3510-
else{
3511-
changeMalicious.style.cursor = "pointer";
3512-
}
35133501
changeMalicious.style.padding = "5px";
35143502
changeMalicious.style.borderRadius = "5px";
35153503
changeMalicious.style.marginBottom = "5px";
35163504
changeMalicious.classList.add("dropdown-item");
35173505
changeMalicious.addEventListener("click", function () {
3518-
if(!manualMalicious){
3519-
return;
3520-
}
3506+
document.getElementById("malicious-nodes-select").value = "Manual"
3507+
document.getElementById("malicious-nodes-select").dispatchEvent(new Event('change'));
3508+
35213509
console.log("Change malicious");
35223510
node.malicious = !node.malicious;
35233511
updateGraph();

nebula/frontend/templates/monitor.html

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,26 @@ <h3>Nodes in the database</h3>
5757
<th>IP</th>
5858
<th>Role</th>
5959
<th>Round</th>
60+
<th>Behaviour</th>
6061
<th>Status</th>
6162
<th>Logs</th>
6263

6364
</tr>
6465
</thead>
6566
{% for uid, idx, ip, port, role, neighbors, latitude, longitude, timestamp, federation, round,
66-
scenario, hash, status
67+
scenario, hash, malicious, status
6768
in nodes %}
6869
<tr id="node-{{ uid }}">
6970
<td id="uid"> {{ uid }}</td>
7071
<td id="idx"> {{ idx }}</td>
7172
<td id="ip"> {{ ip }}</td>
7273
<td id="role"> {{ role }}</td>
7374
<td id="round"> {{ round }}</td>
75+
{% if malicious == "True" %}
76+
<td id="malicious"><span class="badge text-bg-dark">Malicious</span></td>
77+
{% else %}
78+
<td id="malicious"><span class="badge text-bg-secondary" style="width: 60px;">Benign</span></td>
79+
{% endif %}
7480
{% if status %}
7581
<td id="status"><span class="badge text-bg-success">Online</span></td>
7682
{% else %}
@@ -536,6 +542,7 @@ <h3>Topology</h3>
536542
var idx = node_row.querySelector("#idx");
537543
var ip = node_row.querySelector("#ip");
538544
var round = node_row.querySelector("#round");
545+
var malicious = node_row.querySelector("#malicious");
539546
var status = node_row.querySelector("#status");
540547

541548
if (!idx) {
@@ -553,6 +560,11 @@ <h3>Topology</h3>
553560
round.id = "round";
554561
node_row.appendChild(round);
555562
}
563+
if (!malicious) {
564+
malicious = document.createElement("td");
565+
malicious.id = "malicious";
566+
node_row.appendChild(malicious);
567+
}
556568
if (!status) {
557569
status = document.createElement("td");
558570
status.id = "status";
@@ -563,7 +575,15 @@ <h3>Topology</h3>
563575
ip.innerHTML = node[2];
564576
round.innerHTML = node[10];
565577

566-
if (node[13]) {
578+
console.log("malicious: ", node[13])
579+
580+
if (node[13] == "True") {
581+
status.innerHTML = '<span class="badge text-bg-dark">Malicious</span>';
582+
} else {
583+
status.innerHTML = '<span class="badge text-bg-secondary">Benign</span>';
584+
}
585+
586+
if (node[14]) {
567587
status.innerHTML = '<span class="badge text-bg-success">Online</span>';
568588
if (offlineNodes.has(node[2] + ":" + node[3])) {
569589
offlineNodes.delete(node[2] + ":" + node[3]);
@@ -581,7 +601,8 @@ <h3>Topology</h3>
581601
latitude: node[6],
582602
longitude: node[7],
583603
neighbors: node[5],
584-
status: node[13],
604+
malicious: node[13],
605+
status: node[14],
585606
};
586607
updateQueue.push(data_json);
587608
});
@@ -692,7 +713,7 @@ <h3>Topology</h3>
692713
response.json().then(function (data) {
693714
data['nodes_table'].forEach(function (node) {
694715
// Detect if a node has status offline and emit node_remove to the WebSocket
695-
if (!node[13]) {
716+
if (!node[14]) {
696717
if (!offlineNodes.has(node[2] + ":" + node[3])) {
697718
console.log("Node " + node[2] + ":" + node[3] + " is just offline");
698719
offlineNodes.add(node[2] + ":" + node[3]);
@@ -709,6 +730,7 @@ <h3>Topology</h3>
709730
timestamp: node[8],
710731
federation: node[9],
711732
round: node[10],
733+
malicious: node[13],
712734
status: false,
713735
scenario_name: nodeData.scenario_name,
714736
}

0 commit comments

Comments
 (0)