1. 程式人生 > 實用技巧 >實驗6:OpenDaylight 實驗 —— OpenDaylight 及 Postman 實現流表下發

實驗6:OpenDaylight 實驗 —— OpenDaylight 及 Postman 實現流表下發

實驗6:OpenDaylight 實驗 —— OpenDaylight 及 Postman 實現流表下發

一、實驗目的

熟悉 Postman 的使用;熟悉如何使用 OpenDaylight 通過 Postman 下發流表。

二 、實驗 任務

流表有軟超時和硬超時的概念,分別對應流表中的 idle_timeout 和 hard_timeout。

  • idle timeout:如果值為非 0,那麼在對應的時間內如果沒有資料包匹配流表,時間到該流表將被刪除;值為 0 不設軟超時機制。

  • hard timeout:如果值為非 0,那麼在對應的時間內不論是否有資料包匹配流表,時間到流表都會被刪除;值為 0 不設硬超時機制。

推薦閱讀:SDNLAB 文章:OpenFlow 協議超時機制簡介

https://www.sdnlab.com/22563.html

本實驗通過 OpenDaylight 及 Postman 下發關於硬超時的流表,實現拓撲內主機 h1 和 h3 在一定時間內的網路斷開。Postman 是一個 http 請求工具,可用於 RESTAPI 的介面除錯。實驗拓撲如下:

三 、 實驗步驟

1. 實驗環境

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

2. 實驗過程

(1) Postman 安裝

https://www.postman.com/downloads/

站點會監測系統版本,請下載 Linux 版本,解壓到/home/ubuntu/sdn/Postman下即可。進入目錄 sdn/Postman/Postman/Postman 下,執行 Postman 檔案即可

(2) 清理舊資料

  • 先開啟 OpenDaylight 控制器

    $ cd sdn/OpenDaylight/distribution-karaf-0.6.4-Carbon/bin #進入OpenDaylight目錄
    $ ./karaf #啟動控制器
    

  • DELETE

    URL: http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/

  • 清空 Mininet 資料

    $ sudo mn -c
    

(3) 生成拓撲並連線 OpenDaylight

$ sudo mn --topo=single,3 --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13

正常情況下,三臺主機是互通的。

(4) 使用 Postman 填入 JSON 格式的 http 請求

  • 新建put型別請求

    請求URL: http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1

  • 設定type為 Basic Auth, username和password都為 admin

  • 設定Body, 選擇raw, 引數型別為JSON,json內的程式碼如下:

    {
        "flow": [
            {
                "id": "1",
                "match": {
                	"in-port": "1",
                	"ethernet-match": {
                		"ethernet-type": {
                			"type": "0x0800"
            			}
            		},
            		"ipv4-destination": "10.0.0.3/32"
            	},
            	"instructions": {
            		"instruction": [
            			{
            				"order": "0",
            				"apply-actions": {
            					"action": [
                                    {
                                        "order": "0",
                                        "drop-action": {}
                                    }
                                ]
        					}
        				}
        			]
        		},
                "flow-name": "flow1",
                "priority": "65535",
                "hard-timeout": "10",
                "cookie": "2",
                "table_id": "0"
        	}
        ]
    }
    

    (5) 驗證結果

  • 先在 Mininet CLI 中執行 h1 ping h3

  • 點選右上角 send,傳送請求。

  • h1 ping h3 有 10 秒時間是中斷的,結果符合預期。

總結

實驗過程中有遇到 Postman 請求405錯誤, 打聽到的解決方法是重新安裝 OpenDaylight ,感謝小yu姐!!!