NTNX>日記

個人的な趣味による Nutanix Community Edition 日記。Japanese のみですみません。

AHV の OpenFlow ルール表示を工夫してみる。

Nutanix CE の AHV では、ネットワーク関連の機能で Open vSwitch ブリッジの OpenFlow ルールが利用されています。

Open vSwitch の OpenFlow ルールは、ovs-ofctl dump-flows コマンドで確認できますが、デフォルトでは Stats 情報も表示されます。

[root@NTNX-1345a952-A ~]# ovs-ofctl dump-flows br0
 cookie=0x0, duration=679.433s, table=0, n_packets=0, n_bytes=0, priority=42,dl_type=0x9000 actions=drop
 cookie=0x0, duration=679.433s, table=0, n_packets=52, n_bytes=3800, priority=41,in_port="br0.u" actions=resubmit(,3)
 cookie=0x0, duration=703.505s, table=0, n_packets=231204, n_bytes=535866215, priority=0 actions=NORMAL
 cookie=0x0, duration=679.433s, table=0, n_packets=3731512, n_bytes=7947552515, priority=40 actions=resubmit(,3)
 cookie=0x0, duration=679.433s, table=3, n_packets=20, n_bytes=840, priority=1,arp,in_port="br0.u" actions=NORMAL,output:"br0-arp"
 cookie=0x0, duration=679.433s, table=3, n_packets=0, n_bytes=0, priority=1,udp,in_port="br0.u",tp_dst=67 actions=NORMAL,output:"br0-arp"
 cookie=0x0, duration=679.433s, table=3, n_packets=6, n_bytes=2169, priority=1,udp,tp_dst=68 actions=NORMAL,output:"br0-arp"
 cookie=0x0, duration=679.433s, table=3, n_packets=3731538, n_bytes=7947553306, priority=0 actions=NORMAL

そこで、Stats 情報を省略する「--no-stats」 オプションを使用すると、すこしルールの内容を確認しやすくなります。

[root@NTNX-1345a952-A ~]# ovs-ofctl dump-flows br0 --no-stats
 priority=42,dl_type=0x9000 actions=drop
 priority=41,in_port="br0.u" actions=resubmit(,3)
 priority=0 actions=NORMAL
 priority=40 actions=resubmit(,3)
 table=3, priority=1,arp,in_port="br0.u" actions=NORMAL,output:"br0-arp"
 table=3, priority=1,udp,in_port="br0.u",tp_dst=67 actions=NORMAL,output:"br0-arp"
 table=3, priority=1,udp,tp_dst=68 actions=NORMAL,output:"br0-arp"
 table=3, priority=0 actions=NORMAL

また、AHV ではブリッジ チェーンが構成されているため、複数のブリッジにそれぞれ OpenFlow ルールが設定されています。

[root@NTNX-1345a952-A ~]# ovs-vsctl list-br
br.dmx
br.microseg
br.mx
br.nf
br0
br0.local

そこで下記のようなコマンドラインを実行すると、すべてのブリッジのルールをまとめて取得できます。

ovs-vsctl list-br | while read BR; do echo '=========='; echo $BR; ovs-ofctl dump-flows $BR --no-stats; done

このコマンドでは、下記のような感じでルールを出力できます。ルール件数が多いので、ここでは一部のみ表示(tail -n 50 で末尾 50行)しています。

[root@NTNX-1345a952-A ~]# ovs-vsctl list-br | while read BR; do echo '=========='; echo $BR; ovs-ofctl dump-flows $BR --no-stats; done | tail -n 50
 table=12, priority=10 actions=resubmit(,20)
 table=13, priority=10 actions=resubmit(,20)
 table=20, priority=10 actions=resubmit(,21)
 table=21, priority=10 actions=resubmit(,40)
 table=40, priority=10 actions=resubmit(,50)
 table=50, priority=11,in_port=1 actions=output:2
 table=50, priority=11,in_port=2 actions=output:1
 table=50, priority=10 actions=drop
==========
br0
 priority=42,dl_type=0x9000 actions=drop
 priority=41,in_port=6 actions=resubmit(,3)
 priority=0 actions=NORMAL
 priority=40 actions=resubmit(,3)
 table=3, priority=1,arp,in_port=6 actions=NORMAL,output:4
 table=3, priority=1,udp,in_port=6,tp_dst=67 actions=NORMAL,output:4
 table=3, priority=1,udp,tp_dst=68 actions=NORMAL,output:4
 table=3, priority=0 actions=NORMAL
==========
br0.local
 priority=52,in_port=3,vlan_tci=0x0000/0x0fff actions=load:0x100b->NXM_OF_VLAN_TCI[0..12],resubmit(,4),load:0x300->NXM_NX_PKT_MARK[],resubmit(,2)
 priority=52,in_port=2,vlan_tci=0x0000/0x0fff actions=load:0x100b->NXM_OF_VLAN_TCI[0..12],resubmit(,4),load:0x200->NXM_NX_PKT_MARK[],resubmit(,2)
 priority=51,in_port=1 actions=resubmit(,1)
 priority=51,in_port=3 actions=drop
 priority=51,in_port=2 actions=drop
 priority=0 actions=NORMAL
 priority=50 actions=drop
 table=1, hard_timeout=300, priority=65050,vlan_tci=0x000b/0x0fff,dl_dst=50:6b:8d:bb:b2:5f actions=load:0->NXM_OF_VLAN_TCI[0..12],output:3
 table=1, hard_timeout=300, priority=65050,vlan_tci=0x000b/0x0fff,dl_dst=50:6b:8d:a1:f4:72 actions=load:0->NXM_OF_VLAN_TCI[0..12],output:2
 table=1, priority=52,pkt_mark=0x300,vlan_tci=0x000b/0x0fff actions=load:0->NXM_OF_VLAN_TCI[0..12],load:0x3->NXM_OF_IN_PORT[],NORMAL
 table=1, priority=52,pkt_mark=0x200,vlan_tci=0x000b/0x0fff actions=load:0->NXM_OF_VLAN_TCI[0..12],load:0x2->NXM_OF_IN_PORT[],NORMAL
 table=1, priority=51,pkt_mark=0x300 actions=load:0x3->NXM_OF_IN_PORT[],NORMAL
 table=1, priority=51,pkt_mark=0x200 actions=load:0x2->NXM_OF_IN_PORT[],NORMAL
 table=1, priority=50 actions=load:0xffff->NXM_OF_IN_PORT[],NORMAL
 table=2, priority=50 actions=output:1
 table=4, priority=50 actions=learn(table=1,hard_timeout=300,priority=65050,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],load:0->NXM_OF_VLAN_TCI[0..12],output:NXM_OF_IN_PORT[])
 table=5, priority=50 actions=learn(table=1,hard_timeout=300,priority=65050,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_OF_IN_PORT[])
 table=6, priority=100,vlan_tci=0x000b/0x0fff actions=load:0x8da1f472->NXM_NX_REG6[],load:0x506b->NXM_NX_REG7[],resubmit(,7)
 table=7, priority=10 actions=resubmit(,8)
 table=8, priority=10 actions=resubmit(,9)
 table=9, priority=10 actions=resubmit(,10)
 table=10, priority=10 actions=resubmit(,11)
 table=11, priority=2,pkt_mark=0x300,reg6=0x8dbbb25f,reg7=0x506b actions=drop
 table=11, priority=2,pkt_mark=0x300,reg6=0x8dbbb25f,reg7=0x1506b actions=drop
 table=11, priority=2,pkt_mark=0x200,reg6=0x8da1f472,reg7=0x506b actions=drop
 table=11, priority=2,pkt_mark=0x200,reg6=0x8da1f472,reg7=0x1506b actions=drop
 table=11, priority=1,reg6=0x8dbbb25f,reg7=0x506b actions=load:0->NXM_OF_VLAN_TCI[0..12],output:3
 table=11, priority=1,reg6=0x8dbbb25f,reg7=0x1506b actions=output:3
 table=11, priority=1,reg6=0x8da1f472,reg7=0x506b actions=load:0->NXM_OF_VLAN_TCI[0..12],output:2
 table=11, priority=1,reg6=0x8da1f472,reg7=0x1506b actions=output:2

ルールを詳しく調査する場合は、ブリッジごとにルールの行数を付与してみると便利なことがあります。そこで、さきほどのコマン ドラインに、nl コマンドを追加してみます。

ovs-vsctl list-br | while read BR; do echo '=========='; echo $BR; ovs-ofctl dump-flows $BR --no-stats | nl; done

このコマンドラインを実行すると、下記のようにブリッジ単位でルールの先頭に行番号を表示できます。これで、「XX ブリッジの NN 行目のルールで」のような説明がしやすくなるはず・・・

[root@NTNX-1345a952-A ~]# ovs-vsctl list-br | while read BR; do echo '=========='; echo $BR; ovs-ofctl dump-flows $BR --no-stats | nl; done | tail -n 50
    11   table=12, priority=10 actions=resubmit(,20)
    12   table=13, priority=10 actions=resubmit(,20)
    13   table=20, priority=10 actions=resubmit(,21)
    14   table=21, priority=10 actions=resubmit(,40)
    15   table=40, priority=10 actions=resubmit(,50)
    16   table=50, priority=11,in_port=1 actions=output:2
    17   table=50, priority=11,in_port=2 actions=output:1
    18   table=50, priority=10 actions=drop
==========
br0
     1   priority=42,dl_type=0x9000 actions=drop
     2   priority=41,in_port=6 actions=resubmit(,3)
     3   priority=0 actions=NORMAL
     4   priority=40 actions=resubmit(,3)
     5   table=3, priority=1,arp,in_port=6 actions=NORMAL,output:4
     6   table=3, priority=1,udp,in_port=6,tp_dst=67 actions=NORMAL,output:4
     7   table=3, priority=1,udp,tp_dst=68 actions=NORMAL,output:4
     8   table=3, priority=0 actions=NORMAL
==========
br0.local
     1   priority=52,in_port=3,vlan_tci=0x0000/0x0fff actions=load:0x100b->NXM_OF_VLAN_TCI[0..12],resubmit(,4),load:0x300->NXM_NX_PKT_MARK[],resubmit(,2)
     2   priority=52,in_port=2,vlan_tci=0x0000/0x0fff actions=load:0x100b->NXM_OF_VLAN_TCI[0..12],resubmit(,4),load:0x200->NXM_NX_PKT_MARK[],resubmit(,2)
     3   priority=51,in_port=1 actions=resubmit(,1)
     4   priority=51,in_port=3 actions=drop
     5   priority=51,in_port=2 actions=drop
     6   priority=0 actions=NORMAL
     7   priority=50 actions=drop
     8   table=1, hard_timeout=300, priority=65050,vlan_tci=0x000b/0x0fff,dl_dst=50:6b:8d:bb:b2:5f actions=load:0->NXM_OF_VLAN_TCI[0..12],output:3
     9   table=1, hard_timeout=300, priority=65050,vlan_tci=0x000b/0x0fff,dl_dst=50:6b:8d:a1:f4:72 actions=load:0->NXM_OF_VLAN_TCI[0..12],output:2
    10   table=1, priority=52,pkt_mark=0x300,vlan_tci=0x000b/0x0fff actions=load:0->NXM_OF_VLAN_TCI[0..12],load:0x3->NXM_OF_IN_PORT[],NORMAL
    11   table=1, priority=52,pkt_mark=0x200,vlan_tci=0x000b/0x0fff actions=load:0->NXM_OF_VLAN_TCI[0..12],load:0x2->NXM_OF_IN_PORT[],NORMAL
    12   table=1, priority=51,pkt_mark=0x300 actions=load:0x3->NXM_OF_IN_PORT[],NORMAL
    13   table=1, priority=51,pkt_mark=0x200 actions=load:0x2->NXM_OF_IN_PORT[],NORMAL
    14   table=1, priority=50 actions=load:0xffff->NXM_OF_IN_PORT[],NORMAL
    15   table=2, priority=50 actions=output:1
    16   table=4, priority=50 actions=learn(table=1,hard_timeout=300,priority=65050,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],load:0->NXM_OF_VLAN_TCI[0..12],output:NXM_OF_IN_PORT[])
    17   table=5, priority=50 actions=learn(table=1,hard_timeout=300,priority=65050,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_OF_IN_PORT[])
    18   table=6, priority=100,vlan_tci=0x000b/0x0fff actions=load:0x8da1f472->NXM_NX_REG6[],load:0x506b->NXM_NX_REG7[],resubmit(,7)
    19   table=7, priority=10 actions=resubmit(,8)
    20   table=8, priority=10 actions=resubmit(,9)
    21   table=9, priority=10 actions=resubmit(,10)
    22   table=10, priority=10 actions=resubmit(,11)
    23   table=11, priority=2,pkt_mark=0x300,reg6=0x8dbbb25f,reg7=0x506b actions=drop
    24   table=11, priority=2,pkt_mark=0x300,reg6=0x8dbbb25f,reg7=0x1506b actions=drop
    25   table=11, priority=2,pkt_mark=0x200,reg6=0x8da1f472,reg7=0x506b actions=drop
    26   table=11, priority=2,pkt_mark=0x200,reg6=0x8da1f472,reg7=0x1506b actions=drop
    27   table=11, priority=1,reg6=0x8dbbb25f,reg7=0x506b actions=load:0->NXM_OF_VLAN_TCI[0..12],output:3
    28   table=11, priority=1,reg6=0x8dbbb25f,reg7=0x1506b actions=output:3
    29   table=11, priority=1,reg6=0x8da1f472,reg7=0x506b actions=load:0->NXM_OF_VLAN_TCI[0..12],output:2
    30   table=11, priority=1,reg6=0x8da1f472,reg7=0x1506b actions=output:2

ちなみに、今回の Nutanix CE バージョンは ce-2020.09.16-stable です。

以上。

©2023 gowatana
クリエイティブ・コモンズ・ライセンスこの 作品 は クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されています。