Commit dd885d64 authored by zhifan huang's avatar zhifan huang

test add bigger net ping test && use miniupnp when build net

parent 6533148d
clean_ruleset_interval=600
allow 1024-65535 10.0.0.0/8 1024-65535
deny 0-65535 0.0.0.0/0 0-65535
from sys import prefix import sys
import nemu import nemu
import weakref import weakref
import ipaddress import ipaddress
...@@ -10,6 +10,13 @@ execfile(str(fix_file)) ...@@ -10,6 +10,13 @@ execfile(str(fix_file))
IPTABLES = 'iptables' IPTABLES = 'iptables'
class Node(nemu.Node): class Node(nemu.Node):
def __init__(self):
super(Node, self).__init__()
self.Popen(('sysctl', '-q',
'net.ipv4.icmp_echo_ignore_broadcasts=0')).wait()
"""simple nemu.Node used for registry and nodes""" """simple nemu.Node used for registry and nodes"""
def _add_interface(self, iface): def _add_interface(self, iface):
self.iface = iface self.iface = iface
...@@ -102,8 +109,8 @@ def network_demo(): ...@@ -102,8 +109,8 @@ def network_demo():
nm.registrys = {registry: [m0, m1, m2, m3, m4, m5]} nm.registrys = {registry: [m0, m1, m2, m3, m4, m5]}
# for node in [registry, m0, m2, m3, m4, m5]: for node in [g1, m3, m4, m5]:
# print "pid: {}".format(node.pid) print "pid: {}".format(node.pid)
g0_if_0, _ = g1.connect_network(internet) g0_if_0, _ = g1.connect_network(internet)
m0.connect_network(internet) m0.connect_network(internet)
...@@ -144,6 +151,10 @@ def network_demo(): ...@@ -144,6 +151,10 @@ def network_demo():
for node in [m3, m4, m5]: for node in [m3, m4, m5]:
node.add_route(nexthop="10.1.10.1") node.add_route(nexthop="10.1.10.1")
g1.app = g1.Popen('miniupnpd -d -f miniupnpd.conf -P miniupnpd.pid'
' -a %s -i %s' % ( g1.if_s.name, g0_if_0.name), shell=True)
print "---------------"
for node in [m0, m1, m2, m3, m4, m5]: for node in [m0, m1, m2, m3, m4, m5]:
app0 = node.Popen(["ping", "-c", "1", registry.ip], stdout=PIPE) app0 = node.Popen(["ping", "-c", "1", registry.ip], stdout=PIPE)
...@@ -176,4 +187,5 @@ def network_direct(): ...@@ -176,4 +187,5 @@ def network_direct():
return nm return nm
if __name__ == "__main__": if __name__ == "__main__":
network_direct() nm = network_demo()
time.sleep(1000000)
...@@ -74,11 +74,35 @@ class TestPing(unittest.TestCase): ...@@ -74,11 +74,35 @@ class TestPing(unittest.TestCase):
proc = proc.split()[1] proc = proc.split()[1]
subprocess.call(["kill", "-15", proc]) subprocess.call(["kill", "-15", proc])
def test_sample(self): # def test_sample(self):
# """create a network demo, test the connectivity by ping
# wait the network stable then ping 3 times
# """
# nm = network_direct()
# net = nm.registrys
# nodes = []
# registrys = []
# for registry in net:
# reg = re6st_wrap.Re6stRegistry(registry, "2001:db8:42::", recreate=False)
# reg_node = re6st_wrap.Re6stNode(registry, reg, name=reg.name)
# registrys.append(registry)
# reg_node.run("--gateway", "--disable-proto", "none", "--ip", registry.ip)
# nodes.append(reg_node)
# for m in net[registry]:
# node = re6st_wrap.Re6stNode(m, reg)
# node.run("-i" + m.iface.name)
# nodes.append(node)
# wait_stable(nodes)
# for i in range(3):
# time.sleep(20)
# self.assertFalse(ping_test(nodes), "N.{} ping test failed".format(i))
def test_demo(self):
"""create a network demo, test the connectivity by ping """create a network demo, test the connectivity by ping
wait the network stable then ping 3 times wait the network stable then ping 3 times
""" """
nm = network_direct() nm = network_demo()
net = nm.registrys net = nm.registrys
nodes = [] nodes = []
registrys = [] registrys = []
...@@ -95,7 +119,7 @@ class TestPing(unittest.TestCase): ...@@ -95,7 +119,7 @@ class TestPing(unittest.TestCase):
wait_stable(nodes) wait_stable(nodes)
for i in range(3): for i in range(3):
time.sleep(20) time.sleep(30)
self.assertFalse(ping_test(nodes), "N.{} ping test failed".format(i)) self.assertFalse(ping_test(nodes), "N.{} ping test failed".format(i))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment