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

test lo

parent 1d595665
Branches
No related tags found
No related merge requests found
......@@ -365,8 +365,8 @@ def disable_NetworkManager_auto_ip(inter_name):
print(f"Error executing command {cmd_err}: {e}")
def add_ip_address(inter_name, ip_address):
command = ["sudo", "ip", "addr", "add", ip_address + "/24", "dev", inter_name]
def add_ip_address(inter_name, ip_address, mask):
command = ["sudo", "ip", "addr", "add", ip_address + mask, "dev", inter_name]
try:
subprocess.run(command, check=True)
except subprocess.CalledProcessError as e:
......@@ -430,7 +430,10 @@ def update_ospf_rule(input_map):
commands += f"\npassive-interface ens3"
bgp_commands = f"\nrouter bgp {MY_BGP_AS_NUM}"
bgp_commands += f"\nbgp router-id 1.1.{my_id}.1"
lo_ip = f"1.1.{my_id}.1"
bgp_commands += f"\nbgp router-id {lo_ip}"
add_ip_address("lo", lo_ip, "/32")
for iface_number_str, ip in input_map.items():
iface_name = f'ens{int(iface_number_str) + 3}' # setup dhcp on ens inf, no need to set up on tap infs
......@@ -450,11 +453,15 @@ def update_ospf_rule(input_map):
temp_octets[-1] = "1"
ip_peer = ".".join(temp_octets)
bgp_commands += f"\nneighbor {ip_peer} remote-as 1{octets[2]}"
elif subnet.startswith('192.'):
temp_octets = ip.split(".")
temp_octets[-1] = "253" if temp_octets[-1] == "254" else "254"
ip_peer = ".".join(temp_octets)
bgp_commands += f"\nneighbor {ip_peer} remote-as {MY_BGP_AS_NUM}"
# elif subnet.startswith('192.'):
# temp_octets = ip.split(".")
# temp_octets[-1] = "253" if temp_octets[-1] == "254" else "254"
# ip_peer = ".".join(temp_octets)
# bgp_commands += f"\nneighbor {ip_peer} remote-as {MY_BGP_AS_NUM}"
for i in range(12):
bgp_commands += f"\nneighbor 1.1.{i}.1 remote-as {MY_BGP_AS_NUM}"
bgp_commands += f"\nneighbor 1.1.{i}.1 update-source lo"
# bgp_commands += f"\nneighbor PEERS peer-group"
# bgp_commands += f"\nbgp listen range 192.100.0.0/16 peer-group PEERS"
......@@ -465,6 +472,7 @@ def update_ospf_rule(input_map):
for subnet in subnets:
commands += f"\nnetwork {subnet}/24 area 0"
commands += f"\nnetwork {lo_ip}/32 area 0"
commands += "\nexit"
bgp_commands += "\nredistribute ospf"
......
......@@ -134,7 +134,7 @@ class FirewallOpportunistic:
if inter_num in if_utils.map_inf_ip:
ip_address = if_utils.map_inf_ip[inter_num]
if_utils.delete_ip_address(ens_if, ip_address)
if_utils.add_ip_address(private_if, ip_address)
if_utils.add_ip_address(private_if, ip_address, "/24")
# Update mark rules for private_if
# if_utils.delete_mangle_mark_rule(ens_if, inter_num)
......@@ -214,7 +214,7 @@ class IdsOpportunistic:
if inter_num in if_utils.map_inf_ip:
ip_address = if_utils.map_inf_ip[inter_num]
if_utils.delete_ip_address(inter_name, ip_address)
if_utils.add_ip_address(private_if, ip_address)
if_utils.add_ip_address(private_if, ip_address, "/24")
IdsOpportunistic.map_tap_inf_for_ids[inter_num] = (inter_name, new_bridge, public_if)
......@@ -250,7 +250,7 @@ class IdsOpportunistic:
if inter_num in if_utils.map_inf_ip:
ip_address = if_utils.map_inf_ip[inter_num]
# if_utils.delete_ip_address(private_if, ip_address)
if_utils.add_ip_address(next_if, ip_address)
if_utils.add_ip_address(next_if, ip_address, "/24")
del (IdsOpportunistic.map_tap_inf_for_ids[inter_num])
......
......@@ -384,7 +384,7 @@ def proceed_self_stabilizing_VC():
inter_num = int(iface_number_str) + MIN_INTER_NUMBER - 1
iface_name = f'{NAME_INF}{inter_num + 1}'
disable_NetworkManager_auto_ip(iface_name)
add_ip_address(iface_name, ip)
add_ip_address(iface_name, ip, "/24")
map_inf_ip[inter_num] = ip
if_utils.my_id = node.myid
......
......@@ -127,7 +127,7 @@ def main():
# if_utils.apply_nat_rule("10.0.0.2", f"{parts[0]}.{parts[1]}.{parts[2]}.102")
if_utils.disable_NetworkManager_auto_ip("ens4")
if_utils.add_ip_address("ens4", f"10.0.{bgp_index}.254")
if_utils.add_ip_address("ens4", f"10.0.{bgp_index}.254", "/24")
if_utils.setup_dhcp(["ens4"], [f"10.0.{bgp_index}.254"], [f"10.0.{bgp_index}.0"])
b = BPF(src_file=f"inter_op_ebpf.c")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment