tools: avoid adding a new option to bgpyang2golang.py and fix gobgp.yang

pyang has an internal flag "multiple_modules" to handle multiple yang modules.
use it instead of introducing a new option --augment

also, fix warnings and errors in gobgp.yang which were there but not has been
detected for a while due to the usage of --augment.
by using "multiple_modules" flag, pyang detected them.

most notable error is wrong usage of list, which needs a key in its
substatement.

this patch adds key to some of them, and for others uses leaf-list
instead.

Signed-off-by: ISHIDA Wataru <[email protected]>
This commit is contained in:
ISHIDA Wataru
2016-01-09 05:17:57 -08:00
committed by FUJITA Tomonori
parent 6733b6afb2
commit 26c03bb779
9 changed files with 203 additions and 408 deletions
+13 -37
View File
@@ -155,6 +155,9 @@ type BmpServerConfig struct {
//struct for container gobgp:bmp-server
type BmpServer struct {
// original -> gobgp:address
//gobgp:address's original type is inet:ip-address
Address string
// original -> gobgp:bmp-server-config
Config BmpServerConfig
// original -> gobgp:bmp-server-state
@@ -234,6 +237,9 @@ type RpkiServerConfig struct {
//struct for container gobgp:rpki-server
type RpkiServer struct {
// original -> gobgp:address
//gobgp:address's original type is inet:ip-address
Address string
// original -> gobgp:rpki-server-config
Config RpkiServerConfig
// original -> gobgp:rpki-server-state
@@ -814,13 +820,6 @@ type MplsLabelRange struct {
MaxLabel uint32
}
//struct for container gobgp:redistribute-route-type
type RedistributeRouteType struct {
// original -> gobgp:route-type
//gobgp:route-type's original type is ptypes:install-protocol-type
RouteType string
}
//struct for container gobgp:zebra
type Zebra struct {
// original -> gobgp:enabled
@@ -829,7 +828,8 @@ type Zebra struct {
// original -> gobgp:url
Url string
// original -> gobgp:redistribute-route-type
RedistributeRouteTypeList []RedistributeRouteType
//original type is list of identityref
RedistributeRouteType []string
}
//struct for container gobgp:mrt
@@ -1631,18 +1631,12 @@ type PolicyDefinitions struct {
PolicyDefinitionList []PolicyDefinition
}
//struct for container gobgp:as-path
type AsPath struct {
// original -> gobgp:as-path
AsPath string
}
//struct for container bgp-pol:as-path-set
type AsPathSet struct {
// original -> bgp-pol:as-path-set-name
AsPathSetName string
// original -> gobgp:as-path
AsPathList []AsPath
AsPath []string
}
//struct for container bgp-pol:as-path-sets
@@ -1651,18 +1645,12 @@ type AsPathSets struct {
AsPathSetList []AsPathSet
}
//struct for container gobgp:ext-community
type ExtCommunity struct {
// original -> gobgp:ext-community
ExtCommunity string
}
//struct for container bgp-pol:ext-community-set
type ExtCommunitySet struct {
// original -> bgp-pol:ext-community-set-name
ExtCommunitySetName string
// original -> gobgp:ext-community
ExtCommunityList []ExtCommunity
ExtCommunity []string
}
//struct for container bgp-pol:ext-community-sets
@@ -1671,18 +1659,12 @@ type ExtCommunitySets struct {
ExtCommunitySetList []ExtCommunitySet
}
//struct for container gobgp:community
type Community struct {
// original -> gobgp:community
Community string
}
//struct for container bgp-pol:community-set
type CommunitySet struct {
// original -> bgp-pol:community-set-name
CommunitySetName string
// original -> gobgp:community
CommunityList []Community
Community []string
}
//struct for container bgp-pol:community-sets
@@ -1721,19 +1703,13 @@ type TagSets struct {
TagSetList []TagSet
}
//struct for container gobgp:neighbor-info
type NeighborInfo struct {
// original -> gobgp:address
//gobgp:address's original type is inet:ip-address
Address string
}
//struct for container rpol:neighbor-set
type NeighborSet struct {
// original -> rpol:neighbor-set-name
NeighborSetName string
// original -> gobgp:neighbor-info
NeighborInfoList []NeighborInfo
//original type is list of inet:ip-address
NeighborInfo []string
}
//struct for container rpol:neighbor-sets
+1 -5
View File
@@ -182,11 +182,7 @@ func (server *BgpServer) Serve() {
if g.Zebra.Url == "" {
g.Zebra.Url = "unix:/var/run/quagga/zserv.api"
}
redists := make([]string, 0, len(g.Zebra.RedistributeRouteTypeList))
for _, t := range g.Zebra.RedistributeRouteTypeList {
redists = append(redists, t.RouteType)
}
err := server.NewZclient(g.Zebra.Url, redists)
err := server.NewZclient(g.Zebra.Url, g.Zebra.RedistributeRouteType)
if err != nil {
log.Error(err)
}
+27 -38
View File
@@ -508,16 +508,16 @@ func NewNeighborSetFromApiStruct(a *api.DefinedSet) (*NeighborSet, error) {
func NewNeighborSet(c config.NeighborSet) (*NeighborSet, error) {
name := c.NeighborSetName
if name == "" {
if len(c.NeighborInfoList) == 0 {
if len(c.NeighborInfo) == 0 {
return nil, nil
}
return nil, fmt.Errorf("empty neighbor set name")
}
list := make([]net.IP, 0, len(c.NeighborInfoList))
for _, x := range c.NeighborInfoList {
addr := net.ParseIP(x.Address)
list := make([]net.IP, 0, len(c.NeighborInfo))
for _, x := range c.NeighborInfo {
addr := net.ParseIP(x)
if addr == nil {
return nil, fmt.Errorf("invalid address: %s", x.Address)
return nil, fmt.Errorf("invalid address: %s", x)
}
list = append(list, addr)
}
@@ -695,10 +695,7 @@ func (s *AsPathSet) ToApiStruct() *api.DefinedSet {
func NewAsPathSetFromApiStruct(a *api.DefinedSet) (*AsPathSet, error) {
c := config.AsPathSet{
AsPathSetName: a.Name,
AsPathList: make([]config.AsPath, 0, len(a.List)),
}
for _, x := range a.List {
c.AsPathList = append(c.AsPathList, config.AsPath{AsPath: x})
AsPath: a.List,
}
return NewAsPathSet(c)
}
@@ -706,18 +703,18 @@ func NewAsPathSetFromApiStruct(a *api.DefinedSet) (*AsPathSet, error) {
func NewAsPathSet(c config.AsPathSet) (*AsPathSet, error) {
name := c.AsPathSetName
if name == "" {
if len(c.AsPathList) == 0 {
if len(c.AsPath) == 0 {
return nil, nil
}
return nil, fmt.Errorf("empty as-path set name")
}
list := make([]*regexp.Regexp, 0, len(c.AsPathList))
singleList := make([]*singleAsPathMatch, 0, len(c.AsPathList))
for _, x := range c.AsPathList {
if s := NewSingleAsPathMatch(x.AsPath); s != nil {
list := make([]*regexp.Regexp, 0, len(c.AsPath))
singleList := make([]*singleAsPathMatch, 0, len(c.AsPath))
for _, x := range c.AsPath {
if s := NewSingleAsPathMatch(x); s != nil {
singleList = append(singleList, s)
} else {
exp, err := regexp.Compile(strings.Replace(x.AsPath, "_", ASPATH_REGEXP_MAGIC, -1))
exp, err := regexp.Compile(strings.Replace(x, "_", ASPATH_REGEXP_MAGIC, -1))
if err != nil {
return nil, fmt.Errorf("invalid regular expression: %s", x)
}
@@ -900,10 +897,7 @@ func ParseExtCommunityRegexp(arg string) (bgp.ExtendedCommunityAttrSubType, *reg
func NewCommunitySetFromApiStruct(a *api.DefinedSet) (*CommunitySet, error) {
c := config.CommunitySet{
CommunitySetName: a.Name,
CommunityList: make([]config.Community, 0, len(a.List)),
}
for _, x := range a.List {
c.CommunityList = append(c.CommunityList, config.Community{Community: x})
Community: a.List,
}
return NewCommunitySet(c)
}
@@ -911,14 +905,14 @@ func NewCommunitySetFromApiStruct(a *api.DefinedSet) (*CommunitySet, error) {
func NewCommunitySet(c config.CommunitySet) (*CommunitySet, error) {
name := c.CommunitySetName
if name == "" {
if len(c.CommunityList) == 0 {
if len(c.Community) == 0 {
return nil, nil
}
return nil, fmt.Errorf("empty community set name")
}
list := make([]*regexp.Regexp, 0, len(c.CommunityList))
for _, x := range c.CommunityList {
exp, err := ParseCommunityRegexp(x.Community)
list := make([]*regexp.Regexp, 0, len(c.Community))
for _, x := range c.Community {
exp, err := ParseCommunityRegexp(x)
if err != nil {
return nil, err
}
@@ -963,10 +957,7 @@ func (s *ExtCommunitySet) ToApiStruct() *api.DefinedSet {
func NewExtCommunitySetFromApiStruct(a *api.DefinedSet) (*ExtCommunitySet, error) {
c := config.ExtCommunitySet{
ExtCommunitySetName: a.Name,
ExtCommunityList: make([]config.ExtCommunity, 0, len(a.List)),
}
for _, x := range a.List {
c.ExtCommunityList = append(c.ExtCommunityList, config.ExtCommunity{ExtCommunity: x})
ExtCommunity: a.List,
}
return NewExtCommunitySet(c)
}
@@ -974,15 +965,15 @@ func NewExtCommunitySetFromApiStruct(a *api.DefinedSet) (*ExtCommunitySet, error
func NewExtCommunitySet(c config.ExtCommunitySet) (*ExtCommunitySet, error) {
name := c.ExtCommunitySetName
if name == "" {
if len(c.ExtCommunityList) == 0 {
if len(c.ExtCommunity) == 0 {
return nil, nil
}
return nil, fmt.Errorf("empty ext-community set name")
}
list := make([]*regexp.Regexp, 0, len(c.ExtCommunityList))
subtypeList := make([]bgp.ExtendedCommunityAttrSubType, 0, len(c.ExtCommunityList))
for _, x := range c.ExtCommunityList {
subtype, exp, err := ParseExtCommunityRegexp(x.ExtCommunity)
list := make([]*regexp.Regexp, 0, len(c.ExtCommunity))
subtypeList := make([]bgp.ExtendedCommunityAttrSubType, 0, len(c.ExtCommunity))
for _, x := range c.ExtCommunity {
subtype, exp, err := ParseExtCommunityRegexp(x)
if err != nil {
return nil, err
}
@@ -2794,18 +2785,16 @@ func NewRoutingPolicy() *RoutingPolicy {
}
func CanImportToVrf(v *Vrf, path *Path) bool {
f := func(arg []bgp.ExtendedCommunityInterface) []config.ExtCommunity {
ret := make([]config.ExtCommunity, 0, len(arg))
f := func(arg []bgp.ExtendedCommunityInterface) []string {
ret := make([]string, 0, len(arg))
for _, a := range arg {
ret = append(ret, config.ExtCommunity{
ExtCommunity: fmt.Sprintf("RT:%s", a.String()),
})
ret = append(ret, fmt.Sprintf("RT:%s", a.String()))
}
return ret
}
set, _ := NewExtCommunitySet(config.ExtCommunitySet{
ExtCommunitySetName: v.Name,
ExtCommunityList: f(v.ImportRt),
ExtCommunity: f(v.ImportRt),
})
matchSet := config.MatchExtCommunitySet{
ExtCommunitySet: v.Name,
+84 -201
View File
@@ -700,45 +700,32 @@ func TestAsPathConditionEvaluate(t *testing.T) {
// create match condition
asPathSet1 := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "^65001"},
},
AsPath: []string{"^65001"},
}
asPathSet2 := config.AsPathSet{
AsPathSetName: "asset2",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65005$"},
},
AsPath: []string{"65005$"},
}
asPathSet3 := config.AsPathSet{
AsPathSetName: "asset3",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65004"},
config.AsPath{AsPath: "65005$"},
},
AsPath: []string{"65004", "65005$"},
}
asPathSet4 := config.AsPathSet{
AsPathSetName: "asset4",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65000$"},
},
AsPath: []string{"65000$"},
}
asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65010"},
},
AsPath: []string{"65010"},
}
asPathSet6 := config.AsPathSet{
AsPathSetName: "asset6",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "^65010$"},
},
AsPath: []string{"^65010$"},
}
m := make(map[string]DefinedSet)
@@ -798,65 +785,47 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) {
// create match condition
asPathSet1 := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "^65001_65000"},
},
AsPath: []string{"^65001_65000"},
}
asPathSet2 := config.AsPathSet{
AsPathSetName: "asset2",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65004_65005$"},
},
AsPath: []string{"65004_65005$"},
}
asPathSet3 := config.AsPathSet{
AsPathSetName: "asset3",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65001_65000_54000"},
},
AsPath: []string{"65001_65000_54000"},
}
asPathSet4 := config.AsPathSet{
AsPathSetName: "asset4",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "54000_65004_65005"},
},
AsPath: []string{"54000_65004_65005"},
}
asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "^65001 65000 54000 65004 65005$"},
},
AsPath: []string{"^65001 65000 54000 65004 65005$"},
}
asPathSet6 := config.AsPathSet{
AsPathSetName: "asset6",
AsPathList: []config.AsPath{
config.AsPath{AsPath: ".*_[0-9]+_65005"},
},
AsPath: []string{".*_[0-9]+_65005"},
}
asPathSet7 := config.AsPathSet{
AsPathSetName: "asset7",
AsPathList: []config.AsPath{
config.AsPath{AsPath: ".*_5[0-9]+_[0-9]+"},
},
AsPath: []string{".*_5[0-9]+_[0-9]+"},
}
asPathSet8 := config.AsPathSet{
AsPathSetName: "asset8",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "6[0-9]+_6[0-9]+_5[0-9]+"},
},
AsPath: []string{"6[0-9]+_6[0-9]+_5[0-9]+"},
}
asPathSet9 := config.AsPathSet{
AsPathSetName: "asset9",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "6[0-9]+__6[0-9]+"},
},
AsPath: []string{"6[0-9]+__6[0-9]+"},
}
m := make(map[string]DefinedSet)
@@ -945,7 +914,7 @@ func TestAsPathCondition(t *testing.T) {
for k, v := range tests {
s, _ := NewAsPathSet(config.AsPathSet{
AsPathSetName: k,
AsPathList: []config.AsPath{config.AsPath{AsPath: k}},
AsPath: []string{k},
})
c, _ := NewAsPathCondition(config.MatchAsPathSet{
AsPathSet: k,
@@ -987,7 +956,7 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{config.AsPath{AsPath: "65005$"}},
AsPath: []string{"65005$"},
}
ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
@@ -1053,44 +1022,40 @@ func TestAs4PathConditionEvaluate(t *testing.T) {
// create match condition
asPathSet1 := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("^%d", createAs4Value("65001.1"))},
},
AsPath: []string{fmt.Sprintf("^%d", createAs4Value("65001.1"))},
}
asPathSet2 := config.AsPathSet{
AsPathSetName: "asset2",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d$", createAs4Value("65005.1"))},
},
AsPath: []string{fmt.Sprintf("%d$", createAs4Value("65005.1"))},
}
asPathSet3 := config.AsPathSet{
AsPathSetName: "asset3",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d", createAs4Value("65004.1"))},
config.AsPath{AsPath: fmt.Sprintf("%d$", createAs4Value("65005.1"))},
AsPath: []string{
fmt.Sprintf("%d", createAs4Value("65004.1")),
fmt.Sprintf("%d$", createAs4Value("65005.1")),
},
}
asPathSet4 := config.AsPathSet{
AsPathSetName: "asset4",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d$", createAs4Value("65000.1"))},
AsPath: []string{
fmt.Sprintf("%d$", createAs4Value("65000.1")),
},
}
asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d", createAs4Value("65010.1"))},
AsPath: []string{
fmt.Sprintf("%d", createAs4Value("65010.1")),
},
}
asPathSet6 := config.AsPathSet{
AsPathSetName: "asset6",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d$", createAs4Value("65010.1"))},
AsPath: []string{
fmt.Sprintf("%d$", createAs4Value("65010.1")),
},
}
@@ -1160,65 +1125,59 @@ func TestMultipleAs4PathConditionEvaluate(t *testing.T) {
// create match condition
asPathSet1 := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("^%d_%d", createAs4Value("65001.1"), createAs4Value("65000.1"))},
AsPath: []string{
fmt.Sprintf("^%d_%d", createAs4Value("65001.1"), createAs4Value("65000.1")),
},
}
asPathSet2 := config.AsPathSet{
AsPathSetName: "asset2",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d_%d$", createAs4Value("65004.1"), createAs4Value("65005.1"))},
AsPath: []string{
fmt.Sprintf("%d_%d$", createAs4Value("65004.1"), createAs4Value("65005.1")),
},
}
asPathSet3 := config.AsPathSet{
AsPathSetName: "asset3",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d_%d_%d", createAs4Value("65001.1"), createAs4Value("65000.1"), createAs4Value("54000.1"))},
AsPath: []string{
fmt.Sprintf("%d_%d_%d", createAs4Value("65001.1"), createAs4Value("65000.1"), createAs4Value("54000.1")),
},
}
asPathSet4 := config.AsPathSet{
AsPathSetName: "asset4",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d_%d_%d", createAs4Value("54000.1"), createAs4Value("65004.1"), createAs4Value("65005.1"))},
AsPath: []string{
fmt.Sprintf("%d_%d_%d", createAs4Value("54000.1"), createAs4Value("65004.1"), createAs4Value("65005.1")),
},
}
asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("^%d %d %d %d %d$", createAs4Value("65001.1"), createAs4Value("65000.1"), createAs4Value("54000.1"), createAs4Value("65004.1"), createAs4Value("65005.1"))},
AsPath: []string{
fmt.Sprintf("^%d %d %d %d %d$", createAs4Value("65001.1"), createAs4Value("65000.1"), createAs4Value("54000.1"), createAs4Value("65004.1"), createAs4Value("65005.1")),
},
}
asPathSet6 := config.AsPathSet{
AsPathSetName: "asset6",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf(".*_[0-9]+_%d", createAs4Value("65005.1"))},
AsPath: []string{
fmt.Sprintf(".*_[0-9]+_%d", createAs4Value("65005.1")),
},
}
asPathSet7 := config.AsPathSet{
AsPathSetName: "asset7",
AsPathList: []config.AsPath{
config.AsPath{AsPath: ".*_3[0-9]+_[0-9]+"},
},
AsPath: []string{".*_3[0-9]+_[0-9]+"},
}
asPathSet8 := config.AsPathSet{
AsPathSetName: "asset8",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "4[0-9]+_4[0-9]+_3[0-9]+"},
},
AsPath: []string{"4[0-9]+_4[0-9]+_3[0-9]+"},
}
asPathSet9 := config.AsPathSet{
AsPathSetName: "asset9",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "4[0-9]+__4[0-9]+"},
},
AsPath: []string{"4[0-9]+__4[0-9]+"},
}
m := make(map[string]DefinedSet)
@@ -1291,9 +1250,7 @@ func TestAs4PathConditionWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{config.AsPath{
AsPath: fmt.Sprintf("%d$", createAs4Value("65005.1")),
}},
AsPath: []string{fmt.Sprintf("%d$", createAs4Value("65005.1"))},
}
ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
@@ -1351,52 +1308,37 @@ func TestAs4PathConditionEvaluateMixedWith2byteAS(t *testing.T) {
// create match condition
asPathSet1 := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("^%d", createAs4Value("65001.1"))},
},
AsPath: []string{fmt.Sprintf("^%d", createAs4Value("65001.1"))},
}
asPathSet2 := config.AsPathSet{
AsPathSetName: "asset2",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "4000$"},
},
AsPath: []string{"4000$"},
}
asPathSet3 := config.AsPathSet{
AsPathSetName: "asset3",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d", createAs4Value("65004.1"))},
config.AsPath{AsPath: "4000$"},
},
AsPath: []string{fmt.Sprintf("%d", createAs4Value("65004.1")), "4000$"},
}
asPathSet4 := config.AsPathSet{
AsPathSetName: "asset4",
AsPathList: []config.AsPath{
config.AsPath{AsPath: fmt.Sprintf("%d_%d_%d", createAs4Value("54000.1"), 100, 5000)},
},
AsPath: []string{fmt.Sprintf("%d_%d_%d", createAs4Value("54000.1"), 100, 5000)},
}
asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5",
AsPathList: []config.AsPath{
config.AsPath{AsPath: ".*_[0-9]+_100"},
},
AsPath: []string{".*_[0-9]+_100"},
}
asPathSet6 := config.AsPathSet{
AsPathSetName: "asset6",
AsPathList: []config.AsPath{
config.AsPath{AsPath: ".*_3[0-9]+_[0]+"},
},
AsPath: []string{".*_3[0-9]+_[0]+"},
}
asPathSet7 := config.AsPathSet{
AsPathSetName: "asset7",
AsPathList: []config.AsPath{
config.AsPath{AsPath: ".*_3[0-9]+_[1]+"},
},
AsPath: []string{".*_3[0-9]+_[1]+"},
}
m := make(map[string]DefinedSet)
@@ -1478,76 +1420,58 @@ func TestCommunityConditionEvaluate(t *testing.T) {
// create match condition
comSet1 := config.CommunitySet{
CommunitySetName: "comset1",
CommunityList: []config.Community{
config.Community{Community: "65001:10"},
config.Community{Community: "65001:50"},
config.Community{Community: "65001:100"},
},
Community: []string{"65001:10", "65001:50", "65001:100"},
}
comSet2 := config.CommunitySet{
CommunitySetName: "comset2",
CommunityList: []config.Community{
config.Community{Community: "65001:200"},
},
Community: []string{"65001:200"},
}
comSet3 := config.CommunitySet{
CommunitySetName: "comset3",
CommunityList: []config.Community{
config.Community{Community: "4259905936"},
},
Community: []string{"4259905936"},
}
comSet4 := config.CommunitySet{
CommunitySetName: "comset4",
CommunityList: []config.Community{
config.Community{Community: "^[0-9]*:300$"},
},
Community: []string{"^[0-9]*:300$"},
}
comSet5 := config.CommunitySet{
CommunitySetName: "comset5",
CommunityList: []config.Community{
config.Community{Community: "INTERNET"},
},
Community: []string{"INTERNET"},
}
comSet6 := config.CommunitySet{
CommunitySetName: "comset6",
CommunityList: []config.Community{
config.Community{Community: "NO_EXPORT"},
},
Community: []string{"NO_EXPORT"},
}
comSet7 := config.CommunitySet{
CommunitySetName: "comset7",
CommunityList: []config.Community{
config.Community{Community: "NO_ADVERTISE"},
},
Community: []string{"NO_ADVERTISE"},
}
comSet8 := config.CommunitySet{
CommunitySetName: "comset8",
CommunityList: []config.Community{
config.Community{Community: "NO_EXPORT_SUBCONFED"},
},
Community: []string{"NO_EXPORT_SUBCONFED"},
}
comSet9 := config.CommunitySet{
CommunitySetName: "comset9",
CommunityList: []config.Community{
config.Community{Community: "65001:\\d+"},
config.Community{Community: "\\d+:\\d00"},
Community: []string{
"65001:\\d+",
"\\d+:\\d00",
},
}
comSet10 := config.CommunitySet{
CommunitySetName: "comset10",
CommunityList: []config.Community{
config.Community{Community: "65001:1"},
config.Community{Community: "65001:2"},
config.Community{Community: "65001:3"},
Community: []string{
"65001:1",
"65001:2",
"65001:3",
},
}
@@ -1628,25 +1552,17 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65005$"},
},
AsPath: []string{"65005$"},
}
comSet1 := config.CommunitySet{
CommunitySetName: "comset1",
CommunityList: []config.Community{
config.Community{Community: "65001:100"},
config.Community{Community: "65001:200"},
config.Community{Community: "65001:300"},
},
Community: []string{"65001:100", "65001:200", "65001:300"},
}
comSet2 := config.CommunitySet{
CommunitySetName: "comset2",
CommunityList: []config.Community{
config.Community{Community: "65050:\\d+"},
},
Community: []string{"65050:\\d+"},
}
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
@@ -2044,72 +1960,48 @@ func TestExtCommunityConditionEvaluate(t *testing.T) {
// create match condition
ecomSet1 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet1",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:65001:200"},
},
ExtCommunity: []string{"RT:65001:200"},
}
ecomSet2 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet2",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:10.0.0.1:300"},
},
ExtCommunity: []string{"RT:10.0.0.1:300"},
}
ecomSet3 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet3",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: fmt.Sprintf("RT:%s:200", convUintStr(65030000))},
},
ExtCommunity: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030000))},
}
ecomSet4 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet4",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:65002:200"},
},
ExtCommunity: []string{"RT:65002:200"},
}
ecomSet5 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet5",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:10.0.0.2:300"},
},
ExtCommunity: []string{"RT:10.0.0.2:300"},
}
ecomSet6 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet6",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: fmt.Sprintf("RT:%s:200", convUintStr(65030001))},
},
ExtCommunity: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030001))},
}
ecomSet7 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet7",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "SoO:65010:300"},
},
ExtCommunity: []string{"SoO:65010:300"},
}
ecomSet8 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet8",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "SoO:10.0.10.10:[0-9]+"},
},
ExtCommunity: []string{"SoO:10.0.10.10:[0-9]+"},
}
ecomSet9 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet9",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:[0-9]+:[0-9]+"},
},
ExtCommunity: []string{"RT:[0-9]+:[0-9]+"},
}
ecomSet10 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet10",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:.+:\\d00"},
config.ExtCommunity{ExtCommunity: "SoO:.+:\\d00"},
},
ExtCommunity: []string{"RT:.+:\\d00", "SoO:.+:\\d00"},
}
ecomSet11 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet11",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:65001:2"},
config.ExtCommunity{ExtCommunity: "SoO:11.0.10.10:[0-9]+"},
},
ExtCommunity: []string{"RT:65001:2", "SoO:11.0.10.10:[0-9]+"},
}
m := make(map[string]DefinedSet)
@@ -2240,22 +2132,16 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
AsPathSetName: "asset1",
AsPathList: []config.AsPath{
config.AsPath{AsPath: "65005$"},
},
AsPath: []string{"65005$"},
}
ecomSet1 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet1",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:65001:201"},
},
ExtCommunity: []string{"RT:65001:201"},
}
ecomSet2 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet2",
ExtCommunityList: []config.ExtCommunity{
config.ExtCommunity{ExtCommunity: "RT:[0-9]+:[0-9]+"},
},
ExtCommunity: []string{"RT:[0-9]+:[0-9]+"},
}
ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
@@ -2837,10 +2723,7 @@ func createPrefixSet(name string, prefix string, maskLength string) config.Prefi
func createNeighborSet(name string, addr string) config.NeighborSet {
ns := config.NeighborSet{
NeighborSetName: name,
NeighborInfoList: []config.NeighborInfo{
config.NeighborInfo{
Address: addr,
}},
NeighborInfo: []string{addr},
}
return ns
}
+1 -1
View File
@@ -284,7 +284,7 @@ class GoBGPContainer(BGPContainer):
if self.zebra:
config['Global']['Zebra'] = {'Enabled': True,
'RedistributeRouteTypeList':[{'RouteType': 'connect'}],}
'RedistributeRouteType':['connect']}
with open('{0}/gobgpd.conf'.format(self.config_dir), 'w') as f:
print colors.yellow('[{0}\'s new config]'.format(self.name))
+33 -61
View File
@@ -106,10 +106,8 @@ class ImportPolicy(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -175,10 +173,8 @@ class ExportPolicy(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[q2]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[q2]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -264,10 +260,8 @@ class ImportPolicyUpdate(object):
'PrefixList': [p0, p1]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -315,10 +309,8 @@ class ImportPolicyUpdate(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -398,10 +390,8 @@ class ExportPolicyUpdate(object):
'PrefixList': [p0, p1]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[q2]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[q2]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -448,10 +438,8 @@ class ExportPolicyUpdate(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[q2]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[q2]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -546,10 +534,8 @@ class ImportPolicyIPV6(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -618,10 +604,8 @@ class ExportPolicyIPV6(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[q2]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[q2]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -703,10 +687,8 @@ class ImportPolicyIPV6Update(object):
'PrefixList': [p0, p1]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -749,10 +731,8 @@ class ImportPolicyIPV6Update(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -830,10 +810,8 @@ class ExportPolicyIPv6Update(object):
'PrefixList': [p0, p1]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[q2]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[q2]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -876,10 +854,8 @@ class ExportPolicyIPv6Update(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[q2]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[q2]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -993,7 +969,7 @@ class ImportPolicyAsPathCondition(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPathList': [{'AsPath': '^{0}'.format(e1.asn)}]}]}}
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPath': ['^{0}'.format(e1.asn)]}]}}
g1.set_bgp_defined_set(as0)
@@ -1046,7 +1022,7 @@ class ImportPolicyAsPathAnyCondition(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPathList': [{'AsPath': '65098'}]}]}}
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPath': ['65098']}]}}
g1.set_bgp_defined_set(as0)
@@ -1099,7 +1075,7 @@ class ImportPolicyAsPathOriginCondition(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPathList': [{'AsPath': '65090$'}]}]}}
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPath': ['65090$']}]}}
g1.set_bgp_defined_set(as0)
@@ -1152,7 +1128,7 @@ class ImportPolicyAsPathOnlyCondition(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPathList': [{'AsPath': '^65100$'}]}]}}
as0 = {'AsPathSets': {'AsPathSetList': [{'AsPathSetName': 'as0', 'AsPath': ['^65100$']}]}}
g1.set_bgp_defined_set(as0)
@@ -1208,7 +1184,7 @@ class ImportPolicyAsPathMismatchCondition(object):
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList':
[{'CommunitySetName': 'cs0',
'CommunityList': [{'Community': '65100:10'}]}]}}
'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1270,7 +1246,7 @@ class ImportPolicyCommunityCondition(object):
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets':
{'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
{'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1324,7 +1300,7 @@ class ImportPolicyCommunityRegexp(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '6[0-9]+:[0-9]+'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['6[0-9]+:[0-9]+']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1386,7 +1362,7 @@ class ImportPolicyCommunityAction(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1461,7 +1437,7 @@ class ImportPolicyCommunityReplace(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1528,7 +1504,7 @@ class ImportPolicyCommunityRemove(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1613,7 +1589,7 @@ class ImportPolicyCommunityNull(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1688,7 +1664,7 @@ class ExportPolicyCommunityAdd(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1762,7 +1738,7 @@ class ExportPolicyCommunityReplace(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1836,7 +1812,7 @@ class ExportPolicyCommunityRemove(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -1913,7 +1889,7 @@ class ExportPolicyCommunityNull(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -2368,7 +2344,7 @@ class InPolicyReject(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -2428,7 +2404,7 @@ class InPolicyAccept(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'Community': ['65100:10']}]}}
g1.set_bgp_defined_set(cs0)
@@ -2503,10 +2479,8 @@ class InPolicyUpdate(object):
'PrefixList': [p0, p1]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -2555,10 +2529,8 @@ class InPolicyUpdate(object):
'PrefixList': [p0]}
g1.set_prefix_set(ps0)
n0 = {'Address': g1.peers[e1]['neigh_addr'].split('/')[0]}
ns0 = {'NeighborSetName': 'ns0',
'NeighborInfoList': [n0]}
'NeighborInfo': [g1.peers[e1]['neigh_addr'].split('/')[0]]}
g1.set_neighbor_set(ns0)
st0 = {'Name': 'st0',
@@ -2861,7 +2833,7 @@ class ImportPolicyExCommunityOriginCondition(object):
q2 = env.q2
es0 = {'ExtCommunitySets': {'ExtCommunitySetList': [{'ExtCommunitySetName': 'es0',
'ExtCommunityList': [{'ExtCommunity': 'SoO:65001.65100:200'}]}]}}
'ExtCommunity': ['SoO:65001.65100:200']}]}}
g1.set_bgp_defined_set(es0)
@@ -2913,7 +2885,7 @@ class ImportPolicyExCommunityTargetCondition(object):
q2 = env.q2
es0 = {'ExtCommunitySets': {'ExtCommunitySetList': [{'ExtCommunitySetName': 'es0',
'ExtCommunityList': [{'ExtCommunity': 'RT:6[0-9]+:3[0-9]+'}]}]}}
'ExtCommunity': ['RT:6[0-9]+:3[0-9]+']}]}}
g1.set_bgp_defined_set(es0)
+2 -2
View File
@@ -21,6 +21,6 @@ How to use
-p $YANG_DIR/experimental/openconfig/bgp \
-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 \
$YANG_DIR/bgp/bgp.yang $YANG_DIR/bgp/bgp-policy.yang \
$GOBGP_PATH/tools/pyang_plugins/gobgp.yang \
| gofmt > $GOBGP_PATH/config/bgp_configs.go
+6 -28
View File
@@ -45,21 +45,9 @@ def pyang_plugin_init():
class GolangPlugin(plugin.PyangPlugin):
def add_output_format(self, fmts):
self.multiple_modules = True
fmts['golang'] = self
def add_opts(self, optparser):
optlist = [
optparse.make_option("--augment",
dest="augment", action="append",
help="Yang file which has augment statements"),
]
g = optparser.add_option_group("GolangPlugin specific options")
g.add_options(optlist)
def emit(self, ctx, modules, fd):
ctx.golang_identity_map = {}
@@ -70,20 +58,8 @@ class GolangPlugin(plugin.PyangPlugin):
ctx.prefix_rel = {}
ctx.module_deps = []
check_module_deps(ctx, modules[0])
# load augment module
if ctx.opts.augment:
aug_mod_path = ctx.opts.augment
for p in aug_mod_path:
with open(p) as fd:
try:
text = fd.read()
except IOError as ex:
sys.stderr.write("error %s: %s\n" % (aug_mod_path, str(ex)))
sys.exit(1)
aug_mod = ctx.add_module(p, text)
check_module_deps(ctx, aug_mod)
for m in modules:
check_module_deps(ctx, m)
# visit yang statements
visit_modules(ctx)
@@ -207,6 +183,8 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
if is_leaflist(child):
type_obj = child.search_one('type')
type_name = type_obj.arg
val_name_go = val_name_go + 'List'
tag_name += '-list'
# case leafref
if type_name == 'leafref':
@@ -532,7 +510,7 @@ _type_translation_map = {
'inet:ip-prefix': 'string',
'inet:ipv4-address': 'string',
'inet:as-number': 'uint32',
'bgp-set-community-option-type' : 'string',
'bgp-set-community-option-type': 'string',
'identityref' : 'string',
'inet:port-number': 'uint16',
'yang:timeticks': 'int64',
+36 -35
View File
@@ -1,4 +1,4 @@
module bgp-gobgp {
module gobgp {
yang-version "1";
@@ -13,6 +13,7 @@ module bgp-gobgp {
import policy-types {prefix ptypes; }
import bgp-policy {prefix bgp-pol; }
import ietf-inet-types { prefix inet; }
import ietf-yang-types { prefix yang; }
// meta
organization
@@ -403,12 +404,16 @@ module bgp-gobgp {
description "additional RPKI structure";
container rpki-servers {
description
"List of RPKI servers configured on the local system";
list rpki-server {
container rpki-server {
uses gobgp-rpki-server-set;
key "address";
description
"List of RPKI servers configured on the local system";
leaf address {
type leafref {
path "../config/address";
}
}
uses gobgp-rpki-server-set;
}
}
}
@@ -457,12 +462,16 @@ module bgp-gobgp {
description "BGP Monitoring Protocol servers";
container bmp-servers {
description
"List of BMP servers configured on the local system";
list bmp-server {
container bmp-server {
uses gobgp-bmp-server-set;
key "address";
description
"List of BMP servers configured on the local system";
leaf address {
type leafref {
path "../config/address";
}
}
uses gobgp-bmp-server-set;
}
}
}
@@ -568,12 +577,10 @@ module bgp-gobgp {
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
leaf-list neighbor-info {
description
"neighbor ip address";
}
type inet:ip-address;
}
}
@@ -581,12 +588,10 @@ module bgp-gobgp {
"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";
}
leaf-list community {
description
"community set member";
type string;
}
}
@@ -594,12 +599,10 @@ module bgp-gobgp {
"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";
}
leaf-list ext-community {
type string;
description
"extended community set member";
}
}
@@ -607,12 +610,10 @@ module bgp-gobgp {
"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";
}
leaf-list as-path {
type string;
description
"AS path expression";
}
}
@@ -661,9 +662,9 @@ module bgp-gobgp {
description
"Configure url for zebra.";
}
list redistribute-route-type {
leaf route-type {
type ptypes:install-protocol-type;
leaf-list redistribute-route-type {
type identityref {
base ptypes:install-protocol-type;
}
}
}