python代码创建拓扑:
from mininet.net importMininet net =Mininet() # Creating nodes in the network. c0 = net.addController() //创建一个控制器 h0 = net.addHost('h0') //创建一台主机 s0 = net.addSwitch('s0') //创建一台交换机 h1 = net.addHost('h1') # Creating links between nodes in network net.addLink(h0, s0) //创建一条链路,使h0和s0连接起来 net.addLink(h1, s0) # Configuration of IP addresses in interfaces h0.setIP('192.168.1.1',24) //设置h0主机的IP地址为192.168.1.1,掩码位24位 h1.setIP('192.168.1.2',24) net.start() //启动拓扑 net.pingAll() //运行pingalll net.stop() //关闭拓扑
addHost()语法可以对主机cpu进行设置,以百分数的形式;
addLink()语法可以设置带宽bw、延迟delay、最大队列的大小max_queue_size、损耗率loss。
from mininet.net importMininet from mininet.node importCPULimitedHost from mininet.link importTCLink net =Mininet(host=CPULimitedHost, link=TCLink) c0 = net.addController() s0 = net.addSwitch('s0') h0 = net.addHost('h0') h1 = net.addHost('h1', cpu=0.5) h2 = net.addHost('h1', cpu=0.5) net.addLink(s0, h0, bw=10, delay='5ms',max_queue_size=1000, loss=10, use_htb=True) net.addLink(s0, h1) net.addLink(s0, h2) net.start() net.pingAll() net.stop()
交互式界面创建主机、交换机等
1 添加主机h3:
2 添加link:
3 给交换机s1添加端口eth3用于连接h3:
4 给h3赋予IP(10.0.0.3):
5 h1 ping h3
测试网络
1 展示所有的网络信息。
2 所有节点的ping测试。