diff options
Diffstat (limited to 'test/scenario_test/policy/policy_generator.go')
-rw-r--r-- | test/scenario_test/policy/policy_generator.go | 948 |
1 files changed, 352 insertions, 596 deletions
diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go index 5e2308d4..abf0fc0f 100644 --- a/test/scenario_test/policy/policy_generator.go +++ b/test/scenario_test/policy/policy_generator.go @@ -21,41 +21,41 @@ func bindPolicy(outputDir, peer, target, policyName string, isReplace bool, defa log.Fatal(d_err) } - for idx, neighbor := range newConf.NeighborList { + for idx, neighbor := range newConf.Neighbors.NeighborList { ip := net.ParseIP(peer) - if ip.String() == neighbor.NeighborAddress.String() { - ap := &neighbor.ApplyPolicy + if ip.String() == neighbor.NeighborConfig.NeighborAddress.String() { + ap := &neighbor.ApplyPolicy.ApplyPolicyConfig switch target { case "import": if isReplace { - ap.ImportPolicies = []string{policyName} + ap.ImportPolicy = []string{policyName} } else { - ap.ImportPolicies = append(ap.ImportPolicies, policyName) + ap.ImportPolicy = append(ap.ImportPolicy, policyName) } if defaultReject { ap.DefaultImportPolicy = 1 } case "export": if isReplace { - ap.ExportPolicies = []string{policyName} + ap.ExportPolicy = []string{policyName} } else { - ap.ExportPolicies = append(ap.ExportPolicies, policyName) + ap.ExportPolicy = append(ap.ExportPolicy, policyName) } if defaultReject { ap.DefaultExportPolicy = 1 } case "distribute": if isReplace { - ap.DistributePolicies = []string{policyName} + ap.DistributePolicy = []string{policyName} } else { - ap.DistributePolicies = append(ap.DistributePolicies, policyName) + ap.DistributePolicy = append(ap.DistributePolicy, policyName) } if defaultReject { ap.DefaultDistributePolicy = 1 } } - newConf.NeighborList[idx] = neighbor + newConf.Neighbors.NeighborList[idx] = neighbor } } @@ -73,12 +73,16 @@ func bindPolicy(outputDir, peer, target, policyName string, isReplace bool, defa func createPolicyConfig() *config.RoutingPolicy { + cidr := func(pref string) net.IPNet { + _, n, _ := net.ParseCIDR(pref) + return *n + } + ps0 := config.PrefixSet{ PrefixSetName: "ps0", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("192.168.0.0"), - Masklength: 16, + IpPrefix: cidr("192.168.0.0/16"), MasklengthRange: "16..24", }}, } @@ -87,11 +91,9 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "ps1", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("192.168.20.0"), - Masklength: 24, + IpPrefix: cidr("192.168.20.0/24"), }, config.Prefix{ - Address: net.ParseIP("192.168.200.0"), - Masklength: 24, + IpPrefix: cidr("192.168.200.0/24"), }}, } @@ -99,8 +101,7 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "ps2", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("192.168.20.0"), - Masklength: 24, + IpPrefix: cidr("192.168.20.0/24"), }}, } @@ -108,8 +109,7 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "ps3", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("2001:0:10:2::"), - Masklength: 64, + IpPrefix: cidr("2001:0:10:2::/64"), MasklengthRange: "64..128", }}, } @@ -118,11 +118,9 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "ps4", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("2001:0:10:20::"), - Masklength: 64, + IpPrefix: cidr("2001:0:10:20::/64"), }, config.Prefix{ - Address: net.ParseIP("2001:0:10:200::"), - Masklength: 64, + IpPrefix: cidr("2001:0:10:200::/64"), }}, } @@ -130,8 +128,7 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "ps5", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("2001:0:10:20::"), - Masklength: 64, + IpPrefix: cidr("2001:0:10:20::/64"), }}, } @@ -139,8 +136,7 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "ps6", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("192.168.10.0"), - Masklength: 24, + IpPrefix: cidr("192.168.10.0/24"), }}, } @@ -172,771 +168,531 @@ func createPolicyConfig() *config.RoutingPolicy { PrefixSetName: "psExabgp", PrefixList: []config.Prefix{ config.Prefix{ - Address: net.ParseIP("192.168.100.0"), - Masklength: 24, + IpPrefix: cidr("192.168.100.0/24"), MasklengthRange: "16..24", }}, } aspathFrom := config.AsPathSet{ - AsPathSetName: "aspathFrom", - AsPathSetMembers: []string{"^65100"}, + AsPathSetName: "aspathFrom", + AsPathSetMember: []string{"^65100"}, } aspathAny := config.AsPathSet{ - AsPathSetName: "aspAny", - AsPathSetMembers: []string{"65098"}, + AsPathSetName: "aspAny", + AsPathSetMember: []string{"65098"}, } aspathOrigin := config.AsPathSet{ - AsPathSetName: "aspOrigin", - AsPathSetMembers: []string{"65091$"}, + AsPathSetName: "aspOrigin", + AsPathSetMember: []string{"65091$"}, } aspathOnly := config.AsPathSet{ - AsPathSetName: "aspOnly", - AsPathSetMembers: []string{"^65100$"}, + AsPathSetName: "aspOnly", + AsPathSetMember: []string{"^65100$"}, } comStr := config.CommunitySet{ CommunitySetName: "comStr", - CommunityMembers: []string{"65100:10"}, + CommunityMember: []string{"65100:10"}, } comRegExp := config.CommunitySet{ CommunitySetName: "comRegExp", - CommunityMembers: []string{"6[0-9]+:[0-9]+"}, + CommunityMember: []string{"6[0-9]+:[0-9]+"}, } eComOrigin := config.ExtCommunitySet{ ExtCommunitySetName: "eComOrigin", - ExtCommunityMembers: []string{"SoO:65001.65100:200"}, + ExtCommunityMember: []string{"SoO:65001.65100:200"}, } eComTarget := config.ExtCommunitySet{ ExtCommunitySetName: "eComTarget", - ExtCommunityMembers: []string{"RT:6[0-9]+:3[0-9]+"}, + ExtCommunityMember: []string{"RT:6[0-9]+:3[0-9]+"}, } - st0 := config.Statement{ - Name: "st0", - Conditions: config.Conditions{ - MatchPrefixSet: "ps0", - MatchNeighborSet: "nsPeer2", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + createStatement := func(name string, ps, ns string, accept bool) config.Statement { + st := config.Statement{} + st.Name = name + st.Actions.RouteDisposition.AcceptRoute = accept - st1 := config.Statement{ - Name: "st1", - Conditions: config.Conditions{ - MatchPrefixSet: "ps1", - MatchNeighborSet: "nsPeer2", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + if ps != "" { + st.Conditions.MatchPrefixSet.PrefixSet = ps + } - st2 := config.Statement{ - Name: "st2", - Conditions: config.Conditions{ - MatchPrefixSet: "ps2", - MatchNeighborSet: "nsPeer2", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - RejectRoute: true, - }, - } + if ns != "" { + st.Conditions.MatchNeighborSet.NeighborSet = ns + } - st3 := config.Statement{ - Name: "st3", - Conditions: config.Conditions{ - MatchPrefixSet: "ps3", - MatchNeighborSet: "nsPeer2V6", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, + return st } - st4 := config.Statement{ - Name: "st4", - Conditions: config.Conditions{ - MatchPrefixSet: "ps4", - MatchNeighborSet: "nsPeer2V6", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st0 := createStatement("st0", "ps0", "nsPeer2", false) + st1 := createStatement("st1", "ps1", "nsPeer2", false) + st2 := createStatement("st2", "ps2", "nsPeer2", false) + st3 := createStatement("st3", "ps3", "nsPeer2V6", false) + st4 := createStatement("st4", "ps4", "nsPeer2V6", false) + st5 := createStatement("st5", "ps5", "nsPeer2V6", false) - st5 := config.Statement{ - Name: "st5", - Conditions: config.Conditions{ - MatchPrefixSet: "ps5", - MatchNeighborSet: "nsPeer2V6", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - RejectRoute: true, - }, - } + st_aspathlen := createStatement("st_aspathlen", "psExabgp", "nsExabgp", false) + st_aspathlen.Conditions.BgpConditions.AsPathLength.Operator = "ge" + st_aspathlen.Conditions.BgpConditions.AsPathLength.Value = 10 - st_aspathlen := config.Statement{ - Name: "st_aspathlen", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - AsPathLength: config.AsPathLength{ - Operator: "ge", - Value: 10, - }, - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_aspathFrom := createStatement("st_aspathFrom", "psExabgp", "nsExabgp", false) + st_aspathFrom.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspathFrom" - st_aspathFrom := config.Statement{ - Name: "st_aspathlen", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchAsPathSet: "aspathFrom", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_aspathAny := createStatement("st_aspathAny", "psExabgp", "nsExabgp", false) + st_aspathAny.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspAny" - st_aspathAny := config.Statement{ - Name: "st_aspathlen", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchAsPathSet: "aspAny", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_aspathOrigin := createStatement("st_aspathOrigin", "psExabgp", "nsExabgp", false) + st_aspathOrigin.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspOrigin" - st_aspathOrigin := config.Statement{ - Name: "st_aspathlen", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchAsPathSet: "aspOrigin", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_aspathOnly := createStatement("st_aspathOnly", "psExabgp", "nsExabgp", false) + st_aspathOnly.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspOnly" - st_aspathOnly := config.Statement{ - Name: "st_aspathlen", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchAsPathSet: "aspOnly", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_comStr := createStatement("st_community", "psExabgp", "nsExabgp", false) + st_comStr.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" - st_comStr := config.Statement{ - Name: "st_community", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_comRegExp := createStatement("st_community_regexp", "psExabgp", "nsExabgp", false) + st_comRegExp.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comRegExp" - st_comRegExp := config.Statement{ - Name: "st_community_regexp", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comRegExp", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_comAdd := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true) + st_comAdd.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" + st_comAdd.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20"} + st_comAdd.Actions.BgpActions.SetCommunity.Options = "ADD" - st_comAdd := config.Statement{ - Name: "st_community_regexp", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetCommunity: config.SetCommunity{ - Communities: []string{"65100:20"}, - Options: "ADD", - }, - }, - }, - } + st_comReplace := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true) + st_comReplace.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" + st_comReplace.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20", "65100:30"} + st_comReplace.Actions.BgpActions.SetCommunity.Options = "REPLACE" - st_comReplace := config.Statement{ - Name: "st_community_regexp", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetCommunity: config.SetCommunity{ - Communities: []string{"65100:20", "65100:30"}, - Options: "REPLACE", - }, - }, - }, - } + st_comRemove := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true) + st_comRemove.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" + st_comRemove.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20", "65100:30"} + st_comRemove.Actions.BgpActions.SetCommunity.Options = "REMOVE" - st_comRemove := config.Statement{ - Name: "st_community_regexp", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetCommunity: config.SetCommunity{ - Communities: []string{"65100:20", "65100:30"}, - Options: "REMOVE", - }, - }, - }, - } + st_comNull := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true) + st_comNull.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" + st_comNull.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{} + //use REPLACE instead of NULL + st_comNull.Actions.BgpActions.SetCommunity.Options = "REPLACE" - st_comNull := config.Statement{ - Name: "st_community_regexp", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetCommunity: config.SetCommunity{ - Communities: []string{}, - Options: "NULL", - }, - }, - }, - } + st_medReplace := createStatement("st_medReplace", "psExabgp", "nsExabgp", true) + st_medReplace.Actions.BgpActions.SetMed = "100" - st_medReplace := config.Statement{ - Name: "st_medReplace", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetMed: "100", - }, - }, - } + st_medAdd := createStatement("st_medAdd", "psExabgp", "nsExabgp", true) + st_medAdd.Actions.BgpActions.SetMed = "+100" - st_medAdd := config.Statement{ - Name: "st_medAdd", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetMed: "+100", - }, - }, - } + st_medSub := createStatement("st_medSub", "psExabgp", "nsExabgp", true) + st_medSub.Actions.BgpActions.SetMed = "-100" - st_medSub := config.Statement{ - Name: "st_medSub", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetMed: "-100", - }, - }, - } + st_distribute_reject := createStatement("st_community_distriibute", "", "", false) + st_distribute_reject.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" - st_distribute_reject := config.Statement{ - Name: "st_community_distriibute", - Conditions: config.Conditions{ - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_distribute_accept := createStatement("st_distriibute_accept", "ps6", "", true) - st_distribute_accept := config.Statement{ - Name: "st_distriibute_accept", - Conditions: config.Conditions{ - MatchPrefixSet: "ps6", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - }, - } + st_distribute_comm_add := createStatement("st_distribute_comm_add", "", "", true) + st_distribute_comm_add.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr" + st_distribute_comm_add.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20"} + st_distribute_comm_add.Actions.BgpActions.SetCommunity.Options = "ADD" - st_distribute_comm_add := config.Statement{ - Name: "st_distribute_comm_add", - Conditions: config.Conditions{ - BgpConditions: config.BgpConditions{ - MatchCommunitySet: "comStr", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetCommunity: config.SetCommunity{ - Communities: []string{"65100:20"}, - Options: "ADD", - }, - }, - }, - } + st_distribute_med_add := createStatement("st_distribute_med_add", "psExabgp", "nsExabgp", true) + st_distribute_med_add.Actions.BgpActions.SetMed = "+100" - st_distribute_med_add := config.Statement{ - Name: "st_distribute_med_add", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetMed: "+100", - }, - }, - } + st_asprepend := createStatement("st_asprepend", "psExabgp", "nsExabgp", true) + st_asprepend.Actions.BgpActions.SetAsPathPrepend.As = "65005" + st_asprepend.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5 - st_asprepend := config.Statement{ - Name: "st_asprepend", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetAsPathPrepend: config.SetAsPathPrepend{ - As: "65005", - RepeatN: 5, - }, - }, - }, - } + st_asprepend_lastas := createStatement("st_asprepend_lastas", "psExabgp", "nsExabgp", true) + st_asprepend_lastas.Actions.BgpActions.SetAsPathPrepend.As = "last-as" + st_asprepend_lastas.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5 - st_asprepend_lastas := config.Statement{ - Name: "st_asprepend_lastas", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: true, - BgpActions: config.BgpActions{ - SetAsPathPrepend: config.SetAsPathPrepend{ - As: "last-as", - RepeatN: 5, - }, - }, - }, - } - st_eComOrigin := config.Statement{ - Name: "st_eComAS4", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchExtCommunitySet: "eComOrigin", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } - st_eComTarget := config.Statement{ - Name: "st_eComRegExp", - Conditions: config.Conditions{ - MatchPrefixSet: "psExabgp", - MatchNeighborSet: "nsExabgp", - BgpConditions: config.BgpConditions{ - MatchExtCommunitySet: "eComTarget", - }, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, - }, - Actions: config.Actions{ - AcceptRoute: false, - }, - } + st_eComOrigin := createStatement("st_eComAS4", "psExabgp", "nsExabgp", false) + st_eComOrigin.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = "eComOrigin" + + st_eComTarget := createStatement("st_eComRegExp", "psExabgp", "nsExabgp", false) + st_eComTarget.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = "eComTarget" test_01_import_policy_initial := config.PolicyDefinition{ - Name: "test_01_import_policy_initial", - StatementList: []config.Statement{st0}, + Name: "test_01_import_policy_initial", + Statements: config.Statements{ + StatementList: []config.Statement{st0}, + }, } test_02_export_policy_initial := config.PolicyDefinition{ - Name: "test_02_export_policy_initial", - StatementList: []config.Statement{st0}, + Name: "test_02_export_policy_initial", + Statements: config.Statements{ + StatementList: []config.Statement{st0}, + }, } test_03_import_policy_update := config.PolicyDefinition{ - Name: "test_03_import_policy_update", - StatementList: []config.Statement{st1}, + Name: "test_03_import_policy_update", + Statements: config.Statements{ + StatementList: []config.Statement{st1}, + }, } test_03_import_policy_update_softreset := config.PolicyDefinition{ - Name: "test_03_import_policy_update_softreset", - StatementList: []config.Statement{st2}, + Name: "test_03_import_policy_update_softreset", + Statements: config.Statements{ + StatementList: []config.Statement{st2}, + }, } test_04_export_policy_update := config.PolicyDefinition{ - Name: "test_04_export_policy_update", - StatementList: []config.Statement{st1}, + Name: "test_04_export_policy_update", + Statements: config.Statements{ + StatementList: []config.Statement{st1}, + }, } test_04_export_policy_update_softreset := config.PolicyDefinition{ - Name: "test_04_export_policy_update_softreset", - StatementList: []config.Statement{st2}, + Name: "test_04_export_policy_update_softreset", + Statements: config.Statements{ + StatementList: []config.Statement{st2}, + }, } test_05_import_policy_initial_ipv6 := config.PolicyDefinition{ - Name: "test_05_import_policy_initial_ipv6", - StatementList: []config.Statement{st3}, + Name: "test_05_import_policy_initial_ipv6", + Statements: config.Statements{ + StatementList: []config.Statement{st3}, + }, } test_06_export_policy_initial_ipv6 := config.PolicyDefinition{ - Name: "test_06_export_policy_initial_ipv6", - StatementList: []config.Statement{st3}, + Name: "test_06_export_policy_initial_ipv6", + Statements: config.Statements{ + StatementList: []config.Statement{st3}, + }, } test_07_import_policy_update := config.PolicyDefinition{ - Name: "test_07_import_policy_update", - StatementList: []config.Statement{st4}, + Name: "test_07_import_policy_update", + Statements: config.Statements{ + StatementList: []config.Statement{st4}, + }, } test_07_import_policy_update_softreset := config.PolicyDefinition{ - Name: "test_07_import_policy_update_softreset", - StatementList: []config.Statement{st5}, + Name: "test_07_import_policy_update_softreset", + Statements: config.Statements{ + StatementList: []config.Statement{st5}, + }, } test_08_export_policy_update := config.PolicyDefinition{ - Name: "test_08_export_policy_update", - StatementList: []config.Statement{st4}, + Name: "test_08_export_policy_update", + Statements: config.Statements{ + StatementList: []config.Statement{st4}, + }, } test_08_export_policy_update_softreset := config.PolicyDefinition{ - Name: "test_08_export_policy_update_softreset", - StatementList: []config.Statement{st5}, + Name: "test_08_export_policy_update_softreset", + Statements: config.Statements{ + StatementList: []config.Statement{st5}, + }, } test_09_aspath_length_condition_import := config.PolicyDefinition{ - Name: "test_09_aspath_length_condition_import", - StatementList: []config.Statement{st_aspathlen}, + Name: "test_09_aspath_length_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_aspathlen}, + }, } test_10_aspath_from_condition_import := config.PolicyDefinition{ - Name: "test_10_aspath_from_condition_import", - StatementList: []config.Statement{st_aspathFrom}, + Name: "test_10_aspath_from_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_aspathFrom}, + }, } test_11_aspath_any_condition_import := config.PolicyDefinition{ - Name: "test_11_aspath_any_condition_import", - StatementList: []config.Statement{st_aspathAny}, + Name: "test_11_aspath_any_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_aspathAny}, + }, } test_12_aspath_origin_condition_import := config.PolicyDefinition{ - Name: "test_12_aspath_origin_condition_import", - StatementList: []config.Statement{st_aspathOrigin}, + Name: "test_12_aspath_origin_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_aspathOrigin}, + }, } test_13_aspath_only_condition_import := config.PolicyDefinition{ - Name: "test_13_aspath_only_condition_import", - StatementList: []config.Statement{st_aspathOnly}, + Name: "test_13_aspath_only_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_aspathOnly}, + }, } test_14_aspath_only_condition_import := config.PolicyDefinition{ - Name: "test_14_aspath_only_condition_import", - StatementList: []config.Statement{st_comStr}, + Name: "test_14_aspath_only_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comStr}, + }, } test_15_community_condition_import := config.PolicyDefinition{ - Name: "test_15_community_condition_import", - StatementList: []config.Statement{st_comStr}, + Name: "test_15_community_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comStr}, + }, } test_16_community_condition_regexp_import := config.PolicyDefinition{ - Name: "test_16_community_condition_regexp_import", - StatementList: []config.Statement{st_comRegExp}, + Name: "test_16_community_condition_regexp_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comRegExp}, + }, } test_17_community_add_action_import := config.PolicyDefinition{ - Name: "test_17_community_add_action_import", - StatementList: []config.Statement{st_comAdd}, + Name: "test_17_community_add_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comAdd}, + }, } test_18_community_replace_action_import := config.PolicyDefinition{ - Name: "test_18_community_replace_action_import", - StatementList: []config.Statement{st_comReplace}, + Name: "test_18_community_replace_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comReplace}, + }, } test_19_community_remove_action_import := config.PolicyDefinition{ - Name: "test_19_community_remove_action_import", - StatementList: []config.Statement{st_comRemove}, + Name: "test_19_community_remove_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comRemove}, + }, } test_20_community_null_action_import := config.PolicyDefinition{ - Name: "test_20_community_null_action_import", - StatementList: []config.Statement{st_comNull}, + Name: "test_20_community_null_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_comNull}, + }, } test_21_community_add_action_export := config.PolicyDefinition{ - Name: "test_21_community_add_action_export", - StatementList: []config.Statement{st_comAdd}, + Name: "test_21_community_add_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_comAdd}, + }, } test_22_community_replace_action_export := config.PolicyDefinition{ - Name: "test_22_community_replace_action_export", - StatementList: []config.Statement{st_comReplace}, + Name: "test_22_community_replace_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_comReplace}, + }, } test_23_community_remove_action_export := config.PolicyDefinition{ - Name: "test_23_community_remove_action_export", - StatementList: []config.Statement{st_comRemove}, + Name: "test_23_community_remove_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_comRemove}, + }, } test_24_community_null_action_export := config.PolicyDefinition{ - Name: "test_24_community_null_action_export", - StatementList: []config.Statement{st_comNull}, + Name: "test_24_community_null_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_comNull}, + }, } test_25_med_replace_action_import := config.PolicyDefinition{ - Name: "test_25_med_replace_action_import", - StatementList: []config.Statement{st_medReplace}, + Name: "test_25_med_replace_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_medReplace}, + }, } test_26_med_add_action_import := config.PolicyDefinition{ - Name: "test_26_med_add_action_import", - StatementList: []config.Statement{st_medAdd}, + Name: "test_26_med_add_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_medAdd}, + }, } test_27_med_subtract_action_import := config.PolicyDefinition{ - Name: "test_27_med_subtract_action_import", - StatementList: []config.Statement{st_medSub}, + Name: "test_27_med_subtract_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_medSub}, + }, } test_28_med_replace_action_export := config.PolicyDefinition{ - Name: "test_28_med_replace_action_export", - StatementList: []config.Statement{st_medReplace}, + Name: "test_28_med_replace_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_medReplace}, + }, } test_29_med_add_action_export := config.PolicyDefinition{ - Name: "test_29_med_add_action_export", - StatementList: []config.Statement{st_medAdd}, + Name: "test_29_med_add_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_medAdd}, + }, } test_30_med_subtract_action_export := config.PolicyDefinition{ - Name: "test_30_med_subtract_action_export", - StatementList: []config.Statement{st_medSub}, + Name: "test_30_med_subtract_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_medSub}, + }, } test_31_distribute_reject := config.PolicyDefinition{ - Name: "test_31_distribute_reject", - StatementList: []config.Statement{st_distribute_reject}, + Name: "test_31_distribute_reject", + Statements: config.Statements{ + StatementList: []config.Statement{st_distribute_reject}, + }, } test_32_distribute_accept := config.PolicyDefinition{ - Name: "test_32_distribute_accept", - StatementList: []config.Statement{st_distribute_accept}, + Name: "test_32_distribute_accept", + Statements: config.Statements{ + StatementList: []config.Statement{st_distribute_accept}, + }, } test_33_distribute_set_community_action := config.PolicyDefinition{ - Name: "test_33_distribute_set_community_action", - StatementList: []config.Statement{st_distribute_comm_add}, + Name: "test_33_distribute_set_community_action", + Statements: config.Statements{ + StatementList: []config.Statement{st_distribute_comm_add}, + }, } test_34_distribute_set_med_action := config.PolicyDefinition{ - Name: "test_34_distribute_set_med_action", - StatementList: []config.Statement{st_distribute_med_add}, + Name: "test_34_distribute_set_med_action", + Statements: config.Statements{ + StatementList: []config.Statement{st_distribute_med_add}, + }, } test_35_distribute_policy_update := config.PolicyDefinition{ - Name: "test_35_distribute_policy_update", - StatementList: []config.Statement{st1}, + Name: "test_35_distribute_policy_update", + Statements: config.Statements{ + StatementList: []config.Statement{st1}, + }, } test_35_distribute_policy_update_softreset := config.PolicyDefinition{ - Name: "test_35_distribute_policy_update_softreset", - StatementList: []config.Statement{st2}, + Name: "test_35_distribute_policy_update_softreset", + Statements: config.Statements{ + StatementList: []config.Statement{st2}, + }, } test_36_aspath_prepend_action_import := config.PolicyDefinition{ - Name: "test_36_aspath_prepend_action_import", - StatementList: []config.Statement{st_asprepend}, + Name: "test_36_aspath_prepend_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_asprepend}, + }, } test_37_aspath_prepend_action_export := config.PolicyDefinition{ - Name: "test_37_aspath_prepend_action_export", - StatementList: []config.Statement{st_asprepend}, + Name: "test_37_aspath_prepend_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_asprepend}, + }, } test_38_aspath_prepend_action_lastas_import := config.PolicyDefinition{ - Name: "test_38_aspath_prepend_action_lastas_import", - StatementList: []config.Statement{st_asprepend_lastas}, + Name: "test_38_aspath_prepend_action_lastas_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_asprepend_lastas}, + }, } test_39_aspath_prepend_action_lastas_export := config.PolicyDefinition{ - Name: "test_39_aspath_prepend_action_lastas_export", - StatementList: []config.Statement{st_asprepend_lastas}, + Name: "test_39_aspath_prepend_action_lastas_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_asprepend_lastas}, + }, } test_40_ecommunity_origin_condition_import := config.PolicyDefinition{ - Name: "test_40_ecommunity_origin_condition_import", - StatementList: []config.Statement{st_eComOrigin}, + Name: "test_40_ecommunity_origin_condition_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_eComOrigin}, + }, } test_41_ecommunity_target_condition_export := config.PolicyDefinition{ - Name: "test_41_ecommunity_target_condition_export", - StatementList: []config.Statement{st_eComTarget}, - } - - ds := config.DefinedSets{ - PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp}, - NeighborSetList: []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp}, - BgpDefinedSets: config.BgpDefinedSets{ - AsPathSetList: []config.AsPathSet{aspathFrom, aspathAny, aspathOrigin, aspathOnly}, - CommunitySetList: []config.CommunitySet{comStr, comRegExp}, - ExtCommunitySetList: []config.ExtCommunitySet{eComOrigin, eComTarget}, + Name: "test_41_ecommunity_target_condition_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_eComTarget}, }, } + + ds := config.DefinedSets{} + ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp} + ds.NeighborSets.NeighborSetList = []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp} + ds.BgpDefinedSets.AsPathSets.AsPathSetList = []config.AsPathSet{aspathFrom, aspathAny, aspathOrigin, aspathOnly} + ds.BgpDefinedSets.CommunitySets.CommunitySetList = []config.CommunitySet{comStr, comRegExp} + ds.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList = []config.ExtCommunitySet{eComOrigin, eComTarget} + p := &config.RoutingPolicy{ DefinedSets: ds, - PolicyDefinitionList: []config.PolicyDefinition{ - test_01_import_policy_initial, - test_02_export_policy_initial, - test_03_import_policy_update, - test_03_import_policy_update_softreset, - test_04_export_policy_update, - test_04_export_policy_update_softreset, - test_05_import_policy_initial_ipv6, - test_06_export_policy_initial_ipv6, - test_07_import_policy_update, - test_07_import_policy_update_softreset, - test_08_export_policy_update, - test_08_export_policy_update_softreset, - test_09_aspath_length_condition_import, - test_10_aspath_from_condition_import, - test_11_aspath_any_condition_import, - test_12_aspath_origin_condition_import, - test_13_aspath_only_condition_import, - test_14_aspath_only_condition_import, - test_15_community_condition_import, - test_16_community_condition_regexp_import, - test_17_community_add_action_import, - test_18_community_replace_action_import, - test_19_community_remove_action_import, - test_20_community_null_action_import, - test_21_community_add_action_export, - test_22_community_replace_action_export, - test_23_community_remove_action_export, - test_24_community_null_action_export, - test_25_med_replace_action_import, - test_26_med_add_action_import, - test_27_med_subtract_action_import, - test_28_med_replace_action_export, - test_29_med_add_action_export, - test_30_med_subtract_action_export, - test_31_distribute_reject, - test_32_distribute_accept, - test_33_distribute_set_community_action, - test_34_distribute_set_med_action, - test_35_distribute_policy_update, - test_35_distribute_policy_update_softreset, - test_36_aspath_prepend_action_import, - test_37_aspath_prepend_action_export, - test_38_aspath_prepend_action_lastas_import, - test_39_aspath_prepend_action_lastas_export, - test_40_ecommunity_origin_condition_import, - test_41_ecommunity_target_condition_export, + PolicyDefinitions: config.PolicyDefinitions{ + PolicyDefinitionList: []config.PolicyDefinition{ + test_01_import_policy_initial, + test_02_export_policy_initial, + test_03_import_policy_update, + test_03_import_policy_update_softreset, + test_04_export_policy_update, + test_04_export_policy_update_softreset, + test_05_import_policy_initial_ipv6, + test_06_export_policy_initial_ipv6, + test_07_import_policy_update, + test_07_import_policy_update_softreset, + test_08_export_policy_update, + test_08_export_policy_update_softreset, + test_09_aspath_length_condition_import, + test_10_aspath_from_condition_import, + test_11_aspath_any_condition_import, + test_12_aspath_origin_condition_import, + test_13_aspath_only_condition_import, + test_14_aspath_only_condition_import, + test_15_community_condition_import, + test_16_community_condition_regexp_import, + test_17_community_add_action_import, + test_18_community_replace_action_import, + test_19_community_remove_action_import, + test_20_community_null_action_import, + test_21_community_add_action_export, + test_22_community_replace_action_export, + test_23_community_remove_action_export, + test_24_community_null_action_export, + test_25_med_replace_action_import, + test_26_med_add_action_import, + test_27_med_subtract_action_import, + test_28_med_replace_action_export, + test_29_med_add_action_export, + test_30_med_subtract_action_export, + test_31_distribute_reject, + test_32_distribute_accept, + test_33_distribute_set_community_action, + test_34_distribute_set_med_action, + test_35_distribute_policy_update, + test_35_distribute_policy_update_softreset, + test_36_aspath_prepend_action_import, + test_37_aspath_prepend_action_export, + test_38_aspath_prepend_action_lastas_import, + test_39_aspath_prepend_action_lastas_export, + test_40_ecommunity_origin_condition_import, + test_41_ecommunity_target_condition_export, + }, }, } return p |