warnings fixed

This commit is contained in:
2025-11-12 09:01:03 +08:00
parent 11f2d26fce
commit d90a907427
3 changed files with 1959 additions and 61 deletions

View File

@ -121,7 +121,7 @@ u8 *build_opfmsg_reply_ofpbuf(uint8_t type,uint32_t xid,uint16_t len)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_opfmsg_hello(struct ofp_buffer *ofpbuf) handle_opfmsg_hello(struct ofp_buffer *ofpbuf)
{ {
@ -154,7 +154,7 @@ handle_opfmsg_hello(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_opfmsg_features_request(struct ofp_buffer *ofpbuf) handle_opfmsg_features_request(struct ofp_buffer *ofpbuf)
{ {
int feature_reply_len = sizeof(struct ofp_switch_features)+sizeof(struct ofp_header); int feature_reply_len = sizeof(struct ofp_switch_features)+sizeof(struct ofp_header);
@ -189,7 +189,7 @@ handle_opfmsg_features_request(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_get_config_request(struct ofp_buffer *ofpbuf) handle_ofpmsg_get_config_request(struct ofp_buffer *ofpbuf)
{ {
int reply_len = sizeof(struct ofp_switch_config)+sizeof(struct ofp_header); int reply_len = sizeof(struct ofp_switch_config)+sizeof(struct ofp_header);
@ -214,7 +214,7 @@ handle_ofpmsg_get_config_request(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_desc(struct ofp_buffer *ofpbuf) handle_ofpmsg_desc(struct ofp_buffer *ofpbuf)
{ {
int reply_len = sizeof(struct ofp_header)+sizeof(struct ofp_multipart)+sizeof(struct ofp_desc_stats); int reply_len = sizeof(struct ofp_header)+sizeof(struct ofp_multipart)+sizeof(struct ofp_desc_stats);
@ -249,7 +249,7 @@ handle_ofpmsg_desc(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_flow_stats(struct ofp_buffer *ofpbuf) handle_ofpmsg_flow_stats(struct ofp_buffer *ofpbuf)
{ {
int i = 0, reply_len = 0, flow_stats_offset; int i = 0, reply_len = 0, flow_stats_offset;
@ -297,7 +297,7 @@ handle_ofpmsg_flow_stats(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_aggregate(struct ofp_buffer *ofpbuf) handle_ofpmsg_aggregate(struct ofp_buffer *ofpbuf)
{ {
int reply_len = sizeof(struct ofp_header)+ sizeof(struct ofp_multipart)+sizeof(struct ofp_aggregate_stats_reply); int reply_len = sizeof(struct ofp_header)+ sizeof(struct ofp_multipart)+sizeof(struct ofp_aggregate_stats_reply);
@ -316,7 +316,7 @@ handle_ofpmsg_aggregate(struct ofp_buffer *ofpbuf)
if (flow_stats_addr[i] != 0) { if (flow_stats_addr[i] != 0) {
((struct ofp_flow_stats *)flow_stats_addr[i])->duration_sec = htonl(tv.tv_sec - flow_stats_time[i].tv_sec); ((struct ofp_flow_stats *)flow_stats_addr[i])->duration_sec = htonl(tv.tv_sec - flow_stats_time[i].tv_sec);
((struct ofp_flow_stats *)flow_stats_addr[i])->duration_nsec = htonl(tv.tv_usec - flow_stats_time[i].tv_usec); ((struct ofp_flow_stats *)flow_stats_addr[i])->duration_nsec = htonl(tv.tv_usec - flow_stats_time[i].tv_usec);
// Read packet and byte counts from hardware registers // 从硬件寄存器读取数据包计数和字节计数
((struct ofp_flow_stats *)flow_stats_addr[i])->packet_count = fast_reg_rd(FAST_OFP_FLOW_STATS_PKTS + i * sizeof(uint64_t)); ((struct ofp_flow_stats *)flow_stats_addr[i])->packet_count = fast_reg_rd(FAST_OFP_FLOW_STATS_PKTS + i * sizeof(uint64_t));
((struct ofp_flow_stats *)flow_stats_addr[i])->byte_count = fast_reg_rd(FAST_OFP_FLOW_STATS_BYTES + i * sizeof(uint64_t)); ((struct ofp_flow_stats *)flow_stats_addr[i])->byte_count = fast_reg_rd(FAST_OFP_FLOW_STATS_BYTES + i * sizeof(uint64_t));
@ -344,7 +344,7 @@ handle_ofpmsg_aggregate(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_table(struct ofp_buffer *ofpbuf) handle_ofpmsg_table(struct ofp_buffer *ofpbuf)
{ {
int i = 0; int i = 0;
@ -376,7 +376,7 @@ handle_ofpmsg_table(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_port_stats(struct ofp_buffer *ofpbuf) handle_ofpmsg_port_stats(struct ofp_buffer *ofpbuf)
{ {
int i = 0; int i = 0;
@ -410,7 +410,7 @@ handle_ofpmsg_port_stats(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_group_features(struct ofp_buffer *ofpbuf) handle_ofpmsg_group_features(struct ofp_buffer *ofpbuf)
{ {
@ -437,7 +437,7 @@ handle_ofpmsg_group_features(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_port_desc(struct ofp_buffer *ofpbuf) handle_ofpmsg_port_desc(struct ofp_buffer *ofpbuf)
{ {
int i = 0; int i = 0;
@ -467,7 +467,7 @@ handle_ofpmsg_port_desc(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle_ofpmsg_packet_out(struct ofp_buffer *ofpbuf) handle_ofpmsg_packet_out(struct ofp_buffer *ofpbuf)
{ {
struct ofp_packet_out *out = (struct ofp_packet_out *)ofpbuf; struct ofp_packet_out *out = (struct ofp_packet_out *)ofpbuf;
@ -507,7 +507,7 @@ handle_ofpmsg_packet_out(struct ofp_buffer *ofpbuf)
* *
* @return 返回处理状态码 * @return 返回处理状态码
*/ */
static enum ofperr static int
handle__opfmsg_role_request(struct ofp_buffer *ofpbuf) handle__opfmsg_role_request(struct ofp_buffer *ofpbuf)
{ {
int reply_len = sizeof(struct ofp_header)+sizeof(struct ofp_role); int reply_len = sizeof(struct ofp_header)+sizeof(struct ofp_role);
@ -567,6 +567,8 @@ int handle_openflow_callback(struct ofp_buffer *ofpbuf, int len)
return handle_ofpmsg_group_features(ofpbuf); return handle_ofpmsg_group_features(ofpbuf);
case OFPMP_PORT_DESC: case OFPMP_PORT_DESC:
return handle_ofpmsg_port_desc(ofpbuf); return handle_ofpmsg_port_desc(ofpbuf);
// case OFPT_FLOW_MOD:
// return handle_flow_mod(ofpbuf);
default: default:
printf("Unsupported multipart request type: %d\n", ntohs(multipart->type)); printf("Unsupported multipart request type: %d\n", ntohs(multipart->type));
break; break;

View File

@ -30,6 +30,9 @@
- [4. 核心回调与主函数](#4-核心回调与主函数) - [4. 核心回调与主函数](#4-核心回调与主函数)
- [`handle_openflow_callback`](#handle_openflow_callback) - [`handle_openflow_callback`](#handle_openflow_callback)
- [`main`](#main) - [`main`](#main)
- [5. 已实现的协议类型总结](#5-已实现的协议类型总结)
- [A. `handle_openflow_callback` 中处理的类型](#a-handle_openflow_callback-中处理的类型)
- [B. 与 `README.txt` 的比较](#b-与-readmetxt-的比较)
--- ---
@ -278,3 +281,33 @@ int main(int argc, char* argv[])
4. 调用 `openflow_hook_init(mask, handle_openflow_callback)`,将 `mask` 和核心回调函数 `handle_openflow_callback` 注册到 OpenFlow 库。这样,只有 `mask` 中指定类型的消息到达时,`handle_openflow_callback` 才会被调用。 4. 调用 `openflow_hook_init(mask, handle_openflow_callback)`,将 `mask` 和核心回调函数 `handle_openflow_callback` 注册到 OpenFlow 库。这样,只有 `mask` 中指定类型的消息到达时,`handle_openflow_callback` 才会被调用。
5. 调用 `pause()`,使程序进入挂起状态,等待网络事件(即等待 OpenFlow 消息的到来)。 5. 调用 `pause()`,使程序进入挂起状态,等待网络事件(即等待 OpenFlow 消息的到来)。
6. 程序将在此处循环等待和处理消息,直到被终止。 6. 程序将在此处循环等待和处理消息,直到被终止。
---
## 5. 已实现的协议类型总结
### A. `handle_openflow_callback` 中处理的类型
`main_user_openflow.c` 文件中的 `handle_openflow_callback` 函数是主要的消息分发器。它直接处理以下消息类型:
- **`OFPT_HELLO`**: 管理与控制器的初始握手过程。
- **`OFPT_FEATURES_REQUEST`**: 响应控制器,提供交换机的功能特性。
- **`OFPT_GET_CONFIG_REQUEST`**: 响应控制器,提供交换机的当前配置。
- **`OFPT_PACKET_OUT`**: 处理控制器下发的数据包,并从交换机指定端口发出。
- **`OFPT_ROLE_REQUEST`**: 处理控制器的角色变更请求(如 Master/Slave
- **`OFPT_MULTIPART_REQUEST`**: 用于请求各种统计和状态信息的复合类型。已实现的子类型包括:
- **`OFPMP_DESC`**: 交换机的硬件/软件描述信息。
- **`OFPMP_FLOW`**: 单个流的统计信息。
- **`OFPMP_AGGREGATE`**: 聚合统计信息(总流数、包数、字节数)。
- **`OFPMP_TABLE`**: 流表的统计信息。
- **`OFPMP_PORT_STATS`**: 物理或逻辑端口的统计信息。
- **`OFPMP_GROUP_FEATURES`**: 组表的特性。
- **`OFPMP_PORT_DESC`**: 端口的描述信息。
### B. 与 `README.txt` 的比较
`README.txt` 文件提供了一个相似的列表,但存在一个显著差异:
- **`OFPT_FLOW_MOD` (类型 14)**: `README.txt` 文件列出了用于添加流规则的 `OFPT_FLOW_MOD`(记录为 `OFPT_FLOW=14`)。虽然 `README` 提到了用于此目的的 `fast_add_rule` 函数,但在 `main_user_openflow.c``handle_openflow_callback` 函数中**并无**直接处理 `OFPT_FLOW_MOD` 消息的 `case` 分支。这表明该功能可能未完全实现、在其他地方处理,或者 `README.txt` 中的文档领先于当前文件中的具体实现。
根据 `main_user_openflow.c` 中的可执行代码路径,只有 A 部分列出的消息类型被主回调循环主动处理。

1863
openflow/ofp_demo.c Normal file

File diff suppressed because it is too large Load Diff