-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroute.py
33 lines (26 loc) · 1.02 KB
/
route.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Example file for testing
This creates a smallt testnet with two hosts belonging to two distinct networks, which are connected
via seperate switches with a router.
"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
import virtnet
def run(vnet):
"Main functionality"
network1 = vnet.Network("192.168.0.0/24", router=1)
network2 = vnet.Network("10.0.0.0/24", router=2)
switch1 = vnet.Switch("sw1", network=network1)
switch2 = vnet.Switch("sw2", network=network2)
host1 = vnet.Host("host1")
host2 = vnet.Host("host2")
router = vnet.Router("router")
host1.connect(vnet.VirtualLink, switch1, "eth0")
router.connect(vnet.VirtualLink, switch1, "eth0")
router.connect(vnet.VirtualLink, switch2, "eth1")
host2.connect(vnet.VirtualLink, switch2, "eth0")
vnet.update_hosts()
host1.Popen(["ping", "-c", "3", "host2"]).wait()
host1.Popen(["traceroute", "host2"]).wait()
input("Done")
with virtnet.Manager() as context:
run(context)