使用Postman下發流表

任務目的

1、掌握OpenFlow流表相關知識,理解SDN網絡中L2,L3,L4層流表的概念。
2、學習並熟練掌握Postman工具下發L2,L3,L4層流表。

任務環境

設備名稱 軟件環境(鏡像) 硬件環境
控制器 Ubuntu 14.04桌面版
OpenDaylight Lithium
CPU:2核 內存:4G 磁盤:20G
交換機 Ubuntu 14.04命令行版
Open vSwitch 2.3.1
CPU:1核 內存:2G 磁盤:20G
主機 Ubuntu14.04桌面版 CPU:1核 內存:2G 磁盤:20G

注:系統默認的賬戶爲root/root@openlab,openlab/user@openlab。

任務內容

1、學習OpenFlow流表的組成,包頭域的解析流程及流表的匹配流程。
2、OpenDaylight控制器對接Open vSwitch交換機。
3、使用Postman工具,下發相應的L2,L3,L4層流表,並驗證。

實驗原理

SDN的設計目標之一就是將網絡設備的控制功能與轉發功能進行分離,進而將控制功能全部集中到遠程的控制器上完成,而SDN交換機只負責在本地做簡單高速的數據轉發。在SDN交換機運行的過程中,其數據轉發的依據就是流表。

一、 流表結構

所謂流表,其實可被視作是SDN對網絡設備的數據轉發功能的一種抽象。在傳統網絡設備中,交換機和路由器的數據轉發需要依賴設備中保存的二層MAC地址轉發表或者三層的IP地址路由表,SDN交換機中使用的流表也是如此,不過在它的表項中整合了網絡中各個層次的網絡配置信息,從而在進行數據轉發時可以使用更豐富的規則。其流表中的每個表項結果如下圖所示:

OpenFlow1.3流表的每個表項由6部分組成:

1、匹配域:匹配域即OpenFlow1.0流表中的包頭域,用於對交換機接收到的數據包的包頭內容進行匹配。在OpenFlow1.0中,流表的包頭域中包括了12個元組(Tuple),相關內容如下圖所示:

入端口 目的MAC地址 以太網類型 VLAN ID VLAN 優先級 源IP地址 目的IP地址 IP協議 IP TOS位 TCP/UDP源端口 TCP/UDP目的端口
Ingress Port Ehter Des Ether Type VLAN ID VLAN Priority IP Src IP Dst IP Proto IP TOS bits TCP/UDP Src Port TCP/UDP Dst Port

如上圖所示,匹配域中用於和交換機接收到的數據包進行匹配的元組涵蓋了ISO網絡模型中的第二至第四層的網絡配置信息。每一個元組中的數值可以是一個確定的值或者是“ANY”以支持對任意值的匹配。另外,如果交換機能夠在IP地址相關元組上支持子網掩碼的話,將有助於實現更精確的匹配。

2、優先級:流表項的匹配次序。

3、計數器:計數器可以針對交換機中每條流表、每個數據流、每個設備端口、每個轉發隊列進行維護,用於統計數據流表的相關信息。

4、Instructions指令集:每個流表項都包含一組指令,當一個數據包匹配表項時指令會被執行。這些指令可以更改數據包,動作集或者流表處理。

5、超時:最大時間計數或流有效時間

6、cookie:由控制器選擇的不透明數據值。控制器用來過濾流統計數據、流改變和流刪除。但處理數據包時不能使用。

二、 匹配域解析流程

當SDN交換機接收到一個數據包時,將按照優先級從table0依次匹配其本地保存的流表中的表項,並以發生具有最高優先級的匹配表項作爲匹配結果,並根據相應的動作對數據包進行操作。同時,一旦匹配成功,對應的計數器將更新;而如果沒能找到匹配的表項,則將數據包轉發給控制器。
OpenFlow交換機對數據包頭的解析和匹配過程的細節操作如圖所示:

  1. 初始化包頭域,按照包頭域的組成—設置每個字段,其中入端口是接收數據包的物理端口。

  2. 如果數據包類型是VLAN(0x8100),那麼就使用VLAN
    ID和PCP字段進行表查找,解封以太網類型爲先的以太網類型解析做準備。

  3. (可選)如果是ARP數據包(0x0806),那麼匹配字段就可能包含IP源和目的地址。

  4. 如果是IP數據包(0x0800),那麼匹配字段就會包含IP首部。如果IP數據包的分段偏移量不爲0或者設置了多個分段bit位,那麼將所有傳輸端口設爲0。如果IP數據包在IP協議族中的編號爲6或者17(分別是TCP/UDP類型),那麼匹配字段包含傳輸端口。如果編號爲1(ICMP數據包)則包含Type和Code字段。

三、 OpenFlow1.3流表匹配流程

OpenFlow1.3匹配流程圖與之前版本相比多了一個table-miss流表項,事實上此前版本就已經存在table-miss概念,只是沒有在流程圖中呈現出來而已。Of1.3版本的匹配流程大致如下圖所示:

首先SDN交換機解析進入設備的報文,然後從table0開始匹配,按照優先級高低依次匹配該流表中的表項,一個報文在一個流表中只會匹配上一條流表項。通常根據報文的類型,報文頭的字段例如源MAC地址、目的MAC地址、源IP地址、目的IP地址等進行匹配,大部分匹配還支持掩碼進行更精確、靈活的匹配。也可以通過報文的入端口或者元數據信息來進行報文的匹配,一個流表項中可以同時存在多個匹配項,一個報文需要同時普票流表項中所有匹配項才能匹配該流表項。報文匹配按照現有的報文字段進行,比如前一個流表通過apply
actions改變了該報文的某個字段,則下一個表現按照修改後的字段進行匹配。如果匹配成功。則按照指令集裏的動作更新動作集,活更新報文/匹配集字段,或更新元數據和計數器。根據指令是否繼續前往下一個流表,不繼續則終止匹配流程執行動作集,如果指令要去繼續前往下一流表則繼續匹配,下一個流表的ID需要比當前流表ID大。當報文匹配失敗,如果存在無匹配流表項(table-miss)就按照該表項執行指令,一般是將報文轉發給控制器、丟棄或者轉發給其他流表。如果沒有table-miss表項則默認丟棄該報文。

實驗步驟

一、實驗環境檢查

步驟1 登錄OpenDaylight控制器,確保服務已經啓動成功,由於OpenDaylight組件過於龐大,所以啓動比較慢,需等待一段時間,使用命令netstat -an|grep 6633查看端口是否處於監聽狀態:

步驟2 在保證控制器6633端口處於監聽狀態後,使用root用戶登錄交換機,查看交換機與控制器連接情況。執行以下命令:


如上圖所示,當出現交換機與控制器連接不成功時,執行$ ovs-vsctl del-controller br-sw $ovs-vsctl set-controller br-sw tcp:20.0.1.3:6633手動重連,稍等一會後,重新查看連接狀態,如下圖所示controller下方顯示“is_connected:true” 則表明連接成功。

步驟3 登錄主機,查看主機IP地址。

主機1信息截圖如下所示。

主機2信息截圖如下所示。

步驟4 在兩個主機上安裝iPerf打流工具。登錄主機後,使用如下命令安裝iPerf打流工具。

$ sudo apt-get install iperf

步驟5 安裝完成可以使用如下命令檢查是否安裝成功。

$ iperf -s

步驟6 執行Ctrl+c關閉iperf應用程序。

二、L2層流表下發與驗證

L2層即對應OSI模型的二層,也就是說通過匹配源MAC(Ether source)、目的MAC地址(Ether dst)、以太網類型(Ether Type)VLAN id、VLAN優先級等字段來實現流的轉發。本實驗將基於源和目的MAC進行數據流的轉發。

步驟1 登錄控制器,在下方的“Application Finder”中搜索“postman”,並打開自帶的Postman工具,如下圖所示。

步驟2 打開Basic Auth頁籤,Username字段填寫admin,Password字段填寫admin完成認證。如下圖所示。


步驟3 提交方式爲GET,URL地址欄中輸入http://127.0.0.1:8080/restconf/operational/network-topology:network-topology ,設置完成單擊Send按鈕,獲取交換機id信息。如下圖所示。

步驟4 下發第一條流表。

步驟5 單擊頁面右上角的“實驗拓撲”按鈕,查看主機與交換機的連接情況,如下圖所示。


可知主機10.0.0.5與交換機的1端口連接,主機10.0.0.6與交換機的2端口連接。

步驟6 “body”中選擇“raw”,格式爲XML(application/xml),並填寫如下消息體:

流表:匹配源MAC爲fa:16:3e:b4:50:07,目的MAC爲fa:16:3e:5c:04:6e的流量,出端口爲2。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-source>
<address>fa:16:3e:b4:50:07</address>
</ethernet-source>
<ethernet-destination>
<address>fa:16:3e:5c:04:6e</address>
</ethernet-destination>
</ethernet-match>
</match>
<id>107</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

參數說明:

  • Priority:匹配流表的優先級。
  • flow-name:流表的名稱。
  • idle-timeout:設定超時時間(seconds),參數爲0表示永不超時。
  • hard-timeout:最大超時時間(seconds),參數爲0表示永不超時。
  • match:匹配Fields。
  • instructions:修改action配置或pipeline處理。
  • ethernet-source:源MAC地址。
  • ethernet-destination:目的MAC地址。

步驟7 單擊Send按鈕,結果如下圖所示。


說明:可根據用戶需要設置流表超時時間,idle-timeout、hard-timeout同時設置爲0表示永不超時。

步驟8 下發第二條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-source>
<address>fa:16:3e:5c:04:6e</address>
</ethernet-source>
<ethernet-destination>
<address>fa:16:3e:b4:50:07</address>
</ethernet-destination>
</ethernet-match>
</match>
<id>108</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟9 單擊“Send”按鈕,結果如下圖所示。

步驟10 使用root用戶登錄交換機,查看流表,執行命令ovs-ofctl dump-flows br-sw如下圖所示。

步驟11 登錄主機1,ping主機2,如下圖所示。

步驟12 再次查看交換機上的流表,可以看到匹配的流表爲優先級200的流表,其n_bytes值隨着ping而增加,如下圖所示。

步驟13 停止主機上的ping操作。

步驟14 刪除剛剛創建的流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/107 ,使用DELETE方法,如下圖所示。

步驟15 單擊Send按鈕。

步驟16 刪除第二條流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/108 ,使用DELETE方法,如下圖所示。

步驟17 單擊Send按鈕。

三、L3層流表下發與驗證

L3層對應OSI模型的三層,三層流表主要匹配的是IP包的協議類型和IP地址。

場景一 匹配源IP

步驟1 下發第一條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-source>10.0.0.5/32</ipv4-source>
</match>
<id>111</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟2 單擊“Send”按鈕,結果如下圖所示。

步驟3 下發第二條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-source>10.0.0.6/32</ipv4-source>
</match>
<id>112</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟4 單擊Send按鈕,結果如下圖所示。

步驟5 下發第三條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>113</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>NORMAL</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟6 單擊Send按鈕,結果如下圖所示。

步驟7 登錄交換機查看流表,如下圖所示。

步驟8 在主機上ping操作,如下圖所示。

步驟9 交換機上再次查看流表,下發的流表被匹配,如下圖所示。

步驟10 停止主機上的ping操作。

步驟11 刪除剛剛創建的流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/111 ,使用DELETE方法,如下圖所示。

步驟12 單擊Send按鈕。

步驟13 刪除第二條流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/112 ,使用DELETE方法,如下圖所示。

步驟14 單擊Send按鈕。

步驟15 刪除第三條流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/113 ,使用DELETE方法,如下圖所示。

步驟16 單擊Send按鈕。

場景二 匹配nw_proto字段

步驟1 下發第一條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.0.6/32</ipv4-destination>
<ip-match>
<ip-protocol>1</ip-protocol>
</ip-match>
</match>
<id>114</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟2 單擊Send按鈕,結果如下圖所示。

步驟3 下發第二條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.0.5/32</ipv4-destination>
<ip-match>
<ip-protocol>1</ip-protocol>
</ip-match>
</match>
<id>115</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟4 單擊“Send”按鈕,結果如下:

步驟5 下發第三條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>116</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>NORMAL</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟6 單擊“Send”按鈕,結果如下:

步驟7 登錄交換機查看流表下發情況如下截圖。

步驟8 在主機上ping操作。

步驟9 交換機上再次查看流表,下發的流表被匹配。

步驟10 停止主機上的ping操作。

步驟11 刪除剛剛創建的流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/114 ,使用DELETE方法,如下圖所示。

步驟12 單擊Send按鈕。

步驟13 刪除第二條流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/115 ,使用DELETE方法,如下圖所示。

步驟14 單擊Send按鈕。

步驟15 刪除第三條流表,URL輸入:http://127.0.0.1:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:196695411516739/table/0/flow/116 ,使用DELETE方法,如下圖所示。

步驟16 單擊Send按鈕。

四、L4層流表下發與驗證

L4對應的OSI模型中的四層,即流表對應的TCP/UDP源端口(TCP/UDP src port)、TCP/UDP目的端口號(TCP/UDP dst port)字段。本實驗匹配TCP目的端口。

步驟1 下發第一條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<tcp-destination-port>5001</tcp-destination-port>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.0.6/32</ipv4-destination>
<ip-match>
<ip-protocol>6</ip-protocol>
</ip-match>
</match>
<id>117</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟2 單擊Send按鈕,結果如下圖所示。

步驟3 下發第二條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.0.5/32</ipv4-destination>
<ip-match>
<ip-protocol>6</ip-protocol>
</ip-match>
</match>
<id>118</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟4 單擊Send按鈕,結果如下圖所示。

步驟5 下發第三條流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>119</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>FLOOD</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

步驟6 單擊Send按鈕,結果如下圖所示。

步驟7 登錄交換機查看流表下發情況如下圖所示:

步驟8 登錄主機2,使用命令iperf -s啓用Iperf爲服務端,如下圖所示。

步驟9 登錄主機1,使用命令iperf -c 10.0.0.6發送TCP請求,如下圖所示。

步驟10 交換機上再次查看流表,下發的流表被匹配,如下圖所示。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章