Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yang: serialization and config load broken for list with choice node #1424

Open
alexandergall opened this issue Apr 5, 2019 · 0 comments
Open
Labels

Comments

@alexandergall
Copy link
Contributor

Schema snabb-pf-v1.yang

module snabb-pf-v1 {
  namespace snabb:pf-v1;
  prefix pf-v1;

  list foo {
    key "name";
    leaf name {
      type string;
    }
    choice bar {
      mandatory true;
      case case1 {
        leaf case1 {
          type string;
        }
      }
      case case2 {
        leaf case2 {
          type string;
        }
      }
    }
  }
}

Data pf-v1.cfg

foo {
  name "bar";
  case1 "baz";
}

setup.lua

local basic_apps = require("apps.basic.basic_apps")
local app_graph = require('core.config')

return function (conf)
   local graph = app_graph.new()
   app_graph.app(graph, "source", basic_apps.Source)
   app_graph.app(graph, "sink", basic_apps.Sink)
   app_graph.link(graph, "source.output -> sink.input")
   return {foo=graph}
end

schema.lua

local yang = require("lib.yang.yang")
local pf_schema = yang.add_schema_file("snabb-pf-v1.yang")
local config = yang.load_configuration("pf-v1.cfg", {  schema_name = "snabb-pf-v1" })

Writing the compiled configuration fails

$ sudo ./snabb snsh schema.lua
pf-v1.cfg: loading source configuration
pf-v1.cfg: error saving compiled configuration pf-v1.cfg.o: core/main.lua:26: assertion failed!

The error is hidden by a pcall. The actual failure occurs in

return assert(handlers[production.type])(production)
because there is no handler for a production of type choice.

There is another bug which may or may not be related. Run ptree with

$ sudo ./snabb ptree --name foo snabb-pf-v1.yang setup.lua pf-v1.cfg
pf-v1.cfg: loading source configuration
Warning: No assignable CPUs declared; leaving data-plane process without assigned CPU.
No CPUs available; not binding to any NUMA node.

Re-loading the same configuration fails

$ sudo ./snabb config load 7082 pf-v1.cfg
pf-v1.cfg: loading source configuration
pf-v1.cfg: error saving compiled configuration pf-v1.cfg.o: core/main.lua:26: assertion failed!
lib/yang/data.lua:514: missing choice value: bar

A workaround is to wrap the choice node in a container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant