謹(jǐn)以該文檔開始自己源碼閱讀時(shí)光
How does it work?
Mininet creates virtual networks using process-based virtualization and network namespaces - features that are available in recent Linux kernels. In Mininet, hosts are emulated as bash processes running in a network namespace, so any code that would normally run on a Linux server (like a web server or client program) should run just fine within a Mininet "Host". The Mininet "Host" will have its own private network interface and can only see its own processes. Switches in Mininet are software-based switches like Open vSwitch or the OpenFlow reference switch. Links are virtual ethernet pairs, which live in the Linux kernel and connect our emulated switches to emulated hosts (processes).
- bin/mn 主運(yùn)行文件岛杀,安裝后執(zhí)行 mn 即調(diào)用的本程序跟衅,是 Python 程序。
mnexec.c 執(zhí)行一些快速命令眯停,比如關(guān)閉文件描述符等庸队,是 C 程序永罚,編譯后生成二進(jìn)制文件 mnexec 被 Python 庫調(diào)用挖函。
mininet.link 模塊
描述鏈路相關(guān)的接口和連接论咏。包括 Intf 類磷仰、Link 類袍嬉、TCIntf 類和 TCLink 類。
mininet.link.Intf
表示基本的網(wǎng)絡(luò)接口灶平,比如 h1-eth0 表示 host 1 上的 eth0 接口伺通。 屬性包括所在的節(jié)點(diǎn),名稱逢享,所接的 link罐监,mac/ip 信息等。 構(gòu)造的時(shí)候會(huì)傳入節(jié)點(diǎn)瞒爬、端口等屬性笑诅,并綁定接口到對應(yīng)的節(jié)點(diǎn)的端口上调缨。
def __init__( self, name, node=None, port=None, link=None,**params ):
"""name: interface name (e.g. h1-eth0)
node: owning node (where this intf most likely lives)
link: parent link if we're part of a link
other arguments are passed to config()"""
self.node = node
self.name = name
self.link = link
self.mac, self.ip, self.prefixLen = None, None, None
# Add to node (and move ourselves if necessary )
node.addIntf( self, port=port )
# Save params for future reference
self.params = params
self.config( **params )
所支持的方法包括配置 mac/ip 等配置方法,大都是通過 ifconfig 命令在對應(yīng)節(jié)點(diǎn)上調(diào)用cmd方法來實(shí)現(xiàn)吆你。 此外弦叶,還提供了 config() 方法來一次性配置所有的屬性。
mininet.link.TCIntf
被 TC(Linux 下的 traffic control 的工具)自定義的接口妇多,可以配置包括帶寬伤哺、延遲、丟包率者祖、最大隊(duì)列長度等參數(shù)
拓展閱讀:Linux 下的高級流控技術(shù)
https://www.ibm.com/developerworks/cn/linux/1412_xiehy_tc/
mininet.node 模塊
節(jié)點(diǎn)模塊表示網(wǎng)絡(luò)中的基本元素(包括主機(jī)立莉、交換機(jī)和控制器),十分關(guān)鍵七问。
其中蜓耻,每個(gè)主機(jī)默認(rèn)在一個(gè)單獨(dú)的名字空間中,交換機(jī)和控制器都在 root 名字空間中械巡。
- mnexec 通過參數(shù) -n將process
re.py 模塊
在程序中刹淌,都會(huì)加載 re 模塊,該模塊為正則表達(dá)式函數(shù)庫讥耗,
可擴(kuò)展學(xué)習(xí) 正則表達(dá)式
待學(xué)習(xí) mark下
Mininet一個(gè)簡單拓?fù)浯罱ㄟ^程
官網(wǎng)介紹mininet提供分析思路
網(wǎng)絡(luò)命名空間概念和理解
利用linux命令行生成的網(wǎng)絡(luò)
再結(jié)合上面的mininet拓?fù)浯罱ㄟ^程博文就可以清楚理解整個(gè)網(wǎng)絡(luò)的搭建過程有勾。
# Create host namespaces
ip netns add h1 //命名空間
ip netns add h2
# Create switch
ovs-vsctl add-br s1
# Create links
ip link add h1-eth0 type veth peer name s1-eth1 //一對虛擬鏈路創(chuàng)建
ip link add h2-eth0 type veth peer name s1-eth2
ip link show
# Move host ports into namespaces
ip link set h1-eth0 netns h1
ip link set h2-eth0 netns h2
ip netns exec h1 ip link show //在自己的命名空間中執(zhí)行
ip netns exec h2 ip link show
# Connect switch ports to OVS
ovs-vsctl add-port s1 s1-eth1
ovs-vsctl add-port s1 s1-eth2
ovs-vsctl show
# Set up OpenFlow controller
ovs-vsctl set-controller s1 tcp:127.0.0.1
ovs-controller ptcp: &
ovs-vsctl show
# Configure network
ip netns exec h1 ifconfig h1-eth0 10.1
ip netns exec h1 ifconfig lo up
ip netns exec h2 ifconfig h2-eth0 10.2
ip netns exec h1 ifconfig lo up
ifconfig s1-eth1 up
ifconfig s1-eth2 up
# Test network
ip netns exec h1 ping -c1 10.2
所有的設(shè)置在系統(tǒng)關(guān)閉后會(huì)自動(dòng)釋放。