码迷,mamicode.com
首页 > Web开发 > 详细

Mininet(轻量级软件定义网络和测试平台) 之四

时间:2018-05-26 12:58:48      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:mininet

mininet-4

延續上篇博客,我們新增一台h4,並開啟Hub功能
s0.cmd("brctl setageing br0 0")

#!/usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink

if ‘__main__‘ == __name__ :
 net = Mininet(link=TCLink)
 h1 = net.addHost(‘h1‘, ip="192.168.10.1/24", mac="00:00:00:00:00:01")
 h2 = net.addHost(‘h2‘, ip="192.168.10.2/24", mac="00:00:00:00:00:02")
 h3 = net.addHost(‘h3‘, ip="192.168.20.1/24", mac="00:00:00:00:00:03")
 h4 = net.addHost(‘h4‘, ip="192.168.10.3/24", mac="00:00:00:00:00:04")
 r0 = net.addHost(‘r0‘)
 s0 = net.addHost(‘s0‘)
 net.addLink(h1, s0)
 net.addLink(h2, s0)
 net.addLink(s0, r0)
 net.addLink(r0, h3)
 net.addLink(s0, h4)
 net.build()
 r0.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
 r0.cmd(‘ifconfig r0-eth0 192.168.10.254 netmask 255.255.255.0‘)
 r0.cmd(‘ifconfig r0-eth1 192.168.20.254 netmask 255.255.255.0‘)
 h1.cmd("ip route add default via 192.168.10.254 dev h1-eth0")
 h2.cmd("ip rotue add default via 192.168.10.254 dev h2-eth0")
 h3.cmd("ip route add default via 192.168.20.254 dev h3-eth0")
 h4.cmd("ip route add default via 192.168.10.254 dev h4-eth0")
 s0.cmd("brctl addbr br0")
 s0.cmd("brctl addif br0 s0-eth0")
 s0.cmd("brctl addif br0 s0-eth1")
 s0.cmd("brctl addif br0 s0-eth2")
 s0.cmd("brctl addif br0 s0-eth3")
 s0.cmd("brctl setageing br0 0")
 s0.cmd("ifconfig br0 up")
 CLI(net)
 net.stop()

技术分享图片
技术分享图片

Mininet(轻量级软件定义网络和测试平台) 之四

标签:mininet

原文地址:http://blog.51cto.com/12098022/2120534

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!