一、实验目的
- 能够使用源码安装Mininet;
- 能够使用Mininet的可视化工具生成拓扑;
- 能够使用Mininet的命令行生成特定拓扑;
- 能够使用Mininet交互界面管理SDN拓扑;
- 能够使用Python脚本构建SDN拓扑。
二、实验环境
Ubuntu 20.04 Desktop amd64
三、实验要求
3.1 基本要求
- 使用Mininet可视化工具,生成下图所示的拓扑,并保存拓扑文件名为学号.py。
- 使用Mininet的命令行生成如下拓扑:
a) 3台交换机,每个交换机连接1台主机,3台交换机连接成一条线。
b) 3台主机,每个主机都连接到同1台交换机上。 - 在2 b)的基础上,在Mininet交互界面上新增1台主机并且连接到交换机上,再测试新拓扑的连通性。
- 编辑基本要求第1步保存的Python脚本,添加如下网络性能限制,生成拓扑:
a) h1的cpu最高不超过50%;
b) h1和s1之间的链路带宽为10,延迟为5ms,最大队列大小为1000,损耗率50。
3.2 进阶要求 编写Python脚本,生成如下数据中心网络拓扑,要求:
- 编写.py拓扑文件,命名为“学号_fattree.py”;
- 必须通过Mininet的custom参数载入上述文件,不得直接使用miniedit.py生成的.py文件;
- 设备名称必须和下图一致;
- 使用Python的循环功能实现,不得在代码中手工直接添加设备和链路。
四、实验报告
- 请用Markdown排版,提交在博客园班级作业区,不熟悉Markdown的同学可参考Markdown示例
- 基础要求提交以下内容,其余文字请勿赘述,否则扣分
a) 第1步Mininet运行结果截图
b) 第2步的执行结果截图- 3台交换机,每个交换机连接1台主机,3台交换机连接成一条线。
- 3台主机,每个主机都连接到同1台交换机上。
c) 第3步提交修改过的“学号.py”代码、Mininet运行结果
- 3台交换机,每个交换机连接1台主机,3台交换机连接成一条线。
#212106651.py 文件代码
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
def myNetwork():
net = Mininet( topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None,cpu=0.5) #h1的cpu最高不超过50%;
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
info( '*** Add links\n')
#h1和s1之间的链路带宽为10,延迟为5ms,最大队列大小为1000,损耗率50。
net.addLink(h1, s1, bw=10, delay='5ms',max_queue_size=1000, loss=50, use_htb=True)
net.addLink(h2, s1)
net.addLink(s1, s2)
net.addLink(h3, s2)
net.addLink(s2, h4)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
d) 进阶要求为选做,有完成的同学请提交 学号_fattree.py 代码和执行结果截图,有完成比未完成的上机分数更高。
#!/usr/bin/python
#创建网络拓扑
"""Custom topology example
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
L1 = 2 #第一层交换机数量
L2 = L1 * 2 #第二层交换机数量
L3 = L2 * 2 #第三层交换机数量
c = []
a = []
e = []
# add core ovs 1
for i in range( L1 ):
sw = self.addSwitch( 's{}'.format( i + 1 ) )
c.append( sw )
# add aggregation ovs 2
for i in range( L2 ):
sw = self.addSwitch( 's{}'.format( L1 + i + 1 ) )
a.append( sw )
# add edge ovs 3
for i in range( L3 ):
sw = self.addSwitch( 's{}'.format( L1 + L2 + i + 1 ) )
e.append( sw )
# add links between core and aggregation ovs 1 2
for i in range( L1 ):
sw1 = c[i]
for sw2 in a[i/2::L1/2]:
self.addLink( sw2, sw1 )
# add links between aggregation and edge ovs 2 3
for i in range( 0, L2, 2 ):
for sw1 in a[i:i+2]:
x = i
if(i > 1): x = i + 2
y = x + 4
for sw2 in e[x:y]:
self.addLink( sw2, sw1 )
#add hosts and its links with edge ovs 3 h
count = 1
for sw1 in e:
for i in range(2):
host = self.addHost( 'h{}'.format( count ) )
self.addLink( sw1, host )
count += 1
topos = { 'mytopo': ( lambda: MyTopo() ) }
- 个人总结,包括但不限于实验难度、实验过程遇到的困难及解决办法,个人感想,不少于200字。
在这次实验中,通过上机操作,对mininet软件的使用的熟练度有提高,并了解了mininet的相关语法。同样在实验中,也遇到几处问题:
1. 对于在minet中创建拓扑,是否需要考虑控制器的创建?
如果不添加控制器,而是运用CLI的交互式API【net.addHouse()、net.addLink()、net.addSwitch()】来创建只有交换机、主机下的拓扑结构,是无法正常通信,代码如下
ubuntu@ubuntu-VirtualBox:~/212106651$ sudo mininet/examples/miniedit.py
topo=none
Open vSwitch version is 2.13.8
Open vSwitch version is 2.13.8
New Prefs = {'ipBase': '10.0.0.0/8', 'sflow': {'sflowPolling': '30', 'sflowSampling': '400', 'sflowHeader': '128', 'sflowTarget': ''}, 'terminalType': 'xterm', 'startCLI': '1', 'switchType': 'ovs', 'netflow': {'nflowAddId': '0', 'nflowTarget': '', 'nflowTimeout': '600'}, 'dpctl': '', 'openFlowVersions': {'ovsOf11': '1', 'ovsOf10': '1', 'ovsOf13': '1', 'ovsOf12': '1'}}
Getting Hosts and Switches.
Getting Links.
*** Configuring hosts
**** Starting 0 controllers
**** Starting 0 switches
No NetFlow targets specified.
No sFlow targets specified.
NOTE: PLEASE REMEMBER TO EXIT THE CLI BEFORE YOU PRESS THE STOP BUTTON. Not exiting will prevent MiniEdit from quitting and will prevent you from starting the network again during this session.
*** Starting CLI:
mininet> py net.addHost('h1')
<Host h1: pid=2564>
mininet> py net.addHost('h2')
<Host h2: pid=2566>
mininet> py net.addHost('h3')
<Host h3: pid=2568>
mininet> py net.addSwitch('s1')
<OVSSwitch s1: lo:127.0.0.1 pid=2573>
mininet> py net.addSwitch('s2')
<OVSSwitch s2: lo:127.0.0.1 pid=2576>
mininet> py net.addSwitch('s3')
<OVSSwitch s3: lo:127.0.0.1 pid=2579>
mininet> py net.addLink(h1,s1,0,0)
<mininet.link.Link object at 0x7f28c9dd0210>
mininet> py net.addLink(h2,s2,0,0)
<mininet.link.Link object at 0x7f28c9dd0390>
mininet> py net.addLink(h3,s3,0,0)
<mininet.link.Link object at 0x7f28c9dd0510>
mininet> py net.addLink(s1,s2,1,1)
<mininet.link.Link object at 0x7f28c9dd0690>
mininet> py net.addLink(s2,s3,2,1)
<mininet.link.Link object at 0x7f28c9dd07d0>
mininet>
mininet>
mininet> pingall
*** Ping: testing ping reachability
h1 -> *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X
h2 -> *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X
h3 -> *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X
*** Results: 100% dropped (0/6 received)
mininet>
mininet>
mininet> links
h1-eth0<->s1-eth0 (OK OK)
h2-eth0<->s2-eth0 (OK OK)
h3-eth0<->s3-eth0 (OK OK)
s1-eth1<->s2-eth1 (OK OK)
s2-eth2<->s3-eth1 (OK OK)
mininet>
mininet>
mininet> net
h1 h1-eth0:s1-eth0
h2 h2-eth0:s2-eth0
h3 h3-eth0:s3-eth0
s1 s1-eth0:h1-eth0 s1-eth1:s2-eth1
s2 s2-eth0:h2-eth0 s2-eth1:s1-eth1 s2-eth2:s3-eth1
s3 s3-eth0:h3-eth0 s3-eth1:s2-eth2
mininet>
在Linux控制台中输出的pingall结果翻译是:无法分析ping输出:ping:None:名称解析暂时失败
2. 在实验要求的2 b)上添加一台主机后与一台交换机连接,pingall的执行结果却不是全部能够通信?
ubuntu@ubuntu-VirtualBox:~/212106651$ sudo mn --topo=single,3
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> py net.addHost('h4')
<Host h4: pid=2794>
mininet> py net.addLink(h4,s1)
<mininet.link.Link object at 0x7fae71c65a50>
mininet>
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3 *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X
h2 -> h1 h3 *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X
h3 -> h1 h2 *** Error: could not parse ping output: ping: None: Temporary failure in name resolution
X
h4 -> X X X
*** Results: 50% dropped (6/12 received)
mininet>
在执行pingall命令中会发现部分主机之间通信失败,通过命令打印的错误提示会发现,全部的通信的链路中(12条),只有一半(6条)是可以正常通信,在具体的错误信息中发现,主机h1、h2、h3在作为发送方时,向接收方h4发送请求,均是失败。而主机h4作为发送方发送请求时,均无法联系接收方h1、h2、h3,则具体问题是出现刚创建的主机h4上,对所有的主机信息查询,会发现:
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=2732>
<Host h2: h2-eth0:10.0.0.2 pid=2734>
<Host h3: h3-eth0:10.0.0.3 pid=2736>
<Host h4: h4-eth0:None pid=2794> #主机h4并没有设置ip地址信息
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None,s1-eth4:None pid=2741>
<Controller c0: 127.0.0.1:6653 pid=2725>
mininet>
3. 学号_fattree.py文件在Linux中无法正常执行问题
#1.执行后控制台提示需要安装screen(sudo apt install screen)
screen mn --custom /home/mininet/fattree.py --topo mytopo --controller=remote,ip=10.0.0.20,port=6633 --switch ovsk,protocols=OpenFlow10
#2.在安装screen后,再次执行发现弹出窗口后很快就自动关闭
#3.尝试不通过screen来启动py脚本,在控制台中启动
sudo mn --custom /home/mininet/fattree.py --topo mytopo --controller=remote,ip=10.0.0.20,port=6633 --switch ovsk,protocols=OpenFlow10
#结果如下,可以发现命令执行后会自动停止(pkill杀死进程命令,在最后打印中出现)
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16
*** Adding switches:
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14
*** Adding links:
--------------------------------------------------------------------------------
Caught exception. Cleaning up...
Exception: Error creating interface pair (s3-eth1,s1-eth1): RTNETLINK answers: File exists
--------------------------------------------------------------------------------
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_corelt-nox_core ovs-openflowd ovs-controllerovs-testcontroller udpbwtest mnexec ivs ryu-manager 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_corelt-nox_core ovs-openflowd ovs-controllerovs-testcontroller udpbwtest mnexec ivs ryu-manager 2> /dev/null
pkill -9 -f "sudo mnexec"
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'
*** Removing OVS datapaths
ovs-vsctl --timeout=1 list-br
ovs-vsctl --if-exists del-br s1 -- --if-exists del-br s10 -- --if-exists del-br s11 -- --if-exists del-br s12 -- --if-exists del-br s13 -- --if-exists del-br s14 -- --if-exists del-br s2 -- --if-exists del-br s3 -- --if-exists del-br s4 -- --if-exists del-br s5 -- --if-exists del-br s6 -- --if-exists del-br s7 -- --if-exists del-br s8 -- --if-exists del-br s9
ovs-vsctl --timeout=1 list-br
*** Removing all links of the pattern foo-ethX
ip link show | egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'
( ip link del s1-eth1;ip link del s3-eth1;ip link del s3-eth1;ip link del s1-eth1;ip link del s2-eth1;ip link del s3-eth2;ip link del s3-eth2;ip link del s2-eth1;ip link del s1-eth2;ip link del s4-eth1;ip link del s4-eth1;ip link del s1-eth2;ip link del s2-eth2;ip link del s4-eth2;ip link del s4-eth2;ip link del s2-eth2;ip link del s1-eth3;ip link del s5-eth1;ip link del s5-eth1;ip link del s1-eth3;ip link del s2-eth3;ip link del s5-eth2;ip link del s5-eth2;ip link del s2-eth3;ip link del s1-eth4;ip link del s6-eth1;ip link del s6-eth1;ip link del s1-eth4;ip link del s2-eth4;ip link del s6-eth2;ip link del s6-eth2;ip link del s2-eth4;ip link del s7-eth3;ip link del s7-eth4;ip link del s3-eth3;ip link del s7-eth1;ip link del s7-eth1;ip link del s3-eth3;ip link del s4-eth3;ip link del s7-eth2;ip link del s7-eth2;ip link del s4-eth3;ip link del s8-eth3;ip link del s8-eth4;ip link del s3-eth4;ip link del s8-eth1;ip link del s8-eth1;ip link del s3-eth4;ip link del s4-eth4;ip link del s8-eth2;ip link del s8-eth2;ip link del s4-eth4;ip link del s9-eth3;ip link del s9-eth4;ip link del s3-eth5;ip link del s9-eth1;ip link del s9-eth1;ip link del s3-eth5;ip link del s4-eth5;ip link del s9-eth2;ip link del s9-eth2;ip link del s4-eth5;ip link del s10-eth3;ip link del s10-eth4;ip link del s3-eth6;ip link del s10-eth1;ip link del s10-eth1;ip link del s3-eth6;ip link del s4-eth6;ip link del s10-eth2;ip link del s10-eth2;ip link del s4-eth6;ip link del s11-eth3;ip link del s11-eth4;ip link del s5-eth3;ip link del s11-eth1;ip link del s11-eth1;ip link del s5-eth3;ip link del s6-eth3;ip link del s11-eth2;ip link del s11-eth2;ip link del s6-eth3;ip link del s12-eth3;ip link del s12-eth4;ip link del s5-eth4;ip link del s12-eth1;ip link del s12-eth1;ip link del s5-eth4;ip link del s6-eth4;ip link del s12-eth2;ip link del s12-eth2;ip link del s6-eth4;ip link del s13-eth3;ip link del s13-eth4;ip link del s5-eth5;ip link del s13-eth1;ip link del s13-eth1;ip link del s5-eth5;ip link del s6-eth5;ip link del s13-eth2;ip link del s13-eth2;ip link del s6-eth5;ip link del s14-eth3;ip link del s14-eth4;ip link del s5-eth6;ip link del s14-eth1;ip link del s14-eth1;ip link del s5-eth6;ip link del s6-eth6;ip link del s14-eth2;ip link del s14-eth2;ip link del s6-eth6 ) 2> /dev/null
ip link show
*** Killing stale mininet node processes
pkill -9 -f mininet:
*** Shutting down stale tunnels
pkill -9 -f Tunnel=Ethernet
pkill -9 -f .ssh/mn
rm -f ~/.ssh/mn/*
*** Cleanup complete.
#为了方便对脚本执行后的拓扑能够测试性能,对启动脚本代码做出修改:
sudo mn --custom /home/mininet/fattree.py --topo mytopo --controller=remote
*** Creating network
*** Adding controller
Unable to contact the remote controller at 127.0.0.1:6653
Unable to contact the remote controller at 127.0.0.1:6633
Setting remote controller to 127.0.0.1:6653
*** Adding hosts:
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16
*** Adding switches:
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14
*** Adding links:
(s3, s1) (s3, s2) (s4, s1) (s4, s2) (s5, s1) (s5, s2) (s6, s1) (s6, s2) (s7, h1) (s7, h2) (s7, s3) (s7, s4) (s8, h3) (s8, h4) (s8, s3) (s8, s4) (s9, h5) (s9, h6) (s9, s3) (s9, s4) (s10, h7) (s10, h8) (s10, s3) (s10, s4) (s11, h9) (s11, h10) (s11, s5) (s11, s6) (s12, h11) (s12, h12) (s12, s5) (s12, s6) (s13, h13) (s13, h14) (s13, s5) (s13, s6) (s14, h15) (s14, h16) (s14, s5) (s14, s6)
*** Configuring hosts
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16
*** Starting controller
c0
*** Starting 14 switches
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 ...
*** Starting CLI:
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=7071>
<Host h2: h2-eth0:10.0.0.2 pid=7073>
<Host h3: h3-eth0:10.0.0.3 pid=7075>
<Host h4: h4-eth0:10.0.0.4 pid=7077>
<Host h5: h5-eth0:10.0.0.5 pid=7079>
<Host h6: h6-eth0:10.0.0.6 pid=7081>
<Host h7: h7-eth0:10.0.0.7 pid=7083>
<Host h8: h8-eth0:10.0.0.8 pid=7085>
<Host h9: h9-eth0:10.0.0.9 pid=7087>
<Host h10: h10-eth0:10.0.0.10 pid=7089>
<Host h11: h11-eth0:10.0.0.11 pid=7091>
<Host h12: h12-eth0:10.0.0.12 pid=7093>
<Host h13: h13-eth0:10.0.0.13 pid=7095>
<Host h14: h14-eth0:10.0.0.14 pid=7097>
<Host h15: h15-eth0:10.0.0.15 pid=7099>
<Host h16: h16-eth0:10.0.0.16 pid=7101>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None,s1-eth4:None pid=7106>
<OVSSwitch s2: lo:127.0.0.1,s2-eth1:None,s2-eth2:None,s2-eth3:None,s2-eth4:None pid=7109>
<OVSSwitch s3: lo:127.0.0.1,s3-eth1:None,s3-eth2:None,s3-eth3:None,s3-eth4:None,s3-eth5:None,s3-eth6:None pid=7112>
<OVSSwitch s4: lo:127.0.0.1,s4-eth1:None,s4-eth2:None,s4-eth3:None,s4-eth4:None,s4-eth5:None,s4-eth6:None pid=7115>
<OVSSwitch s5: lo:127.0.0.1,s5-eth1:None,s5-eth2:None,s5-eth3:None,s5-eth4:None,s5-eth5:None,s5-eth6:None pid=7118>
<OVSSwitch s6: lo:127.0.0.1,s6-eth1:None,s6-eth2:None,s6-eth3:None,s6-eth4:None,s6-eth5:None,s6-eth6:None pid=7121>
<OVSSwitch s7: lo:127.0.0.1,s7-eth1:None,s7-eth2:None,s7-eth3:None,s7-eth4:None pid=7124>
<OVSSwitch s8: lo:127.0.0.1,s8-eth1:None,s8-eth2:None,s8-eth3:None,s8-eth4:None pid=7127>
<OVSSwitch s9: lo:127.0.0.1,s9-eth1:None,s9-eth2:None,s9-eth3:None,s9-eth4:None pid=7130>
<OVSSwitch s10: lo:127.0.0.1,s10-eth1:None,s10-eth2:None,s10-eth3:None,s10-eth4:None pid=7133>
<OVSSwitch s11: lo:127.0.0.1,s11-eth1:None,s11-eth2:None,s11-eth3:None,s11-eth4:None pid=7136>
<OVSSwitch s12: lo:127.0.0.1,s12-eth1:None,s12-eth2:None,s12-eth3:None,s12-eth4:None pid=7139>
<OVSSwitch s13: lo:127.0.0.1,s13-eth1:None,s13-eth2:None,s13-eth3:None,s13-eth4:None pid=7142>
<OVSSwitch s14: lo:127.0.0.1,s14-eth1:None,s14-eth2:None,s14-eth3:None,s14-eth4:None pid=7145>
<RemoteController c0: 127.0.0.1:6653 pid=7063>
mininet>
#正常执行
4.执行学号_fattree.py文件后,对创建的拓扑进行pingall测试,结果是全部失败
mininet> pingall
*** Ping: testing ping reachability
h1 -> X X X X X X X X X X X X X X X
h2 -> X X X X X X X X X X X X X X X
h3 -> X X X X X X X X X X X X X X X
h4 -> X X X X X X X X X X X X X X X
h5 -> X X X X X X X X X X X X X X X
h6 -> X X X X X X X X X X X X X X X
h7 -> X X X X X X X X X X X X X X X
h8 -> X X X X X X X X X X X X X X X
h9 -> X X X X X X X X X X X X X X X
h10 -> X X X X X X X X X X X X X X X
h11 -> X X X X X X X X X X X X X X X
h12 -> X X X X X X X X X X X X X X X
h13 -> X X X X X X X X X X X X X X X
h14 -> X X X X X X X X X X X X X X X
h15 -> X X X X X X X X X X X X X X X
h16 -> X X X X X X X X X X X X X X X
*** Results: 100% dropped (0/240 received)
mininet>
标签:mininet,--,ip,拓扑,实践,link,del,SDN,s1
From: https://www.cnblogs.com/lyf5446/p/16705881.html