今日も秋田で IoT

旧 Trema 日記

Flow エントリをポート指定で消す (その1)

今回は、出力ポートが同じである複数のフローエントリを消す方法を紹介します。

早速ですが、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).
                                     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);

ポイントは、このフィールド中の out_port です。ここにポート番号が指定された場合、Output アクションで指定されたポート番号と一致したエントリのみ削除されることになります。特に指定する必要がない場合には OFPP_NONE を指定する必要があります。

通常は削除したい Flow エントリの match を含む Flow Mod メッセージを作り、command に OFPFC_DELETE または OFPFC_DELETE_STRICT でスイッチに送れば該当するエントリが削除されます。しかし、out_port に値を指定すると、該当するエントリのうち、アクションの出力ポートが out_port で指定された値と同一の場合のみ、そのエントリが削除されます。

この out_port の指定を使えば、例えばあるリンクが故障した場合、そのリンクに接続するポートに対して出力するアクションを含むフローエントリを一括して削除することができます。match はすべてワイルドカードに、command は OFPFC_DELETE にした上で、out_port にそのポート番号を格納した Flow Mod メッセージを作り、スイッチに送ればよいです。

次回以降、具体例を紹介したいと思います。