Skip to content
Snippets Groups Projects
Commit 91840f37 authored by NGUYEN Do Duc Anh's avatar NGUYEN Do Duc Anh
Browse files

add initiate configuration for monitor

parent 992aa0be
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
sudo modprobe br_netfilter # To enable switch functions inside Ubuntu VM
sudo brctl addbr br0
sudo ip link set br0 up
sudo brctl stp br0 on
# Create private and public tap interface for monitor
for i in {4..13}; do
sudo ip tuntap add public$i mode tap
sudo ip link set dev public$i up
sudo ip tuntap add private$i mode tap
sudo ip link set dev private$i up
sudo brctl addbr br$i
sudo ip link set br$i up
sudo brctl addif br$i ens$i
sudo brctl addif br$i public$i
sudo brctl addif br0 private$i
done
\ No newline at end of file
......@@ -26,7 +26,6 @@ def setup_firewall(inter_num):
print(f"Command output: {e.output}") # Any output (stdout/stderr)
def process_packet(new_packet):
global my_id, name_interface
......@@ -91,13 +90,13 @@ def process_packet(new_packet):
def main():
rule_check = "sudo iptables -C FORWARD -p tcp -j NFQUEUE --queue-num 1"
rule_check = "sudo iptables -C FORWARD -i br0 -p tcp -j NFQUEUE --queue-num 1"
try:
subprocess.run(rule_check, shell=True, check=True)
print("Rule already exists, no need to add it.")
except subprocess.CalledProcessError:
try:
rule_1 = "sudo iptables -I FORWARD -p tcp -j NFQUEUE --queue-num 1"
rule_1 = "sudo iptables -I FORWARD -i br0 -p tcp -j NFQUEUE --queue-num 1"
subprocess.run(rule_1, shell=True, check=True)
for i in range(MIN_INTER_NUMBER, MAX_INTER_NUMBER):
......
......@@ -126,10 +126,6 @@ def check_all_interfaces():
return f"Error executing command: {e}"
# def initiate_me():
# message = struct.pack('!I', myid)
# broadcast_packet(message)
def drop_me():
message = struct.pack('!II', Cmd.DROP_ME, node.myid)
broadcast_packet(message)
......@@ -234,12 +230,13 @@ def proceed_simple_VC():
# Start a new Python process to run another script based on Node decision
subprocess.run(f"sudo {DIR}/ubuntu_base/./initiate", shell=True, check=True)
print("A bridge br0 created")
if node.state == State.DECIDED_IN_VC:
subprocess.run(f"sudo {DIR}/ubuntu_base/./initiate_for_monitor", shell=True, check=True)
print("./initiate_for_monitor is executed")
subprocess.Popen([sys.executable, f'{DIR}/ubuntu_base/opportunistic_monitor.py'])
elif node.state == State.DECIDED_NOT_VC:
subprocess.run(f"sudo {DIR}/ubuntu_base/./initiate", shell=True, check=True)
print("./initiate is executed")
subprocess.Popen([sys.executable, f'{DIR}/ubuntu_base/opportunistic_node.py', str(node.myid)])
else:
print("Error I cannot decide!!")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment