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

实验3:OpenFlow协议分析实践

时间:2022-09-25 18:45:16浏览次数:57  
标签:OFPT struct OpenFlow 实践 header ofp 实验 message switch

实验3:OpenFlow协议分析实践

一、实验目的

  • 能够运用 wireshark 对 OpenFlow 协议数据交互过程进行抓包;
  • 能够借助包解析工具,分析与解释 OpenFlow协议的数据包交互过程与机制。

二、实验环境

Ubuntu 20.04 Desktop amd64

三、实验要求

(一)基本要求

搭建如下拓扑

进行相关IP配置

命令行拓扑完整性测试

查看抓包结果

OFPT_HELLO:

从控制器6633端口到交换机36512端口,使用OpenFlow1.0协议:

从控制器36512端口到交换机6633端口,使用OpenFlow1.5协议:

OFPT_HELLO后,双方协商使用openflow1.0协议

OFPT_FEATURES_REQUEST:

从控制器6633端口到交换机36512端口,请求特征信息

OFPT_SET_CONFIG:

OFPT_PORT_STATUS:

从交换机36512端口到控制器6633端口当交换机端口发生变化时,告知控制器相应的端口状态

OFPT_FEATURES_REPLY:

交换机36512端口到控制器6633端口,回复特征信息

OFPT_PACKET_IN:

分析抓取的数据包

OFPT_FLOW_MOD:

分析抓取的flow_mod数据包,控制器通过6633端口向交换机36528端口下发流表项,指导数据的转发处理

OFPT_PACKET_OUT:

控制器6633端口向交换机36528端口发送数据,并告知交换机输出到1端口

流程图

回答问题:

显然使用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 */

};
1.OFPT_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. */
};
/* 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.OFPT_FEATURES_REQUEST
源码:

与OFPT_HELLO代码一致

图片:

3.OFPT_SET_CONFIG
源码:
点击查看代码
/* Switch configuration. */
struct ofp_switch_config {
    struct ofp_header header;
    uint16_t flags;             /* OFPC_* flags. */
    uint16_t miss_send_len;     /* Max bytes of new flow that datapath should
                                   send to the controller. */
};
图片:

4.OFPT_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;
};
图片:

5.OFPT_FEATURES_REPLY:
代码:
点击查看代码
/* Description of a physical port */
struct ofp_phy_port {
    uint16_t port_no;
    uint8_t hw_addr[OFP_ETH_ALEN];
    char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */

    uint32_t config;        /* Bitmap of OFPPC_* flags. */
    uint32_t state;         /* Bitmap of OFPPS_* flags. */

    /* Bitmaps of OFPPF_* that describe features.  All bits zeroed if
     * unsupported or unavailable. */
    uint32_t curr;          /* Current features. */
    uint32_t advertised;    /* Features being advertised by the port. */
    uint32_t supported;     /* Features supported by the port. */
    uint32_t peer;          /* Features advertised by peer. */
};

/* 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. */

    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. */
};
图片:

6.OFPT_PACKET_IN:
源码:
点击查看代码
struct ofp_packet_in {
    struct ofp_header header;
    uint32_t buffer_id;     /* ID assigned by datapath. */
    uint16_t total_len;     /* Full length of frame. */
    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. */
};
图片:

7.OFPT_FLOW_MOD:
源码:
点击查看代码
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).
                                     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. */
};
图片:

8.OFPT_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). */
    uint16_t in_port;             /* Packet's input port (OFPP_NONE if none). */
    uint16_t actions_len;         /* 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.) */
};
图片:

四、实验心得

  • 本次实验较简单,主要是使用wireshark进行抓包以及对抓包结果进行分析制作流程图
  • 进行IP配置时,既可以在./miniedit.py中选中主机进行配置,也可在生成的拓扑文件中进行设置
  • 运行wireshark后,运行拓扑结构后,未在抓包列表中找到OFPT_FLOW_MOD类型,多次重复无果后,尝试输入pingall得到想要的结果
  • 刚开始查找flow_mod包时,未查找到指定包,多次修改过滤条件仍无效。在等待一段时间之后,不使用任何条件成功找到
  • 在进行抓包时必须一次性完成所有包的查找分析,否则再次启动虚拟机时,会发生两次抓包同一个包而端口不一致的情况

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

相关文章

  • 【Vue项目实践】(vue3 + Element Plus)excel 导出
    安装依赖yarnadd--savexlsxfile-saver1、添加导出按钮以及点击事件<el-buttontype="primary"round@click="exportClick">导出表格</el-button>2、在table表......
  • linux源码包 实验报告
    实验任务linux源码包的基础命令 实验环境一台centos7 实验步骤1.下载软件包将软件包拖进远程连接    2.解压缩  3.解压tar包  4.yum安......
  • 实验2:Open vSwitch虚拟交换机实践
    一、基本要求:1.a)1.b)......
  • 实验1:SDN拓扑实践
    实验1:SDN拓扑实践一、实验要求(一)基本要求1.使用Mininet可视化工具,生成下图所示的拓扑,并保存拓扑文件名为学号.py。2.使用Mininet的命令行生成如下拓扑:a)3台交换机,......
  • linux文件内容查看命令 实验报告
    实验任务Linux查看文件基础命令 实验环境一台centos7 实验步骤1.显示文件全部内容Cat+想要查看的文件名  2.显示文件全部内容并加行号  3.空行不......
  • 实验3:OpenFlow协议分析实践
    一、实验目的1.能够运用wireshark对OpenFlow协议数据交互过程进行抓包;2.能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机制。二、实验环境Ubuntu......
  • 实验1:SDN拓扑实践
    (一)基本要求1.使用Mininet可视化工具,生成下图所示的拓扑,并保存拓扑文件名为学号.py。2.使用Mininet的命令行生成如下拓扑:a)3台交换机,每个交换机连接1台主机,3台交换机连......
  • 【Vue项目实践】套用github 上的项目(vue3 + Element Plus)运行 可编辑表格
    在Vue3+ElementPlus中生成动态表格gitclonehttps://github.com/kalacloudCode/how-to-build-dynamic-table-in-vue-element-plus.git参考博客:vue3+Element......
  • 实验1:SDN拓扑实践
    基本要求一.第1步Mininet运行结果截图二.第2步的执行结果截图a)3台交换机,每个交换机连接1台主机,3台交换机连接成一条线。b)3台主机,每个主机都连接到同1台交换机......
  • 实验2:Open vSwitch虚拟交换机实践
    基础要求提交ovs-vsctl基础操作实践:创建OVS交换机,以ovs-xxxxxxxxx命名,其中xxxxxxxxx为本人学号。在创建的交换机上增加端口p0和p1,设置p0的端口号为100,p1的端口号为101,类......