Skip to content

Commit

Permalink
BGPm for 201811 (#3601)
Browse files Browse the repository at this point in the history
* Feature is downported

* Add monitors to the test minigraphs

* Test

* No pfx filer

* Fix bgp sample

* Quagga requires to activate peer-group before configuration
  • Loading branch information
pavel-shirshov authored and yxieca committed Oct 16, 2019
1 parent 241b6fa commit c259f40
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 2 deletions.
27 changes: 27 additions & 0 deletions dockers/docker-fpm-quagga/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
!
route-map TO_BGP_SPEAKER_V4 deny 10
!
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
route-map FROM_BGPMON_V4 deny 10
!
route-map TO_BGPMON_V4 permit 10
!
{% endif %}
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
Expand Down Expand Up @@ -130,6 +136,27 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endfor %}
{% endif %}
{% endblock bgp_peers_with_range %}
{% block bgp_monitors %}
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
neighbor BGPMON_V4 peer-group
neighbor BGPMON_V4 activate
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if prefix | ipv4 and name == 'Loopback0' %}
neighbor BGPMON_V4 update-source {{ prefix | ip }}
{% endif %}
{% endfor %}
neighbor BGPMON_V4 route-map FROM_BGPMON_V4 in
neighbor BGPMON_V4 route-map TO_BGPMON_V4 out
neighbor BGPMON_V4 send-community
neighbor BGPMON_V4 maximum-prefix 1
{% for neighbor_addr, bgp_session in BGP_MONITORS.items() %}
neighbor {{ neighbor_addr }} remote-as {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
neighbor {{ neighbor_addr }} peer-group BGPMON_V4
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
neighbor {{ neighbor_addr }} activate
{% endfor %}
{% endif %}
{% endblock bgp_monitors %}
!
{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %}
maximum-paths 64
Expand Down
8 changes: 6 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ def parse_cpg(cpg, hname):
bgp_session = bgp_sessions[peer]
if hostname.lower() == bgp_session['name'].lower():
bgp_session['asn'] = asn
bgp_monitors = { key: bgp_sessions[key] for key in bgp_sessions if bgp_sessions[key].has_key('asn') and bgp_sessions[key]['name'] == 'BGPMonitor' }
bgp_sessions = { key: bgp_sessions[key] for key in bgp_sessions if bgp_sessions[key].has_key('asn') and int(bgp_sessions[key]['asn']) != 0 }
return bgp_sessions, myasn, bgp_peers_with_range

return bgp_sessions, myasn, bgp_peers_with_range, bgp_monitors


def parse_meta(meta, hname):
Expand Down Expand Up @@ -421,6 +423,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
u_devices = None
hwsku = None
bgp_sessions = None
bgp_monitors = []
bgp_asn = None
intfs = None
vlan_intfs = None
Expand Down Expand Up @@ -464,7 +467,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
if child.tag == str(QName(ns, "DpgDec")):
(intfs, lo_intfs, mgmt_intf, vlans, vlan_members, pcs, pc_members, acls) = parse_dpg(child, hostname)
elif child.tag == str(QName(ns, "CpgDec")):
(bgp_sessions, bgp_asn, bgp_peers_with_range) = parse_cpg(child, hostname)
(bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname)
elif child.tag == str(QName(ns, "PngDec")):
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports) = parse_png(child, hostname)
elif child.tag == str(QName(ns, "UngDec")):
Expand All @@ -485,6 +488,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
'type': current_device['type']
}}
results['BGP_NEIGHBOR'] = bgp_sessions
results['BGP_MONITORS'] = bgp_monitors
results['BGP_PEER_RANGE'] = bgp_peers_with_range
if mgmt_routes:
# TODO: differentiate v4 and v6
Expand Down
15 changes: 15 additions & 0 deletions src/sonic-config-engine/tests/sample_output/bgpd_quagga.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
!
route-map TO_BGP_SPEAKER_V4 deny 10
!
route-map FROM_BGPMON_V4 deny 10
!
route-map TO_BGPMON_V4 permit 10
!
router bgp 65100
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
Expand Down Expand Up @@ -92,6 +96,17 @@ router bgp 65100
neighbor fc00::76 soft-reconfiguration inbound
maximum-paths 64
exit-address-family
neighbor BGPMON_V4 peer-group
neighbor BGPMON_V4 activate
neighbor BGPMON_V4 update-source 10.1.0.32
neighbor BGPMON_V4 route-map FROM_BGPMON_V4 in
neighbor BGPMON_V4 route-map TO_BGPMON_V4 out
neighbor BGPMON_V4 send-community
neighbor BGPMON_V4 maximum-prefix 1
neighbor 10.20.30.40 remote-as 65100
neighbor 10.20.30.40 peer-group BGPMON_V4
neighbor 10.20.30.40 description BGPMonitor
neighbor 10.20.30.40 activate
!
maximum-paths 64
!
Expand Down
24 changes: 24 additions & 0 deletions src/sonic-config-engine/tests/simple-sample-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<CpgDec>
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
<PeeringSessions>
<BGPSession>
<StartRouter>switch-t0</StartRouter>
<StartPeer>10.1.0.32</StartPeer>
<EndRouter>BGPMonitor</EndRouter>
<EndPeer>10.20.30.40</EndPeer>
<Multihop>30</Multihop>
<HoldTime>10</HoldTime>
<KeepAliveTime>3</KeepAliveTime>
</BGPSession>
<BGPSession>
<MacSec>false</MacSec>
<StartRouter>switch-t0</StartRouter>
Expand Down Expand Up @@ -42,6 +51,21 @@
</BGPSession>
</PeeringSessions>
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
<a:BGPRouterDeclaration>
<a:ASN>0</a:ASN>
<a:BgpGroups/>
<a:Hostname>BGPMonitor</a:Hostname>
<a:Peers>
<BGPPeer>
<ElementType>BGPPeer</ElementType>
<Address>10.1.0.32</Address>
<RouteMapIn i:nil="true"/>
<RouteMapOut i:nil="true"/>
<Vrf i:nil="true"/>
</BGPPeer>
</a:Peers>
<a:RouteMaps/>
</a:BGPRouterDeclaration>
<a:BGPRouterDeclaration>
<a:ASN>65100</a:ASN>
<a:Hostname>switch-t0</a:Hostname>
Expand Down
24 changes: 24 additions & 0 deletions src/sonic-config-engine/tests/t0-sample-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<CpgDec>
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
<PeeringSessions>
<BGPSession>
<StartRouter>switch-t0</StartRouter>
<StartPeer>10.1.0.32</StartPeer>
<EndRouter>BGPMonitor</EndRouter>
<EndPeer>10.20.30.40</EndPeer>
<Multihop>30</Multihop>
<HoldTime>10</HoldTime>
<KeepAliveTime>3</KeepAliveTime>
</BGPSession>
<BGPSession>
<MacSec>false</MacSec>
<StartRouter>switch-t0</StartRouter>
Expand Down Expand Up @@ -80,6 +89,21 @@
</BGPSession>
</PeeringSessions>
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
<a:BGPRouterDeclaration>
<a:ASN>0</a:ASN>
<a:BgpGroups/>
<a:Hostname>BGPMonitor</a:Hostname>
<a:Peers>
<BGPPeer>
<ElementType>BGPPeer</ElementType>
<Address>10.1.0.32</Address>
<RouteMapIn i:nil="true"/>
<RouteMapOut i:nil="true"/>
<Vrf i:nil="true"/>
</BGPPeer>
</a:Peers>
<a:RouteMaps/>
</a:BGPRouterDeclaration>
<a:BGPRouterDeclaration>
<a:ASN>65100</a:ASN>
<a:Hostname>switch-t0</a:Hostname>
Expand Down
4 changes: 4 additions & 0 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,7 @@ def test_metadata_ntp(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'10.0.10.1': {}, '10.0.10.2': {}}")

def test_minigraph_bgp_mon(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "BGP_MONITORS"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'10.20.30.40': {'rrclient': 0, 'name': 'BGPMonitor', 'local_addr': '10.1.0.32', 'nhopself': 0, 'holdtime': '10', 'asn': '0', 'keepalive': '3'}}")

0 comments on commit c259f40

Please sign in to comment.