Features Request でスイッチから情報を取得する (その3)
今回は Trema の話はすこしお休みして、OpenFlow spec 1.0 の仕様書を見てみましょう。
Features Reply の中身は以下のように定義されています。
/* 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. */ }; OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
- datapath_id : 言わずと知れた Datapath ID です。
- n_buffers : バッファのサイズが格納されます。
- n_tables : フローテーブルの数が返されます。OpenFlow 1.1 以降であれば複数のテーブルを扱うことができますが、OpenFlow 1.0 では一つしか扱えません。ですので、ここには 1 が格納されるはずです。
- capabilities : スイッチのケイパビリティを示すビットマップが返されます(後述)。
- actions : スイッチがサポートするアクション一覧を示すビットマップが返されます(後述)。
- ports : スイッチが持つポート一覧が返されます。
スイッチのケイパビリティ
capabilities で返されるビットマップの各ビットは、以下のように定義されています。
enum ofp_capabilities { OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */ OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */ OFPC_PORT_STATS = 1 << 2, /* Port statistics. */ OFPC_STP = 1 << 3, /* 802.1d spanning tree. */ OFPC_RESERVED = 1 << 4, /* Reserved, must be zero. */ OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */ OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */ OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP pkts. */ };
- OFPC_FLOW_STATS, OFPC_TABLE_STATS, OFPC_PORT_STATS, OFPC_QUEUE_STATS : Stats Request/Reply による統計情報の取得に対応しているか否かを示すビットです。
- OFPC_STP : スパニングツリープロトコルへの対応を示します。
- OFPC_IP_REASM : フラグメントされた IP パケットのリアセンブルに対応しているか否かを示します。
- OFPC_ARP_MATCH_IP : ARP 中の IP アドレスへのマッチに対応しているかを示します。
最後の三つについては、どのような機能なのか説明が難しいですが、知らなくても特に困らないでしょう。時間があればそのうち試して、謎を解明してみたいと思います。
スイッチがサポートするアクション
actions で返されるビットマップの各ビットの意味は、ofp_action_type の定義に対応します。
enum ofp_action_type { OFPAT_OUTPUT, /* Output to switch port. */ OFPAT_SET_VLAN_VID, /* Set the 802.1q VLAN id. */ OFPAT_SET_VLAN_PCP, /* Set the 802.1q priority. */ OFPAT_STRIP_VLAN, /* Strip the 802.1q header. */ OFPAT_SET_DL_SRC, /* Ethernet source address. */ OFPAT_SET_DL_DST, /* Ethernet destination address. */ OFPAT_SET_NW_SRC, /* IP source address. */ OFPAT_SET_NW_DST, /* IP destination address. */ OFPAT_SET_NW_TOS, /* IP ToS (DSCP field, 6 bits). */ OFPAT_SET_TP_SRC, /* TCP/UDP source port. */ OFPAT_SET_TP_DST, /* TCP/UDP destination port. */ OFPAT_ENQUEUE, /* Output to queue. */ OFPAT_VENDOR = 0xffff };
ビットマップの定義になっていませんが、OUTPUT が 1<<0, SET_VLAN_VID が 1<<1 という具合に対応していると考えればよいでしょう。
おわりに
今回説明できなかった Features Request/Reply で取得できるポートの情報に関しては、次回詳しく見ていきます。