2019 SDN大作業


簡單的負載均衡

1.分組情況

組名:藍藍的大白牙

學號 姓名 貢獻度
031702507 黃皓 13%
031702508 石曉楠 24%
031702511 古力亞爾 13%
031702525 周鑫煌 20%
031702532 陳聰(組長) 30%

2.作業內容

Github倉庫

視頻鏈接

3.實現關鍵

以如下拓撲為基礎

img

搭建拓撲的代碼如下:

from mininet.topo import Topo

class MyTopo( Topo ):

    def __init__( self ):
    
        # initilaize topology   
        Topo.__init__( self )
    
        # add hosts and switches
        host1 = self.addHost( 'h1' )
        host2 = self.addHost( 'h2' )
    host3 = self.addHost( 'h3' )
        switch1 = self.addSwitch( 's1' )
        switch2 = self.addSwitch( 's2' )
        switch3 = self.addSwitch( 's3' )


        # add links
        self.addLink(host1,switch1)
        self.addLink(switch1,switch2)
        self.addLink(switch1,switch3)
        self.addLink(switch2,switch3)
        self.addLink(switch2,host2)
        self.addLink(switch2,host3)


topos = { 'mytopo': ( lambda: MyTopo() ) }

針對s2這個交換機來看,初始情況下來自h2和h3的數據包都往是s2的1端口通過,欲實現在s2端口1滿載時來自h3的數據包改為往s2-eth2通過。

端口的滿載狀態通過該端口的數據率得以判斷。

#獲取s2端口1的流量 
uri = 'http://127.0.0.1:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:2/node-connector/openflow:2:1'

response, content = http.request(uri=uri, method='GET')

content = json.loads(content)

statistics = content['node-connector'][0]['opendaylight-port-statistics:flow-capable-node-connector-statistics']

bytes1 = statistics['bytes']['transmitted']
#間隔1s后獲取bytes2
speed=float(bytes2-bytes1)/1

下發的流表項代碼:

	#s2流表
	#在檢測h2發包的時候s2的1口流量空閑時發的流表
	h2_to_s2_1 ='{"flow": [{"id": "0","match": {"ethernet-match":'\
           		'{"ethernet-type": {"type": "2048"}},'\
				'"ipv4-source":"10.0.0.2/32","ipv4-destination": "10.0.0.1/32"},'\
        		'"instructions": {"instruction": [{"order": "0",'\
        		'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        		'"priority": "101","cookie": "1","table_id": "0"}]}'
	#在檢測h3發包的時候s2的1口流量空閑時發的流表
	h3_to_s2_1 ='{"flow": [{"id": "1","match": {"ethernet-match":'\
           		'{"ethernet-type": {"type": "2048"}},'\
				'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        		'"instructions": {"instruction": [{"order": "0",'\
            	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        		'"priority": "101","cookie": "1","table_id": "0"}]}'
	h3_to_s2_1_full ='{"flow": [{"id": "1","match": {"ethernet-match":'\
            		'{"ethernet-type": {"type": "2048"}},'\
	 			'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
         		'"instructions": {"instruction": [{"order": "0",'\
            	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "1"},"order": "0"}]}}]},'\
         		'"priority": "100","cookie": "1","table_id": "0"}]}'
	#在檢測h3發包的時候s2的1口流量滿載時發的流表	
	h3_to_s2_2 ='{"flow": [{"id": "2","match": {"ethernet-match":'\
           		'{"ethernet-type": {"type": "2048"}},'\
				'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        		'"instructions": {"instruction": [{"order": "0",'\
            	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "2"},"order": "0"}]}}]},'\
        		'"priority": "101","cookie": "1","table_id": "0"}]}'
	h3_to_s2_2_full ='{"flow": [{"id": "2","match": {"ethernet-match":'\
            		'{"ethernet-type": {"type": "2048"}},'\
	 			'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
         		'"instructions": {"instruction": [{"order": "0",'\
             	'"apply-actions": {"action": [{"output-action": {'\
            	'"output-node-connector": "2"},"order": "0"}]}}]},'\
        		'"priority": "100","cookie": "1","table_id": "0"}]}'
	#s3流表
	s3_1='{"flow": [{"id": "0","match": {"ethernet-match":'\
        '{"ethernet-type": {"type": "2048"}},'\
		'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        '"instructions": {"instruction": [{"order": "0",'\
        '"apply-actions": {"action": [{"output-action": {'\
        '"output-node-connector": "1"},"order": "0"}]}}]},'\
        '"priority": "101","cookie": "1","table_id": "0"}]}'
	#s1流表
	s1_h2_To_h1='{"flow": [{"id": "0","match": {"ethernet-match":'\
        	'{"ethernet-type": {"type": "2048"}},'\
			'"ipv4-source":"10.0.0.2/32","ipv4-destination": "10.0.0.1/32"},'\
        	'"instructions": {"instruction": [{"order": "0",'\
        	'"apply-actions": {"action": [{"output-action": {'\
        	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        	'"priority": "101","cookie": "1","table_id": "0"}]}'
	s1_h3_To_h1='{"flow": [{"id": "1","match": {"ethernet-match":'\
        	'{"ethernet-type": {"type": "2048"}},'\
			'"ipv4-source":"10.0.0.3/32","ipv4-destination": "10.0.0.1/32"},'\
        	'"instructions": {"instruction": [{"order": "0",'\
        	'"apply-actions": {"action": [{"output-action": {'\
        	'"output-node-connector": "1"},"order": "0"}]}}]},'\
        	'"priority": "101","cookie": "1","table_id": "0"}]}'
	headers = {'Content-type': 'application/json'}

操作步驟:

  1. 在創建拓撲前,先打開opendaylight控制器
  2. 創建拓撲,並查看拓撲結構
  3. 測試主機之間的連通
  4. wireshark抓包監控流量
  5. 調用負載均衡程序controller.py,使用sudo python controller.py命令執行
  6. 查看交換機s2流表項

此時s2-eth1通暢,h3數據包從1端口出的優先級高
img

此時s2-eth1滿載,h3數據包從2端口出的優先級高
img

4.心得體會

黃皓:SDN這門課本就是創新課,很多知識都很新,有很高的實用性和很強的實踐性。老師上課的時候也覺得很有意思,結合上課時的知識再加上實驗課馬上動手操作實踐,對於這門課了解的也更加深刻,還知道了P4語言,邊緣計算,SVN,ryu控制器,opendaylight控制器,postman的使用,Wireshark的抓包等。在小組匯報中選擇了SDN+機器學習的課題,雖然在最后的大作業中沒有選擇這個題目,但是還是對機器學習和SDN二者的發展和結合有了淺層的了解。負載均衡構建在原有網絡結構之上,它提供了一種透明且廉價有效的方法擴展服務器和網絡設備的帶寬、加強網絡數據處理能力、增加吞吐量、提高網絡的可用性和靈活性。負載均衡有許多種算法可以用在各種各樣的場景下,本次大作業因為時間考試等關系,選擇了比較簡單的應用場景,但還是從中學習了很多,切實了解了負載均衡的思想。

陳聰:上學期剛把計算機網絡學完,還在感嘆創造者的智慧,這學期的SDN課就讓我拓開了眼界。通過它較為短暫的發展史我也逐步了解的SDN究竟為何物,是否以某個不為人知的事物影響並服務着我們的生活。這門課程學習中的幾個實驗也着實讓我找尋到了樂趣,即使有些時候因學習資料的匱乏和不確定性而心煩意亂(無能狂怒)。由此看來,還得好好培養艱苦奮斗的精神。
今后我也會深入學習網絡方面的知識,從繁雜紛亂中找到美好。

石曉楠:在本學期SDN的第一節課,老師問我們對SDN了解多少的時候,說實話我對SDN是真的一無所知,想着又是軟件又是網絡的,應該很難吧。隨着課程的深入,我掌握了越來越多的東西,了解了mininet的使用方法,建拓撲啊之類的,還學會了下發流表,RYU控制器的一些基礎的使用方法。老師發布的“閱讀作業”也讓我了解了一些SDN的知識。平時的作業有時候做的並不是特別好,但還是有所收獲。課程雖然短暫,但也算學習了一些新的知識。期末做的有關機器學習和SDN聯系的匯報,也讓我對這方面內容有了更深的了解和理解。最后的大作業,讓我對這門課的理解也更深入了一些,是有關負載均衡的內容,我們的組長帶領着我們完成了這個實驗,可算是收獲了很多,希望以后還有機會能夠深入的了解,接觸SDN。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM