just all finished

This commit is contained in:
2025-11-19 09:02:51 +08:00
parent e4c7bf757d
commit e97093b2f5
4 changed files with 93 additions and 741 deletions

View File

@@ -7,14 +7,14 @@ struct timeval start_tv;
static enum ofperr handle_openflow(struct ofp_buffer *ofpbuf,int len);
/* 64位主机序转网络序 */
/* 64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static inline uint64_t
htonll(uint64_t n)
{
return htonl(1) == 1 ? n : ((uint64_t) htonl(n) << 32) | htonl(n >> 32);
}
/* 64位网络序转主机序 */
/* 64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static inline uint64_t
ntohll(uint64_t n)
{
@@ -23,7 +23,7 @@ ntohll(uint64_t n)
/* 打印报文 */
/* <EFBFBD><EFBFBD>ӡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void pkt_print(u8* pkt, int len)
{
//return;
@@ -61,7 +61,7 @@ void pkt_print(u8* pkt, int len)
/* 构造OpenFlow协议报文头 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OpenFlowЭ<EFBFBD><EFBFBD><EFBFBD>ͷ */
void build_ofp_header(struct ofp_header *ofpbuf_header,uint16_t len,uint8_t type,uint32_t xid)
{
SHOW_FUN(0);
@@ -73,7 +73,7 @@ void build_ofp_header(struct ofp_header *ofpbuf_header,uint16_t len,uint8_t type
SHOW_FUN(1);
}
/* 构造OpenFlow回复报文 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OpenFlow<EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
u8 *build_reply_ofpbuf(uint8_t type,uint32_t xid,uint16_t len)
{
SHOW_FUN(0);
@@ -87,7 +87,7 @@ u8 *build_reply_ofpbuf(uint8_t type,uint32_t xid,uint16_t len)
/* 向控制器发送OpenFlow报文 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OpenFlow<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void send_openflow_message(struct ofp_buffer *ofpmsg,int len)
{
SHOW_FUN(0);
@@ -102,7 +102,7 @@ void send_openflow_message(struct ofp_buffer *ofpmsg,int len)
}
/* 建立连接向控制器发送HELLO报文 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HELLO<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void send_hello_message()
{
struct ofp_header* ofp_header_hello;
@@ -126,7 +126,7 @@ void send_hello_message()
}
/* 向控制器发送Packet-in报文 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Packet-in<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void send_packet_in_message_meter(int in_port,u8 *pkt6,int len)
{
SHOW_FUN(0);
@@ -389,7 +389,7 @@ void send_packet_in_message_old()
}
/* 与控制器建立TCP连接 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void open_openflow_connect(char *controller_ip)
{
struct sockaddr_in controller_addr;
@@ -432,7 +432,7 @@ void open_openflow_connect_ipv6(char *controller_ip){
}
/* 关闭openflow连接 */
/* <EFBFBD>ر<EFBFBD>openflow<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void close_openflow_connect()
{
SHOW_FUN(0);
@@ -441,8 +441,8 @@ void close_openflow_connect()
}
/* 处理hello消息
* 判断是否为OpenFlow1.3版本 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>hello<EFBFBD><EFBFBD>Ϣ
* <EFBFBD>ж<EFBFBD><EFBFBD>Ƿ<EFBFBD>ΪOpenFlow1.3<EFBFBD> */
static enum ofperr
handle_hello(struct ofp_buffer *ofpbuf)
{
@@ -458,8 +458,8 @@ handle_hello(struct ofp_buffer *ofpbuf)
SHOW_FUN(1);
}
/* 处理hello消息
* 待完善 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>hello<EFBFBD><EFBFBD>Ϣ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static enum ofperr
handle_error(struct ofp_buffer *ofpbuf)
{
@@ -471,7 +471,7 @@ handle_error(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理Echo消息 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Echo<EFBFBD><EFBFBD>Ϣ */
static enum ofperr
handle_echo_request(struct ofp_buffer *ofpbuf)
{
@@ -487,7 +487,7 @@ handle_echo_request(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理experimenter实验者消息(暂不需要) */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>experimenterʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ(<28>ݲ<EFBFBD><DDB2><EFBFBD>Ҫ) */
static enum ofperr
handle_experimenter(struct ofp_buffer *ofpbuf)
{
@@ -499,9 +499,9 @@ handle_experimenter(struct ofp_buffer *ofpbuf)
}
/* 处理features_request消息
* 回复features_reply消息
* capabilities字段中填写switch所支持内容*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>features_request<EFBFBD><EFBFBD>Ϣ
* <EFBFBD>ظ<EFBFBD>features_reply<EFBFBD><EFBFBD>Ϣ
* capabilities<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дswitch<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
static enum ofperr
handle_features_request(struct ofp_buffer *ofpbuf)
{
@@ -526,8 +526,8 @@ handle_features_request(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理get_config_request消息
* 回复get_config_reply消息 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>get_config_request<EFBFBD><EFBFBD>Ϣ
* <EFBFBD>ظ<EFBFBD>get_config_reply<EFBFBD><EFBFBD>Ϣ */
static enum ofperr
handle_get_config_request(struct ofp_buffer *ofpbuf)
{
@@ -549,7 +549,7 @@ handle_get_config_request(struct ofp_buffer *ofpbuf)
}
/* 处理set_config消息 */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>set_config<EFBFBD><EFBFBD>Ϣ */
static enum ofperr
handle_set_config(struct ofp_buffer *ofpbuf,int len)
{
@@ -562,8 +562,8 @@ handle_set_config(struct ofp_buffer *ofpbuf,int len)
return 0;
}
/* 处理Packet-out消息
* 指导某条具体报文或用于LLDP*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Packet-out<EFBFBD><EFBFBD>Ϣ
* ָ<EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>LLDP*/
static enum ofperr
handle_packet_out(struct ofp_buffer *ofpbuf)
{
@@ -624,8 +624,8 @@ handle_packet_out(struct ofp_buffer *ofpbuf)
//#undef SHIWANG_MODE
/* 处理flow_mod消息
* 解析流表,把相应的E-RR-P表送入XTRXTR_C进程中*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>flow_mod<EFBFBD><EFBFBD>Ϣ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>E-R<EFBFBD><EFBFBD>R-P<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XTR<EFBFBD><EFBFBD>XTR_C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
static enum ofperr
handle_flow_mod(struct ofp_buffer *ofpbuf)
{
@@ -662,12 +662,12 @@ handle_flow_mod(struct ofp_buffer *ofpbuf)
printf("filed:OFPXMT_OFB_ETH_TYPE,len:%d\n",oxm->length);
break;
//subid 信息
//subid <EFBFBD><EFBFBD>Ϣ
case OFPXMT_OFB_IPV6_SRC:
printf("filed:OFPXMT_OFB_IPV6_SRC,len:%d\n",oxm->length);//ipv6 128λ-24λsubid
printf(">>\toxm----subid\n");
pkt_print((u8 *)oxm+4,8);
memcpy((u8 *)&configure_subid_r->subid,(u8 *)oxm+4,8);//5字节 caba编址 subid(24位3字节) 从8+32位后开始
memcpy((u8 *)&configure_subid_r->subid,(u8 *)oxm+4,8);//5<EFBFBD>ֽ<EFBFBD> caba<EFBFBD><EFBFBD>ַ subid(24λ3<EFBFBD>ֽ<EFBFBD>) <20><>8+32λ<32><CEBB>ʼ
break;
case OFPXMT_OFB_IPV6_DST:
@@ -726,11 +726,11 @@ handle_flow_mod(struct ofp_buffer *ofpbuf)
case OFPXMT_OFB_ETH_TYPE:
printf("filed:OFPXMT_OFB_ETH_TYPE,len:%d\n",oxm->length);
break;
//subid 信息
//subid <EFBFBD><EFBFBD>Ϣ
case OFPXMT_OFB_IPV6_SRC:
printf("filed:OFPXMT_OFB_IPV6_SRC,len:%d\n",oxm->length);
break;
//rloc信息
//rloc<EFBFBD><EFBFBD>Ϣ
case OFPXMT_OFB_IPV6_DST:
printf("filed:OFPXMT_OFB_IPV6_DST,len:%d\n",oxm->length);
pkt_print((u8*)oxm+4,16 );
@@ -738,7 +738,7 @@ handle_flow_mod(struct ofp_buffer *ofpbuf)
printf(">>\t\tconfigure_p_r->rloc___address=%p\n",(u8 *)&configure_p_r->rloc);
pkt_print((u8 *)&configure_p_r->port, 20);
break;
//port信息
//port<EFBFBD><EFBFBD>Ϣ
case OFPXMT_OFB_IN_PORT:
printf("oxm->length_address=%p\n",&(oxm->length));
printf("filed:OFPXMT_OFB_IN_PORT,len:%d\n",oxm->length);
@@ -802,7 +802,7 @@ handle_flow_mod(struct ofp_buffer *ofpbuf)
}
/* 处理group_mod消息(暂不需要) */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>group_mod<EFBFBD><EFBFBD>Ϣ(<28>ݲ<EFBFBD><DDB2><EFBFBD>Ҫ) */
static enum ofperr
handle_group_mod(struct ofp_buffer *ofpbuf)
{
@@ -814,7 +814,7 @@ handle_group_mod(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理Port_mod消息(暂不需要) */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Port_mod<EFBFBD><EFBFBD>Ϣ(<28>ݲ<EFBFBD><DDB2><EFBFBD>Ҫ) */
static enum ofperr
handle_port_mod(struct ofp_buffer *ofpbuf)
{
@@ -826,7 +826,7 @@ handle_port_mod(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理table_mod消息(暂不需要) */
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>table_mod<EFBFBD><EFBFBD>Ϣ(<28>ݲ<EFBFBD><DDB2><EFBFBD>Ҫ) */
static enum ofperr
handle_table_mod(struct ofp_buffer *ofpbuf)
{
@@ -852,7 +852,7 @@ magicrouter_strlcpy(char *dst, const char *src, size_t size)
}
/* 处理复合消息,描述交换机子类型OFPMP_DESC的请求消息*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OFPMP_DESC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
static enum ofperr
handle_ofpmp_desc(struct ofp_buffer *ofpbuf)
{
@@ -885,7 +885,7 @@ handle_ofpmp_desc(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理复合消息,单独流统计子类型OFPMP_FLOW_STATS的请求消息*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OFPMP_FLOW_STATS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
static enum ofperr
handle_ofpmp_flow_stats(struct ofp_buffer *ofpbuf)
{
@@ -910,7 +910,7 @@ handle_ofpmp_flow_stats(struct ofp_buffer *ofpbuf)
ofp_flow_stats->priority = htons(0);
ofp_flow_stats->idle_timeout = htons(0);
ofp_flow_stats->hard_timeout = htons(0);
ofp_flow_stats->flags = htons(0);//含义
ofp_flow_stats->flags = htons(0);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ofp_flow_stats->cookie = htonll(0);
ofp_flow_stats->packet_count = htonll(12);
ofp_flow_stats->byte_count = htonll(1033);
@@ -929,7 +929,7 @@ handle_ofpmp_flow_stats(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理复合消息,总的流统计子类型OFPMP_AGGREGATE的请求消息*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OFPMP_AGGREGATE<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
static enum ofperr
handle_ofpmp_aggregate(struct ofp_buffer *ofpbuf)
{
@@ -1074,7 +1074,7 @@ void read_port_stats(char ifname[6],struct ofp_port_stats *of_stats)
LOG_ERR("read %s stats Error!\n",ifname);
}
//------------------------------------------------------------------
/* 处理复合消息,端口统计子类型OFPMP_PORT_STATS的请求消息*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OFPMP_PORT_STATS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
static enum ofperr
handle_ofpmp_port_stats(struct ofp_buffer *ofpbuf)
{
@@ -1106,7 +1106,7 @@ handle_ofpmp_port_stats(struct ofp_buffer *ofpbuf)
}
/* 处理复合消息,表特征子类型OFPMP_TABLE_FEATURES的请求消息*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OFPMP_TABLE_FEATURES<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
static enum ofperr
handle_ofpmp_table_features(struct ofp_buffer *ofpbuf)
{
@@ -1442,7 +1442,7 @@ handle_ofpmp_table_features(struct ofp_buffer *ofpbuf)
/* 处理复合消息,端口描述子类型OFPMP_PORT_DESC的请求消息*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OFPMP_PORT_DESC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
static enum ofperr
handle_ofpmp_port_desc(struct ofp_buffer *ofpbuf)
{
@@ -1478,8 +1478,8 @@ handle_ofpmp_port_desc(struct ofp_buffer *ofpbuf)
}
/* 处理复合消息
* 判断哪种消息子类型,进行相应处理*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
static enum ofperr
handle_multipart_request(struct ofp_buffer *ofpbuf)
{
@@ -1623,8 +1623,8 @@ handle_meter_mod(struct ofp_buffer *ofpbuf)
return 0;
}
/* 处理OpenFlow消息
* 判断哪种消息类型,进行相应处理*/
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>OpenFlow<EFBFBD><EFBFBD>Ϣ
* <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
static enum ofperr
handle_openflow(struct ofp_buffer *ofpbuf,int len)
{
@@ -1720,7 +1720,7 @@ handle_openflow(struct ofp_buffer *ofpbuf,int len)
}
/*从控制器接收openflow消息*/
/*<EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>openflow<EFBFBD><EFBFBD>Ϣ*/
void *recv_openflow_message(void *argv)
{
int recv_len;
@@ -1825,7 +1825,7 @@ pthread_t ofp_init(char *controller_ip)
gettimeofday(&start_tv,NULL);
start_tv.tv_usec = 0;
ofp_tid = openflow_listener(controller_ip); //启动线程与Openflow控制器连接
ofp_tid = openflow_listener(controller_ip); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>Openflow<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//pcap_tid = start_pcap();
//pthread_join(ofp_tid, NULL);
@@ -1846,14 +1846,14 @@ int ofp_init(char *controller_ip)
gettimeofday(&start_tv,NULL);
start_tv.tv_usec = 0;
ofp_tid = openflow_listener(controller_ip); //启动线程与Openflow控制器连接
ofp_tid = openflow_listener(controller_ip); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>Openflow<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pcap_tid = start_pcap();
pthread_join(ofp_tid, NULL);
pthread_join(pcap_tid, NULL);
/* 关闭Socket连坑 */
/* <EFBFBD>ر<EFBFBD>Socket<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
close_openflow_connect();
SHOW_FUN(1);
exit(0);