# P4 07
## 20201102 龍帆軒
==這次的練習是試著使用p4runtime來實作control plane==
使用的topology如下,3個switch分別有host,然後有一個tunnel連接h1 h2

要實作controller要先了解p4runtime_lib的一些東西
先從helper.py開始看
++helper.py++
1. Contains the P4InfoHelper class which is used to parse the p4info files.
2. Provides translation methods from entity name to and from ID number.
3. Builds P4 program-dependent sections of P4Runtime table entries.
p4info是一個將table action ID 都寫在裡面的檔案
可以在執行make run指令後在build資料夾裡找到
下圖為p4info.txt

helper.py裡面只有一個class 叫做 P4InfoHelper
一開始的初始化(init)是將 p4info 檔案丟進一個空的 p4info 物件

接下來的get函式會將 p4info 裡的 entity_type 丟進 o 這個變數 去尋找對應的名稱或ID

get_id 會還傳self的ID
get_name會回傳self的name
get_alias會回傳self的alias

getattr就是將 id 搜尋的函式與 name 搜尋函式合成

get match field 就是在 p4info.helper 裡的 table 搜尋所提供的 name 或 ID

get match field id 就是搜尋對應的ID
get match field name 就是搜尋對應的name
get match field pb 就是去找到對應的p4runtime_pb2

###### tags: `P4`