You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ODL REST API添加流时遇400错误:请求报文格式异常

Fixing ODL REST API 400 "Child 'flow' was not found in parent schema node" Error

Looks like you ran into a common schema mismatch issue when sending flow rules to OpenDayLight's REST API. Let's break down what's going wrong and how to fix it:

Why This Error Happens

The 400 "malformed-message" error tells us that ODL's schema parser can't recognize your request body structure. Specifically, it's expecting your <flow> element to be wrapped inside a parent container (like <flows>) that matches the Yang model it uses for flow management—right now you're sending <flow> directly as the root element, which doesn't align with the API's requirements.

Step-by-Step Fixes

1. Correct the XML Request Structure

Wrap your <flow> element inside a root <flows> tag with the proper ODL namespace. Here's how your corrected XML should look (I've filled in some missing required fields too):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flows xmlns="urn:opendaylight:flow:inventory">
    <flow>
        <priority>2</priority>
        <flow-name>Foo</flow-name>
        <match>
            <ethernet-match>
                <ethernet-type>
                    <type>2048</type>
                </ethernet-type>
            </ethernet-match>
        </match>
        <!-- Required fields you might have missed -->
        <table_id>0</table_id>
        <idle-timeout>0</idle-timeout>
        <hard-timeout>0</hard-timeout>
        <instructions>
            <instruction>
                <order>0</order>
                <apply-actions>
                    <action>
                        <order>0</order>
                        <!-- Example action: send to LOCAL port; adjust to your needs -->
                        <output-action>
                            <output-node-connector>LOCAL</output-node-connector>
                        </output-action>
                    </action>
                </apply-actions>
            </instruction>
        </instructions>
    </flow>
</flows>

2. Verify Your Request URL

Make sure your REST API URL matches the structure expected by ODL. For adding a single flow to a specific node and table, the URL should look something like this:

http://<your-odl-ip>:8181/restconf/config/opendaylight-inventory:nodes/node/<node-id>/table/0/flow/<unique-flow-id>

If you're adding multiple flows at once, adjust the URL to target the parent flows container instead of a single flow entry.

3. Double-Check Request Headers

Ensure you're sending these critical headers in your request:

  • Content-Type: application/xml (tells ODL you're sending XML data)
  • Authorization: Basic YWRtaW46YWRtaW4= (base64-encoded admin/admin credentials, adjust if you changed the default)

Key Notes to Avoid Future Issues

  • Don't skip required fields: ODL requires fields like table_id, idle-timeout, and instructions for valid flow rules—omitting them can trigger similar schema errors.
  • Namespace matters: The xmlns attribute in the <flows> tag is non-negotiable; it tells ODL which Yang model to use for parsing your request.
  • Match your ODL version: If you're using an older ODL release (like Helium) or newer ones (like Neon), the schema structure might have minor differences—cross-reference your version's documentation if you still run into issues.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:24:16