# SDN_NFV Lab 1: ONOS and Mininet Installation > - 課程名稱:軟體定義網路及網路功能虛擬化 > - 修課時間:113-1 > - SDN_NFV Lab: Lab 1 ONOS and Mininet Installation (Environment Setup & Basic Operation) ## Part1: Activate ONOS APPS ### 1. When ONOS activate “org.onosproject.openflow,” what APPs does it activate? ### 解題邏輯 在我們 Build ONOS 完之後,有些 App 就已經安裝好並處於 activate 狀態(如下圖),其中也包含 `org.onosproject.openflow`。 ![image](https://hackmd.io/_uploads/rkT8_HQ6R.png) 因此我先 deactivate `org.onosproject.openflow` app,然後輸入`apps -a -s` 列出當前所有處於啟用狀態的 app 清單(activated apps),而後再次 activate `org.onosproject.openflow` app,並再次列出當前被啟用的 app 清單,進行肉眼比對(如下圖紅框) ```bash= app deactivate org.onosproject.openflow #停用 onos openflow App app activate org.onosproject.openflow #啟用 onos openflow App ``` ```bash= apps -a -s # Show activated apps only ``` ![image](https://hackmd.io/_uploads/H1ApkBXpR.png) #### ANS:下列為再次重新 activate `org.onosproject.openflow` app 後,自動啟動的 apps: - org.onosproject.optical-model - org.onosproject.lidpprovider - org.onosproject.openflow-base ## 2. After we activate ONOS and run P.17 Mininet command, will H1 ping H2 successfully? Why or why not? ```cmd= # P.17 Mininet command: sudo mn --topo=linear,3 --controller=remote,127.0.0.1:6653 \ --switch=ovs,protocols=OpenFlow14 ``` P.15 投影片已教學如何透過 ONOS GUI 來啟用 Reactive Forwarding 功能的 app,所以學生這時就已經啟用了 `org.onosproject.fwd` app,因此後續使用 H1 ping H2 的執行結果是成功的。 但是如果在安裝/啟用 `org.onosproject.fwd` app 之前,在主機之間執行 ping 應該不起作用,並且經證實,我手動 deactivate `org.onosproject.fwd` app 之後,嘗試在 host 間 pingall 就通通失敗了(如下圖)。 ![image](https://hackmd.io/_uploads/r14Oi8XTR.png) > 仍待驗證:我想應該是因為 Openflow Switch 上沒有預設的封包轉發規則(forwarding entries)。再加上當發生 table missing 時,packet in 的功能不是 Switch 開機預設就有,需要 config 才會 packet in 送入 Controller 進行處理,不然預設就是將封包 drop 掉。([參考資料](https://wiki.onosproject.org/display/ONOS11/Experimental+Features)) ## Observe ONOS listening port with terminal command “netstat" > Hint: Observe the Network connection > 1. Bring up and enter a new terminal > 2. Deativate/activate apps and use “netstat: in the new terminal to observe network connection ### 3. Which TCP port does the controller listen to the OpenFlow connection request from the switch? (Take screenshot and explain your answer.) #### ANS: ONOS Controller 會在 TCP port 6653 監聽想要建立連線的 Openflow switches ![image](https://hackmd.io/_uploads/rk2PO_maR.png) 在 ONOS Build 好了之後,使用 `netstat -nlpt` 指令,來監聽/檢查網路連接和 port 的狀態。當我使用 app deactivate org.onosproject.openflow 將此 App deactivate 之後,再次使用 `netstat -nlpt` 指令查看,前後對比可以發現 TCP port 6653 已經沒有在被監聽,不處於服務狀態。 ### 4. In question 3, which APP enables the controller to listen on the TCP port? #### Ans: **org.openproject.openflow**,要啟用這個 app ,TCP port 6653 才會被啟用,並才能讀到 mininet 所建立的 device 和網路拓樸。 ## Part2 : Create a custom Topology :::spoiler Write a Python script to build the following topology ![image](https://hackmd.io/_uploads/S1ziHvVTA.png) ::: > file name:lab1_part2_110950009.py ```python= from mininet.topo import Topo class lab1_part2_110950009( Topo ): def __init__( self ): Topo.__init__( self ) # Add hosts h1 = self.addHost( 'h1' ) h2 = self.addHost( 'h2' ) h3 = self.addHost( 'h3' ) h4 = self.addHost( 'h4' ) h5 = self.addHost( 'h5' ) # Add switches s1 = self.addSwitch( 's1' ) s2 = self.addSwitch( 's2' ) s3 = self.addSwitch( 's3' ) s4 = self.addSwitch( 's4' ) # Add links self.addLink( h1, s1 ) self.addLink( h2, s2 ) self.addLink( h3, s3 ) self.addLink( h4, s4 ) self.addLink( h5, s4 ) self.addLink( s1, s4 ) self.addLink( s1, s2 ) self.addLink( s2, s4 ) self.addLink( s3, s2 ) self.addLink( s3, s4 ) topos = { 'topo_part2_110950009': lab1_part2_110950009 } ``` :::spoiler 成果截圖 ![image](https://hackmd.io/_uploads/r1LPM_Vp0.png) ::: ## Part3 : Statically assign Hosts IP Address in Mininet > file name:lab1_part3_110950009.pylab1_part3_110950009.py ```python= from mininet.topo import Topo class lab1_part3_110950009( Topo ): def __init__( self ): Topo.__init__( self ) # Add hosts h1 = self.addHost( 'h1', ip='192.168.0.1/27') h2 = self.addHost( 'h2', ip='192.168.0.2/27') h3 = self.addHost( 'h3', ip='192.168.0.3/27') h4 = self.addHost( 'h4', ip='192.168.0.4/27') h5 = self.addHost( 'h5', ip='192.168.0.5/27') # Add switches s1 = self.addSwitch( 's1' ) s2 = self.addSwitch( 's2' ) s3 = self.addSwitch( 's3' ) s4 = self.addSwitch( 's4' ) # Add links self.addLink( h1, s1 ) self.addLink( h2, s2 ) self.addLink( h3, s3 ) self.addLink( h4, s4 ) self.addLink( h5, s4 ) self.addLink( s1, s4 ) self.addLink( s1, s2 ) self.addLink( s2, s4 ) self.addLink( s3, s2 ) self.addLink( s3, s4 ) topos = { 'topo_part3_110950009': lab1_part3_110950009 } ``` ![image](https://hackmd.io/_uploads/ByoQm_NT0.png) > Topology with assign Hosts IP Address and CLI `dump` :::spoiler Picture of all host `ifconfig` - ![image](https://hackmd.io/_uploads/r1m18i7aC.png) - ![image](https://hackmd.io/_uploads/HkLmUsXpC.png) - ![image](https://hackmd.io/_uploads/Sy5EIo7TC.png) - ![image](https://hackmd.io/_uploads/S13HLjXpR.png) - ![image](https://hackmd.io/_uploads/rywILiQaR.png) ::: ## Part 4: What you’ve learned or solved 為了觀察狀態變化,把幾個 app 給 deactive,但不知道什麼原因,重新啟用後,系統出現了登入問題,努力 troubleshooting 但仍舊未果,最後是全部重來解決了這個問題,但我那天晚上沒有睡覺,所以我學到了 linux 的指令操作,還有**心態要穩**,並且要記得要時間管理,也許到一個程度無法解決時,直接重灌可能是一個好的方法? ### 複習 - Reactive Forwarding - Status listen 狀態的詳細意思 - netstat -nlpt