# P4 14 ## 龍帆軒 20201228 ### P4Runtime Controller (這次將之前 P4Runtime 的報告重新整理) 自己寫的 controller 要把 table entries 那些裝在 switch 上 controller 的流程圖大概如下 ![](https://i.imgur.com/Ev83arw.png) 接下來會從每個state開始說明 首先會將一個 p4infohelper 這個物件創立出來 ```p4info_helper = p4runtime_lib.helper.P4InfoHelper(p4info_file_path)``` 這個的目的是為了更好操作我們的table entry, p4info_helper 有很多function 可以呼叫 #### Create Switch Connections 我們會將一個switch 建立好 ``` s1 = p4runtime_lib.bmv2.Bmv2SwitchConnection( name='s1', address='127.0.0.1:50051', device_id=0, proto_dump_file='logs/s1-p4runtime-requests.txt') ``` 我們可以看到是使用 bmv2 的 switch 然後會將資料丟到 logs 這個資料夾裡 >可以去utils/p4runtime_lib/helper.py找定義 #### Send Master Arbitration 建立完成後就可以傳送 arbritration 來宣告這個 controller 是 master ```s1.MasterArbitrationUpdate()``` >可以去utils/p4runtime_lib/switch.py找定義 #### Install P4 Program 設定好 master 後就可以安裝 p4 program 上去了 ``` s1.SetForwardingPipelineConfig(p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path) ``` >詳細解釋可以去看 Report 08 #### Write Tunnel Rules 之後就是將 tunnel 建立好,兩個方向都要考慮到 ``` writeTunnelRules(p4info_helper, ingress_sw=s1, egress_sw=s2, tunnel_id=100, dst_eth_addr="08:00:00:00:02:22", dst_ip_addr="10.0.2.2") ``` 這樣可以將 h1 連接到 h2 ###### tags: `P4`