Skip to content

Commit

Permalink
Copy communities from route table to static routes
Browse files Browse the repository at this point in the history
Change-Id: I6267ddd57437d3758bb1b0d93d51d90f16aa9469
Closes-Bug: 1549465
  • Loading branch information
Sachin Bansal committed Mar 7, 2016
1 parent acf4c45 commit 0afe7bc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
14 changes: 9 additions & 5 deletions src/config/schema-transformer/config_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
41 changes: 25 additions & 16 deletions src/config/schema-transformer/test/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,58 +1316,67 @@ 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")
routes.add_route(route)
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):
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions src/schema/routing_policy.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
</xsd:simpleType>

<xsd:complexType name='CommunityListType'>
<xsd:annotation>
<xsd:documentation>
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"
</xsd:documentation>
</xsd:annotation>
<xsd:element name='community' type='xsd:string' maxOccurs='unbounded'/>
</xsd:complexType>

Expand Down
4 changes: 2 additions & 2 deletions src/schema/vnc_cfg.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,8 @@ targetNamespace="http://www.contrailsystems.com/2012/VNC-CONFIG/0">
<xsd:annotation>
<xsd:documentation>
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
Expand Down

0 comments on commit 0afe7bc

Please sign in to comment.