open flow 协议分析实践

OpenFlow起源与发展

OpenFlow 是 Software Definded Network 的一种,由斯坦福大学的 Nick McKeown 教授在 2008 年 4 月 ACM Communications Review 上发表的一篇论文 OpenFlow: enabling innovation in campus networks 里首先提出来的。它最初的出发点是用于网络研究人员实验其创新网络架构、协议,考虑到实际的网络创新思想需要在实际网络上才能更好地验证,而研究人员又无法修改在网的网络设备,故而提出了 OpenFlow 的控制转发分离架构,将控制逻辑从网络设备盒子中引出来,研究者可以通过一组定义明确的接口对网络设备进行任意的编程从而实现新型的网络协议、拓扑架构而无需改动网络设备本身。

什么是open flow?

OpenFlow是一种网络通信协议°,应用于SDN架构中控制器和转发器之间的通信。软件定义网络SDN的一个核心思想就是“转发、控制分离”,要实现转、控分离,就需要在控制器与转发器之间建立一个通信接口标准,允许控制器直接访问和控制转发器的转发平面。OpenFlow引入了“流表”的概念,转发器通过流表来指导数据包的转发。控制器正是通过OpenFlow提供的接口在转发器上部署相应的流表,从而实现对转发平面的控制。

OpenFlow的实践分析

一、实验目的:

能够运用wireshark 对OpenFlow协议数据交互过程进行抓包;

能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机制。

二、实验环境:

VMware Workstion Pro 17

Ubuntu22.04 Desktop amd64,且完整安装了 Mininet;

三、基础实验要求:

1.在Mininet可视化界面搭建如下拓扑;

2.完成相关IP地址的配置,实现主机与主机之间的IP通信;

3.使用抓包软件Wireshark获取控制器与交换机之间的通信数据包进行分析;

四、实验分析

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

在终端输入sudo ./../mininet/examples/miniedit.py搭建拓扑

  • 配置网段

  • 配置IP地址

保存为.py文件

2.查看抓包结果,分析OpenFlow协议中交换机与控制器的消息交互过程,画出相关交互图或流程图。运行sudo wireshark命令,并选择any模式进行抓包,开启另一个终端,命令运行topo.py文件,运行pingall

(1)Hello

OFPT_HELLO 源端口6633 -> 目的端口34068,从控制器到交换机

也有源端口34068->目的端口6633的,即交换机到控制器的另一个包,此处协议为openflow1.5

(2)Features_Request

控制器与交换机建立连接,并使用openflow1.0OFPT_FEATURES_REQUEST源端口6633->目的端口34068,从控制器到交换机

(3)SET_CONFIG

控制器请求交换器的特征信息

OFPT_SET_CONFIG源端口6633->目的端口34068,从控制器到交换机

(4)Port_Status

控制器要求交换机按照所给出的信息进行配置OFPT_PORT_STATUS源端口35828->目的端口6633,从交换机到控制器

(5)Feature Reply

当交换机端口发生变化时,交换机告知控制器相应的端口状态OFPT_FEATURES_REPLY源端口号34068->目的端口6633,从交换机到控制器

​​​​​​​(6)Packet_IN

交换机告知控制器它的特征信息

OFPT_PACKET_IN源端口34068->目的端口6633,从交换机到控制器

(7)Packet_Out

交换机告知控制器有数据包进来,请求控制器指示OFPT_PACKET_OUT源端口6633->目的端口35844,从控制器到交换机

(8)Flow_Mod

控制器要求交换机按照所给出的action进行处理OFPT_FLOW_MOD源端口6633->目的端口35844,从控制器到交换机

控制器对交换机进行流表的添加、删除、变更等操作

上述OFPT_PACKET_IN、OFPT_PACKET_OUT、OFPT_FLOW_MOD三种消息报文的交互会频繁多从出现在交换机和控制器之间。

五、交互图

分析OpenFlow协议中交换机与控制器的消息交互过程,画出相关交互图或流程图。交互过程:交换机或控制器首先发送hello报文,确定openflow通信版本。交换机或控制器收到hello报文之后,回复一个hello报文,协商版本。控制器发送feature_request报文,查询交换机具体信息。交换机收到feature_request报文之后,回复feature_reply,报告自己的详细信息给控制器。工作过程中控制器会不断发送echo_request给交换机,交换机回复echo_reply消息给控制器,确认连接。

六、进阶要求

将抓包结果对照OpenFlow源码,了解OpenFlow主要消息类型对应的数据结构定义。相关数据结构可在openflow安装目录openflow/include/openflow当中的openflow.h头文件中查询到
1. 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;

};

可以看到对应了HELLO报文的四个参数

2. FEATURES_REQUEST

源码参数格式与HELLO相同,与上述ofp_header结构体中数据相同

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

};

可以看到与图中信息一一对应,包括交换机物理端口的信息

  1. PACKET_IN

PACKET_IN有两种情况:

交换机查找流表,发现没有匹配条目,但是这种包没有抓到过

enum ofp_packet_in_reason {

    OFPR_NO_MATCH,          /* No matching flow. */

    OFPR_ACTION             /* Action explicitly output to controller. */

};

有匹配条目,对应的action是OUTPUT=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. */

};

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

};

8. 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];

};

七、个人总结

本次实验我们通过抓取数据包、分析数据包学习了OpenFlow协议下控制器和交换机的交互过程。交换机和控制器的交互过程涉及到多个不同用途的数据包,通过wireshark我们捕获所有数据包,后续通过设置过滤规则进行数据包的过滤,查看每一个OpenFlow数据包的源端口、目的端口、类型和相关字段。进阶要求中通过数据包字段和源码的比较让我更进一步了解与掌握了OpenFlow协议。这次实验是验证性实验,实验难度相对会容易些,只需要建立拓扑后在wireshark中操作,就是找包的时候数据比较多,看起来比较累眼睛。通过阅读openflow的源码,能理清楚其中的数据结构,并和实际抓到的包的详细信息对应起来,从而理解openflow协议的数据包交互过程。除此之外,对wireshark中过滤器的使用也有了更深刻的了解,对openflow协议有了更深刻的认识。

首先,OpenFlow协议的核心在于其控制平面与数据平面的分离。其次,OpenFlow协议的流表概念让我印象深刻。然而,实践过程中也遇到了挑战。总的来说,OpenFlow协议的实践分析是一次宝贵的学习经历。它不仅提升了我的技术技能,也让我认识到了SDN在未来的网络发展中的潜力。尽管存在挑战,但OpenFlow协议无疑为网络工程师提供了强大的工具,以构建更加智能、可控的网络环境。随着技术的不断进步,我相信OpenFlow及其相关的SDN技术将继续推动网络领域的创新和发展。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值