如何通过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界面
- Open the Dlux interface in your browser:
http://<your-odl-server-ip>:8181/index.html, log in withadmin/admin. - Navigate to Network > Flow Management (the exact menu path might vary slightly by ODL version—look for "Flow Tables" or "OpenFlow Flow Management").
- Select your target OpenFlow switch (the one showing up in your topology) from the dropdown.
- 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.,
1000for 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.,1orLOCALfor 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) orIdle Timeout(delete if no traffic matches for the duration).
- Priority: Higher numbers mean the flow is matched first (e.g.,
- 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:1with your actual switch ID (check Dlux topology to find this). - The
idfield is a custom identifier for the flow—use something descriptive to make deletion/modification easier.
方法1:Dlux Web界面
- Go back to Flow Management and select your switch.
- Find the flow you want to delete in the list.
- 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界面
- In Flow Management, locate the flow you want to edit.
- Click the Edit button to open the flow form.
- Adjust any parameters (priority, match fields, instructions, timeouts) as needed.
- 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




