1. 程式人生 > 實用技巧 >攜程筆試題3--2020-09-08

攜程筆試題3--2020-09-08

一、實驗目的

掌握 Mininet 的自定義拓撲生成方法:命令列建立、Python 指令碼編寫

二、實驗任務

通過使用命令列建立、Python 指令碼編寫生成拓撲,熟悉 Mininet 的基本功能。

三、實驗步驟

1. 實驗環境

安裝了 Ubuntu 18.04.5 Desktop amd64 的虛擬機器

2. 實驗過程

(1)針對特定拓撲的命令列快速建立
// 最小拓撲,1 臺交換機下掛 2 臺主機
$ sudo mn --topo minimal

// 簡單拓撲,1 臺交換機下掛 n 臺主機,此處 n=3,n=2 即為最小拓撲
$ sudo mn --topo single,3

// 線性拓撲,交換機連成一線,每臺交換機下掛 1 臺主機,此處有 3 臺交換機 3 臺主機
$ sudo mn --topo linear,3

// 樹形拓撲,基於深度 depth 和扇出 fanout,此處均為 2
$ sudo mn --topo tree, fanout=2,depth=2

(2) 參考修改實驗指令碼,使之變成一個線性拓撲(交換機和主機數均為3)。

# coding=UTF-8
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
setLogLevel('info') #print the log when Configuring hosts, starting switches and controller
net = Mininet(host=CPULimitedHost, link=TCLink) # 如不限制性能,引數為空
# 建立網路節點
c0 = net.addController()
h1 = net.addHost('h1', cpu=0.5)
h2 = net.addHost('h2', cpu=0.5)
h3 = net.addHost('h3')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
# 建立節點間的鏈路
net.addLink(h1, s1,bw=10,delay='5ms',max_queue_size=1000,loss=10,use_htb=True)
net.addLink(h2, s2)
net.addLink(h3, s3)
net.addLink(s1,s2)
net.addLink(s2,s3)
# 配置主機 ip
h1.setIP('10.0.0.1', 24)
h2.setIP('10.0.0.2', 24)
h3.setIP('10.0.0.3', 24)
net.start()
dumpNodeConnections(net.hosts)
net.pingAll()
h1,h2,h3 = net.get('h1','h2','h3')
net.iperf((h1,h3))
net.iperf((h1,h2))
net.iperf((h2,h3))
net.stop()

(3)使用iperf完成拓撲內三臺主機相互之間的簡單效能測試。

(4)問題解決

  • 環境問題
sudo mn -c # 清理環境
  • 100% 丟包後iperl會導致5001無法連線報錯

心得體會

剛剛開始遇到(4)環境問題時查了git issue才得以解決,這次操作已經比較熟練,實驗順利。