diff --git a/src/config/schema-transformer/config_db.py b/src/config/schema-transformer/config_db.py index 703634dcdc4..dcb7f94f1f1 100644 --- a/src/config/schema-transformer/config_db.py +++ b/src/config/schema-transformer/config_db.py @@ -778,8 +778,8 @@ def init_static_ip_routes(self): static_route_entries = primary_ri.obj.get_static_route_entries( ) or StaticRouteEntriesType() for sr in static_route_entries.get_route() or []: - self.ip_routes[sr.prefix] = sr.next_hop - #end init_static_ip_routes + self.ip_routes[sr.prefix] = (sr.next_hop, sr.community) + # end init_static_ip_routes def update_static_ip_routes(self, new_ip_routes): primary_ri = self.get_primary_routing_instance() @@ -790,8 +790,10 @@ def update_static_ip_routes(self, new_ip_routes): return static_route_entries = StaticRouteEntriesType() - for prefix, next_hop_ip in new_ip_routes.items(): - static_route = StaticRouteType(prefix=prefix, next_hop=next_hop_ip) + for prefix, nh_comm in new_ip_routes.items(): + static_route = StaticRouteType(prefix=prefix, + next_hop=nh_comm[0], + community=nh_comm[1]) static_route_entries.add_route(static_route) primary_ri.obj.set_static_route_entries(static_route_entries) @@ -882,7 +884,9 @@ def update_route_table(self): self.delete_route(route.prefix) # end if route.next_hop_type == "ip-address": - new_ip_map[route.prefix] = route.next_hop + cattr = route.get_community_attributes() + communities = cattr.community_attribute if cattr else None + new_ip_map[route.prefix] = (route.next_hop, communities) else: self.add_route(route.prefix, route.next_hop) # end for route diff --git a/src/config/schema-transformer/test/test_service.py b/src/config/schema-transformer/test/test_service.py index ceed22b4a4f..52c9e85f49a 100644 --- a/src/config/schema-transformer/test/test_service.py +++ b/src/config/schema-transformer/test/test_service.py @@ -1316,33 +1316,42 @@ def test_add_delete_static_route(self): self._vnc_lib.route_table_create(rt) vn1.add_route_table(rt) self._vnc_lib.virtual_network_update(vn1) + comm_attr = CommunityAttributes(community_attribute=['1:1']) routes = RouteTableType() route = RouteType(prefix="1.1.1.1/0", - next_hop="10.10.10.10", next_hop_type="ip-address") + next_hop="10.10.10.10", next_hop_type="ip-address", + community_attributes=comm_attr) routes.add_route(route) rt.set_routes(routes) self._vnc_lib.route_table_update(rt) @retries(5) - def _match_route_table(vn, prefix, next_hop, should_present=True): + def _match_route_table(vn, prefix, next_hop, communities, + should_be_present=True): ri = self._vnc_lib.routing_instance_read( fq_name=self.get_ri_name(vn)) sr_list = ri.get_static_route_entries() if sr_list is None: - if should_present: + if should_be_present: raise Exception("sr is None") else: return found = False for sr in sr_list.get_route() or []: - if sr.prefix == prefix and sr.next_hop == next_hop: + if (sr.prefix == prefix and sr.next_hop == next_hop and + sr.community == communities): found = True break - if found != should_present: + if found != should_be_present: raise Exception("route " + prefix + "" + next_hop + "not found") return - _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10") + _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", ['1:1']) + + route.community_attributes.community_attribute.append('1:2') + rt.set_routes(routes) + self._vnc_lib.route_table_update(rt) + _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", ['1:1', '1:2']) route = RouteType(prefix="2.2.2.2/0", next_hop="20.20.20.20", next_hop_type="ip-address") @@ -1350,24 +1359,24 @@ def _match_route_table(vn, prefix, next_hop, should_present=True): rt.set_routes(routes) self._vnc_lib.route_table_update(rt) - _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10") - _match_route_table(vn1, "2.2.2.2/0", "20.20.20.20") + _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", ['1:1', '1:2']) + _match_route_table(vn1, "2.2.2.2/0", "20.20.20.20", []) vn2.add_route_table(rt) self._vnc_lib.virtual_network_update(vn2) - _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10") - _match_route_table(vn1, "2.2.2.2/0", "20.20.20.20") - _match_route_table(vn2, "1.1.1.1/0", "10.10.10.10") - _match_route_table(vn2, "2.2.2.2/0", "20.20.20.20") + _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", ['1:1', '1:2']) + _match_route_table(vn1, "2.2.2.2/0", "20.20.20.20", []) + _match_route_table(vn2, "1.1.1.1/0", "10.10.10.10", ['1:1', '1:2']) + _match_route_table(vn2, "2.2.2.2/0", "20.20.20.20", []) # delete second route and check vn ri sr entries routes.delete_route(route) rt.set_routes(routes) self._vnc_lib.route_table_update(rt) - _match_route_table(vn1, "2.2.2.2/0", "20.20.20.20", False) - _match_route_table(vn2, "2.2.2.2/0", "20.20.20.20", False) + _match_route_table(vn1, "2.2.2.2/0", "20.20.20.20", [], False) + _match_route_table(vn2, "2.2.2.2/0", "20.20.20.20", [], False) @retries(5) def _match_route_table_cleanup(vn): @@ -1379,14 +1388,14 @@ def _match_route_table_cleanup(vn): vn2.del_route_table(rt) self._vnc_lib.virtual_network_update(vn2) - _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10") + _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", ['1:1', '1:2']) _match_route_table_cleanup(vn2) # delete first route and check vn ri sr entries rt.set_routes(None) self._vnc_lib.route_table_update(rt) - _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", False) + _match_route_table(vn1, "1.1.1.1/0", "10.10.10.10", [], False) vn1.del_route_table(rt) self._vnc_lib.virtual_network_update(vn1) diff --git a/src/schema/routing_policy.xsd b/src/schema/routing_policy.xsd index 92003bd7d36..1f566c62757 100644 --- a/src/schema/routing_policy.xsd +++ b/src/schema/routing_policy.xsd @@ -23,6 +23,21 @@ + + + List of Community attributes + This list indicates the attributes with which routes are tagged while + publishing. The attributes will be represented as bgp community in + the path attribute. Each attribute is indicated as string + 1. String with two integer seperated by ':'. E.g. "64512:123" + 2. Wellknown community as string. Possible values are + "no-export" + "accept-own" + "no-advertise" + "no-export-subconfed" + "no-reoriginate" + + diff --git a/src/schema/vnc_cfg.xsd b/src/schema/vnc_cfg.xsd index 07e1b15a9e2..26147feaf9e 100644 --- a/src/schema/vnc_cfg.xsd +++ b/src/schema/vnc_cfg.xsd @@ -1669,8 +1669,8 @@ targetNamespace="http://www.contrailsystems.com/2012/VNC-CONFIG/0"> List of Community attributes - This list indicates the attributes with which routes are tagged while - publishing. The attributes will be represented as bgp community in + This list indicates the attributes with which routes are tagged while + publishing. The attributes will be represented as bgp community in the path attribute. Each attribute is indicated as string 1. String with two integer seperated by ':'. E.g. "64512:123" 2. Wellknown community as string. Possible values are