Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
lwip weave tunnel test 02
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniexie committed Sep 12, 2019
1 parent 220b97b commit 0008762
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 45 deletions.
24 changes: 24 additions & 0 deletions src/test-apps/happy/lib/WeaveState.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ def getNodeWeaveIPAddress(self, node_id=None, state=None):
return addr
return None

def getNodeInterfaceWeaveIPAddress(self, interface_id, node_id, state=None):
"""This function attempts to get weave IP address of a paticular node's interface.
Args:
interface_id(str): A string containing a node interface id, example: "wlan0" or "wpan0".
node_id(str): A string containing a node id, example: "BorderGateway", "ThreadNode".
state(json data): node's json data, default is None.
Returns:
str. The return value:
None: not found weave address
addr: found weave address
"""
weave_global_prefix = self.getFabricGlobalPrefix(state)
if weave_global_prefix is None:
return None
node_interface_addresses = self.getNodeInterfaceAddresses(interface_id, node_id, state)
if node_interface_addresses == []:
return None
for addr in node_interface_addresses:
if IP.prefixMatchAddress(weave_global_prefix, addr):
return addr
return None

def getWeaveNetworkIds(self, state=None):
networks_record = self.getWeaveNetworks(state)
return networks_record.keys()
Expand Down
14 changes: 11 additions & 3 deletions src/test-apps/happy/test-templates/WeavePing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"case_cert_path": None,
"case_key_path": None,
"use_persistent_storage": True,
"use_lwip": False,
"plaid_server_env": {},
"plaid_client_env": {}
}
Expand Down Expand Up @@ -93,6 +94,11 @@ def __init__(self, opts = options):
HappyNetwork.__init__(self)
WeaveTest.__init__(self)
self.__dict__.update(opts)
self.fabric_id = self.getFabricId()
if self.use_lwip:
self.service_weave_id = self.getServiceWeaveID("Tunnel")
self.service_weave_addr = self.getServiceWeaveIPAddress("Tunnel")
self.gateway_weave_addr = self.getNodeInterfaceWeaveIPAddress("wpan0", self.border_gateway)

def __pre_check(self):
# clear network info
Expand Down Expand Up @@ -275,8 +281,11 @@ def __start_client_side(self, client_info):

cmd += " --count " + str(self.count)

if self.tap:
cmd += " --tap-device " + self.tap
if self.use_lwip:
cmd += " --fabric-id " + str(self.fabric_id)
cmd += " --tap-device " + self.client_tap
cmd += " --node-id " + client_info['client_weave_id']
cmd += " --ipv6-gateway " + self.gateway_weave_addr

if self.case:
if self.case_shared:
Expand All @@ -288,7 +297,6 @@ def __start_client_side(self, client_info):
self.cert_file = self.case_cert_path if self.case_cert_path else os.path.join(self.main_conf['log_directory'], client_info["client_weave_id"].upper() + '-cert.weave-b64')
self.key_file = self.case_key_path if self.case_key_path else os.path.join(self.main_conf['log_directory'], client_info["client_weave_id"].upper() + '-key.weave-b64')
cmd += ' --node-cert ' + self.cert_file + ' --node-key ' + self.key_file

self.start_simple_weave_client(cmd, client_info['client_ip'],
self.server_ip, self.server_weave_id,
client_info['client_node_id'], client_info['client_process_tag'], use_persistent_storage=self.use_persistent_storage, env=self.plaid_client_env)
Expand Down
33 changes: 28 additions & 5 deletions src/test-apps/happy/test-templates/WeaveTunnelStart.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"case": False,
"service_dir_server": None,
"use_lwip": False,
"client_tap_wlan": None,
"client_tap_wpan": None,
"service_process_tag": "WEAVE-SERVICE-TUNNEL",
"gateway_process_tag": "WEAVE-GATEWAY-TUNNEL",
"case_cert_path": None,
Expand Down Expand Up @@ -115,8 +117,25 @@ def __init__(self, opts = options):
self.service, self.service_tap, service_v4route_prefix)[0]

BR_v4route_prefix = self.getNodeRoutePrefix("v4", self.border_gateway)
self.client_ipv4_addr = self.getNodeAddrMatchingPrefix(
self.border_gateway, self.client_tap, BR_v4route_prefix)[0]
self.client_ipv4_addr_wlan = self.getNodeAddrMatchingPrefix(
self.border_gateway, self.client_tap_wlan, BR_v4route_prefix)[0]

self.service_weave_addr = self.getServiceWeaveIPAddress("Tunnel")

weave_prefix = self.getFabricRecord().get('global_prefix', "")

# get client BorderGateway's wlan weave address
client_addrs_wlan = self.getNodeInterfaceAddresses(self.client_tap_wlan, self.border_gateway)
client_ipv6_addrs_wlan = [addr for addr in client_addrs_wlan if IP.isIpv6(addr)]
self.client_weave_addr_wlan = [addr
for addr in client_ipv6_addrs_wlan if IP.prefixMatchAddress(weave_prefix, addr)][0]

# get client BorderGateway's wpan weave address
if self.client_tap_wpan:
client_addrs_wpan = self.getNodeInterfaceAddresses(self.client_tap_wpan, self.border_gateway)
client_ipv6_addrs_wpan = [addr for addr in client_addrs_wpan if IP.isIpv6(addr)]
self.client_weave_addr_wpan = [addr
for addr in client_ipv6_addrs_wpan if IP.prefixMatchAddress(weave_prefix, addr)][0]

self.gateway_process_tag += self.test_tag
self.service_process_tag += self.test_tag
Expand Down Expand Up @@ -231,6 +250,7 @@ def __start_tunnel_at_service(self):
cmd += " --tap-device " + self.service_tap
cmd += " --ipv4-gateway " + self.service_ipv4_gateway
cmd += " --node-addr " + self.service_ipv4_addr
cmd += " --node-addr " + self.service_weave_addr

if self.service_faults:
cmd += " --faults " + self.service_faults
Expand All @@ -241,7 +261,6 @@ def __start_tunnel_at_service(self):

cmd += " --debug-resource-usage"
cmd += " --print-fault-counters"

cmd = self.runAsRoot(cmd)
self.start_weave_process(self.service, cmd, self.service_process_tag,
strace=self.strace, sync_on_output=self.sync_on_service_output,
Expand Down Expand Up @@ -299,10 +318,14 @@ def __start_tunnel_at_gateway(self):

# if device is tap device, we need to provide tap-interface, ipv4-gateway, node-addr
if self.use_lwip:
cmd += " --tap-device " + self.client_tap
cmd += " --tap-device " + self.client_tap_wlan
cmd += " --ipv4-gateway " + self.client_ipv4_gateway
cmd += " --node-addr " + self.client_ipv4_addr
cmd += " --node-addr " + self.client_ipv4_addr_wlan
cmd += " --node-addr " + self.client_weave_addr_wlan
cmd += " --service-dir-server " + self.service_ipv4_addr
if self.client_tap_wpan:
cmd += " --tap-device " + self.client_tap_wpan
cmd += " --node-addr " + self.client_weave_addr_wpan

if self.primary:
cmd += " --primary-intf " + self.primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def setUp(self):
self.use_lwip = True
topology_shell_script = os.path.dirname(os.path.realpath(__file__)) + \
"/../../../topologies/standalone/thread_wifi_on_tap_ap_service.sh"
# tap interface, ipv4 gateway and node addr should be provided if device is tap device
# both BorderRouter and cloud node are tap devices here
self.BR_tap = "wlan0"
self.cloud_tap = "eth0"
else:
self.use_lwip = False
topology_shell_script = os.path.dirname(os.path.realpath(__file__)) + \
Expand Down Expand Up @@ -80,8 +76,8 @@ def __start_tunnel_between(self, gateway, service):
options["service"] = service
options["use_lwip"] = self.use_lwip
if self.use_lwip:
options["client_tap"] = self.BR_tap
options["service_tap"] = self.cloud_tap
options["client_tap_wlan"] = "wlan0"
options["service_tap"] = "eth0"

weave_tunnel = WeaveTunnelStart.WeaveTunnelStart(options)
ret = weave_tunnel.run()
Expand Down
50 changes: 19 additions & 31 deletions src/test-apps/happy/tests/standalone/tunnel/test_weave_tunnel_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,30 @@
import WeaveTunnelStart
import WeaveTunnelStop
import WeaveUtilities
import subprocess

class test_weave_tunnel_02(unittest.TestCase):
def setUp(self):
self.tap = None

if "WEAVE_SYSTEM_CONFIG_USE_LWIP" in os.environ.keys() and os.environ["WEAVE_SYSTEM_CONFIG_USE_LWIP"] == "1":
self.topology_file = os.path.dirname(os.path.realpath(__file__)) + \
"/../../../topologies/standalone/thread_wifi_on_tap_ap_service.json"
self.tap = "wpan0"
self.use_lwip = True
topology_shell_script = os.path.dirname(os.path.realpath(__file__)) + \
"/../../../topologies/standalone/thread_wifi_on_tap_ap_service.sh"
else:
self.topology_file = os.path.dirname(os.path.realpath(__file__)) + \
"/../../../topologies/standalone/thread_wifi_ap_service.json"

self.show_strace = False

# setting Mesh for thread test
options = WeaveStateLoad.option()
options["quiet"] = True
options["json_file"] = self.topology_file

setup_network = WeaveStateLoad.WeaveStateLoad(options)
ret = setup_network.run()
self.use_lwip = False
topology_shell_script = os.path.dirname(os.path.realpath(__file__)) + \
"/../../../topologies/standalone/thread_wifi_ap_service.sh"
output = subprocess.call([topology_shell_script])

# Wait for a second to ensure that Weave ULA addresses passed dad
# and are no longer tentative
time.sleep(2)


def tearDown(self):
# cleaning up
options = WeaveStateUnload.option()
options["quiet"] = True
options["json_file"] = self.topology_file

teardown_network = WeaveStateUnload.WeaveStateUnload(options)
teardown_network.run()
subprocess.call(["happy-state-delete"])


def test_weave_tunnel(self):
# TODO: Once LwIP bugs are fix, enable this test on LwIP
if "WEAVE_SYSTEM_CONFIG_USE_LWIP" in os.environ.keys() and os.environ["WEAVE_SYSTEM_CONFIG_USE_LWIP"] == "1":
print hred("WARNING: Test skipped due to LwIP-based network cofiguration!")
return

# topology has nodes: ThreadNode, BorderRouter, onhub and cloud
# we run tunnel between BorderRouter and cloud

Expand All @@ -99,7 +79,11 @@ def __start_tunnel_between(self, gateway, service):
options["quiet"] = True
options["border_gateway"] = gateway
options["service"] = service
options["tap"] = self.tap
options["use_lwip"] = self.use_lwip
if self.use_lwip:
options["client_tap_wlan"] = "wlan0"
options["client_tap_wpan"] = "wpan0"
options["service_tap"] = "eth0"

weave_tunnel = WeaveTunnelStart.WeaveTunnelStart(options)
ret = weave_tunnel.run()
Expand All @@ -118,7 +102,11 @@ def __run_ping_test_between(self, nodeA, nodeB):
options["udp"] = True
options["endpoint"] = "Tunnel"
options["count"] = "10"
options["tap"] = self.tap
options["use_lwip"] = self.use_lwip
if self.use_lwip:
options["client_tap"] = "wpan0"
options["service_tap"] = "wlan0"
options["border_gateway"] = "BorderRouter"

weave_ping = WeavePing.WeavePing(options)
ret = weave_ping.run()
Expand Down

0 comments on commit 0008762

Please sign in to comment.