Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """p3-template.py:
  3.  
  4. This mininet script creates a linear routed multi-hop topology:
  5.  
  6. 2001:638:709:a::/64 2001:638:709:f::/64 2001:638:709:b::/64
  7. .------------------..------------------..------------------.
  8.  
  9. h1 ------ s1 ------ r1 ------ s0 ------ r2 ------ s2 ------ h2
  10. eth0 eth0 eth1 eth0 eth1 eth0
  11.  
  12. Assign the following IPv6 addresses and prefixes:
  13.  
  14. h1-eth0 2001:638:709:a::1/64
  15. r1-eth0 2001:638:709:a::f/64
  16. r1-eth1 2001:638:709:f::1/64
  17. r2-eth0 2001:638:709:f::2/64
  18. r2-eth1 2001:638:709:b::f/64
  19. h2-eth0 2001:638:709:b::1/64
  20.  
  21. Debugging hints:
  22.  
  23. - If you get a 'network unreachable' error, then most likely a
  24. forwarding table entry is missing somewhere or wrong.
  25. - If you get a 'destination unreachable' error, then most likely
  26. neighbor discovery failed somewhere.
  27. - Use the 'ip -6 address', 'ip -6 route', and 'ip -6 neigh'
  28. commands to inspect the forwarding tables and the neighbor
  29. mapping tables.
  30. - If pings from h1 to h2 do not work, try to ping r1 from h1 and
  31. try to ping r1 from h2. (Test whether the links work first.)
  32. - You can print the result of the configuration commands to see
  33. whether any errors occurred.
  34. - You can run tcpdump (or even wireshark) to capture packets in
  35. order to see what is going on.
  36. """
  37.  
  38. from mininet.cli import CLI
  39. from mininet.net import Mininet
  40. from mininet.nodelib import LinuxBridge
  41. from mininet.log import setLogLevel
  42.  
  43.  
  44.  
  45.  
  46.  
  47. if __name__ == '__main__':
  48. setLogLevel('info')
  49.  
  50. net = Mininet(switch=LinuxBridge, controller=None)
  51.  
  52. h1 = net.addHost('h1', ip=None)
  53. h2 = net.addHost('h2', ip=None)
  54. r1 = net.addHost('r1', ip=None)
  55. r2 = net.addHost('r2', ip=None)
  56.  
  57. s0 = net.addSwitch('s0')
  58. s1 = net.addSwitch('s1')
  59. s2 = net.addSwitch('s2')
  60.  
  61. # enabling forwarding:
  62. r1.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
  63. r2.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
  64.  
  65. net.addLink(h1, s1)
  66. net.addLink(s1, r1)
  67. net.addLink(r1, s0)
  68. net.addLink(s0, r2)
  69. net.addLink(r2, s2)
  70. net.addLink(s2, h2)
  71.  
  72.  
  73. print h1.cmd("ip -V")
  74.  
  75.  
  76.  
  77. # assigning IP addresses:
  78. h1.cmd("ip addr add 2001:638:709:a::1/64 dev h1-eth0") # h1 -- s1
  79. r1.cmd("ip addr add 2001:638:709:a::f/64 dev r1-eth0") # s1 -- r1
  80. r1.cmd("ip addr add 2001:638:709:f::1/64 dev r1-eth1") # r1 -- s0
  81. r2.cmd("ip addr add 2001:638:709:f::2/64 dev r2-eth0") # s0 -- r2
  82. r2.cmd("ip addr add 2001:638:709:b::f/64 dev r2-eth1") # r2 -- s2
  83. h2.cmd("ip addr add 2001:638:709:b::1/64 dev h2-eth0") # s2 -- h2
  84.  
  85. # adding default routes:
  86. h1.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:a::f dev h1-eth0")
  87. h2.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:b::f dev h2-eth0")
  88. r1.cmd("ip -6 route add 2001:638:709:b::/64 via 2001:638:709:f::2 dev r1-eth1")
  89. r2.cmd("ip -6 route add 2001:638:709:a::/64 via 2001:638:709:f::1 dev r2-eth0")
  90.  
  91. net.start()
  92. CLI(net)
  93. net.stop()
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. #!/usr/bin/env python
  108.  
  109. from mininet.cli import CLI
  110. from mininet.net import Mininet
  111. from mininet.nodelib import LinuxBridge
  112. from mininet.log import setLogLevel
  113.  
  114.  
  115. if __name__ == '__main__':
  116. setLogLevel('info')
  117.  
  118. net = Mininet(switch=LinuxBridge, controller=None)
  119.  
  120. h1 = net.addHost('h1',ip=None)
  121. h2 = net.addHost('h2',ip=None)
  122.  
  123. s0 = net.addSwitch('s0')
  124. s1 = net.addSwitch('s1')
  125. s2 = net.addSwitch('s2')
  126. s3 = net.addSwitch('s3')
  127.  
  128. r1 = net.addHost('r1',ip=None)
  129. r2 = net.addHost('r2',ip=None)
  130. r3 = net.addHost('r3',ip=None)
  131. r4 = net.addHost('r4',ip=None)
  132.  
  133. r1.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
  134. r2.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
  135. r3.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
  136. r4.cmd("sysctl -w net.ipv6.conf.all.forwarding=1")
  137.  
  138. net.addLink(h1,s1)
  139. net.addLink(h2,s2)
  140. net.addLink(s0,r1, intfName2='r1-eth1')
  141. net.addLink(s1,r1, intfName2='r1-eth0')
  142. net.addLink(s0,r2, intfName2='r2-eth0')
  143. net.addLink(s2,r2, intfName2='r2-eth1')
  144. net.addLink(s1,r3, intfName2='r3-eth0')
  145. net.addLink(s3,r3, intfName2='r3-eth1')
  146. net.addLink(s3,r4, intfName2='r4-eth0')
  147. net.addLink(s2,r4, intfName2='r4-eth1')
  148.  
  149. print h1.cmd('ip -V')
  150.  
  151. h1.cmd("ip -6 addr add 2001:638:709:a::1/64 dev h1-eth0")
  152. h1.cmd("ip route add 2001:638:709:f::/64 via 2001:638:709:a::f dev h1-eth0")
  153. h1.cmd("ip route add 2001:638:709:b::/64 via 2001:638:709:a::f dev h1-eth0")
  154.  
  155. h2.cmd("ip -6 addr add 2001:638:709:b::1/64 dev h2-eth0")
  156. h2.cmd("ip route add 2001:638:709:e::/64 via 2001:638:709:b::e dev h2-eth0")
  157. h2.cmd("ip route add 2001:638:709:a::/64 via 2001:638:709:b::e dev h2-eth0")
  158.  
  159. r1.cmd("ip -6 addr add 2001:638:709:a::f/64 dev r1-eth0")
  160. r1.cmd("ip -6 addr add 2001:638:709:f::1/64 dev r1-eth1")
  161. r1.cmd("ip -6 route add 2001:638:709:b::/64 dev r1-eth1 via 2001:638:709:f::2")
  162.  
  163. r2.cmd("ip addr add 2001:638:709:f::2/64 dev r2-eth0")
  164. r2.cmd("ip addr add 2001:638:709:b::f/64 dev r2-eth1")
  165. r2.cmd("ip route add 2001:638:709:a::/64 via 2001:638:709:f::1 dev r2-eth0")
  166.  
  167. r3.cmd("ip addr add 2001:638:709:a::e/64 dev r3-eth0")
  168. r3.cmd("ip addr add 2001:638:709:e::1/64 dev r3-eth1")
  169. r3.cmd("ip route add 2001:638:709:b::/64 via 2001:638:709:e::2 dev r3-eth1")
  170.  
  171. r4.cmd("ip addr add 2001:638:709:e::2/64 dev r4-eth0")
  172. r4.cmd("ip addr add 2001:638:709:b::e/64 dev r4-eth1")
  173. r4.cmd("ip route add 2001:638:709:a::/64 via 2001:638:709:e::1 dev r4-eth0")
  174.  
  175. net.start()
  176. CLI(net)
  177. net.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement