summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-02 02:13:30 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-01-09 05:17:57 -0800
commitcc8d0fd748f83d774ec59e680586421cd9d9a6d2 (patch)
tree393a564c3d6389084f098732528b3b4206cd60de /tools
parent0c1c373e498db1023e4f307f362598a096e36df0 (diff)
config: refactor config structure
- change config variable name to chaincase from camelcase - remove unnecessary wrapper structs which only contain one slice field Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'tools')
-rw-r--r--tools/config/example_toml.go118
-rw-r--r--tools/pyang_plugins/README.rst2
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py25
-rw-r--r--tools/route-server/quagga-rsconfig.go2
4 files changed, 62 insertions, 85 deletions
diff --git a/tools/config/example_toml.go b/tools/config/example_toml.go
index 50abc3cb..01999f21 100644
--- a/tools/config/example_toml.go
+++ b/tools/config/example_toml.go
@@ -15,44 +15,39 @@ func main() {
RouterId: "10.0.0.1",
},
},
- Neighbors: config.Neighbors{
- NeighborList: []config.Neighbor{
- config.Neighbor{
- Config: config.NeighborConfig{
- PeerAs: 12333,
- AuthPassword: "apple",
- NeighborAddress: "192.168.177.33",
- },
- AfiSafis: config.AfiSafis{
-
- AfiSafiList: []config.AfiSafi{
- config.AfiSafi{AfiSafiName: "ipv4-unicast"},
- config.AfiSafi{AfiSafiName: "ipv6-unicast"},
- },
- },
- ApplyPolicy: config.ApplyPolicy{
+ Neighbors: []config.Neighbor{
+ config.Neighbor{
+ Config: config.NeighborConfig{
+ PeerAs: 12333,
+ AuthPassword: "apple",
+ NeighborAddress: "192.168.177.33",
+ },
+ AfiSafis: []config.AfiSafi{
+ config.AfiSafi{AfiSafiName: "ipv4-unicast"},
+ config.AfiSafi{AfiSafiName: "ipv6-unicast"},
+ },
+ ApplyPolicy: config.ApplyPolicy{
- Config: config.ApplyPolicyConfig{
- ImportPolicy: []string{"pd1"},
- DefaultImportPolicy: config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE,
- },
+ Config: config.ApplyPolicyConfig{
+ ImportPolicyList: []string{"pd1"},
+ DefaultImportPolicy: config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE,
},
},
+ },
- config.Neighbor{
- Config: config.NeighborConfig{
- PeerAs: 12334,
- AuthPassword: "orange",
- NeighborAddress: "192.168.177.32",
- },
+ config.Neighbor{
+ Config: config.NeighborConfig{
+ PeerAs: 12334,
+ AuthPassword: "orange",
+ NeighborAddress: "192.168.177.32",
},
+ },
- config.Neighbor{
- Config: config.NeighborConfig{
- PeerAs: 12335,
- AuthPassword: "grape",
- NeighborAddress: "192.168.177.34",
- },
+ config.Neighbor{
+ Config: config.NeighborConfig{
+ PeerAs: 12335,
+ AuthPassword: "grape",
+ NeighborAddress: "192.168.177.34",
},
},
},
@@ -84,59 +79,34 @@ func policy() config.RoutingPolicy {
}
ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: "10.0.0.2",
- }},
+ NeighborSetName: "ns1",
+ NeighborInfoList: []string{"10.0.0.2"},
}
cs := config.CommunitySet{
CommunitySetName: "community1",
- CommunityList: []config.Community{
- config.Community{Community: "65100:10"},
- },
+ CommunityList: []string{"65100:10"},
}
ecs := config.ExtCommunitySet{
ExtCommunitySetName: "ecommunity1",
- ExtCommunityList: []config.ExtCommunity{
- config.ExtCommunity{ExtCommunity: "RT:65001:200"},
- },
+ ExtCommunityList: []string{"RT:65001:200"},
}
as := config.AsPathSet{
AsPathSetName: "aspath1",
- AsPathList: []config.AsPath{
- config.AsPath{AsPath: "^65100"},
- },
+ AsPathList: []string{"^65100"},
}
bds := config.BgpDefinedSets{
-
- CommunitySets: config.CommunitySets{
- CommunitySetList: []config.CommunitySet{cs},
- },
-
- ExtCommunitySets: config.ExtCommunitySets{
- ExtCommunitySetList: []config.ExtCommunitySet{ecs},
- },
-
- AsPathSets: config.AsPathSets{
- AsPathSetList: []config.AsPathSet{as},
- },
+ CommunitySets: []config.CommunitySet{cs},
+ ExtCommunitySets: []config.ExtCommunitySet{ecs},
+ AsPathSets: []config.AsPathSet{as},
}
ds := config.DefinedSets{
-
- PrefixSets: config.PrefixSets{
- PrefixSetList: []config.PrefixSet{ps},
- },
-
- NeighborSets: config.NeighborSets{
- NeighborSetList: []config.NeighborSet{ns},
- },
-
+ PrefixSets: []config.PrefixSet{ps},
+ NeighborSets: []config.NeighborSet{ns},
BgpDefinedSets: bds,
}
@@ -185,7 +155,7 @@ func policy() config.RoutingPolicy {
BgpActions: config.BgpActions{
SetCommunity: config.SetCommunity{
SetCommunityMethod: config.SetCommunityMethod{
- Communities: []string{"65100:20"},
+ CommunitiesList: []string{"65100:20"},
},
Options: "ADD",
},
@@ -195,17 +165,13 @@ func policy() config.RoutingPolicy {
}
pd := config.PolicyDefinition{
- Name: "pd1",
- Statements: config.Statements{
- StatementList: []config.Statement{s},
- },
+ Name: "pd1",
+ Statements: []config.Statement{s},
}
p := config.RoutingPolicy{
- DefinedSets: ds,
- PolicyDefinitions: config.PolicyDefinitions{
- PolicyDefinitionList: []config.PolicyDefinition{pd},
- },
+ DefinedSets: ds,
+ PolicyDefinitions: []config.PolicyDefinition{pd},
}
return p
diff --git a/tools/pyang_plugins/README.rst b/tools/pyang_plugins/README.rst
index b7dcf7ab..fae7c71e 100644
--- a/tools/pyang_plugins/README.rst
+++ b/tools/pyang_plugins/README.rst
@@ -1,7 +1,7 @@
What's this ?
=============
This is a pyang plugin to generate config/bgp_configs.go from
-openconfig yang files (see [https://github.com/openconfig/public](https://github.com/openconfig/public))
+openconfig yang files (see https://github.com/openconfig/public).
How to use
==========
diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py
index 5c06a154..cc2b81f2 100644
--- a/tools/pyang_plugins/bgpyang2golang.py
+++ b/tools/pyang_plugins/bgpyang2golang.py
@@ -128,6 +128,10 @@ def dig_leafref(type_obj):
def emit_class_def(ctx, yang_statement, struct_name, prefix):
o = StringIO.StringIO()
+
+ if len(yang_statement.i_children) == 1 and is_list(yang_statement.i_children[0]):
+ return
+
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:
@@ -138,6 +142,7 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
container_or_list_name = child.uniq_name
val_name_go = convert_to_golang(child.arg)
child_prefix = get_orig_prefix(child.i_orig_module)
+ tag_name = child.uniq_name.lower()
print >> o, ' // original -> %s:%s' % \
(child_prefix, container_or_list_name)
@@ -197,7 +202,7 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
# case translation required
elif is_translation_required(type_obj):
- print >> o, ' //original type is list of %s' % (type_obj.arg)
+ print >> o, ' // original type is list of %s' % (type_obj.arg)
emit_type_name = '[]'+translate_type(type_name)
# case other primitives
@@ -214,24 +219,30 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
elif is_container(child) or is_choice(child):
key = child_prefix+':'+container_or_list_name
t = ctx.golang_struct_names[key]
- emit_type_name = t.golang_name
+ val_name_go = t.golang_name
+ if len(t.i_children) == 1 and is_list(t.i_children[0]):
+ l = t.i_children[0]
+ emit_type_name = '[]' + l.golang_name
+ else:
+ emit_type_name = t.golang_name
# case list
elif is_list(child):
key = child_prefix+':'+container_or_list_name
t = ctx.golang_struct_names[key]
val_name_go = val_name_go + 'List'
+ tag_name += '-list'
emit_type_name = '[]' + t.golang_name
if is_container(child):
name = emit_type_name
if name.startswith(convert_to_golang(struct_name)) and name.endswith("Config"):
- name = 'Config'
+ tag_name = 'config'
+ val_name_go = 'Config'
elif name.startswith(convert_to_golang(struct_name)) and name.endswith("State"):
- name = 'State'
- print >> o, ' %s\t%s' % (name, emit_type_name)
- else:
- print >> o, ' %s\t%s' % (val_name_go, emit_type_name)
+ tag_name = 'state'
+ val_name_go = 'State'
+ print >> o, ' {0}\t{1} `mapstructure:"{2}"`'.format(val_name_go, emit_type_name, tag_name)
print >> o, '}'
print o.getvalue()
diff --git a/tools/route-server/quagga-rsconfig.go b/tools/route-server/quagga-rsconfig.go
index b104af8a..efd17cb3 100644
--- a/tools/route-server/quagga-rsconfig.go
+++ b/tools/route-server/quagga-rsconfig.go
@@ -57,7 +57,7 @@ func create_config_files(nr int, outputDir string) {
c.Config.NeighborAddress = fmt.Sprintf("10.0.0.%d", i)
c.Config.AuthPassword = fmt.Sprintf("hoge%d", i)
- gobgpConf.Neighbors.NeighborList = append(gobgpConf.Neighbors.NeighborList, c)
+ gobgpConf.Neighbors = append(gobgpConf.Neighbors, c)
q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP("10.0.255.1"))
quaggaConfigList = append(quaggaConfigList, q)
os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, i), 0755)