Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """p3-template.py:
- This mininet script creates a linear routed multi-hop topology:
- 2001:638:709:a::/64 2001:638:709:f::/64 2001:638:709:b::/64
- .------------------..------------------..------------------.
- h1 ------ s1 ------ r1 ------ s0 ------ r2 ------ s2 ------ h2
- eth0 eth0 eth1 eth0 eth1 eth0
- Assign the following IPv6 addresses and prefixes:
- h1-eth0 2001:638:709:a::1/64
- r1-eth0 2001:638:709:a::f/64
- r1-eth1 2001:638:709:f::1/64
- r2-eth0 2001:638:709:f::2/64
- r2-eth1 2001:638:709:b::f/64
- h2-eth0 2001:638:709:b::1/64
- Debugging hints:
- - If you get a 'network unreachable' error, then most likely a
- forwarding table entry is missing somewhere or wrong.
- - If you get a 'destination unreachable' error, then most likely
- neighbor discovery failed somewhere.
- - Use the 'ip -6 address', 'ip -6 route', and 'ip -6 neigh'
- commands to inspect the forwarding tables and the neighbor
- mapping tables.
- - If pings from h1 to h2 do not work, try to ping r1 from h1 and
- try to ping r1 from h2. (Test whether the links work first.)
- - You can print the result of the configuration commands to see
- whether any errors occurred.
- - You can run tcpdump (or even wireshark) to capture packets in
- order to see what is going on.
- """
- from mininet.cli import CLI
- from mininet.net import Mininet
- from mininet.nodelib import LinuxBridge
- from mininet.log import setLogLevel
- if __name__ == '__main__':
- setLogLevel('info')
- net = Mininet(switch=LinuxBridge, controller=None)
- h1 = net.addHost('h1', ip=None)
- h2 = net.addHost('h2', ip=None)
- r1 = net.addHost('r1', ip=None)
- r2 = net.addHost('r2', ip=None)
- s0 = net.addSwitch('s0')
- s1 = net.addSwitch('s1')
- s2 = net.addSwitch('s2')
- # enabling forwarding:
- r1.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
- r2.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
- net.addLink(h1, s1)
- net.addLink(s1, r1)
- net.addLink(r1, s0)
- net.addLink(s0, r2)
- net.addLink(r2, s2)
- net.addLink(s2, h2)
- print h1.cmd("ip -V")
- # assigning IP addresses:
- h1.cmd("ip addr add 2001:638:709:a::1/64 dev h1-eth0") # h1 -- s1
- r1.cmd("ip addr add 2001:638:709:a::f/64 dev r1-eth0") # s1 -- r1
- r1.cmd("ip addr add 2001:638:709:f::1/64 dev r1-eth1") # r1 -- s0
- r2.cmd("ip addr add 2001:638:709:f::2/64 dev r2-eth0") # s0 -- r2
- r2.cmd("ip addr add 2001:638:709:b::f/64 dev r2-eth1") # r2 -- s2
- h2.cmd("ip addr add 2001:638:709:b::1/64 dev h2-eth0") # s2 -- h2
- # adding default routes:
- h1.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:a::f dev h1-eth0")
- h2.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:b::f dev h2-eth0")
- r1.cmd("ip -6 route add 2001:638:709:b::/64 via 2001:638:709:f::2 dev r1-eth1")
- r2.cmd("ip -6 route add 2001:638:709:a::/64 via 2001:638:709:f::1 dev r2-eth0")
- net.start()
- CLI(net)
- net.stop()
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #!/usr/bin/env python
- from mininet.cli import CLI
- from mininet.net import Mininet
- from mininet.nodelib import LinuxBridge
- from mininet.log import setLogLevel
- if __name__ == '__main__':
- setLogLevel('info')
- net = Mininet(switch=LinuxBridge, controller=None)
- h1 = net.addHost('h1',ip=None)
- h2 = net.addHost('h2',ip=None)
- s0 = net.addSwitch('s0')
- s1 = net.addSwitch('s1')
- s2 = net.addSwitch('s2')
- s3 = net.addSwitch('s3')
- r1 = net.addHost('r1',ip=None)
- r2 = net.addHost('r2',ip=None)
- r3 = net.addHost('r3',ip=None)
- r4 = net.addHost('r4',ip=None)
- r1.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
- r2.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
- r3.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
- r4.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
- net.addLink(h1,s1)
- net.addLink(h2,s2)
- net.addLink(s0,r1, intfName2='r1-eth1')
- net.addLink(s1,r1, intfName2='r1-eth0')
- net.addLink(s0,r2, intfName2='r2-eth0')
- net.addLink(s2,r2, intfName2='r2-eth1')
- net.addLink(s1,r3, intfName2='r3-eth0')
- net.addLink(s3,r3, intfName2='r3-eth1')
- net.addLink(s3,r4, intfName2='r4-eth0')
- net.addLink(s2,r4, intfName2='r4-eth1')
- print h1.cmd('ip -V')
- h1.cmd("ip -6 addr add 2001:638:709:a::1/64 dev h1-eth0")
- h1.cmd("ip route add 2001:638:709:f::/64 via 2001:638:709:a::f dev h1-eth0")
- h1.cmd("ip route add 2001:638:709:b::/64 via 2001:638:709:a::f dev h1-eth0")
- h2.cmd("ip -6 addr add 2001:638:709:b::1/64 dev h2-eth0")
- h2.cmd("ip route add 2001:638:709:e::/64 via 2001:638:709:b::e dev h2-eth0")
- h2.cmd("ip route add 2001:638:709:a::/64 via 2001:638:709:b::e dev h2-eth0")
- r1.cmd("ip -6 addr add 2001:638:709:a::f/64 dev r1-eth0")
- r1.cmd("ip -6 addr add 2001:638:709:f::1/64 dev r1-eth1")
- r1.cmd("ip -6 route add 2001:638:709:b::/64 dev r1-eth1 via 2001:638:709:f::2")
- r2.cmd("ip addr add 2001:638:709:f::2/64 dev r2-eth0")
- r2.cmd("ip addr add 2001:638:709:b::f/64 dev r2-eth1")
- r2.cmd("ip route add 2001:638:709:a::/64 via 2001:638:709:f::1 dev r2-eth0")
- r3.cmd("ip addr add 2001:638:709:a::e/64 dev r3-eth0")
- r3.cmd("ip addr add 2001:638:709:e::1/64 dev r3-eth1")
- r3.cmd("ip route add 2001:638:709:b::/64 via 2001:638:709:e::2 dev r3-eth1")
- r4.cmd("ip addr add 2001:638:709:e::2/64 dev r4-eth0")
- r4.cmd("ip addr add 2001:638:709:b::e/64 dev r4-eth1")
- r4.cmd("ip route add 2001:638:709:a::/64 via 2001:638:709:e::1 dev r4-eth0")
- net.start()
- CLI(net)
- net.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement