Skip to content

Commit

Permalink
[frr]: Support for nhopself, keepalive and holdtime timers, prefer gl…
Browse files Browse the repository at this point in the history
…obal ebgp nexthop (#1024)

* RR client support in minigraph for FRR
* Fix python warning from previous rrclient commit and move config handling to a more relevant place for this cmd
* Add config support for nhopself, keepalive and holdtime timers.
* Add route-map to prefer global nexthops for ebgp learned prefixes.
  • Loading branch information
nikos-github authored and Shuotian Cheng committed Oct 11, 2017
1 parent 6c15acc commit 51ebdf4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
13 changes: 13 additions & 0 deletions dockers/docker-fpm-frr/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_session['asn'] | int != 0 %}
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
neighbor {{ neighbor_addr }} timers {{ bgp_session['keepalive'] }} {{ bgp_session['holdtime'] }}
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1
{% endif %}
Expand All @@ -59,6 +60,9 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
neighbor {{ neighbor_addr }} activate
{% if bgp_session['rrclient'] | int != 0 %}
neighbor {{ neighbor_addr }} route-reflector-client
{% endif %}
{% if bgp_session['nhopself'] | int != 0 %}
neighbor {{ neighbor_addr }} next-hop-self
{% endif %}
maximum-paths 64
exit-address-family
Expand All @@ -68,6 +72,12 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
neighbor {{ neighbor_addr }} activate
{% if bgp_session['rrclient'] | int != 0 %}
neighbor {{ neighbor_addr }} route-reflector-client
{% endif %}
{% if bgp_session['nhopself'] | int != 0 %}
neighbor {{ neighbor_addr }} next-hop-self
{% endif %}
{% if bgp_session['asn'] != DEVICE_METADATA['localhost']['bgp_asn'] %}
neighbor {{ neighbor_addr }} route-map set-next-hop-global-v6 in
{% endif %}
maximum-paths 64
exit-address-family
Expand All @@ -81,3 +91,6 @@ maximum-paths 64
route-map ISOLATE permit 10
set as-path prepend {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
!
route-map set-next-hop-global-v6 permit 10
set ipv6 next-hop prefer-global
!
27 changes: 20 additions & 7 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,38 @@ def parse_cpg(cpg, hname):
start_peer = session.find(str(QName(ns, "StartPeer"))).text
end_router = session.find(str(QName(ns, "EndRouter"))).text
end_peer = session.find(str(QName(ns, "EndPeer"))).text
rrclient = 1 if session.find(str(QName(ns, "RRClient"))) is not None else 0
if session.find(str(QName(ns, "HoldTime"))) is not None:
holdtime = session.find(str(QName(ns, "HoldTime"))).text
else:
holdtime = 180
if session.find(str(QName(ns, "KeepAliveTime"))) is not None:
keepalive = session.find(str(QName(ns, "KeepAliveTime"))).text
else:
keepalive = 60
nhopself = 1 if session.find(str(QName(ns, "NextHopSelf"))) is not None else 0
if end_router == hname:
bgp_sessions[start_peer] = {
'name': start_router,
'local_addr': end_peer
'local_addr': end_peer,
'rrclient': rrclient,
'holdtime': holdtime,
'keepalive': keepalive,
'nhopself': nhopself
}
else:
bgp_sessions[end_peer] = {
'name': end_router,
'local_addr': start_peer
'local_addr': start_peer,
'rrclient': rrclient,
'holdtime': holdtime,
'keepalive': keepalive,
'nhopself': nhopself
}
elif child.tag == str(QName(ns, "Routers")):
for router in child.findall(str(QName(ns1, "BGPRouterDeclaration"))):
asn = router.find(str(QName(ns1, "ASN"))).text
hostname = router.find(str(QName(ns1, "Hostname"))).text
if router.find(str(QName(ns1, "RRClient"))):
rrclient = '1'
else:
rrclient = '0'
if hostname == hname:
myasn = asn
peers = router.find(str(QName(ns1, "Peers")))
Expand All @@ -260,7 +274,6 @@ def parse_cpg(cpg, hname):
bgp_session = bgp_sessions[peer]
if hostname == bgp_session['name']:
bgp_session['asn'] = asn
bgp_session['rrclient'] = rrclient

return bgp_sessions, myasn, bgp_peers_with_range

Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_minigraph_neighbors(self):
def test_minigraph_bgp(self):
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v "BGP_NEIGHBOR[\'10.0.0.59\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'rrclient': '0', 'local_addr': '10.0.0.58', 'asn': '64600', 'name': 'ARISTA02T1'}")
self.assertEqual(output.strip(), "{'rrclient': 0, 'name': 'ARISTA02T1', 'local_addr': '10.0.0.58', 'nhopself': 0, 'holdtime': '180', 'asn': '64600', 'keepalive': '60'}")

def test_minigraph_peers_with_range(self):
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v BGP_PEER_RANGE.values\(\)'
Expand Down

0 comments on commit 51ebdf4

Please sign in to comment.