summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/scenario_test/policy/policy_generator.go50
-rw-r--r--test/scenario_test/route_server_policy_test.py114
2 files changed, 160 insertions, 4 deletions
diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go
index 0d81fadc..9b35c5aa 100644
--- a/test/scenario_test/policy/policy_generator.go
+++ b/test/scenario_test/policy/policy_generator.go
@@ -207,6 +207,14 @@ func createPolicyConfig() *config.RoutingPolicy {
CommunitySetName: "comRegExp",
CommunityMembers: []string{"6[0-9]+:[0-9]+"},
}
+ eComOrigin := config.ExtCommunitySet{
+ ExtCommunitySetName: "eComAS4",
+ ExtCommunityMembers: []string{"SoO:65001.65100:200"},
+ }
+ eComTarget := config.ExtCommunitySet{
+ ExtCommunitySetName: "eComRegExp",
+ ExtCommunityMembers: []string{"RT:6[0-9]+:3[0-9]+"},
+ }
st0 := config.Statement{
Name: "st0",
@@ -612,6 +620,34 @@ func createPolicyConfig() *config.RoutingPolicy {
},
},
}
+ 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,
+ },
+ }
test_01_import_policy_initial := config.PolicyDefinition{
Name: "test_01_import_policy_initial",
@@ -833,15 +869,25 @@ func createPolicyConfig() *config.RoutingPolicy {
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},
+ }
+
+ 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},
},
}
-
p := &config.RoutingPolicy{
DefinedSets: ds,
PolicyDefinitionList: []config.PolicyDefinition{
@@ -889,6 +935,8 @@ func createPolicyConfig() *config.RoutingPolicy {
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
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index e4cd6750..4f524228 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -2691,6 +2691,112 @@ class GoBGPTest(GoBGPTestBase):
self.assertListEqual(path_asns, expected)
+ """
+ import-policy test
+ ---------------------------------------
+ exabgp ->(extcommunity=origin:65001.65100:200)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1
+ | |
+ | ->x peer2-rib |
+ ---------------------------------------
+ """
+ def test_40_ecommunity_origin_condition_import(self):
+
+ # generate exabgp configuration file
+ prefix1 = "192.168.100.0/24"
+ asns = ['65100'] + [str(asn) for asn in range(65099, 65090, -1)]
+ extcommunity = 'origin:4259970636:200'
+ as_path = reduce(lambda a, b: a + " " + b, asns)
+
+ e = ExabgpConfig(EXABGP_COMMON_CONF)
+ e.add_route(prefix1, aspath=as_path, extcommunity=extcommunity)
+ e.write()
+
+ self.quagga_num = 2
+
+ peer1 = "10.0.0.1"
+ peer2 = "10.0.0.2"
+ w = self.wait_per_retry
+
+ # policy:test_40_ecommunity_origin_condition_import which rejects paths
+ # that have origin:4259970636:200 in its extended community attr
+ # is attached to peer2(10.0.0.2)'s import-policy.
+ self.setup_config(peer2, "test_40_ecommunity_origin_condition_import", "import", add_exabgp=True)
+ self.initialize()
+
+ addresses = self.get_neighbor_address(self.gobgp_config)
+ self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
+ # check local-rib in peer1
+ path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(path)
+
+ # check show ip bgp on peer1(quagga1)
+ qpath = self.get_route(peer1, prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(qpath)
+
+ # check local-rib in peer2
+ path = self.get_paths_in_localrib(peer2, prefix1, retry=1, interval=w)
+ self.assertIsNone(path)
+
+ # check show ip bgp on peer2(quagga2)
+ qpath = self.get_route(peer2, prefix1, retry=1, interval=w)
+ self.assertIsNone(qpath)
+
+ """
+ export-policy test
+ ---------------------------------------
+ exabgp ->(extcommunity=origin:65010:320)-> | -> peer1-rib -> peer1-adj-rib-out | --> peer1
+ | |
+ | -> peer2-rib ->x peer2-adj-rib-out |
+ ---------------------------------------
+ """
+ def test_41_ecommunity_target_condition_export(self):
+
+ # generate exabgp configuration file
+ prefix1 = "192.168.100.0/24"
+ asns = ['65100'] + [str(asn) for asn in range(65099, 65090, -1)]
+ extcommunity = 'target:65010:320'
+ as_path = reduce(lambda a, b: a + " " + b, asns)
+
+ e = ExabgpConfig(EXABGP_COMMON_CONF)
+ e.add_route(prefix1, aspath=as_path, extcommunity=extcommunity)
+ e.write()
+
+ self.quagga_num = 2
+
+ peer1 = "10.0.0.1"
+ peer2 = "10.0.0.2"
+ w = self.wait_per_retry
+
+ # policy:test_41_ecommunity_target_condition_export which rejects paths
+ # that have target:65010:320 in its extended community attr
+ # is attached to peer2(10.0.0.2)'s export-policy.
+ self.setup_config(peer2, "test_41_ecommunity_target_condition_export", "export", add_exabgp=True)
+ self.initialize()
+
+ addresses = self.get_neighbor_address(self.gobgp_config)
+ self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
+ # check local-rib in peer1
+ path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(path)
+
+ # check show ip bgp on peer1(quagga1)
+ qpath = self.get_route(peer1, prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(qpath)
+
+ # check local-rib in peer2
+ path = self.get_paths_in_localrib(peer2, prefix1, retry=1, interval=w)
+ self.assertIsNotNone(path)
+
+ # check local-rib in peer2
+ path = self.get_adj_rib_out(peer2, prefix1, retry=1, interval=w)
+ self.assertIsNone(path)
+
+ # check show ip bgp on peer2(quagga2)
+ qpath = self.get_route(peer2, prefix1, retry=1, interval=w)
+ self.assertIsNone(qpath)
+
class ExabgpConfig(object):
@@ -2721,12 +2827,14 @@ neighbor 10.0.255.1 {
self.config_name = config_name
print >> self.o, self.basic_conf_begin
- def add_route(self, prefix, aspath='', community='', med='0'):
+ def add_route(self, prefix, aspath='', community='', med='0', extcommunity=''):
value = {'prefix': prefix,
'aspath': aspath,
'community': community,
- 'med': med}
- r = "route %(prefix)s next-hop 10.0.0.100 as-path [%(aspath)s] community [%(community)s] med %(med)s;" % value
+ 'med': med,
+ 'extended-community': extcommunity}
+ r = "route %(prefix)s next-hop 10.0.0.100 as-path [%(aspath)s] community [%(community)s] " \
+ "med %(med)s extended-community [%(extended-community)s];" % value
print >> self.o, r
def write(self):