@@ -640,6 +640,8 @@ class ServiceChainTest : public ::testing::Test {
640
640
extcomm_spec.communities .push_back (lb.GetExtCommunityValue ());
641
641
642
642
attr_spec.push_back (&extcomm_spec);
643
+
644
+
643
645
BgpAttrPtr attr = bgp_server_->attr_db ()->Locate (attr_spec);
644
646
645
647
request.data .reset (new BgpTable::RequestData (attr, flags, label));
@@ -916,16 +918,23 @@ class ServiceChainTest : public ::testing::Test {
916
918
const vector<uint32_t > sg_ids, const set<string> tunnel_encaps,
917
919
const SiteOfOrigin &soo, const vector<uint32_t > &commlist,
918
920
const vector<string> &origin_vn_path, const LoadBalance &lb,
919
- const vector<int > tag_list) {
921
+ const vector<int > tag_list, bool retain_as_path= false ) {
920
922
BgpAttrPtr attr = path->GetAttr ();
921
923
if (attr->nexthop ().to_v4 ().to_string () != path_id)
922
924
return false ;
923
925
if (GetOriginVnFromRoute (path) != origin_vn)
924
926
return false ;
925
927
if (label && path->GetLabel () != label)
926
928
return false ;
927
- if (attr->as_path_count ())
928
- return false ;
929
+ if (retain_as_path) {
930
+ if (!attr->as_path_count ()) {
931
+ return false ;
932
+ }
933
+ } else {
934
+ if (attr->as_path_count ()) {
935
+ return false ;
936
+ }
937
+ }
929
938
if (sg_ids.size ()) {
930
939
vector<uint32_t > path_sg_ids = GetSGIDListFromRoute (path);
931
940
if (path_sg_ids.size () != sg_ids.size ())
@@ -1019,7 +1028,7 @@ class ServiceChainTest : public ::testing::Test {
1019
1028
const SiteOfOrigin &soo, const vector<uint32_t > &commlist,
1020
1029
const vector<string> &origin_vn_path,
1021
1030
const LoadBalance &lb, const vector<int > tag_list,
1022
- bool replication=false ) {
1031
+ bool replication=false , bool retain_as_path= false ) {
1023
1032
task_util::TaskSchedulerLock lock;
1024
1033
BgpRoute *route = RouteLookup (instance, prefix, replication);
1025
1034
if (!route)
@@ -1036,7 +1045,7 @@ class ServiceChainTest : public ::testing::Test {
1036
1045
found = true ;
1037
1046
if (MatchPathAttributes (path, path_id, origin_vn, label,
1038
1047
sg_ids, tunnel_encap, soo, commlist, origin_vn_path,
1039
- lb, tag_list)) {
1048
+ lb, tag_list, retain_as_path )) {
1040
1049
break ;
1041
1050
}
1042
1051
return false ;
@@ -1063,14 +1072,14 @@ class ServiceChainTest : public ::testing::Test {
1063
1072
1064
1073
void VerifyRouteAttributes (const string &instance,
1065
1074
const string &prefix, const string &path_id, const string &origin_vn,
1066
- int label = 0 , bool replication=false ) {
1075
+ int label = 0 , bool replication=false , bool retain_as_path= false ) {
1067
1076
task_util::WaitForIdle ();
1068
1077
vector<string> path_ids = list_of (path_id);
1069
1078
vector<uint32_t > commlist = list_of (CommunityType::AcceptOwnNexthop);
1070
1079
TASK_UTIL_EXPECT_TRUE (CheckRouteAttributes (
1071
1080
instance, prefix, path_ids, origin_vn, label, vector<uint32_t >(),
1072
1081
set<string>(), SiteOfOrigin (), commlist, vector<string>(),
1073
- LoadBalance (), vector<int >(), replication));
1082
+ LoadBalance (), vector<int >(), replication, retain_as_path ));
1074
1083
}
1075
1084
1076
1085
void VerifyRouteAttributes (const string &instance, const string &prefix,
@@ -1263,9 +1272,10 @@ class ServiceChainTest : public ::testing::Test {
1263
1272
}
1264
1273
1265
1274
void SetServiceChainInformation (const string &instance,
1266
- const string &filename) {
1275
+ const string &filename, bool retain_as_path= false ) {
1267
1276
auto_ptr<autogen::ServiceChainInfo> params = GetChainConfig (filename);
1268
1277
params->sc_head = true ;
1278
+ params->retain_as_path = retain_as_path;
1269
1279
ifmap_test_util::IFMapMsgPropertyAdd (&config_db_, " routing-instance" ,
1270
1280
instance, sc_family_ == SCAddress::INET ?
1271
1281
" service-chain-information" : (sc_family_ == SCAddress::INET6 ?
@@ -3876,6 +3886,54 @@ TYPED_TEST(ServiceChainTest, ExtConnectRouteOriginVnUnresolved1) {
3876
3886
this ->DeleteConnectedRoute (NULL , this ->BuildConnPrefix (" 1.1.2.3" , 32 ));
3877
3887
}
3878
3888
3889
+ //
3890
+ // Service chain route should be added for routes with unresolved origin
3891
+ // vn if there is at least one route target matching an export target of
3892
+ // the destination instance. Also AsPath should be retained.
3893
+ //
3894
+ // 1. Create Service Chain with 192.168.1.0/24 as vn subnet
3895
+ // 2. Add connected route
3896
+ // 3. Add MX leaked route 10.1.1.0/24 with unresolved OriginVn
3897
+ // 4. Verify that ext connect route 10.1.1.0/24 is added
3898
+ //
3899
+ TYPED_TEST (ServiceChainTest, ExtConnectRouteRetainAsPath1) {
3900
+ if (this ->GetFamily () == Address::EVPN) return ;
3901
+ vector<string> instance_names =
3902
+ list_of (" blue" )(" blue-i1" )(" red-i2" )(" red" )(" green" );
3903
+ multimap<string, string> connections =
3904
+ map_list_of (" blue" , " blue-i1" ) (" red-i2" , " red" );
3905
+ this ->NetworkConfig (instance_names, connections);
3906
+ this ->VerifyNetworkConfig (instance_names);
3907
+
3908
+ this ->SetServiceChainInformation (" blue-i1" ,
3909
+ " controller/src/bgp/testdata/service_chain_1.xml" , true );
3910
+
3911
+ // Add Connected
3912
+ this ->AddConnectedRoute (NULL , this ->BuildConnPrefix (" 1.1.2.3" , 32 ), 100 ,
3913
+ this ->BuildNextHopAddress (" 2.3.4.5" ));
3914
+
3915
+ // Add Ext connect route with targets of both red and green.
3916
+ this ->AddVpnRoute (NULL , " red" , this ->BuildPrefix (" 10.1.1.0" , 24 ), 100 );
3917
+
3918
+ // Verify that MX leaked route is present in red
3919
+ this ->VerifyRouteExists (" red" , this ->BuildPrefix (" 10.1.1.0" , 24 ));
3920
+
3921
+ // Verify that ExtConnect route is present in blue
3922
+ this ->VerifyRouteExists (" blue" , this ->BuildPrefix (" 10.1.1.0" , 24 ));
3923
+ this ->VerifyRouteAttributes (" blue" , this ->BuildPrefix (" 10.1.1.0" , 24 ),
3924
+ this ->BuildNextHopAddress (" 2.3.4.5" ), " red" ,
3925
+ 0 , false , true );
3926
+ this ->VerifyRouteExists (" blue" ,
3927
+ this ->BuildReplicationPrefix (" 10.1.1.0" , 24 ), true );
3928
+ this ->VerifyRouteAttributes (" blue" ,
3929
+ this ->BuildReplicationPrefix (" 10.1.1.0" , 24 ),
3930
+ this ->BuildNextHopAddress (" 2.3.4.5" ), " red" , 0 , true , true );
3931
+
3932
+ // Delete ExtRoute and connected route
3933
+ this ->DeleteVpnRoute (NULL , " red" , this ->BuildPrefix (" 10.1.1.0" , 24 ));
3934
+ this ->DeleteConnectedRoute (NULL , this ->BuildConnPrefix (" 1.1.2.3" , 32 ));
3935
+ }
3936
+
3879
3937
//
3880
3938
// Service chain route must not be added for routes with unresolved origin
3881
3939
// vn if there is no route target matching an export target of destination
0 commit comments