summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-07-13 17:12:15 +0900
committerNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-07-15 19:12:55 +0900
commitb56ddd477bccd5ae0bd830b95de977ba516f066b (patch)
tree56d8390df6b37d28a0022d3ba7ba3d5fb5e9e182
parentb73c4df33906a09acce12a4159f96626ae045797 (diff)
scenaio_test: add extended community test
-rw-r--r--policy/policy.go2
-rw-r--r--test/scenario_test/policy/policy_generator.go50
-rw-r--r--test/scenario_test/route_server_policy_test.py114
3 files changed, 161 insertions, 5 deletions
diff --git a/policy/policy.go b/policy/policy.go
index 788f4a7a..5f97e12e 100644
--- a/policy/policy.go
+++ b/policy/policy.go
@@ -719,6 +719,7 @@ func NewExtCommunityCondition(extComSetName string, defExtComSetList []config.Ex
matchAll := false
e := &ExtCommunityElement{
isRegExp: false,
+ comStr: c,
}
matchType, val := getECommunitySubType(c)
if !matchType {
@@ -863,7 +864,6 @@ func (c *ExtCommunityCondition) evaluate(path *table.Path) bool {
matched := false
matchStr := ""
-
for _, member := range c.ExtCommunityList {
for _, eCommunity := range eCommunities {
ec := eCommunity.(bgp.ExtendedCommunityInterface)
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):