Open vSwitch系列之十 調用北向接口下發流表


Open vSwitch系列之一 Open vSwitch誕生
Open vSwitch系列之二 安裝指定版本ovs
Open vSwitch系列之三 ovs-vsctl命令使用
Open vSwitch系列之四 ovs-ofctl命令使用
Open vSwitch系列之五 網橋特性功能配置
Open vSwitch系列之六 vlan隔離
Open vSwitch系列之七 meter表限速
Open vSwitch系列之八 vxlan隧道
Open vSwitch系列之九 Group表
Open vSwitch系列之十 調用北向接口下發流表
OpenvSwitch系列之十一 ovs-dpdk

postman介紹

在開發中,前端和后端是分開開發的,當后端開發完成之后會測試接口。Postman就是一個后端接口的測試工具,通過postman可以發送GET、POST、DELETE等請求。通過Postman可以調用控制器的北向接口,下發流表到交換機

GET請求
Get請求需要注意兩點,第一請求方法是get,第二是URL

POST請求
POST請求需要注意三點:第一 請求方式是POST,第二URL,第三請求的body體。

Postman下發流表的標准格式

postman下發一條流表需要准備4個部分,分別是:

  1. 動作
  2. URL
  3. 身份認證
  4. body體

動作:PUT
URL:替換自己控制器的ip和交換機switch_id,還要注意flow_id即url最后一個參數,該參數要和body體中一致。
控制器ip:8181/restconf/config/opendaylight-inventory:nodes/node/你的交換機switch_id/flow-node-inventory:table/0/flow/flow6
認證信息:Basic Auth, username: admin password:admin

body體:格式為 raw --> Json。body體里的內容就是流表的信息。

body體具體內容:
body體就是一個流表的具體內容,分為三大塊:流表元數據、匹配、動作。
元數據:流表名字,id,優先級等
匹配:流表匹配規則,如經典匹配十二元組
動作:標准動作轉發和丟棄

物理端口匹配

匹配進端口為1,動作是轉發到222端口

ovs-ofctl add-flow br0 in_port=1,action=output:222
控制器ip地址:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/flow-node-inventory:table/0/flow/demo_14
{
  "flow": [
    {
      "id": "demo_14",
      "flow-name": "demo_14",
      "table_id": 0,
      "match": {
        "in-port": "1",
        "ethernet-match": {
          
        }
      },
      "instructions": {
        "instruction": [
          {
            "order": "0",
            "apply-actions": {
              "action": [
                {
                  "order": "0",
                  "output-action": {
                    "output-node-connector": "222"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

mac地址匹配

匹配源mac地址:78:45:c4:1c:ba:b9,目的mac地址:00:50:56:c0:00:08,動作是丟棄

ovs-ofctl add-flow br0 dl_src=78:45:c4:1c:ba:b9,dl_dst=00:50:56:c0:00:08,aciton=drop
控制器ip地址:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/flow-node-inventory:table/0/flow/demo_four
{
  "flow": [
    {
      "id": "demo_four",
      "flow-name": "demo_four",
      "table_id": 0,
      "match": {
        "ethernet-match": {
          "ethernet-source": {
            "mask": "ff:ff:ff:ff:ff:ff",
            "address": "78:45:c4:1c:ba:b9"
          },
          "ethernet-destination": {
            "mask": "ff:ff:ff:ff:ff:ff",
            "address": "00:50:56:c0:00:08"
          }
        }
      },
      "instructions": {
        "instruction": [
          {
            "order": "0",
            "apply-actions": {
              "action": [
                {
                  "order": "0",
                  "drop-action": {
                    
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

ip地址匹配

匹配源ip地址為30.0.0.1/32,目的ip為30.0.0.2/32的流表,動作是轉發到222端口

ovs-ofctl add-flow br0 ip,nw_src=30.0.0.1/32,nw_dst=30.0.0.2/32,aciton=output:222
控制器ip地址:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/flow-node-inventory:table/0/flow/demo_14
{
  "flow": [
    {
      "id": "demo_14",
      "flow-name": "demo_14",
      "table_id": 0,
      "match": {
        "ethernet-match": {
          "ethernet-type": {
            "type": "0x0800"
          }
        },
        "ipv4-source": "30.0.0.1/32",
        "ipv4-destination": "30.0.0.2/32"
      },
      "instructions": {
        "instruction": [
          {
            "order": "0",
            "apply-actions": {
              "action": [
                {
                  "order": "0",
                  "output-action": {
                    "output-node-connector": "222"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

udp端口匹配

匹配 源端口為112,目的端口為2321的UDP數據包,動作是轉發到222端口。

ovs-ofctl add-flow br0 udp,udp_src=112,udp_dst=2321,action=output:222
控制器ip地址:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/flow-node-inventory:table/0/flow/demo_13
{
  "flow": [
    {
      "id": "demo_13",
      "flow-name": "demo_13",
      "table_id": 0,
      "match": {
        "ethernet-match": {
          "ethernet-type": {
            "type": "0x0800"
          }
        },
        "ip-match": {
          "ip-protocol": 17
        },
        "udp-destination-port": "2321",
        "udp-source-port": "112"
      },
      "instructions": {
        "instruction": [
          {
            "order": "0",
            "apply-actions": {
              "action": [
                {
                  "order": "0",
                  "output-action": {
                    "output-node-connector": "222"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

tcp端口匹配

匹配源端口是888,目的端口是999的TCP流量,動作是轉發到222端口

ovs-ofctl add-flow br0 tcp,tcp_src=888,tcp_dst=999,action=output:222
控制器ip地址:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/flow-node-inventory:table/0/flow/demo_14
{
  "flow": [
    {
      "id": "demo_14",
      "flow-name": "demo_14",
      "table_id": 0,
      "match": {
        "ethernet-match": {
          "ethernet-type": {
            "type": "0x0800"
          }
        },
        "ip-match": {
          "ip-protocol": 6
        },
        "tcp-destination-port": "999",
        "tcp-source-port": "888"
      },
      "instructions": {
        "instruction": [
          {
            "order": "0",
            "apply-actions": {
              "action": [
                {
                  "order": "0",
                  "output-action": {
                    "output-node-connector": "222"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

meter表

meter表,限速為10k,超過限制的流量丟棄。

ovs-ofctl add-meter s1 meter=1,kbps,band=type=drop,rate=10 -O OpenFlow13
控制器ip:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/meter/1
{
  "meter": {

    "meter-id": "1",
    "meter-name": "guestMeter",
    "flags": "meter-kbps",

    "meter-band-headers": {
      "meter-band-header": {
        "band-id": "0",
        "meter-band-types": { "flags": "ofpmbt-drop" },
        "drop-burst-size": "0",
        "drop-rate": "10"
      }
    }
  }
}

匹配進端口為1的流量,經過meter表限速,然后轉發到2端口

ovs-ofctl add-flow s1 priority=200,in_port=1,action=meter:1,output:2 -O OpenFlow13
控制器ip地址:8181/restconf/config/opendaylight-inventory:nodes/node/交換機switch_id/flow-node-inventory:table/0/flow/flow1
{
  "flow": {
  "id": "flow1",   
  "table_id": "0",
  "priority": "120",
  "name":"flow_name"


  "match": {
    "in-port":"1"
    },
   

    "instructions": {
      "instruction": [
        {
          "order": "0",
          "meter": { "meter-id": "1" }
        },
        {
          "order": "1",
          "apply-actions": {
            "action": {
              "order": "1",
              "output-action": {
                "output-node-connector": "2"
              }
            }
          }
        }
      ]
    }
  }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM