Mark Bergsma has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/255544

Change subject: Add BGP MED support
......................................................................

Add BGP MED support

Adds a global pybal.conf configuration option 'bgp-med' which sets a
BGP MED attribute on all NLRI if non-zero. This can be used e.g. for
BGP failover between multiple PyBal instances where the router selects
the routes for the the PyBal instance with the lowest MED value as sent
by PyBal.

Change-Id: I589be24c275cc73a5c04312e68bdf509e8c2533f
---
M pybal/pybal.py
1 file changed, 6 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal 
refs/changes/44/255544/1

diff --git a/pybal/pybal.py b/pybal/pybal.py
index e34bc66..b4ac395 100755
--- a/pybal/pybal.py
+++ b/pybal/pybal.py
@@ -469,21 +469,20 @@
                                                   
peerAddr=self.globalConfig.get('bgp-peer-address'))
 
             asPath = [int(asn) for asn in self.globalConfig.get('bgp-as-path', 
str(self.bgpPeering.myASN)).split()]
-            attributes = {}
+            med = self.globalConfig.getint('bgp-med', 0)
+            baseAttrs = [bgp.OriginAttribute(), bgp.ASPathAttribute(asPath)]
+            if med: baseAttrs.append(bgp.MEDAttribute(med))
 
+            attributes = {}
             try:
-                attributes[(bgp.AFI_INET, bgp.SAFI_UNICAST)] = 
bgp.FrozenAttributeDict([
-                    bgp.OriginAttribute(),
-                    bgp.ASPathAttribute(asPath),
+                attributes[(bgp.AFI_INET, bgp.SAFI_UNICAST)] = 
bgp.FrozenAttributeDict(baseAttrs + [
                     
bgp.NextHopAttribute(self.globalConfig['bgp-nexthop-ipv4'])])
             except KeyError:
                 if (bgp.AFI_INET, bgp.SAFI_UNICAST) in BGPFailover.prefixes:
                     raise ValueError("IPv4 BGP NextHop (global configuration 
variable 'bgp-nexthop-ipv4') not set")
 
             try:
-                attributes[(bgp.AFI_INET6, bgp.SAFI_UNICAST)] = 
bgp.FrozenAttributeDict([
-                    bgp.OriginAttribute(),
-                    bgp.ASPathAttribute(asPath),
+                attributes[(bgp.AFI_INET6, bgp.SAFI_UNICAST)] = 
bgp.FrozenAttributeDict(baseAttrs + [
                     bgp.MPReachNLRIAttribute((bgp.AFI_INET6, bgp.SAFI_UNICAST,
                                              
bgp.IPv6IP(self.globalConfig['bgp-nexthop-ipv6']), []))])
             except KeyError:

-- 
To view, visit https://gerrit.wikimedia.org/r/255544
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I589be24c275cc73a5c04312e68bdf509e8c2533f
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: bgp-med
Gerrit-Owner: Mark Bergsma <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to