首页 > 其他分享 >实验3:OpenFlow协议分析实践

实验3:OpenFlow协议分析实践

时间:2022-10-05 22:46:11浏览次数:52  
标签:OFPT struct OpenFlow 实践 header ofp 实验 message switch

一、基础要求只需要提交导入到/home/用户名/学号/lab3/目录下的拓扑文件,wireshark抓包的结果截图和对应的文字说明;
1.Hello
控制器6633端口(我最高能支持OpenFlow 1.0) ---> 交换机40498端口

交换机40498端口(我最高能支持OpenFlow 1.0) ---> 控制器6633端口

2.Features Request
控制器6633端口(我需要你的特征信息) ---> 交换机40498端口

3.Set Conig
控制器6633端口(请按照我给你的flag和max bytes of packet进行配置) ---> 交换机40498端口

4.Port Status
当交换机端口发生变化时,告知控制器相应的端口状态。

5.Features Reply
Features Reply消息包括Openflow Header 和Features Reply Message
交换机40498端口(这是我的特征信息,请查收) ---> 控制器6633端口

6.Packet in
交换机40498端口(有数据包进来,请指示)--- 控制器6633端口

7.Flow mod
控制器通过6633端口向交换机40498端口下发流表项,指导数据的转发处理

8.Packet_out
控制器6633端口向交换机40498端口发送数据,并告知交换机输出到65531端口。

9.流程图:

10.交换机与控制器建立通信时是使用TCP协议还是UDP协议?
交换机与控制器建立通信时使用的是TCP协议,如下图:

二、进阶要求
消息类型:

点击查看代码
enum ofp_type {
    /* Immutable messages. */
    OFPT_HELLO,               /* Symmetric message */
    OFPT_ERROR,               /* Symmetric message */
    OFPT_ECHO_REQUEST,        /* Symmetric message */
    OFPT_ECHO_REPLY,          /* Symmetric message */
    OFPT_VENDOR,              /* Symmetric message */

    /* Switch configuration messages. */
    OFPT_FEATURES_REQUEST,    /* Controller/switch message */
    OFPT_FEATURES_REPLY,      /* Controller/switch message */
    OFPT_GET_CONFIG_REQUEST,  /* Controller/switch message */
    OFPT_GET_CONFIG_REPLY,    /* Controller/switch message */
    OFPT_SET_CONFIG,          /* Controller/switch message */

    /* Asynchronous messages. */
    OFPT_PACKET_IN,           /* Async message */
    OFPT_FLOW_REMOVED,        /* Async message */
    OFPT_PORT_STATUS,         /* Async message */

    /* Controller command messages. */
    OFPT_PACKET_OUT,          /* Controller/switch message */
    OFPT_FLOW_MOD,            /* Controller/switch message */
    OFPT_PORT_MOD,            /* Controller/switch message */

    /* Statistics messages. */
    OFPT_STATS_REQUEST,       /* Controller/switch message */
    OFPT_STATS_REPLY,         /* Controller/switch message */

    /* Barrier messages. */
    OFPT_BARRIER_REQUEST,     /* Controller/switch message */
    OFPT_BARRIER_REPLY,       /* Controller/switch message */

    /* Queue Configuration messages. */
    OFPT_QUEUE_GET_CONFIG_REQUEST,  /* Controller/switch message */
    OFPT_QUEUE_GET_CONFIG_REPLY     /* Controller/switch message */

};

Hello:

点击查看代码
/* Header on all OpenFlow packets. */
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;      /* Transaction id associated with this packet.
                           Replies use the same id as was in the request
                           to facilitate pairing. */  //关联id
};
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;
};

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;       /* Transaction id associated with this packet.
                           Replies use the same id as was in the request
                           to facilitate pairing. */  //关联id
};

//该参数与hello报文结构相同

Set Conig:

点击查看代码
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
};   
/* Switch configuration. */
struct ofp_switch_config {
    struct ofp_header header;
    uint16_t flags;        /* OFPC_* flags. */  //flag指示交换机如何处理 IP 分片数据包,不同的flag值对应不同的处理方式     
    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);

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);

Features Reply:

点击查看代码
/* Switch features. */
struct ofp_switch_features {
    struct ofp_header header;
    uint64_t datapath_id;   /* Datapath unique ID.  The lower 48-bits are for
                               a MAC address, while the upper 16-bits are
                               implementer-defined. */  //标识id

    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);

Packet-in:

点击查看代码
/* Why is this packet being sent to the controller? */
enum ofp_packet_in_reason {
    OFPR_NO_MATCH,          /* No matching flow. */  //没有匹配的项目
    OFPR_ACTION             /* Action explicitly output to controller. */  //action列表中包含转发给控制器的动作
};

/* Packet received on port (datapath -> controller). */
struct ofp_packet_in {
    struct ofp_header header;
    uint32_t buffer_id;    /* ID assigned by datapath. */
    uint16_t total_len;    /* Full length of frame. */  //data字段的长度
    uint16_t in_port;      /* Port on which frame was received. */  //进入交换机的端口号
    uint8_t reason;        /* 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);

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;          /* One 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;        /* Buffered packet to apply to (or -1).  //缓存区ID 
                                     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;           /* One of OFPFF_*. */  //标志位 
    struct ofp_action_header actions[0]; /* The action length is inferred
                                            from the length field in the
                                            header. */  //action列表
};
OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);

Packet-out:

点击查看代码
/* Send packet (controller -> datapath). */
struct ofp_packet_out {
    struct ofp_header header;
    uint32_t buffer_id;       /* ID assigned by datapath (-1 if none). */  //交换机缓存区id
    uint16_t in_port;      
 /* Packet's input port (OFPP_NONE if none). */
    uint16_t actions_len;     /* Size of action array in bytes. */ //action列表的长度
    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建立拓扑,回到wireshark运用过滤器寻找,不然会找不到Hello报文。通过这次实验加深了对wireshark的使用熟练度,了解了openflow 交换机和控制器的交互过程和主要的消息类型与对应的信息。

标签:OFPT,struct,OpenFlow,实践,header,ofp,实验,message,switch
From: https://www.cnblogs.com/CipherOuO/p/16756626.html

相关文章

  • 实验3:OpenFlow协议分析实践
    实验3:OpenFlow协议分析实践一、实验目的能够运用wireshark对OpenFlow协议数据交互过程进行抓包;能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机制......
  • 实验4:开源控制器实践——OpenDaylight
    实验4:开源控制器实践——OpenDaylight一、实验目的能够独立完成OpenDaylight控制器的安装配置;能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环境Ub......
  • 实验3:OpenFlow协议分析实践
    实验3:OpenFlow协议分析实践一、实验目的能够运用wireshark对OpenFlow协议数据交互过程进行抓包;能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机......
  • 实验3:OpenFlow协议分析实践
    一、实验目的能够运用wireshark对OpenFlow协议数据交互过程进行抓包;能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机制。二、实验环境Ubuntu20......
  • 实验3:OpenFlow协议分析实践
    实验3:OpenFlow协议分析实践一、实验目的能够运用wireshark对OpenFlow协议数据交互过程进行抓包;能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机制......
  • 实验三
    (一)基本要求搭建下图所示拓扑,完成相关IP配置,并实现主机与主机之间的IP通信。用抓包软件获取控制器与交换机之间的通信数据。HELLO:互相发送Hello消息互相协商Openflo......
  • 实验4:开源控制器实践——OpenDaylight
    基本要求利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight控制器通过Postman工具调用OpenDaylight提供的API下发流表,实现拓扑内主机h1和h3网络中断10s实验......
  • 实验3:OpenFlow协议分析实践
    一.实验目的搭建下图所示拓扑,完成相关IP配置,并实现主机与主机之间的IP通信。用抓包软件获取控制器与交换机之间的通信数据。#!/usr/bin/envpythonfromminine......
  • 实验4:开源控制器实践——OpenDaylight
    实验4:开源控制器实践——OpenDaylight一、实验目的能够独立完成OpenDaylight控制器的安装配置;能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环境Ub......
  • KUBERNETES服务健康检查配置最佳实践
    ​简介K8S服务健康检查从两个维度进行,分别为:就绪状态检查(readiness)和存活状态检查(liveness)。存活探针和就绪探针被称作健康检查。这些容器探针是一些周期性运行的小进程......