# Mininet p4 2 [TOC] p4c compiler 官網 https://github.com/p4lang/p4c 有p4c compiler 詳細的說明 ![](https://hackmd.io/_uploads/HydZ5QLNh.png) https://github.com/p4lang/behavioral-model target(simple_switch ) ![](https://hackmd.io/_uploads/Skfg5QIE2.png) Compile p4c(program) and behavioral-model on The Raspberry pi Attention: Memory 可能不足 (rasberry pi 3 以前) --- ![](https://hackmd.io/_uploads/S1Xtj7IEn.png) cli_input -> 同等於 cli 下 連接 Switch ``` simple_switch CLI --Thrift-port 9090 ``` cmd.txt ``` table_add mac_forward forward 00:00:0a:00:01:01 => 1 table_add mac_forward forward 00:00:0a:00:01:02 => 2 ``` topology.db (給controller 用的 p4run 完產生) ![](https://hackmd.io/_uploads/B1EbFvUV3.png) ### 分析 log file ``` [20:35:11.450] [bmv2] [D] [thread 5204] Adding interface s1-eth1 as port 1 Adding interface s1-eth2 as port 2 [20:35:11.483] [bmv2] [D] [thread 5204] Adding interface s1-eth2 as port 2 [20:35:11.506] [bmv2] [I] [thread 5204] Starting Thrift server on port 9090 ``` s1-eth1 -> port 1 s1-eth2 -> port 2 simple_switch_CLI --thrift-port 9090 (來連接) h1 ping h2 Receive and Parser ``` [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Processing packet received on port 1 [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Parser 'parser': start [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Parser 'parser' entering state 'start' [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Extracting header 'ethernet' [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Parser state 'start' has no switch, going to default next state [20:35:20.132] [bmv2] [T] [thread 5210] [4.0] [cxt 0] Bytes parsed: 14 [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Parser 'parser': end [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Pipeline 'ingress': start [20:35:20.132] [bmv2] [T] [thread 5210] [4.0] [cxt 0] Applying table 'MyIngress.mac_forward' [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Looking up key: * hdr.ethernet.dstAddr: 00000a000102 ``` Ingress ``` * hdr.ethernet.dstAddr: 00000a000102 [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Table 'MyIngress.mac_forward': hit with handle 1 [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Dumping entry 1 Match key: * hdr.ethernet.dstAddr: EXACT 00000a000102 Action entry: MyIngress.forward - 2, ``` dstMac Match 第二條Flow (hit with handle 1 ) ``` table_add mac_forward forward 00:00:0a:00:01:02 => 2 ``` Egress ``` [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Action entry is MyIngress.forward - 2, [20:35:20.132] [bmv2] [T] [thread 5210] [4.0] [cxt 0] Action MyIngress.forward [20:35:20.132] [bmv2] [T] [thread 5210] [4.0] [cxt 0] basic.p4(72) Primitive standard_metadata.egress_spec = port [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Pipeline 'ingress': end [20:35:20.132] [bmv2] [D] [thread 5210] [4.0] [cxt 0] Egress port is 2 [20:35:20.133] [bmv2] [D] [thread 5213] [4.0] [cxt 0] Pipeline 'egress': start [20:35:20.133] [bmv2] [D] [thread 5213] [4.0] [cxt 0] Pipeline 'egress': end [20:35:20.133] [bmv2] [D] [thread 5213] [4.0] [cxt 0] Deparser 'deparser': start [20:35:20.133] [bmv2] [D] [thread 5213] [4.0] [cxt 0] Deparsing header 'ethernet' [20:35:20.133] [bmv2] [D] [thread 5213] [4.0] [cxt 0] Deparser 'deparser': end [20:35:20.133] [bmv2] [D] [thread 5215] [4.0] [cxt 0] Transmitting packet of size 98 out of port 2 ``` ping reply (也是差不多的流程)