OpenFlow 交換機與控制器交互步驟
1. 利用Mininet仿真平台構建如下圖所示的網絡拓撲,配置主機h1和h2的IP地址(h1:10.0.0.1,h2:10.0.0.2),測試兩台主機之間的網絡連通性
- miniedit.py設置
- start CLI
- 支持OpenFlow 1.0 1.1 1.2 1.3
- 其他使用默認設置(Controller選擇默認的openflow reference)
2. 利用Wireshark工具,捕獲拓撲中交換機與控制器之間的通信數據,對OpenFlow協議類型的各類報文進行分析,寫出你的分析內容。
-
hello
控制器6633端口(我最高能支持OpenFlow 1.0) ---> 交換機35534端口
交換機35534端口(我最高能支持OpenFlow 1.3)---> 控制器6633端口
於是雙方建立連接,並使用OpenFlow 1.0 -
Features Request
控制器6633端口(我需要你的特征信息) ---> 交換機35534端口
-
Set Config
控制器6633端口(請按照我給你的flag和max bytes of packet進行配置) ---> 交換機35534端口
-
Features Reply
交換機35534端口(這是我的特征信息,請查收)--- 控制器6633端口
Features 消息包括 OpenFlow Header 和 Features Reply Message
對照Features Reply Message結構
struct ofp_switch_features{
struct ofp_header header;
uint64_t datapath_id; /*唯一標識 id 號*/
uint32_t n_buffers; /*交緩沖區可以緩存的最大數據包個數*/
uint8_t n_tables; /*流表數量*/
uint8_t pad[3]; /*align to 64 bits*/
uint32_t capabilities; /*支持的特殊功能,具體見 ofp_capabilities*/
uint32_t actions; /*支持的動作,具體見 ofp_actions_type*/
struct ofp_phy_port ports[0]; /*物理端口描述列表,具體見 ofp_phy_port*/
};
對應到抓取到的報文,逐項查看報文內容
OpenFlow 1.0
.000 0001 = Version: 1.0 (0x01)
Type: OFPT_FEATURES_REPLY (6)
Length: 176
Transaction ID: 3488621760
Datapath unique ID: 0x0000000000000002
MAC addr: 00:00:00_00:00:00 (00:00:00:00:00:00)
Implementers part: 0x0002
n_buffers: 256
n_tables: 254
Pad: 000000
capabilities: 0x000000c7
.... .... .... .... .... .... .... ...1 = Flow statistics: True
.... .... .... .... .... .... .... ..1. = Table statistics: True
.... .... .... .... .... .... .... .1.. = Port statistics: True
.... .... .... .... .... .... .... 0... = Group statistics: False
.... .... .... .... .... .... ..0. .... = Can reassemble IP fragments: False
.... .... .... .... .... .... .1.. .... = Queue statistics: True
.... .... .... .... .... ...0 .... .... = Switch will block looping ports: False
actions: 0x00000fff
.... .... .... .... .... .... .... ...1 = Output to switch port: True
.... .... .... .... .... .... .... ..1. = Set the 802.1q VLAN id: True
.... .... .... .... .... .... .... .1.. = Set the 802.1q priority: True
.... .... .... .... .... .... .... 1... = Strip the 802.1q header: True
.... .... .... .... .... .... ...1 .... = Ethernet source address: True
.... .... .... .... .... .... ..1. .... = Ethernet destination address: True
.... .... .... .... .... .... .1.. .... = IP source address: True
.... .... .... .... .... .... 1... .... = IP destination address: True
.... .... .... .... .... ...1 .... .... = IP ToS (DSCP field, 6 bits): True
.... .... .... .... .... ..1. .... .... = TCP/UDP source port: True
.... .... .... .... .... .1.. .... .... = TCP/UDP destination port: True
.... .... .... .... .... 1... .... .... = Output to queue: True
Port data 1
Port number: 65534
HW Address: e6:73:a1:3c:74:c0 (e6:73:a1:3c:74:c0)
Port Name: s2
Config flags: 0x00000001
.... .... .... .... .... .... .... ...1 = Port is administratively down: True
.... .... .... .... .... .... .... ..0. = Disable 802.1D spanning tree on port: False
.... .... .... .... .... .... .... .0.. = Drop all packets except 802.1D spanning tree packets: False
.... .... .... .... .... .... .... 0... = Drop received 802.1D STP packets: False
.... .... .... .... .... .... ...0 .... = Do not include this port when flooding: False
.... .... .... .... .... .... ..0. .... = Drop packets forwarded to port: False
.... .... .... .... .... .... .0.. .... = Do not send packet-in msgs for port: False
State flags: 0x00000001
.... .... .... .... .... .... .... ...1 = No physical link present: True
Current features: 0x00000000
.... .... .... .... .... .... .... ...0 = 10 Mb half-duplex rate support: False
.... .... .... .... .... .... .... ..0. = 10 Mb full-duplex rate support: False
.... .... .... .... .... .... .... .0.. = 100 Mb half-duplex rate support: False
.... .... .... .... .... .... .... 0... = 100 Mb full-duplex rate support: False
.... .... .... .... .... .... ...0 .... = 1 Gb half-duplex rate support: False
.... .... .... .... .... .... ..0. .... = 1 Gb full-duplex rate support: False
.... .... .... .... .... .... .0.. .... = 10 Gb full-duplex rate support: False
.... .... .... .... .... .... 0... .... = Copper medium: False
.... .... .... .... .... ...0 .... .... = Fiber medium: False
.... .... .... .... .... ..0. .... .... = Auto-negotiation: False
.... .... .... .... .... .0.. .... .... = Pause: False
.... .... .... .... .... 0... .... .... = Asymmetric pause: False
Advertised features: 0x00000000
Features supported: 0x00000000
Features advertised by peer: 0x00000000
Port data 2
Port number: 1
HW Address: 2a:ca:66:29:0e:ae (2a:ca:66:29:0e:ae)
Port Name: s2-eth1
Config flags: 0x00000000
.... .... .... .... .... .... .... ...0 = Port is administratively down: False
.... .... .... .... .... .... .... ..0. = Disable 802.1D spanning tree on port: False
.... .... .... .... .... .... .... .0.. = Drop all packets except 802.1D spanning tree packets: False
.... .... .... .... .... .... .... 0... = Drop received 802.1D STP packets: False
.... .... .... .... .... .... ...0 .... = Do not include this port when flooding: False
.... .... .... .... .... .... ..0. .... = Drop packets forwarded to port: False
.... .... .... .... .... .... .0.. .... = Do not send packet-in msgs for port: False
State flags: 0x00000000
.... .... .... .... .... .... .... ...0 = No physical link present: False
Current features: 0x000000c0
.... .... .... .... .... .... .... ...0 = 10 Mb half-duplex rate support: False
.... .... .... .... .... .... .... ..0. = 10 Mb full-duplex rate support: False
.... .... .... .... .... .... .... .0.. = 100 Mb half-duplex rate support: False
.... .... .... .... .... .... .... 0... = 100 Mb full-duplex rate support: False
.... .... .... .... .... .... ...0 .... = 1 Gb half-duplex rate support: False
.... .... .... .... .... .... ..0. .... = 1 Gb full-duplex rate support: False
.... .... .... .... .... .... .1.. .... = 10 Gb full-duplex rate support: True
.... .... .... .... .... .... 1... .... = Copper medium: True
.... .... .... .... .... ...0 .... .... = Fiber medium: False
.... .... .... .... .... ..0. .... .... = Auto-negotiation: False
.... .... .... .... .... .0.. .... .... = Pause: False
.... .... .... .... .... 0... .... .... = Asymmetric pause: False
Advertised features: 0x00000000
Features supported: 0x00000000
Features advertised by peer: 0x00000000
Port data 3
Port number: 2
HW Address: 66:01:64:ad:24:89 (66:01:64:ad:24:89)
Port Name: s2-eth2
Config flags: 0x00000000
.... .... .... .... .... .... .... ...0 = Port is administratively down: False
.... .... .... .... .... .... .... ..0. = Disable 802.1D spanning tree on port: False
.... .... .... .... .... .... .... .0.. = Drop all packets except 802.1D spanning tree packets: False
.... .... .... .... .... .... .... 0... = Drop received 802.1D STP packets: False
.... .... .... .... .... .... ...0 .... = Do not include this port when flooding: False
.... .... .... .... .... .... ..0. .... = Drop packets forwarded to port: False
.... .... .... .... .... .... .0.. .... = Do not send packet-in msgs for port: False
State flags: 0x00000000
.... .... .... .... .... .... .... ...0 = No physical link present: False
Current features: 0x000000c0
.... .... .... .... .... .... .... ...0 = 10 Mb half-duplex rate support: False
.... .... .... .... .... .... .... ..0. = 10 Mb full-duplex rate support: False
.... .... .... .... .... .... .... .0.. = 100 Mb half-duplex rate support: False
.... .... .... .... .... .... .... 0... = 100 Mb full-duplex rate support: False
.... .... .... .... .... .... ...0 .... = 1 Gb half-duplex rate support: False
.... .... .... .... .... .... ..0. .... = 1 Gb full-duplex rate support: False
.... .... .... .... .... .... .1.. .... = 10 Gb full-duplex rate support: True
.... .... .... .... .... .... 1... .... = Copper medium: True
.... .... .... .... .... ...0 .... .... = Fiber medium: False
.... .... .... .... .... ..0. .... .... = Auto-negotiation: False
.... .... .... .... .... .0.. .... .... = Pause: False
.... .... .... .... .... 0... .... .... = Asymmetric pause: False
Advertised features: 0x00000000
Features supported: 0x00000000
Features advertised by peer: 0x00000000
- Packet_in
交換機35534端口(有數據包進來,請指示)--- 控制器6633端口
結合Packet_in的結構
struct ofp_packet_in {
struct ofp_header header;
uint32_t buffer_id; /*Packet-in消息所攜帶的數據包在交換機緩存區中的ID*/
uint16_t total_len; /*data字段的長度*/
uint16_t in_port; /*數據包進入交換機時的端口號*/
uint8_t reason; /*發送Packet-in消息的原因,具體見 ofp_packet_in_reason*/
uint8_t pad;
uint8_t data[0]; /*攜帶的數據包*/
};
分析抓取的數據包,可以發現是因為交換機發現此時自己並沒有匹配的流表(Reason: No matching flow (table-miss flow entry) (0)),所以要問控制器如何處理
OpenFlow 1.0
.000 0001 = Version: 1.0 (0x01)
Type: OFPT_PACKET_IN (10)
Length: 108
Transaction ID: 0
Buffer Id: 0x00000100
Total length: 90
In port: 1
Reason: No matching flow (table-miss flow entry) (0)
Pad: 00
Ethernet II, Src: 96:3f:21:4c:f5:0e (96:3f:21:4c:f5:0e), Dst: IPv6mcast_16 (33:33:00:00:00:16)
Destination: IPv6mcast_16 (33:33:00:00:00:16)
Address: IPv6mcast_16 (33:33:00:00:00:16)
.... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
.... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
Source: 96:3f:21:4c:f5:0e (96:3f:21:4c:f5:0e)
Address: 96:3f:21:4c:f5:0e (96:3f:21:4c:f5:0e)
.... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
Type: IPv6 (0x86dd)
Internet Protocol Version 6, Src: ::, Dst: ff02::16
0110 .... = Version: 6
.... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
.... 0000 00.. .... .... .... .... .... = Differentiated Services Codepoint: Default (0)
.... .... ..00 .... .... .... .... .... = Explicit Congestion Notification: Not ECN-Capable Transport (0)
.... .... .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
Payload Length: 36
Next Header: IPv6 Hop-by-Hop Option (0)
Hop Limit: 1
Source: ::
Destination: ff02::16
IPv6 Hop-by-Hop Option
Next Header: ICMPv6 (58)
Length: 0
[Length: 8 bytes]
Router Alert
Type: Router Alert (0x05)
00.. .... = Action: Skip and continue (0)
..0. .... = May Change: No
...0 0101 = Low-Order Bits: 0x05
Length: 2
Router Alert: MLD (0)
PadN
Type: PadN (0x01)
00.. .... = Action: Skip and continue (0)
..0. .... = May Change: No
...0 0001 = Low-Order Bits: 0x01
Length: 0
PadN: <none>
Internet Control Message Protocol v6
Type: Multicast Listener Report Message v2 (143)
Code: 0
Checksum: 0x7a2f [correct]
[Checksum Status: Good]
Reserved: 0000
Number of Multicast Address Records: 1
Multicast Address Record Changed to exclude: ff02::1:ff4c:f50e
Record Type: Changed to exclude (4)
Aux Data Len: 0
Number of Sources: 0
Multicast Address: ff02::1:ff4c:f50e
- Packet_out
控制器6633端口(請按照我給你的action進行處理) ---> 交換機35534端口
結合Packet_out的結構
struct ofp_packet_out {
struct ofp_header header;
uint32_t buffer_id; /*交換機緩存區id,如果為-1則指定的為packet-out消息攜帶的data字段*/
uint16_t in_port; /*如果buffer_id為‐1,並且action列表中指定了Output=TABLE的動作,in_port將作為data段數據包的額外匹配信息進行流表查詢*/
uint16_t actions_len; /*action列表的長度,可以用來區分actions和data段*/
struct ofp_action_header actions[0]; /*動作列表*/
uint8_t data[0]; /*數據緩存區,可以存儲一個以太網幀,可選*/
}
告訴輸出到交換機的65531端口
OpenFlow 1.0
.000 0001 = Version: 1.0 (0x01)
Type: OFPT_PACKET_OUT (13)
Length: 24
Transaction ID: 0
Buffer Id: 0x00000100
In port: 1
Actions length: 8
Actions type: Output to switch port (0)
Action length: 8
Output port: 65531
Max length: 0
接下來是另一台交換機(端口35536)與控制器(端口6633)的交互過程
h1 ping h2
- packet_in
- flow_mod
結合flow_mod結構
struct ofp_flow_mod {
struct ofp_header header;
struct ofp_match match; /*流表的匹配域*/
uint64_t cookie; /*流表項標識符*/
uint16_t command; /*可以是ADD,DELETE,DELETE-STRICT,MODIFY,MODIFY-STRICT*/
uint16_t idle_timeout; /*空閑超時時間*/
uint16_t hard_timeout; /*最大生存時間*/
uint16_t priority; /*優先級,優先級高的流表項優先匹配*/
uint32_t buffer_id; /*緩存區ID ,用於指定緩存區中的一個數據包按這個消息的action列表處理*/
uint16_t out_port; /*如果這條消息是用於刪除流表則需要提供額外的匹配參數*/
uint16_t flags; /*標志位,可以用來指示流表刪除后是否發送flow‐removed消息,添加流表時是否檢查流表重復項,添加的流表項是否為應急流表項。*/
struct ofp_action_header actions[0]; /*action列表*/
};
分析抓取的flow_mod數據包,控制器通過6633端口向交換機35334端口、交換機35336端口下發流表項,指導數據的轉發處理
PS.把控制器從openflow reference改成ovs controller
在hello報文中可以發現控制器支持的OpenFlow版本從1.0變成了1.3,因此,經過協商交換機和控制器之間將通過1.3版本的OpenFlow協議進行通信
- flow_mod