# Mininet-containernet 5 Dynamic Routing OSPF Topology ![](https://hackmd.io/_uploads/ByzYax183.png) Script ``` #!/usr/bin/env python from mininet.net import Containernet from mininet.cli import CLI from mininet.link import TCLink, Link from mininet.log import info, setLogLevel if '__main__' == __name__: setLogLevel('info') net = Containernet() h1 = net.addHost('h1') h2 = net.addHost('h2') r1 = net.addDocker('r1', dimage="kathara/quagga:latest", volumes=["/home/user/server-test/test-quagga-ospf/dynamic_routing/r1/quagga:/etc/quagga"]) r2 = net.addDocker('r2', dimage="kathara/quagga:latest", volumes=["/home/user/server-test/test-quagga-ospf/dynamic_routing/r2/quagga:/etc/quagga"]) r3 = net.addDocker('r3', dimage="kathara/quagga:latest", volumes=["/home/user/server-test/test-quagga-ospf/dynamic_routing/r3/quagga:/etc/quagga"]) net.addLink(h1, r1) net.addLink(h2, r2) net.addLink(r1, r2) net.addLink(r1, r3) net.addLink(r2, r3) net.build() r1.cmd("ifconfig r1-eth0 0") r1.cmd("ifconfig r1-eth1 0") r1.cmd("ifconfig r1-eth2 0") r2.cmd("ifconfig r2-eth0 0") r2.cmd("ifconfig r2-eth1 0") r2.cmd("ifconfig r2-eth2 0") r3.cmd("ifconfig r3-eth0 0") r3.cmd("ifconfig r3-eth1 0") r1.cmd("ip addr add 192.168.1.254/24 brd + dev r1-eth0") r1.cmd("ip addr add 12.1.1.1/24 brd + dev r1-eth1") r1.cmd("ip addr add 13.1.1.1/24 brd + dev r1-eth2") r2.cmd("ip addr add 192.168.2.254/24 brd + dev r2-eth0") r2.cmd("ip addr add 12.1.1.2/24 brd + dev r2-eth1") r2.cmd("ip addr add 23.1.1.2/24 brd + dev r2-eth2") r3.cmd("ip addr add 13.1.1.3/24 brd + dev r3-eth0") r3.cmd("ip addr add 23.1.1.3/24 brd + dev r3-eth1") r1.cmd("/etc/init.d/quagga restart") r2.cmd("/etc/init.d/quagga restart") r3.cmd("/etc/init.d/quagga restart") h1.cmd("ifconfig h1-eth0 0") h1.cmd("ip address add 192.168.1.1/24 dev h1-eth0") h1.cmd("ip route add default via 192.168.1.254 dev h1-eth0") h2.cmd("ifconfig h2-eth0 0") h2.cmd("ip address add 192.168.2.1/24 dev h2-eth0") h2.cmd("ip route add default via 192.168.2.254 dev h2-eth0") CLI(net) net.stop() ``` R1 OSPF configured File ``` root@ubuntu:/home/user/server-test/test-quagga-ospf/dynamic_routing/r1/quagga# cat ospfd.conf hostname R1 password zebra router ospf ospf router-id 12.1.1.1 network 192.168.1.0/24 area 0.0.0.0 network 12.1.1.0/24 area 0.0.0.0 network 13.1.1.0/24 area 0.0.0.0 log file /var/log/quagga/zebra.log ``` R1 login (OSPF) ``` root@ubuntu:/home/user/Desktop# docker exec -it f691 bash root@r1:/# nc localhost 2603 bash: nc: command not found root@r1:/# nc localhost 2604 bash: nc: command not found root@r1:/# telnet localhost 2604 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Hello, this is Quagga (version 1.0.20160315). Copyright 1996-2005 Kunihiro Ishiguro, et al. User Access Verification Password: R1> ``` Privilege Mode ``` enable ``` Lookup OSPF info ``` R1# show ip ospf OSPF Routing Process, Router ID: 12.1.1.1 Area ID: 0.0.0.0 (Backbone) Number of interfaces in this area: Total: 3, Active: 3 Number of fully adjacent neighbors in this area: 2 Area has no authentication ``` ## Show ospf Neighbor (r1) ``` R1# show ip ospf neighbor Neighbor ID Pri State Dead Time Address Interface RXmtL RqstL DBsmL 12.1.1.2 1 Full/DR 35.437s 12.1.1.2 r1-eth1:12.1.1.1 0 0 0 13.1.1.3 1 Full/DR 36.582s 13.1.1.3 r1-eth2:13.1.1.1 0 0 0 ``` Show ospf Routing table (r1) ``` R1# show ip ospf route ============ OSPF network routing table ============ N 12.1.1.0/24 [10] area: 0.0.0.0 directly attached to r1-eth1 N 13.1.1.0/24 [10] area: 0.0.0.0 directly attached to r1-eth2 N 23.1.1.0/24 [20] area: 0.0.0.0 via 12.1.1.2, r1-eth1 via 13.1.1.3, r1-eth2 N 192.168.1.0/24 [10] area: 0.0.0.0 directly attached to r1-eth0 N 192.168.2.0/24 [20] area: 0.0.0.0 via 12.1.1.2, r1-eth1 ============ OSPF router routing table ============= ============ OSPF external routing table =========== ``` 我們能觀察 (Routing Metric) 20 -> ospf 學到的路徑 H1 ping H2 success !! ``` containernet> h1 ping h2 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 64 bytes from 192.168.2.1: icmp_seq=1 ttl=62 time=0.169 ms 64 bytes from 192.168.2.1: icmp_seq=2 ttl=62 time=0.132 ms 64 bytes from 192.168.2.1: icmp_seq=3 ttl=62 time=0.114 ms ``` ## Test R2-eth1 shut down ``` ifconfig r2-eth1 down ``` ![](https://hackmd.io/_uploads/Byt5SbkLn.png) eht1 interface -> 會直接 Disappear OSPF 會快速尋徑 ``` R1# show ip ospf route ============ OSPF network routing table ============ N 13.1.1.0/24 [10] area: 0.0.0.0 directly attached to r1-eth2 N 23.1.1.0/24 [20] area: 0.0.0.0 via 13.1.1.3, r1-eth2 N 192.168.1.0/24 [10] area: 0.0.0.0 directly attached to r1-eth0 N 192.168.2.0/24 [30] area: 0.0.0.0 via 13.1.1.3, r1-eth2 ``` Traceroute ``` root@ubuntu:/home/user/server-test/test-quagga-ospf# traceroute 192.168.2.1 traceroute to 192.168.2.1 (192.168.2.1), 30 hops max, 60 byte packets 1 192.168.1.254 (192.168.1.254) 0.073 ms 0.021 ms 0.022 ms 2 13.1.1.3 (13.1.1.3) 0.240 ms 0.030 ms 0.025 ms 3 23.1.1.2 (23.1.1.2) 0.049 ms 0.027 ms 0.028 ms 4 192.168.2.1 (192.168.2.1) 0.050 ms 0.042 ms 0.040 ms ```