# Rest API 下rule(ofdpa-ovs)
1. 啟動onos
打開Poxy ARP app
2. 設定S2 driver 為 ofdpa-ovs
在config文件的這個目錄下
```
onos-netcfg 127.0.0.1 ofdpa.json
```
3. 用mininet建 topology
`sudo mn --topo=linear,2 --controller=remote,ip=127.0.0.1:6653`

4. 打開Rest API網址
http://localhost:8181/onos/v1/docs/
5. 下flow rule


```
deviceID:onos GUI上查看switch的設備ID
```

```
appID:org.onosproject.rest
```
```
stream:flow rule的程式碼
```

S1 flow rule:
```
{
"priority":40001,
"timeout":0,
"isPermanent":true,
"deviceId":"of:0000000000000001",
"treatment":{
"deferred":[],
"instructions":[
{
"type":"OUTPUT",
"port":"2"
}
]
},
"selector":{
"criteria":[
{
"type":"ETH_TYPE",
"ethType":"0x0800"
},
{
"type":"IPV4_SRC",
"ip":"10.0.0.1/32"
}
]
}
}
```
PS:針對S1的 rule 要下2次哦。 下面是回來的flow rule
```
{
"priority":40001,
"timeout":0,
"isPermanent":true,
"deviceId":"of:0000000000000001",
"treatment":{
"deferred":[],
"instructions":[
{
"type":"OUTPUT",
"port":"1"
}
]
},
"selector":{
"criteria":[
{
"type":"ETH_TYPE",
"ethType":"0x0800"
},
{
"type":"IPV4_DST",
"ip":"10.0.0.1/32"
}
]
}
}
```
S2 下group rule:


group1:
```
{
"type":"INDIRECT",
"appCookie":"0x10001",
"groupId":"100",
"buckets":[
{
"treatment":{
"instructions":[
{
"type":"OUTPUT",
"port":"1"
}
]
}
}
]
}
```
group2:
```
{
"type":"INDIRECT",
"appCookie":"0x10002",
"groupId":"101",
"buckets":[
{
"treatment":{
"instructions":[
{
"type":"OUTPUT",
"port":"2"
}
]
}
}
]
}
```
S2 下flow rule:
```
{
"priority":40001,
"timeout":0,
"tableId": "60",
"isPermanent":true,
"deviceId":"of:0000000000000002",
"treatment":{
"deferred":[],
"instructions":[
{
"type":"GROUP",
"groupId":"100"
}
]
},
"selector":{
"criteria":[
{
"type":"ETH_TYPE",
"ethType":"0x0800"
},
{
"type":"IPV4_SRC",
"ip":"10.0.0.1/32"
}
]
}
}
```
PS:針對S2的 rule 也要下2次哦。 下面是回來的flow rule
```
{
"priority":40001,
"timeout":0,
"tableId": "60",
"isPermanent":true,
"deviceId":"of:0000000000000002",
"treatment":{
"deferred":[],
"instructions":[
{
"type":"GROUP",
"groupId":"101"
}
]
},
"selector":{
"criteria":[
{
"type":"ETH_TYPE",
"ethType":"0x0800"
},
{
"type":"IPV4_DST",
"ip":"10.0.0.1/32"
}
]
}
}
```
在S2中還需對table 63下一條rule
Poxy ARP 在driver是ofdpa-ovs的情況下
這個app
並沒有下把ARP packet送給controller的flow rule
所以需要手動下一條rule去讓ARP送給controller
```
{
"priority":0,
"timeout":0,
"tableId": "63",
"isPermanent":true,
"deviceId":"of:0000000000000002",
"treatment":{
"deferred":[],
"instructions":[
{
"type": "OUTPUT",
"port": "CONTROLLER"
}
]
},
"selector":{
"criteria":[]
}
}
```
6. 查看rule是否下成功


7. 測試

8. 刪除fule

關閉mininet Ctrl+d
清除mininet中的topology
```
sudo mn -c
```
onos 重啟
```
ok clean
```