工具:Mininet
拓扑:
一开始设想的拓扑是这样的
实验目的:
实现将fowarding路线从h1-s1-s2-h2(default)改成h1-s1-s3-h2,反过来也一样
使用mininet提供的接口写的python脚本来建立这个拓扑,这一步很简单
from mininet.topo import Topo
class MyTopo(Topo):
def build(self):
#Add hosts and switches
leftHost = self.addHost('h1')
rightHost = self.addHost('h2')
leftSwitch = self.addSwitch('s1')
rightSwitch1 = self.addSwitch('s2')
rightSwitch2 = self.addSwitch('s3')
#Add links
self.addLink(leftHost, leftSwitch)
self.addLink(leftSwitch, rightSwitch1)
self.addLink(leftSwitch, rightSwitch2)
self.addLink(rightSwitch1, rightHost)
self.addLink(rightSwitch2, rightHost)
topos = {'mytopo':(lambda:MyTopo() ) }
sudo mn --custom FILE_PATH --topo mytopo --mac
创建topo时可选的几个实用选项,这些在mininet walkthrough里都可以找到:
--custom: 按后面FILE_PATH对应的文件里给的脚本自定义拓扑
--topo mytopo:指定使用脚本文件中的哪个topo
--mac:这个对于简化实验来说很关键,在这个实验里它把H1的eth0和H2的eth0的mac地址分别设置为了00:00:00:00:00:01和00:00:00:00:00:02(注意,h2的eth1并没有被设置为00:00:00:00:00:02或00:00:00:00:00:03)
--test pingall:可以让所有host节点互ping,看网络是不是通的
此时,h1 ping h2,是可以ping通的,但是走的path是h1-s1-s2-h2,
下面我打