Skip to content

Commit c259f40

Browse files
pavel-shirshovyxieca
authored andcommitted
BGPm for 201811 (sonic-net#3601)
* Feature is downported * Add monitors to the test minigraphs * Test * No pfx filer * Fix bgp sample * Quagga requires to activate peer-group before configuration
1 parent 241b6fa commit c259f40

File tree

6 files changed

+100
-2
lines changed

6 files changed

+100
-2
lines changed

dockers/docker-fpm-quagga/bgpd.conf.j2

+27
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
2323
!
2424
route-map TO_BGP_SPEAKER_V4 deny 10
2525
!
26+
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
27+
route-map FROM_BGPMON_V4 deny 10
28+
!
29+
route-map TO_BGPMON_V4 permit 10
30+
!
31+
{% endif %}
2632
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
2733
bgp log-neighbor-changes
2834
bgp bestpath as-path multipath-relax
@@ -130,6 +136,27 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
130136
{% endfor %}
131137
{% endif %}
132138
{% endblock bgp_peers_with_range %}
139+
{% block bgp_monitors %}
140+
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
141+
neighbor BGPMON_V4 peer-group
142+
neighbor BGPMON_V4 activate
143+
{% for (name, prefix) in LOOPBACK_INTERFACE %}
144+
{% if prefix | ipv4 and name == 'Loopback0' %}
145+
neighbor BGPMON_V4 update-source {{ prefix | ip }}
146+
{% endif %}
147+
{% endfor %}
148+
neighbor BGPMON_V4 route-map FROM_BGPMON_V4 in
149+
neighbor BGPMON_V4 route-map TO_BGPMON_V4 out
150+
neighbor BGPMON_V4 send-community
151+
neighbor BGPMON_V4 maximum-prefix 1
152+
{% for neighbor_addr, bgp_session in BGP_MONITORS.items() %}
153+
neighbor {{ neighbor_addr }} remote-as {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
154+
neighbor {{ neighbor_addr }} peer-group BGPMON_V4
155+
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
156+
neighbor {{ neighbor_addr }} activate
157+
{% endfor %}
158+
{% endif %}
159+
{% endblock bgp_monitors %}
133160
!
134161
{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %}
135162
maximum-paths 64

src/sonic-config-engine/minigraph.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,10 @@ def parse_cpg(cpg, hname):
360360
bgp_session = bgp_sessions[peer]
361361
if hostname.lower() == bgp_session['name'].lower():
362362
bgp_session['asn'] = asn
363+
bgp_monitors = { key: bgp_sessions[key] for key in bgp_sessions if bgp_sessions[key].has_key('asn') and bgp_sessions[key]['name'] == 'BGPMonitor' }
363364
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 }
364-
return bgp_sessions, myasn, bgp_peers_with_range
365+
366+
return bgp_sessions, myasn, bgp_peers_with_range, bgp_monitors
365367

366368

367369
def parse_meta(meta, hname):
@@ -421,6 +423,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
421423
u_devices = None
422424
hwsku = None
423425
bgp_sessions = None
426+
bgp_monitors = []
424427
bgp_asn = None
425428
intfs = None
426429
vlan_intfs = None
@@ -464,7 +467,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
464467
if child.tag == str(QName(ns, "DpgDec")):
465468
(intfs, lo_intfs, mgmt_intf, vlans, vlan_members, pcs, pc_members, acls) = parse_dpg(child, hostname)
466469
elif child.tag == str(QName(ns, "CpgDec")):
467-
(bgp_sessions, bgp_asn, bgp_peers_with_range) = parse_cpg(child, hostname)
470+
(bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname)
468471
elif child.tag == str(QName(ns, "PngDec")):
469472
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports) = parse_png(child, hostname)
470473
elif child.tag == str(QName(ns, "UngDec")):
@@ -485,6 +488,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
485488
'type': current_device['type']
486489
}}
487490
results['BGP_NEIGHBOR'] = bgp_sessions
491+
results['BGP_MONITORS'] = bgp_monitors
488492
results['BGP_PEER_RANGE'] = bgp_peers_with_range
489493
if mgmt_routes:
490494
# TODO: differentiate v4 and v6

src/sonic-config-engine/tests/sample_output/bgpd_quagga.conf

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
1616
!
1717
route-map TO_BGP_SPEAKER_V4 deny 10
1818
!
19+
route-map FROM_BGPMON_V4 deny 10
20+
!
21+
route-map TO_BGPMON_V4 permit 10
22+
!
1923
router bgp 65100
2024
bgp log-neighbor-changes
2125
bgp bestpath as-path multipath-relax
@@ -92,6 +96,17 @@ router bgp 65100
9296
neighbor fc00::76 soft-reconfiguration inbound
9397
maximum-paths 64
9498
exit-address-family
99+
neighbor BGPMON_V4 peer-group
100+
neighbor BGPMON_V4 activate
101+
neighbor BGPMON_V4 update-source 10.1.0.32
102+
neighbor BGPMON_V4 route-map FROM_BGPMON_V4 in
103+
neighbor BGPMON_V4 route-map TO_BGPMON_V4 out
104+
neighbor BGPMON_V4 send-community
105+
neighbor BGPMON_V4 maximum-prefix 1
106+
neighbor 10.20.30.40 remote-as 65100
107+
neighbor 10.20.30.40 peer-group BGPMON_V4
108+
neighbor 10.20.30.40 description BGPMonitor
109+
neighbor 10.20.30.40 activate
95110
!
96111
maximum-paths 64
97112
!

src/sonic-config-engine/tests/simple-sample-graph.xml

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
<CpgDec>
33
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
44
<PeeringSessions>
5+
<BGPSession>
6+
<StartRouter>switch-t0</StartRouter>
7+
<StartPeer>10.1.0.32</StartPeer>
8+
<EndRouter>BGPMonitor</EndRouter>
9+
<EndPeer>10.20.30.40</EndPeer>
10+
<Multihop>30</Multihop>
11+
<HoldTime>10</HoldTime>
12+
<KeepAliveTime>3</KeepAliveTime>
13+
</BGPSession>
514
<BGPSession>
615
<MacSec>false</MacSec>
716
<StartRouter>switch-t0</StartRouter>
@@ -42,6 +51,21 @@
4251
</BGPSession>
4352
</PeeringSessions>
4453
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
54+
<a:BGPRouterDeclaration>
55+
<a:ASN>0</a:ASN>
56+
<a:BgpGroups/>
57+
<a:Hostname>BGPMonitor</a:Hostname>
58+
<a:Peers>
59+
<BGPPeer>
60+
<ElementType>BGPPeer</ElementType>
61+
<Address>10.1.0.32</Address>
62+
<RouteMapIn i:nil="true"/>
63+
<RouteMapOut i:nil="true"/>
64+
<Vrf i:nil="true"/>
65+
</BGPPeer>
66+
</a:Peers>
67+
<a:RouteMaps/>
68+
</a:BGPRouterDeclaration>
4569
<a:BGPRouterDeclaration>
4670
<a:ASN>65100</a:ASN>
4771
<a:Hostname>switch-t0</a:Hostname>

src/sonic-config-engine/tests/t0-sample-graph.xml

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
<CpgDec>
33
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
44
<PeeringSessions>
5+
<BGPSession>
6+
<StartRouter>switch-t0</StartRouter>
7+
<StartPeer>10.1.0.32</StartPeer>
8+
<EndRouter>BGPMonitor</EndRouter>
9+
<EndPeer>10.20.30.40</EndPeer>
10+
<Multihop>30</Multihop>
11+
<HoldTime>10</HoldTime>
12+
<KeepAliveTime>3</KeepAliveTime>
13+
</BGPSession>
514
<BGPSession>
615
<MacSec>false</MacSec>
716
<StartRouter>switch-t0</StartRouter>
@@ -80,6 +89,21 @@
8089
</BGPSession>
8190
</PeeringSessions>
8291
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
92+
<a:BGPRouterDeclaration>
93+
<a:ASN>0</a:ASN>
94+
<a:BgpGroups/>
95+
<a:Hostname>BGPMonitor</a:Hostname>
96+
<a:Peers>
97+
<BGPPeer>
98+
<ElementType>BGPPeer</ElementType>
99+
<Address>10.1.0.32</Address>
100+
<RouteMapIn i:nil="true"/>
101+
<RouteMapOut i:nil="true"/>
102+
<Vrf i:nil="true"/>
103+
</BGPPeer>
104+
</a:Peers>
105+
<a:RouteMaps/>
106+
</a:BGPRouterDeclaration>
83107
<a:BGPRouterDeclaration>
84108
<a:ASN>65100</a:ASN>
85109
<a:Hostname>switch-t0</a:Hostname>

src/sonic-config-engine/tests/test_cfggen.py

+4
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,7 @@ def test_metadata_ntp(self):
236236
output = self.run_script(argument)
237237
self.assertEqual(output.strip(), "{'10.0.10.1': {}, '10.0.10.2': {}}")
238238

239+
def test_minigraph_bgp_mon(self):
240+
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "BGP_MONITORS"'
241+
output = self.run_script(argument)
242+
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 commit comments

Comments
 (0)