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
...@@ -101,9 +108,9 @@ def network_demo(): ...@@ -101,9 +108,9 @@ def network_demo():
nm.object = [registry, internet, m0, m1, m2, m3, m4, m5, g1, switch0, switch1] nm.object = [registry, internet, m0, m1, m2, m3, m4, m5, g1, switch0, switch1]
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)
...@@ -140,10 +147,14 @@ def network_demo(): ...@@ -140,10 +147,14 @@ def network_demo():
for node in [m1, m2]: for node in [m1, m2]:
node.add_route(nexthop="10.1.9.1") node.add_route(nexthop="10.1.9.1")
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)
...@@ -162,10 +173,10 @@ def network_direct(): ...@@ -162,10 +173,10 @@ def network_direct():
nm.registrys = {registry: [m0]} nm.registrys = {registry: [m0]}
re_if_0, m_if_0 = nemu.P2PInterface.create_pair(registry, m0) re_if_0, m_if_0 = nemu.P2PInterface.create_pair(registry, m0)
registry._ip = u"10.1.2.1" registry._ip = u"10.1.2.1"
re_if_0.add_v4_address(u"10.1.2.1", prefix_len=24) re_if_0.add_v4_address(u"10.1.2.1", prefix_len=24)
m_if_0.add_v4_address(u"10.1.2.2", prefix_len=24) m_if_0.add_v4_address(u"10.1.2.2", prefix_len=24)
re_if_0.up = m_if_0.up = True re_if_0.up = m_if_0.up = True
...@@ -174,6 +185,7 @@ def network_direct(): ...@@ -174,6 +185,7 @@ def network_direct():
ret = app0.wait() ret = app0.wait()
assert ret == 0, "network construct failed" assert ret == 0, "network construct failed"
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 = []
...@@ -92,10 +116,10 @@ class TestPing(unittest.TestCase): ...@@ -92,10 +116,10 @@ class TestPing(unittest.TestCase):
node = re6st_wrap.Re6stNode(m, reg) node = re6st_wrap.Re6stNode(m, reg)
node.run("-i" + m.iface.name) node.run("-i" + m.iface.name)
nodes.append(node) nodes.append(node)
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