1. How to Run
P4 Behavior Model v2
~ An P4 Software Switch Reference Implementation ~
Twitter: @ebiken
How to Run P4 Behavior Model v2 | 2017/08/06 1
2. • data plane 記述言語である “P4” 対応のハードウェア実装(ASIC, SmartNIC etc.)が増え
つつあるが、数十万~数百万円と、P4とは何かをまず試してみるにはコスト的に敷居が
高い。
• また、各ハードウェア実装(以降ターゲット)によってサポートされるP4機能が異なるため、
P4言語そのものを試すには制約が少ないソフトウェア実装が好ましい。
• そのため、P4を初めて試す際や、P4を用いたアプリケーションのPOC等を実施する際に
は、P4コミュニティで実装がすすめられているリファレンス実装である “P4 BMv2
(Behavior Model version 2)” を用いると有効である。
• 本文書では、P4 BMv2 を用いてP4のコンパイルおよびP4スイッチを動作させるための手
順を紹介する。
About this document
How to Run P4 Behavior Model v2 | 2017/08/06 2
3. • 既存パケット処理専用ASICの課題(P4のモチベーション)
• パケット処理を高速(Tbps)かつ安価に実施する場合、専用ASICが利用される。
• 新しいプロトコル・処理方法に対応したASICの開発には2~3年必要。
• 標準化完了~対応製品利用可能まで5年程度必要。
• ネットワーク製品の進化がユーザーニーズに追い付かなくなっていた。
How to Run P4 Behavior Model v2 | 2017/08/06 3
P4について
Reference:
• “The P4 Language Specification”
• Version 1.0.3 | November 2, 2016
• プログラム可能なパケット処理専用ASICの開発
• パケット処理(Dataplane)の基本動作(Parse/Match/Action)を
プログラム可能なASICとプログラム言語(P4)を設計。
• P4 : Programming Protocol-Independent Packet Processors
• 仕様提唱企業:Barefoot Networks
• P4は「データプレーン定義言語」であるため、様々なターゲット
プラットフォームへコンパイル可能
• P4対応 Ethernet Switch (ASIC)
• SmartNIC (NPU, FPGA)
• Software (CPU)
17. How to Run P4 Behavior Model v2 | 2017/08/06 17
bmv2 (behavior model)
1. GitHub から bmv2 (behavioral-model) repository をクローン
$ git clone https://github.com/p4lang/behavioral-model.git bmv2
$ cd bmv2
2. 依存パッケージをインストール
> under ~/bmv2$
$ ./install_deps.sh script
3. ビルド
> Build
$ ./autogen.sh
$ ./configure
$ make -j2
$ sudo make install # if you need to install bmv2
4. テスト実行
> Run test
$ make check
19. • P4 Program のコンパイル、Agentの利用、設定の投入、等、P4 Applicationを動作させる
ために必要な基本的な手順すべてが含まれるため、サンプルとして ”Target: l2_switch”
を用いた Layer 2 (mac learning) switch の動作手順を記載します。
How to Run P4 Behavior Model v2 | 2017/08/06 19
Layer 2 switch using P4 BMv2
host1 host2
l2_switch (BMv2)
veth0: 172.20.0.1/24
vtap1vtap0
veth1: 172.20.0.1/24
learn_client runtime_CLI
Notes
• Two veth/vtap pair are created.
• host1/host2 are network
namespace (netns) to emulate
hosts connected to switch.
• learn_client runs outside of
l2_switch (BMv2) and receives
packets from l2_switch / update
table entries dynamically.
• runtime_CLI are used to set initial
table entries on l2_switch, and
check table entries on runtime.
20. 1. veth/vtap pair, netns hosts の作成
2. l2_switch の起動
3. learn_client の起動
4. CLI の起動・設定の投入
5. host 間で ping による疎通確認
6. Table Entry の確認
How to Run P4 Behavior Model v2 | 2017/08/06 20
Layer 2 switch using P4 BMv2 (steps)
21. How to Run P4 Behavior Model v2 | 2017/08/06 21
Layer 2 switch using P4 BMv2 (作業ログ)
1. veth/vtap pair, netns hosts の作成
# Create netns hosts
ip netns add host0
ip netns add host1
# Create veth
ip link add veth0 type veth peer name vtap0
ip link add veth1 type veth peer name vtap1
# Connect veth between host0 and host1
ip link set veth0 netns host0
ip link set veth1 netns host1
ip link set dev vtap0 up
ip link set dev vtap1 up
# Link up loopback and veth
ip netns exec host0 ip link set veth0 up
ip netns exec host0 ifconfig lo up
ip netns exec host1 ip link set veth1 up
ip netns exec host1 ifconfig lo up
# Set IP address
ip netns exec host0 ip addr add 172.20.0.1/24 dev veth0
ip netns exec host1 ip addr add 172.20.0.2/24 dev veth1
ip link set dev vtap0 up
ip link set dev vtap1 up
2. l2_switch の起動
$ cd bmv2/targets/l2_switch
~/bmv2/targets/l2_switch$ sudo ./l2_switch l2_switch.json -i 0@vtap0 -i 1@vtap1 --nanolog ¥
ipc:///tmp/bm-0-log.ipc --log-console -L debug --notifications-addr ¥
ipc:///tmp/bmv2-0-notifications.ipc
3. learn_client の起動
~/bmv2/targets/l2_switch/learn_client$ sudo ./learn_client
4. CLI の起動・設定の投入
~/bmv2/targets/l2_switch$ ./runtime_CLI
table_set_default smac mac_learn
table_set_default dmac broadcast
mc_mgrp_create 1
mc_node_create 0 1
mc_node_create 1 2
mc_node_associate 1 0
mc_node_associate 1 1