You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过OpenDaylight增删改流表?SDN环境流控操作问询

Hey there! Since you've already got your SDN environment up and running with Open vSwitch (OVS) and OpenDaylight (ODL), and you can ping between your virtual/physical hosts, adding, deleting, and modifying flow tables should be a smooth process. Let's walk through the two main ways to do this—using the Dlux web interface (since you mentioned you're using Dlux for topology viewing) and the REST API for scriptable operations.

准备工作

First, make sure your ODL instance has the necessary features installed to manage flow tables. Log into the ODL Karaf console (default port 8101, username/password admin/admin) and run:

feature:install odl-openflowplugin-flow-services-ui odl-restconf

This ensures the flow management UI and REST API endpoints are enabled.

添加流表

方法1:使用Dlux Web界面

  1. Open the Dlux interface in your browser: http://<your-odl-server-ip>:8181/index.html, log in with admin/admin.
  2. Navigate to Network > Flow Management (the exact menu path might vary slightly by ODL version—look for "Flow Tables" or "OpenFlow Flow Management").
  3. Select your target OpenFlow switch (the one showing up in your topology) from the dropdown.
  4. Click the Add Flow button to open the flow creation form, then fill in the key parameters:
    • Priority: Higher numbers mean the flow is matched first (e.g., 1000 for high-priority rules).
    • Match Fields: Define what traffic this flow targets—like source/destination IP, Ethernet type, protocol (ICMP/TCP/UDP), or port numbers.
    • Instructions: Choose what to do with matched traffic—common options include:
      • Output: Forward to a specific switch port (e.g., 1 or LOCAL for the switch itself).
      • Drop: Discard the traffic entirely.
      • Modify fields (e.g., rewrite source IP).
    • Timeout Settings (optional): Set Hard Timeout (auto-delete after fixed time) or Idle Timeout (delete if no traffic matches for the duration).
  5. Click Submit to save the flow. You can test it immediately—for example, if you added a drop rule for a specific IP, pinging that IP should now fail.

方法2:使用REST API (curl命令)

If you prefer scriptable operations, use ODL's RESTCONF API with curl. Here's an example of adding a flow that drops all ICMP traffic to 192.168.1.100:

curl -u admin:admin -X POST -H "Content-Type: application/json" -d '{
    "flow": [
        {
            "id": "drop-icmp-to-192.168.1.100",
            "table_id": 0,
            "priority": 1000,
            "match": {
                "ipv4-destination": "192.168.1.100/32",
                "ethernet-type": 2048,
                "ip-protocol": 1
            },
            "instructions": {
                "instruction": [
                    {
                        "order": 0,
                        "apply-actions": {
                            "action": [
                                {
                                    "order": 0,
                                    "drop-action": {}
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}' http://<your-odl-server-ip>:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/drop-icmp-to-192.168.1.100
  • Replace openflow:1 with your actual switch ID (check Dlux topology to find this).
  • The id field is a custom identifier for the flow—use something descriptive to make deletion/modification easier.
删除流表

方法1:Dlux Web界面

  1. Go back to Flow Management and select your switch.
  2. Find the flow you want to delete in the list.
  3. Click the Delete button next to it, confirm the action, and the flow will be removed immediately.

方法2:REST API

Use a DELETE request targeting the exact flow path you used to create it:

curl -u admin:admin -X DELETE http://<your-odl-server-ip>:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/drop-icmp-to-192.168.1.100
修改流表

方法1:Dlux Web界面

  1. In Flow Management, locate the flow you want to edit.
  2. Click the Edit button to open the flow form.
  3. Adjust any parameters (priority, match fields, instructions, timeouts) as needed.
  4. Click Submit to save the changes.

方法2:REST API

Use a PUT request to overwrite the existing flow with your updated configuration. For example, changing the drop rule above to forward traffic to port 2:

curl -u admin:admin -X PUT -H "Content-Type: application/json" -d '{
    "flow": [
        {
            "id": "drop-icmp-to-192.168.1.100",
            "table_id": 0,
            "priority": 1000,
            "match": {
                "ipv4-destination": "192.168.1.100/32",
                "ethernet-type": 2048,
                "ip-protocol": 1
            },
            "instructions": {
                "instruction": [
                    {
                        "order": 0,
                        "apply-actions": {
                            "action": [
                                {
                                    "order": 0,
                                    "output-action": {
                                        "output-node-connector": "2"
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}' http://<your-odl-server-ip>:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/drop-icmp-to-192.168.1.100
验证流表生效

To confirm your flows are applied correctly, log into your OVS host and run:

ovs-ofctl dump-flows <your-ovs-bridge-name>

This will show all active flows on the bridge—you should see the ones you added/modified via ODL listed here.

内容的提问来源于stack exchange,提问作者sweetpea

火山引擎 最新活动