SDN第三次上機作業


實驗任務一

試驗任務二

OpenFlow協議中交換機與控制器的消息交互過程如下圖所示

Hello

首先,控制器與交互及互相發送 Hello 消息。

Features Request

其次,OpenFlow 連接建立之后,控制器需要獲得交換機的特性信息,因此控制器向交換機發送 Features Request 消息查詢交換機特性.

Features Reply

交換機在收到控制器發出的 Features Request 消息后,將自己的特性告訴給控制器,返回 Features Request 消息.

Set config

知道了交換機的特性之后就要配置交換機了。

Packet-in

有兩種情況會觸發交換機向控制器發送 Packet_in 消息

  • 1.數據包在交換機中匹配不到流表,則向controller發送Packet_in消息
  • 2.數據包在流表中有匹配的條目,但是其中所指示的 action 列表中包含轉發給控制器的動作(Output = CONTROLLER)

    (注:該圖是因為匹配不到流表,屬於第一種)

Flow-Mod / Packet-out

當控制器收到 Packet-in 消息時有兩種響應的方式:

  • Flow-Mod:控制器收到 Packet‐in 消息后,可以發送 Flow‐Mod 消息向交換機下發一個流表項。
  • Packet-out:與Flow-Mod不同的是,控制器不會下發流表,而是直接告訴交換機該如何做。

    (Flow-Mod)

    (Packet_out)

實驗任務三

Q:交換機與控制器建立通信時是使用TCP協議還是UDP協議?TCP協議

進階任務

OFPT_Hello

Hello包定義了一個header,header數據結構如下:

struct ofp_header {
    uint8_t version;    /* 版本號 */
    uint8_t type;       /* Openflow 協議類型. */
    uint16_t length;    /* Openflow 數據包包頭. */
    uint32_t xid;       /* 數據包編號. */
};
struct ofp_hello {
    struct ofp_header header;
};

OFPT_ERROR

如果連接失敗,會發送一個error包,error類型如下。

enum ofp_error_type {
    OFPET_HELLO_FAILED,         /* Hello protocol failed. */
    OFPET_BAD_REQUEST,          /* Request was not understood. */
    OFPET_BAD_ACTION,           /* Error in action description. */
    OFPET_FLOW_MOD_FAILED,      /* Problem modifying flow entry. */
    OFPET_PORT_MOD_FAILED,      /* Port mod request failed. */
    OFPET_QUEUE_OP_FAILED       /* Queue operation failed. */
};

OFPT_FEATURES

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

OFPT_PACKET_IN

OFPT_PACKET_IN產生的原因有兩種,一種是沒匹配到流表,另一種是匹配到了,動作是轉發的控制器,代碼如下

enum ofp_packet_in_reason {
    OFPR_NO_MATCH,          /* No matching flow. */
    OFPR_ACTION             /* Action explicitly output to controller. */
};

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

OFPT_PACKET_OUT

packet_in事件之后,一般會觸發兩類事件,packet_out和flow_mod。兩者都是指導交換機如何處理數據包,區別是是否下發流表項。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.) */
};

OFPT_FLOW_MOD

Flow-Mod:控制器收到 Packet‐in 消息后,可以發送 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. */
};
OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);

/* Why was this flow removed? */
enum ofp_flow_removed_reason {
    OFPRR_IDLE_TIMEOUT,         /* Flow idle time exceeded idle_timeout. */
    OFPRR_HARD_TIMEOUT,         /* Time exceeded hard_timeout. */
    OFPRR_DELETE                /* Evicted by a DELETE flow mod. */
};

個人心得

源碼閱讀其實有很多內容可寫,如果把整個流程寫出來,就太麻煩了。所以這邊就非常簡單寫了一些OpenFlow主要消息類型對應的數據結構定義。還有交互過程也應該詳細一些的。不過不太符合作業簡要的要求,就沒寫太多。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM