Skip to content

Commit

Permalink
Merge branch '85-failed-on-olsr_route-mode' into 'main'
Browse files Browse the repository at this point in the history
Resolve "failed on olsr_route mode"

Closes #85

See merge request dependencies/oasis!88
  • Loading branch information
penglei0 committed Dec 10, 2024
2 parents ae41bc8 + 19ec25e commit 2fac03f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/config/protocol-multi-hops-test-olsr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests:
test_tools:
iperf:
interval: 1
interval_num: 40
interval_num: 10
client_host: 0
server_host: 3
rtt:
Expand Down
22 changes: 15 additions & 7 deletions src/protosuites/bats/bats_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
from interfaces.network import INetwork
from interfaces.host import IHost
from tools.cfg_generator import generate_cfg_files
from tools.cfg_generator import generate_cfg_files, generate_olsr_cfg_files
from protosuites.proto import (ProtoConfig, IProtoSuite)
from var.global_var import g_root_path

Expand Down Expand Up @@ -67,12 +67,17 @@ def pre_run(self, network: INetwork):
# configurations are separated by network
logging.info(
f"########################## BATSProtocol Source path: %s, %s", self.source_path, net_id)
# BTP OR BRTP
test_tun_mode = 'BRTP' if self.get_protocol_name() == 'BRTP' else 'BTP'
generate_cfg_files(host_num, hosts_ip_range,
self.virtual_ip_prefix, f'{self.source_path}/{net_id}',
test_tun_mode,
cfg_template_path)
routing_type_name = network.get_routing_strategy().routing_type()
if routing_type_name == 'OLSRRouting':
self.virtual_ip_prefix = '172.23.1.'
generate_olsr_cfg_files(
host_num, self.virtual_ip_prefix, f'{self.source_path}/{net_id}')
else:
test_tun_mode = 'BRTP' if self.get_protocol_name() == 'BRTP' else 'BTP'
generate_cfg_files(host_num, hosts_ip_range,
self.virtual_ip_prefix, f'{self.source_path}/{net_id}',
test_tun_mode,
cfg_template_path)
# generate some error log if the license file is not correct
self._verify_license()
for i in range(host_num):
Expand All @@ -93,7 +98,10 @@ def run(self, network: INetwork):
if routing_type_name == 'OLSRRouting':
self.protocol_args += " --olsr_adaption_enabled=true"
self.protocol_args += " --use_netlink_routing_table=true"
self.protocol_args += " --use_user_routing_table=false"
self.protocol_args += " --use_system_link_config=true"
self.protocol_args += " --use_user_link_config=false"

host_num = len(hosts)
for i in range(host_num):
hosts[i].cmd(
Expand Down
39 changes: 39 additions & 0 deletions src/tools/cfg_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def _generate_node_ips(self, num_nodes):
node_ips.append([all_ips[i * 2 - 1], all_ips[i * 2]])
return node_ips

def _generate_oslr_node_ips(self, num_nodes, virtual_ip_prefix):
node_ips = []
for i in range(num_nodes):
node_ips.append(f"{virtual_ip_prefix}{i+1}")
return node_ips

def generate_cfg(self, num_nodes, virtual_ip_prefix):
node_ips = self._generate_node_ips(num_nodes)
tun_mappings = self._generate_tun_cfg(node_ips, virtual_ip_prefix)
Expand All @@ -188,6 +194,31 @@ def generate_cfg(self, num_nodes, virtual_ip_prefix):
tun_mappings=tun_mappings))
logging.info("Generated %s/h%d.ini", self.path, i)

def generate_oslr_cfg(self, num_nodes, virtual_ip_prefix):
node_ips = self._generate_oslr_node_ips(num_nodes, virtual_ip_prefix)
for i in range(num_nodes):
tcp_proxy_cnt, tcp_proxies = 0, ""
if i == 0:
tcp_proxy_cnt = 1
tcp_proxies = self._generate_tcp_proxy_item(
i, node_ips[-1], node_ips[-1])
port_forward = ""
# oasis core didn't support port forward but ini configs have port forward rules.
# port forward rules for h0, h1, ..., h(n-1) to h(n)
if i != num_nodes - 1:
# generate port forward from h0 to the last node in the chain.
port_forward = self._generate_port_forward_item(
node_ips[-1][0])
with open(f"{self.path}/h{i}.ini", "w", encoding="utf-8") as f:
f.write(self.template.format(link_cnt=0, links="",
route_cnt=0, routes="",
tcp_proxy_cnt=tcp_proxy_cnt, tcp_proxies=tcp_proxies,
port_forward=port_forward,
tun_ip=f"{virtual_ip_prefix}{i+1}", tun_mapping_cnt=0,
tun_mode=self.tun_mode,
tun_mappings=""))
logging.info("Generated %s/h%d.ini", self.path, i)


def generate_cfg_files(num_nodes, node_ip_range="10.0.0.0/8",
virtual_ip_prefix="1.0.0.",
Expand All @@ -201,6 +232,14 @@ def generate_cfg_files(num_nodes, node_ip_range="10.0.0.0/8",
generator.generate_cfg(num_nodes, virtual_ip_prefix)


def generate_olsr_cfg_files(num_nodes, virtual_ip_prefix="172.23.1.",
output_dir="/tmp"):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
generator = ConfigGenerator(path=output_dir)
generator.generate_oslr_cfg(num_nodes, virtual_ip_prefix)


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(
Expand Down

0 comments on commit 2fac03f

Please sign in to comment.