# P4 08 ### 龍帆軒 ## controller實作 從mycontroller.py裡的main開始看  >把switch1 跟 switch2 的data dump到給定的txt檔  > 傳送master arbitration來設定這個controller為master > 可以去utils/p4runtime_lib/switch.py找定義 > > ``` request=p4runtime_pb2.StreamMessageRequest``` > 在 p4lang/p4runtime/blob/master/proto/p4/v1/p4runtime.proto 可以看到定義 >  > oneof 的用法是只有一個在update裡的資料會被改動 >  > > `request.arbitration.device_id=self.device.id` > 設定目前要被arbitrate的client  > 這幾行是在安裝p4 program到每個switch上 > `SetForwardingPipelineConfig()`可以在switch.py找定義 >  > 去p4runtime.proto找 `SetFowardingPipelineConfigRequest()` >  > 可以看到是在定義每個action代表的動作  > 把tunnel的traffic rules寫進去 > `writeTunnelRules()`可以在mycontroller.py上面一點找到 > `writeTunnelRules()`是在做3件事 > 1.tunnel ingress rule : encapsulates traffic into a tunnel with the specified ID > 2.tunnel transit rule : forwards traffic based on the specified ID > 3.tunnel egress rule : decapsulates traffic with the specified ID and sends it to the host  > 從switch1 跟 switch2 讀取table entry >  > 更詳細的在report 07  > 每兩秒印出tunnel counters >  > `sw.ReadCounters()`可以在p4runtime_lib/switch.py裡找到 >  > `ReadRequest()`在p4runtime.proto可以找到 > >Entity 可以從p4runtime.proto上方找到 > >可以看到我們設定entities為2 就是要讀table entry > `yield`是在迴圈裡遇到這行statement便會暫停跳出去 p4runtime_pb2 找不到 ###### tags: `P4`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up