---
# System prepended metadata

title: Rest API 下rule（ofdpa-ovs）

---

# 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`
![](https://i.imgur.com/M3Eug99.jpg)

4. 打開Rest API網址
http://localhost:8181/onos/v1/docs/
5. 下flow rule
![](https://i.imgur.com/bdIWQ0f.png)

![](https://i.imgur.com/NTkuOLC.png)
```
deviceID:onos GUI上查看switch的設備ID
```
![](https://i.imgur.com/d2EcEGs.png)
```
appID：org.onosproject.rest
```
```
stream：flow rule的程式碼
```
![](https://i.imgur.com/1StE2IA.png)

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：
![](https://i.imgur.com/KKhI2nt.png)
![](https://i.imgur.com/6lRQuok.png)

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是否下成功
![](https://i.imgur.com/pnh2TGO.png)
![](https://i.imgur.com/ZKMXXBm.png)

7. 測試
![](https://i.imgur.com/pppX3vY.png)
8. 刪除fule
![](https://i.imgur.com/ElrB9l4.png)

關閉mininet Ctrl+d

清除mininet中的topology
```
sudo mn -c 
```
onos 重啟
```
ok clean

```


