- 拓撲文件
![]()
![]()
- 抓包流程圖
1、hello
55394向6633發送hello包,并且使用openflow1.0
![]()
6633向55394發送hello包,并且使用openflow1.0
![]()
2、features_request
控制器6633端口(我需要你的特征信息) ---> 交換機55394端口
![]()
3、Set Conig
控制器6633端口(請按照我給你的flag和max bytes of packet進行配置) ---> 交換機55394端口
![]()
4、Port_Status
當交換機端口發生變化時,告知控制器相應的端口狀態。
![]()
5、Features Reply
交換機55394端口(這是我的特征信息,請查收) ---> 控制器6633端口
![]()
6、Packet_in
有兩種情況:
交換機查找流表,發現沒有匹配條目時
有匹配條目但是對應的action是OUTPUT=CONTROLLER時,交換機35534端口(有數據包進來,請指示)--- 控制器6633端口
![]()
7、Flow_mod
控制器通過6633端口向交換機34286端口、交換機34286端口下發流表項,指導數據的轉發處理
![]()
8、Packet_out
控制器6633端口(請按照我給你的action進行處理) ---> 交換機55394端口
![]()
9、交互圖
![]()
- 回答問題:交換機與控制器建立通信時是使用TCP協議還是UDP協議?
答:交換機和控制器建立通信時是使用TCP協議 - 進階作業
1、Hello
![]()
struct ofp_header {
uint8_t version; /* 版本號OFP_VERSION. */
uint8_t type; /* 消息類型One of the OFPT_ constants. */
uint16_t length; /* 長度Length including this ofp_header. */
uint32_t xid; /* ID Transaction id associated with this packet.
Replies use the same id as was in the request
to facilitate pairing. */
};
OFP_ASSERT(sizeof(struct ofp_header) == 8);
/* OFPT_HELLO. This message has an empty body, but implementations must
* ignore any data included in the body, to allow for future extensions. */
struct ofp_hello {
struct ofp_header header;
};
2、Features Request

struct ofp_header {
uint8_t version; /* 版本號OFP_VERSION. */
uint8_t type; /* 消息類型One of the OFPT_ constants. */
uint16_t length; /* 長度Length including this ofp_header. */
uint32_t xid; /* ID Transaction id associated with this packet.
Replies use the same id as was in the request
to facilitate pairing. */
};
3、Set Config

enum ofp_config_flags {
/* Handling of IP fragments. */
OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
OFPC_FRAG_DROP = 1, /* Drop fragments. */
OFPC_FRAG_REASM = 2, /* Reassemble (only if OFPC_IP_REASM set). */
OFPC_FRAG_MASK = 3
};//不同flag代表不同的處理方式
/* Switch configuration. */
struct ofp_switch_config {
struct ofp_header header;
uint16_t flags; /*用來指示交換機如何處理 IP 分片數據包 OFPC_* flags. */
uint16_t miss_send_len; /* 用來指示當一個交換機無法處理的數據包到達時,將數據包發給控制器的最大字節數。Max bytes of new flow that datapath should
send to the controller. */
};
OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
4、Port_Status

/* A physical port has changed in the datapath */
struct ofp_port_status {
struct ofp_header header;
uint8_t reason; /* One of OFPPR_*. */
uint8_t pad[7]; /* Align to 64-bits. */
struct ofp_phy_port desc;
};
OFP_ASSERT(sizeof(struct ofp_port_status) == 64);
//這個是當交換機端口發生變化時,告知控制器相應的端口狀態,發生變化包括增加、刪除、修改物理端口,則需發送port status來告知
5、Features Reply

/* Switch features. */
struct ofp_switch_features {
struct ofp_header header;
uint64_t datapath_id; /* 唯一標識ID號Datapath unique ID. The lower 48-bits are for
a MAC address, while the upper 16-bits are
implementer-defined. */
uint32_t n_buffers; /*緩沖區可緩存的最大數據包個數 Max packets buffered at once. */
uint8_t n_tables; /* 流表數量Number of tables supported by datapath. */
uint8_t pad[3]; /* Align to 64-bits. */
/* Features. */
uint32_t capabilities; /*支持的特殊功能Bitmap of support "ofp_capabilities". */
uint32_t actions; /* 支持的動作 Bitmap of supported "ofp_action_type"s. */
/* Port info.*/
struct ofp_phy_port ports[0]; /*物理端口描述列表 Port definitions. The number of ports
is inferred from the length field in
the header. */
};
OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
6、Packet_in

/* Packet received on port (datapath -> controller). */
struct ofp_packet_in {
struct ofp_header header;
uint32_t buffer_id; /*Packet-in消息所攜帶的數據包在交換機緩存區中的ID ID assigned by datapath. */
uint16_t total_len; /* data字段的長度Full length of frame. */
uint16_t in_port; /* 數據包進入交換機時的端口號Port on which frame was received. */
uint8_t reason; /*發送Packet-in消息的原因 Reason packet is being sent (one of OFPR_*) */
uint8_t pad;
uint8_t data[0]; /*攜帶的數據包 Ethernet frame, halfway through 32-bit word,
so the IP header is 32-bit aligned. The
amount of data is inferred from the length
field in the header. Because of padding,
offsetof(struct ofp_packet_in, data) ==
sizeof(struct ofp_packet_in) - 2. */
};
OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
7、Flow_mod

/* Flow setup and teardown (controller -> datapath). */
struct ofp_flow_mod {
struct ofp_header header;
struct ofp_match match; /* 流表的匹配域 Fields to match */
uint64_t cookie; /*流表項標識符 Opaque controller-issued identifier. */
/* Flow actions. */
uint16_t command; /* 可以是ADD,DELETE,DELETE-STRICT,MODIFY,MODIFY-STRICTOne of OFPFC_*. */
uint16_t idle_timeout; /*空閑超時時間 Idle time before discarding (seconds). */
uint16_t hard_timeout; /* 最大生存時間 Max time before discarding (seconds). */
uint16_t priority; /*優先級,優先級高的流表項優先匹配 Priority level of flow entry. */
uint32_t buffer_id; /*緩存區ID ,用于指定緩存區中的一個數據包按這個消息的action列表處理 Buffered packet to apply to (or -1).
Not meaningful for OFPFC_DELETE*. */
uint16_t out_port; /*如果這條消息是用于刪除流表則需要提供額外的匹配參數 For OFPFC_DELETE* commands, require
matching entries to include this as an
output port. A value of OFPP_NONE
indicates no restriction. */
uint16_t flags; /*標志位,可以用來指示流表刪除后是否發送flow‐removed消息,添加流表時是否檢查流表重復項,添加的流表項是否為應急流表項。 One of OFPFF_*. */
struct ofp_action_header actions[0]; /* action列表The action length is inferred
from the length field in the
header. */
};
OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);
8、Packet_out

/* Send packet (controller -> datapath). */
struct ofp_packet_out {
struct ofp_header header;
uint32_t buffer_id; /*交換機緩存區id,如果為-1則指定的為packet-out消息攜帶的data字段 ID assigned by datapath (-1 if none). */
uint16_t in_port; /* 如果buffer_id為‐1,并且action列表中指定了Output=TABLE的動作,in_port將作為data段數據包的額外匹配信息進行流表查詢Packet's
input port (OFPP_NONE if none). */
uint16_t actions_len; /*action列表的長度,可以用來區分actions和data段 Size of action array in bytes. */
struct ofp_action_header actions[0]; /*動作列表 Actions. */
/* uint8_t data[0]; */ /*數據緩存區,可以存儲一個以太網幀,可選 Packet data. The length is inferred
from the length field in the header.
(Only meaningful if buffer_id == -1.) */
};
OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);
- 個人總結
本次實驗主要是學會了能夠運用 wireshark 對 OpenFlow 協議數據交互過程進行抓包,用抓包軟件獲取控制器與交換機之間的通信數據包。能夠借助包解析工具,分析與解釋 OpenFlow協議的數據包交互過程與機制。進階實驗主要是對源代碼進行分析,這個花費了較多時間去了解,在實驗過程中遇到的問題,通過詢問同學以及查找資料也學習到了很多知識,并且本次實驗讓我對wireshark抓包的使用更加的熟練。












