Commit 78a1dac7 authored by zhifan huang's avatar zhifan huang

add a 2 node test

parent e1aa324b
from sys import prefix
import nemu import nemu
import weakref import weakref
import ipaddress import ipaddress
...@@ -30,7 +31,7 @@ class Node(nemu.Node): ...@@ -30,7 +31,7 @@ class Node(nemu.Node):
return addr return addr
def connect_network(self, internet): def connect_network(self, internet):
""" create a p2p interface with internet, and assaing ipaddress for """ create a p2p interface with internet, and asgin ipaddress for
interface interface
internet: Internet object internet: Internet object
...@@ -145,9 +146,34 @@ def network_demo(): ...@@ -145,9 +146,34 @@ def network_demo():
for node in [m0, m1, m2, m3, m4, m5]: for node in [m0, m1, m2, m3, m4, m5]:
app0 = m1.Popen(["ping", "-c", "1", registry.ip], stdout=PIPE) app0 = node.Popen(["ping", "-c", "1", registry.ip], stdout=PIPE)
ret = app0.wait() ret = app0.wait()
assert ret == 0, "network construct failed" assert ret == 0, "network construct failed"
return nm return nm
def network_direct():
"""one server and one client connect direct"""
registry = Node()
m0 = Node()
nm = NetManager()
nm.registrys = {registry: [m0]}
re_if_0, m_if_0 = nemu.P2PInterface.create_pair(registry, m0)
registry._ip = u"10.1.2.1"
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)
re_if_0.up = m_if_0.up = True
for node in [m0]:
app0 = node.Popen(["ping", "-c", "1", "10.1.2.1"], stdout=PIPE)
ret = app0.wait()
assert ret == 0, "network construct failed"
return nm
if __name__ == "__main__":
network_direct()
...@@ -78,7 +78,7 @@ class TestPing(unittest.TestCase): ...@@ -78,7 +78,7 @@ class TestPing(unittest.TestCase):
"""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_demo() nm = network_direct()
net = nm.registrys net = nm.registrys
nodes = [] nodes = []
registrys = [] registrys = []
......
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