paloma blog

NWエンジニアやってます。主に自宅環境のお遊びを書きます。Pythonもちょっと。タイトルは好きなカクテルから。

mininetでopenflowの勉強 確認コマンド編

openflowをちょっと触ってみるかで以前VMを立てたのですが、途中でデスクトップ環境いじりをやってしまったので本件が止まってしまっていました。 続きやります。

今回は確認コマンド系を見たいと思います。

NW構成

mininet@mininet-vm:~$ sudo mn

で作られるデフォルト構成です。

mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0

スイッチ1台にホスト2台。

dpctlコマンド

openflowの状態確認はdpctlコマンドでできるみたいです。
manを見るとopenflowのデータパス管理と出てきます。

iNAME
       dpctl - administer OpenFlow datapaths

dpctl show

openflowの情報。
mininet内で動かしているので10Gになってます。

LOCAL(s1)のdownは何なんでしょうか。

mininet> dpctl show
*** s1 ------------------------------------------------------------------------
OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000001
n_tables:254, n_buffers:0
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
 1(s1-eth1): addr:ae:8b:93:8b:47:83
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(s1-eth2): addr:0e:d4:6e:44:96:65
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(s1): addr:a2:29:c1:bc:47:40
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max
OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0

dpctl dump-tables

フローテーブル情報。
matchパケットをどう処理するかが書いてある感じですね。
forwardとかblockと行った文字が見当たりません。
デフォルトだと全転送でHUBみたいです。

mininet> dpctl dump-tables
*** s1 ------------------------------------------------------------------------
OFPST_TABLE reply (xid=0x2):
  table 0:
    active=0, lookup=22, matched=9
    max_entries=1000000
    matching:
      exact match or wildcard: in_port eth_{src,dst,type} vlan_{vid,pcp} ip_{src,dst} nw_{proto,tos} tcp_{src,dst}

  table 1:
    active=0, lookup=0, matched=0
    (same features)

  tables 2...253: ditto
  

詳細系のコマンドはmininetでは確認できませんでした。(v1.0)

mininet> dpctl dump-table-features
*** s1 ------------------------------------------------------------------------
ovs-ofctl: dump-table-features needs OpenFlow 1.3 or later ('-O OpenFlow13')
mininet> dpctl dump-table-desc
*** s1 ------------------------------------------------------------------------
ovs-ofctl: dump-table-desc needs OpenFlow 1.4 or later ('-O OpenFlow14')

dpctl dump-flows

現在のフロー情報。
FWでいうセッションテーブルみたいな感じですね。

h1 -> h2へのping後の取得です。
3発打ちましたが新しいものが上にスタックされる感じですね。
そして各スイッチはこれに沿って転送するわけですね。
フローテーブルにないものはコントローラーに問い合わせると。
しばらくすると消えてしまいます。デフォだと60秒ですかね。

mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
 cookie=0x0, duration=19.435s, table=0, n_packets=2, n_bytes=196, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=fe:b7:02:da:0c:d7,dl_dst=be:27:c9:4b:6a:a3,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth1"
 cookie=0x0, duration=18.434s, table=0, n_packets=2, n_bytes=196, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=be:27:c9:4b:6a:a3,dl_dst=fe:b7:02:da:0c:d7,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth2"
 cookie=0x0, duration=14.298s, table=0, n_packets=1, n_bytes=42, idle_timeout=60, priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=be:27:c9:4b:6a:a3,dl_dst=fe:b7:02:da:0c:d7,arp_spa=10.0.0.1,arp_tpa=10.0.0.2,arp_op=1 actions=output:"s1-eth2"
 cookie=0x0, duration=14.298s, table=0, n_packets=1, n_bytes=42, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=fe:b7:02:da:0c:d7,dl_dst=be:27:c9:4b:6a:a3,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=1 actions=output:"s1-eth1"
 cookie=0x0, duration=14.288s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=fe:b7:02:da:0c:d7,dl_dst=be:27:c9:4b:6a:a3,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=2 actions=output:"s1-eth1"
 cookie=0x0, duration=14.288s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=be:27:c9:4b:6a:a3,dl_dst=fe:b7:02:da:0c:d7,arp_spa=10.0.0.1,arp_tpa=10.0.0.2,arp_op=2 actions=output:"s1-eth2"

HTTPでアクセスするとこんな感じ、

mininet> h2 python -m http.server 80 &
mininet> h1 curl h2
bash: curl: command not found
mininet> h1 wget --spider h2
Spider mode enabled. Check if remote file exists.
--2022-12-22 05:48:37--  http://10.0.0.2/
Connecting to 10.0.0.2:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1293 (1.3K) [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.

mininet> 
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
 cookie=0x0, duration=7.899s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=36:ff:b0:51:ea:a2,dl_dst=72:18:af:6f:18:ff,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=2 actions=output:"s1-eth1"
 cookie=0x0, duration=2.868s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=36:ff:b0:51:ea:a2,dl_dst=72:18:af:6f:18:ff,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=1 actions=output:"s1-eth1"
 cookie=0x0, duration=2.867s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=72:18:af:6f:18:ff,dl_dst=36:ff:b0:51:ea:a2,arp_spa=10.0.0.1,arp_tpa=10.0.0.2,arp_op=2 actions=output:"s1-eth2"
 cookie=0x0, duration=7.893s, table=0, n_packets=4, n_bytes=400, idle_timeout=60, priority=65535,tcp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=72:18:af:6f:18:ff,dl_dst=36:ff:b0:51:ea:a2,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,tp_src=39344,tp_dst=80 actions=output:"s1-eth2"
 cookie=0x0, duration=7.886s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,tcp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=36:ff:b0:51:ea:a2,dl_dst=72:18:af:6f:18:ff,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_tos=0,tp_src=80,tp_dst=39344 actions=output:"s1-eth1"

arp問い合わせが毎回だとちょっと嫌なのでタイマーを長くしたいところです。

Openflowパケットキャプチャ

mininetにwiresharkも入ってますので中身を見てみます。

通常

一応TCPなので3wayハンドシェイクから始まって後は定期的にやり取りしてますね。

ICMP

h1->h2にpingした時。
TCPレイヤの上にopenflowヘッダでカプセル化される様です。
へー。知らなかった。
中身のフィールドは当然ながらオリジナルレイヤと同じですね。

HTTP

HTTPアクセス時も同じですね。
IPヘッダ上はloopbackでやり取りしてるのにキャプチャのsrc, dstはopenflow内のIPが見えます。
これは仕様でしょうか?切り分けの時パッと見だと戸惑いそう。

まとめ

簡単に確認系コマンドを見てみました。
まあNW機器を触ってる身としてはコマンドの違いはあれどこの辺の内容は割と理解できますね。
次回はコントローラー系を操作してみたいと思います。