> For the complete documentation index, see [llms.txt](https://openwrt-nctu.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openwrt-nctu.gitbook.io/project/experiment-sdn/pica8-setting.md).

# pica8 基本設定

## 網路架構與 pica8 設定

在我們實驗架設的環境中，把 WiFi AP 連上 pica8 Switch 來提供對外網路連線，架構大致如下圖所示:

![](/files/-LPdbS-dlKU2g2Q7uXgO)

以下是 pica8 的網卡設定，可以看到有兩張網卡: eth0 和 eth1 分別對應對外網路 (用來 SSH 進入 pica8) 以及對內網路 (用來 SSH 其他 WiFi AP)

```
PICOS-OVS$ifconfig
br0       Link encap:Ethernet  HWaddr 08:9e:01:61:65:3f
          inet6 addr: fe80::a9e:1ff:fe61:653f/64 Scope:Link
          UP BROADCAST RUNNING PROMISC  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:0 (0.0 B)  TX bytes:368 (368.0 B)

eth0      Link encap:Ethernet  HWaddr 08:9e:01:61:65:40
          inet addr:140.113.xxx.xxx  Bcast:140.113.xxx.255  Mask:255.255.255.0
          inet6 addr: fe80::a9e:1ff:fe61:6540/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16764 errors:0 dropped:0 overruns:0 frame:0
          TX packets:663 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1482645 (1.4 MiB)  TX bytes:106647 (104.1 KiB)
          Base address:0xa000

eth1      Link encap:Ethernet  HWaddr 08:9e:01:61:65:41
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a9e:1ff:fe61:6541/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2815 (2.7 KiB)  TX bytes:4980 (4.8 KiB)
          Base address:0xe000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:26 errors:0 dropped:0 overruns:0 frame:0
          TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2728 (2.6 KiB)  TX bytes:2728 (2.6 KiB)

```

## pica8 flow table 設定 (bridge mode)

為了提供 WiFi AP 連網功能，我們要先設定好 pica8 上面 port 的對應關係，一開始，我們先從簡單的 bridge 模式開始，也就是，把所有 WiFi AP 的封包都導到 port 1 (連接至一個路由器)。

此模式並沒有用到 SDN (software-defined network) 的功能，只是純粹的把網路連載一起，所以不牽涉到 SDN controller 的設定，WiFi AP 也不需要安裝 SDN 的 client (例如: OpenFlow)。

```
ovs-ofctl add-flow br0 "in_port=2,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=3,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=4,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=5,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=6,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=7,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=8,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=9,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=10,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=11,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=12,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=13,priority=1,actions=output:1";
ovs-ofctl add-flow br0 "in_port=14,priority=1,actions=output:1";
```

同時，對於從 port 1 來的資料，也都轉傳至每一個 WiFi AP。

```
ovs-ofctl add-flow br0 "in_port=1,priority=1,actions=output:2, output:3, output:4, output:5, output:6, output:7, output:8, output:9, output:10, output:11, output:12, output:13, output:14"
```

此指令是刪除所有的 flow 規則。 &#x20;

```
ovs-ofctl del-flows br0
```

&#x20; 當然，我們也可以透過指令來查詢目前 flow 的設定。

```
PICOS-OVS$ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
 flow_id=32, cookie=0x0, duration=28.464s, table=0, n_packets=n/a, n_bytes=0, idle_age=28, priority=1,in_port=5 actions=output:1
 flow_id=34, cookie=0x0, duration=28.419s, table=0, n_packets=n/a, n_bytes=402, idle_age=5, priority=1,in_port=7 actions=output:1
 flow_id=42, cookie=0x0, duration=23.149s, table=0, n_packets=n/a, n_bytes=1392, idle_age=4, priority=1,in_port=1 actions=output:2,output:3,output:4,output:5,output:6,output:7,output:8,output:9,output:10,output:11,output:12,output:13,output:14
 flow_id=37, cookie=0x0, duration=28.372s, table=0, n_packets=n/a, n_bytes=0, idle_age=28, priority=1,in_port=10 actions=output:1
 flow_id=31, cookie=0x0, duration=28.488s, table=0, n_packets=n/a, n_bytes=344, idle_age=1, priority=1,in_port=4 actions=output:1
 flow_id=38, cookie=0x0, duration=28.357s, table=0, n_packets=n/a, n_bytes=274, idle_age=13, priority=1,in_port=11 actions=output:1
 flow_id=33, cookie=0x0, duration=28.440s, table=0, n_packets=n/a, n_bytes=274, idle_age=13, priority=1,in_port=6 actions=output:1
 flow_id=29, cookie=0x0, duration=28.524s, table=0, n_packets=n/a, n_bytes=402, idle_age=5, priority=1,in_port=2 actions=output:1
 flow_id=35, cookie=0x0, duration=28.402s, table=0, n_packets=n/a, n_bytes=0, idle_age=28, priority=1,in_port=8 actions=output:1
 flow_id=39, cookie=0x0, duration=28.342s, table=0, n_packets=n/a, n_bytes=274, idle_age=10, priority=1,in_port=12 actions=output:1
 flow_id=36, cookie=0x0, duration=28.387s, table=0, n_packets=n/a, n_bytes=344, idle_age=1, priority=1,in_port=9 actions=output:1
 flow_id=41, cookie=0x0, duration=28.310s, table=0, n_packets=n/a, n_bytes=274, idle_age=13, priority=1,in_port=14 actions=output:1
 flow_id=40, cookie=0x0, duration=28.326s, table=0, n_packets=n/a, n_bytes=0, idle_age=28, priority=1,in_port=13 actions=output:1
 flow_id=30, cookie=0x0, duration=28.510s, table=0, n_packets=n/a, n_bytes=1008, idle_age=4, priority=1,in_port=3 actions=output:1
```
