实验3:OpenFlow协议分析实践

实验3:OpenFlow协议分析实践

第一部分:基本实验

实验步骤1

  • 搭建下图所示拓扑,完成相关 IP 配置,并实现主机与主机之间的 IP 通信。用抓包软件获取控制器与交换机之间的通信数据包。

    主机 IP地址
    h1 192.168.0.101/24
    h2 192.168.0.102/24
    h3 192.168.0.103/24
    h4 192.168.0.104/24

  • 导出的拓扑文件

实验步骤2

  • 查看抓包结果,分析OpenFlow协议中交换机与控制器的消息交互过程,画出相关交互图或流程图。

  • 控制器(端口6633)与交换机(端口41424)相互交换hello报文建立连接,并使用OpenFlow 1.0

  • 控制器向交换机发送hello报文

  • 交换机向控制器发送hello报文

  • 控制器(端口6633)向交换机(端口41424)发送Features Request报文,请求获取交换机的特征信息

  • 控制器(端口6633)向交换机(端口41424)发送Set Config报文,要求交换机按照指定的flag和max bytes of packet进行配置

  • 当交换机端口发生变化时,发送Port_Status报文告知控制器相应的端口状态

  • 交换机(端口41424)向控制器(端口6633)回送Features Reply报文,通知控制器查收自己的特征信息

  • 当交换机(端口41424)查找流表,发现没有匹配条目或者有匹配条目但是对应的action是OUTPUT=CONTROLLER时

  • 向控制器(端口6633)发送Packet_in报文,询问控制器要如何处理
    下述截图交换机发送Packet_in报文的原因是查找流表时候没有发现匹配条目

    交换机由于有匹配条目但是对应的action是OUTPUT=CONTROLLER而发送Packet_in报文的情况在抓包时候没有找到

  • 控制器(端口6633)收到Packet_in报文后回送给交换机(端口41424)Packet_out报文,指示它按照自己得action进行处理

  • 由于stop capturing packets过快,未能通过pingall测试抓取到flow_mod数据包,因此再重新进行一次capturing packets

  • 控制器(端口6633)向交换机(端口41562)发送Flow_mod报文,指导数据的转发处理

  • mininet命令行输入pingall

  • 抓取flow_mod数据包

  • 交互图

实验步骤3

  • 交换机与控制器建立通信时是使用TCP协议还是UDP协议?
    使用TCP协议,通过抓包可知

第二部分:进阶实验

实验要求

将抓包结果对照OpenFlow源码,了解OpenFlow主要消息类型对应的数据结构定义。

  • 相关数据结构可在openflow安装目录openflow/include/openflow当中的openflow.h头文件中查询到。

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

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

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

Features Reply数据包

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

Packet_in数据包

enum ofp_packet_in_reason {
    OFPR_NO_MATCH,          /* No matching flow. */
    OFPR_ACTION             /* Action explicitly output to 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. */
    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. */
};

Packet_out数据包

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.) */
};

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. */
};
struct ofp_action_header {
    uint16_t type;                  /* One of OFPAT_*. */
    uint16_t len;                   /* Length of action, including this
                                       header.  This is the length of action,
                                       including any padding to make it
                                       64-bit aligned. */
    uint8_t pad[4];
};

第三部分:反思与总结

实验难度:

  • 适中

实验过程遇到的困难及解决方法

  • 首先是在抓包时候,前面一直发现自己没能抓到hello数据包,后面细看了pdf才发现要先打开wireshark软件
    再运行拓扑文件,不然在wireshark的capture packets中会遗漏前面的数据包。接着就是由于自己为先提前
    细看pdf需要抓取的包(Flow_mod),在实验中关闭抓包过程过早,导致重新开启下一轮抓包,出现了实验报告中
    前面的交换机端口号与后面不匹配的情况。因此下次我要认真阅读完需要实验的内容再开始做,防止今天的错误
    再次发生。最后就是在进阶实验中对源码的搜寻有点艰难,看着一段段代码,眼睛迷迷糊糊,好在能通过wireshark
    内的数据包格式来对应。

个人感想

  • 通过这次实验,通过多次地抓包对wireshark的抓包的过程、过滤器的使用以及抓包的作用有了更加清楚的认识,相信
    自己后面能够灵活运用这次实验学到的新知识点。并且对openflow的交互流程有了更加深刻的认识,通过自己的不断抓包
    对每一个流程会产生什么类型的包,以及包的作用有了理解性地掌握。懂得了如何运用openflow.h文件的源码来认识
    抓到包的主要类型和数据结构。
posted @ 2021-09-23 13:04  运动ing的美食探险家  阅读(113)  评论(0编辑  收藏  举报