zoukankan      html  css  js  c++  java
  • 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"
                  }
                }
              }
            }
          ]
        }
      }
    }
    
  • 相关阅读:
    家庭记账本APP开发准备(二)
    使用花生壳5做内网穿透
    课堂练习之可视化的强化版
    第五周总结
    课堂练习之疫情可视化
    第四周总结
    第三周总结
    第二周总结
    课堂练习之最大子数组
    软工第二学期开课博客
  • 原文地址:https://www.cnblogs.com/goldsunshine/p/14486056.html
Copyright © 2011-2022 走看看