mininet multihomed topology

8 篇文章 2 订阅
7 篇文章 4 订阅

 multihomed topology created in mininet to test the performance for mptcp or multipath quic.
 7h.py

#!/usr/bin/python
#  author zsy
#  2020.12.11
#
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import TCLink
import time
#        ----r2-----
#    0  / 1          \0 1
#h1----r1            r4---h2---h3
#       \ 2          /2
#        ----r3------

#      2-------3
#  1---         ----6---7
#      4-------5
max_queue_size = 20  
net = Mininet( cleanup=True )
h1 = net.addHost('h1',ip='10.0.1.1')
r1 = net.addHost('r1',ip='10.0.1.2')
r2 = net.addHost('r2',ip='10.0.2.2')
r3 = net.addHost('r3',ip='10.0.4.2')
r4 = net.addHost('r4',ip='10.0.5.2')
h2 = net.addHost('h2',ip='10.0.6.2')
h3 = net.addHost('h3',ip='10.0.7.2')
c0 = net.addController('c0')

net.addLink(h1,r1,intfName1='h1-eth0',intfName2='r1-eth0',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)
net.addLink(r1,r2,intfName1='r1-eth1',intfName2='r2-eth0',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)
net.addLink(r2,r4,intfName1='r2-eth1',intfName2='r4-eth0',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)
net.addLink(r4,h2,intfName1='r4-eth1',intfName2='h2-eth0',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)
net.addLink(h2,h3,intfName1='h2-eth1',intfName2='h3-eth0',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)

net.addLink(r1,r3,intfName1='r1-eth2',intfName2='r3-eth0',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)
net.addLink(r3,r4,intfName1='r3-eth1',intfName2='r4-eth2',cls=TCLink , bw=2, delay='20ms', max_queue_size=max_queue_size)

net.build()

h1.cmd("ifconfig h1-eth0 10.0.1.1/24")
h1.cmd("route add default gw 10.0.1.2")

r1.cmd("ifconfig r1-eth0 10.0.1.2/24")
r1.cmd("ifconfig r1-eth1 10.0.2.1/24")
r1.cmd("ifconfig r1-eth2 10.0.4.1/24")

r1.cmd("ip route flush all proto static scope global")
r1.cmd("ip route add 10.0.2.1/24 dev r1-eth1 table 5000")
r1.cmd("ip route add default via 10.0.2.2 dev r1-eth1 table 5000")

r1.cmd("ip route add 10.0.4.1/24 dev r1-eth2 table 5001")
r1.cmd("ip route add default via 10.0.4.2 dev r1-eth2 table 5001")
r1.cmd("ip rule add from 10.0.2.1 table 5000")
r1.cmd("ip rule add from 10.0.4.1 table 5001")
r1.cmd("ip route add default gw 10.0.2.2  dev r1-eth1")

r1.cmd("ip route add to 10.0.1.0/24 via 10.0.1.1")
r1.cmd("ip route add to 10.0.2.0/24 via 10.0.2.2")
r1.cmd("ip route add to 10.0.3.0/24 via 10.0.2.2")
r1.cmd("ip route add to 10.0.6.0/24 via 10.0.2.2")
r1.cmd("ip route add to 10.0.7.0/24 via 10.0.2.2")
r1.cmd('sysctl net.ipv4.ip_forward=1')

r2.cmd("ifconfig r2-eth0 10.0.2.2/24")
r2.cmd("ifconfig r2-eth1 10.0.3.1/24")

r2.cmd("ip route add to 10.0.1.0/24 via 10.0.2.1")
r2.cmd("ip route add to 10.0.2.0/24 via 10.0.2.1")
r2.cmd("ip route add to 10.0.3.0/24 via 10.0.3.2")
r2.cmd("ip route add to 10.0.6.0/24 via 10.0.3.2")
r2.cmd("ip route add to 10.0.7.0/24 via 10.0.3.2")
r2.cmd('sysctl net.ipv4.ip_forward=1')


r3.cmd("ifconfig r3-eth0 10.0.4.2/24")
r3.cmd("ifconfig r3-eth1 10.0.5.1/24")

r3.cmd("ip route add to 10.0.1.0/24 via 10.0.4.1")
r3.cmd("ip route add to 10.0.4.0/24 via 10.0.4.1")
r3.cmd("ip route add to 10.0.5.0/24 via 10.0.5.5")
r3.cmd("ip route add to 10.0.6.0/24 via 10.0.5.2")
r3.cmd("ip route add to 10.0.7.0/24 via 10.0.5.2")
r3.cmd('sysctl net.ipv4.ip_forward=1')


r4.cmd("ifconfig r4-eth0 10.0.3.2/24")
r4.cmd("ifconfig r4-eth1 10.0.6.1/24")
r4.cmd("ifconfig r4-eth2 10.0.5.2/24")


r4.cmd("ip route flush all proto static scope global")
r4.cmd("ip route add 10.0.3.2/24 dev r4-eth0 table 5000")
r4.cmd("ip route add default via 10.0.3.1 dev r4-eth0 table 5000")

r4.cmd("ip route add 10.0.5.2/24 dev r4-eth2 table 5001")
r4.cmd("ip route add default via 10.0.4.2 dev r4-eth2 table 5001")
r4.cmd("ip rule add from 10.0.3.2 table 5000")
r4.cmd("ip rule add from 10.0.5.2 table 5001")
r4.cmd("ip route add default gw 10.0.3.1  dev r4-eth0")


r4.cmd("ip route add to 10.0.1.0/24 via 10.0.3.1")
r4.cmd("ip route add to 10.0.2.0/24 via 10.0.3.1")
r4.cmd("ip route add to 10.0.3.0/24 via 10.0.3.1")
r4.cmd("ip route add to 10.0.4.0/24 via 10.0.5.1")
r4.cmd("ip route add to 10.0.5.0/24 via 10.0.5.1")
r4.cmd("ip route add to 10.0.6.0/24 via 10.0.6.2")
r4.cmd("ip route add to 10.0.7.0/24 via 10.0.6.2")
r4.cmd('sysctl net.ipv4.ip_forward=1')


h2.cmd("ifconfig h2-eth0 10.0.6.2/24")
h2.cmd("ifconfig h2-eth1 10.0.7.1/24")

h2.cmd("ip route add to 10.0.1.0/24 via 10.0.6.1")
h2.cmd("ip route add to 10.0.2.0/24 via 10.0.6.1")
h2.cmd("ip route add to 10.0.3.0/24 via 10.0.6.1")
h2.cmd("ip route add to 10.0.4.0/24 via 10.0.6.1")
h2.cmd("ip route add to 10.0.5.0/24 via 10.0.6.1")
h2.cmd("ip route add to 10.0.6.0/24 via 10.0.6.1")
h2.cmd("ip route add to 10.0.7.0/24 via 10.0.7.2")
h2.cmd('sysctl net.ipv4.ip_forward=1')

h3.cmd("ifconfig h3-eth0 10.0.7.2/24")
h3.cmd("route add default gw 10.0.7.1")
net.start()
time.sleep(1)
CLI(net)
net.stop()

Reference:
[1] mininet topology

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值