summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authoroc <oc@yunify.com>2018-11-05 21:10:25 +0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-07 15:29:59 +0900
commit5ab45752ce5a7dbbb16f357f8d405fb272eab512 (patch)
treeb28e1ea84f32593b67da825f44011f50d75d7eff /tools
parent60202fccc41ab35f616e050e13aeb20f82444533 (diff)
api: fix regression that match set option has no default value
The commit 000589f3c "api: Implement UpdatePolicy()" introduced a regression: if match-set-options is not defined in config file, gobgpd starts with error: failed to get policy info: not found... This fix set match-set-options to default when needed.
Diffstat (limited to 'tools')
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py
index 62497f09..01ee9c3b 100644
--- a/tools/pyang_plugins/bgpyang2golang.py
+++ b/tools/pyang_plugins/bgpyang2golang.py
@@ -546,14 +546,6 @@ def emit_enum(prefix, name, stmt, substmts, fd):
print(' %s: %d,' % (enum_name, i), file=fd)
print('}\n', file=fd)
- print('func (v %s) ToInt() int {' % type_name, file=fd)
- print('i, ok := %sToIntMap[v]' % type_name, file=fd)
- print('if !ok {', file=fd)
- print('return -1', file=fd)
- print('}', file=fd)
- print('return i', file=fd)
- print('}', file=fd)
-
print('var IntTo%sMap = map[int]%s {' % (type_name, type_name), file=fd)
for i, sub in enumerate(substmts):
enum_name = '%s_%s' % (const_prefix, convert_const_prefix(sub.arg))
@@ -580,6 +572,19 @@ def emit_enum(prefix, name, stmt, substmts, fd):
print(' return v', file=fd)
print('}', file=fd)
+ print('func (v %s) ToInt() int {' % type_name, file=fd)
+ print('_v := v.DefaultAsNeeded()')
+ print('i, ok := %sToIntMap[_v]' % type_name, file=fd)
+
+ else:
+ print('func (v %s) ToInt() int {' % type_name, file=fd)
+ print('i, ok := %sToIntMap[v]' % type_name, file=fd)
+ print('if !ok {', file=fd)
+ print('return -1', file=fd)
+ print('}', file=fd)
+ print('return i', file=fd)
+ print('}', file=fd)
+
def emit_typedef(ctx, mod, fd):
prefix = mod.i_prefix