diff options
Diffstat (limited to 'tools/pyang_plugins')
-rw-r--r-- | tools/pyang_plugins/README.rst | 1 | ||||
-rw-r--r-- | tools/pyang_plugins/bgpyang2golang.py | 36 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 343 |
3 files changed, 377 insertions, 3 deletions
diff --git a/tools/pyang_plugins/README.rst b/tools/pyang_plugins/README.rst index dc4e2a0e..eaf3f89e 100644 --- a/tools/pyang_plugins/README.rst +++ b/tools/pyang_plugins/README.rst @@ -22,4 +22,5 @@ How to use -p $YANG_DIR/experimental/openconfig/policy \ -f golang $YANG_DIR/experimental/openconfig/bgp/bgp.yang \ --augment $YANG_DIR/experimental/openconfig/bgp/bgp-policy.yang \ + --augment $GOBGP_PATH/tools/pyang_plugins/gobgp.yang \ | gofmt > $GOBGP_PATH/config/bgp_configs.go diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index 569cc9bf..8ba5ef41 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -52,7 +52,7 @@ class GolangPlugin(plugin.PyangPlugin): def add_opts(self, optparser): optlist = [ optparse.make_option("--augment", - dest="augment", + dest="augment", action="append", help="Yang file which has augment statements"), ] g = optparser.add_option_group("GolangPlugin specific options") @@ -75,7 +75,7 @@ class GolangPlugin(plugin.PyangPlugin): # load augment module if ctx.opts.augment: aug_mod_path = ctx.opts.augment - for p in aug_mod_path.split(","): + for p in aug_mod_path: with open(p) as fd: try: text = fd.read() @@ -151,6 +151,10 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix): print >> o, '//struct for container %s:%s' % (prefix, yang_statement.arg) print >> o, 'type %s struct {' % convert_to_golang(struct_name) for child in yang_statement.i_children: + + if child.path in _path_exclude: + continue + container_or_list_name = child.uniq_name val_name_go = convert_to_golang(child.arg) child_prefix = get_orig_prefix(child.i_orig_module) @@ -254,9 +258,21 @@ def get_orig_prefix(module): return module.i_prefix +def get_path(c): + path = '' + if c.parent is not None: + p = '' + if hasattr(c, 'i_module'): + mod = c.i_module + prefix = mod.search_one('prefix') + + p = prefix.arg + ":" if prefix else '' + path = get_path(c.parent) + "/" + p + c.arg + return path + + def visit_children(ctx, module, children): for c in children: - prefix = '' if is_case(c): prefix = get_orig_prefix(c.parent.i_orig_module) @@ -298,6 +314,8 @@ def visit_children(ctx, module, children): ctx.golang_struct_names[prefix+':'+c.uniq_name] = c ctx.golang_struct_def.append(c) + c.path = get_path(c) + # print(c.path) if hasattr(c, 'i_children'): visit_children(ctx, module, c.i_children) @@ -325,6 +343,8 @@ def visit_typedef(ctx, module): child_map = {} for stmts in module.substmts: if stmts.keyword == 'typedef': + stmts.path = get_path(stmts) + # print(stmts.path) name = stmts.arg stmts.golang_name = convert_to_golang(name) if stmts.golang_name == 'PeerType': @@ -375,6 +395,9 @@ def emit_typedef(ctx, module): t_map = ctx.golang_typedef_map[prefix] for name, stmt in t_map.items(): + if stmt.path in _typedef_exclude: + continue + # skip identityref type because currently skip identity if get_type_spec(stmt) == 'identityref': continue @@ -528,6 +551,13 @@ _module_excluded = ["ietf-inet-types", "ietf-yang-types", ] +_path_exclude = ["/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:transport/bgp:config/bgp:local-address", + "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:transport/bgp:state/bgp:local-address", + "/rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/rpol:neighbor-set/rpol:neighbor", + "/rpol:routing-policy/rpol:defined-sets/bgp-pol:bgp-defined-sets/bgp-pol:community-sets/bgp-pol:community-set/bgp-pol:community-member", + "/rpol:routing-policy/rpol:defined-sets/bgp-pol:bgp-defined-sets/bgp-pol:ext-community-sets/bgp-pol:ext-community-set/bgp-pol:ext-community-member"] + +_typedef_exclude =["/bgp-types:bgp-origin-attr-type"] def generate_header(ctx): print _COPYRIGHT_NOTICE diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang new file mode 100644 index 00000000..c3c4d800 --- /dev/null +++ b/tools/pyang_plugins/gobgp.yang @@ -0,0 +1,343 @@ +module bgp-gobgp { + + yang-version "1"; + + // namespace + namespace "https://github.com/osrg/gobgp"; + + prefix "gobgp"; + + // import some basic types + import bgp { prefix bgp; } + import routing-policy {prefix rpol; } + import bgp-policy {prefix bgp-pol; } + import ietf-inet-types { prefix inet; } + + // meta + organization + "GoBGP"; + + contact + "GoBGP http://osrg.github.io/gobgp/"; + + description + "This module contains definitions for GoBGP-specific configuration. + It augments bgp modules with GoBGP-specific options."; + + revision "2015-08-10" { + description + "Updated model to augment base bgp modules"; + reference "TBD"; + } + + typedef bgp-origin-attr-type { + type enumeration { + enum IGP { + value 0; + description "Origin of the NLRI is internal"; + } + enum EGP { + value 1; + description "Origin of the NLRI is EGP"; + } + enum INCOMPLETE { + value 2; + description "Origin of the NLRI is neither IGP or EGP"; + } + } + } + + grouping gobgp-message-counter { + description + "Counters for all BGPMessage types"; + + leaf OPEN { + type uint64; + description + "Number of BGP open messages announcing, withdrawing + or modifying paths exchanged."; + } + + leaf REFRESH { + type uint64; + description + "Number of BGP Route-Refresh messages indicating an + error condition has occurred exchanged."; + } + + leaf KEEPALIVE { + type uint64; + description + "Number of BGP Keepalive messages indicating an + error condition has occurred exchanged."; + } + + leaf DYNAMIC-CAP { + type uint64; + description + "Number of BGP dynamic-cap messages indicating an + error condition has occurred exchanged."; + } + + leaf DISCARDED { + type uint64; + description + "Number of discarded messages indicating an + error condition has occurred exchanged."; + } + + leaf TOTAL { + type uint64; + description + "Number of total messages indicating an + error condition has occurred exchanged."; + } + } + + + grouping gobgp-timer { + description "additional timer"; + + leaf idle-hold-time-after-reset { + type decimal64 { + fraction-digits 2; + } + default 30; + description + "Time interval in seconds that a BGP session will be + in idle state after neighbor reset operation."; + } + } + + + grouping gobgp-neighbor-timer { + description "additional timer"; + + leaf downtime { + type yang:timeticks; + description + "This timer determines the amount of time since the + BGP last transitioned out of the Established state"; + } + + leaf update-recv-time { + type int64; + description + "The number of seconds elasped since January 1, 1970 UTC + last time the BGP session received an UPDATE message"; + } + } + + + grouping gobgp-in-policy { + description + "additional policy"; + + leaf-list in-policy { + type leafref { + path "/rpol:routing-policy/rpol:policy-definitions/" + + "rpol:policy-definition/rpol:name"; + //require-instance true; + } + description + "list of policy names in sequence to be applied on + sending a routing update in the current context, e.g., + for the current other route server clients."; + } + + leaf default-in-policy { + type rpol:default-policy-type; + default REJECT-ROUTE; + description + "explicitly set a default policy if no policy definition + in the in-policy chain is satisfied."; + } + } + + grouping gobgp-route-server-config { + description + "Configuration parameter specifying whether + the neighbor is route server client or not."; + + leaf route-server-client { + type boolean; + default "false"; + description + "Configure the neighbor as a route server client."; + } + } + + grouping gobgp-route-server-config-set { + description + "set of configurations for route server client."; + + container route-server { + description + "Configure the local router as a route server"; + + container config { + description + "Configuration parameters relating to route server + client(s) used for the BGP neighbor"; + uses gobgp-route-server-config; + } + container state { + config false; + description + "State information relating to route server + client(s) used for the BGP neighbor"; + uses gobgp-route-server-config; + } + } + } + + + // augment statements + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:state/bgp:messages/bgp:sent" { + description "additional counters"; + uses gobgp-message-counter; + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:state/bgp:messages/bgp:received" { + description "additional counters"; + uses gobgp-message-counter; + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:state" { + description "additional state elements"; + + leaf admin-down { + type boolean; + description + "The state of administrative operation. If the state is true, it indicates the neighbor is disabled by the administrator"; + } + + leaf established-count { + type uint32; + description + "The number of how many the peer became established state"; + } + + leaf flops { + type uint32; + description + "The number of flip-flops"; + } + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:timers/bgp:config" { + description "additional timer"; + uses gobgp-timer; + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:timers/bgp:state" { + description "additional timers"; + uses gobgp-timer; + uses gobgp-neighbor-timer; + } + + augment "/bgp:bgp/bgp:peer-groups/bgp:peer-group" { + description "route server configuration for peer-group"; + uses gobgp-route-server-config-set; + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor" { + description "route server configuration for neighbor"; + uses gobgp-route-server-config-set; + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:transport/bgp:config" { + description "neighbor's local ip address, whose type is inet:ip-address"; + leaf local-address { + type inet:ip-address; + } + } + + augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:transport/bgp:state" { + description "neighbor's local ip address, whose type is inet:ip-address"; + leaf local-address { + type inet:ip-address; + } + } + + augment "/bgp:bgp/bgp:global/bgp:apply-policy/bgp:config" { + description "addtional policy"; + uses gobgp-in-policy; + + } + + augment "/bgp:bgp/bgp:global/bgp:apply-policy/bgp:state" { + description "additional policy"; + uses gobgp-in-policy; + + } + + augment "/rpol:routing-policy/rpol:policy-definitions/" + + "rpol:policy-definition/rpol:statements/rpol:statement/" + + "rpol:actions/bgp-pol:bgp-actions/bgp-pol:set-as-path-prepend" { + description "as number used for aspath prepend"; + + leaf as { + type union { + type inet:as-number; + type string { + pattern "last-as"; + } + } + description + "autonomous system number or 'last-as' which means + the leftmost as number in the AS-path to be prepended"; + } + } + + augment "/rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/rpol:neighbor-set" { + description "alternative for the existing neighbor element"; + + list neighbor-info { + leaf address { + type inet:ip-address; + description + "neighbor ip address"; + } + } + } + + augment "/rpol:routing-policy/rpol:defined-sets/" + + "bgp-pol:bgp-defined-sets/bgp-pol:community-sets/bgp-pol:community-set" { + description "alternative for the existing community-member"; + + list community { + leaf community { + type string; + description + "community set member"; + } + } + } + + augment "/rpol:routing-policy/rpol:defined-sets/" + + "bgp-pol:bgp-defined-sets/bgp-pol:ext-community-sets/bgp-pol:ext-community-set" { + description "alternative for the existing ext-community-member"; + + list ext-community { + leaf ext-community { + type string; + description + "extended community set member"; + } + } + } + + augment "/rpol:routing-policy/rpol:defined-sets/" + + "bgp-pol:bgp-defined-sets/bgp-pol:as-path-sets/bgp-pol:as-path-set" { + description "alternative for the existing as-path-set-member"; + + list as-path { + leaf as-path { + type string; + description + "AS path expression"; + } + } + } +} |