summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/lib/packet/bgp.py19
-rw-r--r--ryu/services/protocols/bgp/api/base.py1
-rw-r--r--ryu/services/protocols/bgp/api/rtconf.py4
-rw-r--r--ryu/services/protocols/bgp/core_managers/table_manager.py7
-rw-r--r--ryu/tests/unit/packet/.test_bgp.py.swpbin0 -> 1024 bytes
5 files changed, 23 insertions, 8 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 89ed191e..6aabc843 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -106,10 +106,11 @@ BGP_ATTR_ORIGIN_INCOMPLETE = 0x02
AS_TRANS = 23456 # RFC 4893
-# Well known commmunities (RFC 1997)
-BGP_COMMUNITY_NO_EXPORT = 0xffffff01
-BGP_COMMUNITY_NO_ADVERTISE = 0xffffff02
-BGP_COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03
+# Well known commmunities
+BGP_COMMUNITY_BLACKHOLE = 0xffff029a # RFC 7999
+BGP_COMMUNITY_NO_EXPORT = 0xffffff01 # RFC 1997
+BGP_COMMUNITY_NO_ADVERTISE = 0xffffff02 # RFC 1997
+BGP_COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03 # RFC 1997
# RFC 4360
# The low-order octet of Type field (subtype)
@@ -3963,10 +3964,11 @@ class BGPPathAttributeCommunities(_PathAttribute):
_ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
# String constants of well-known-communities
+ BLACKHOLE = int('0xFFFF029A', 16)
NO_EXPORT = int('0xFFFFFF01', 16)
NO_ADVERTISE = int('0xFFFFFF02', 16)
NO_EXPORT_SUBCONFED = int('0xFFFFFF03', 16)
- WELL_KNOW_COMMUNITIES = (NO_EXPORT, NO_ADVERTISE, NO_EXPORT_SUBCONFED)
+ WELL_KNOW_COMMUNITIES = (BLACKHOLE, NO_EXPORT, NO_ADVERTISE, NO_EXPORT_SUBCONFED)
def __init__(self, communities,
flags=0, type_=None, length=None):
@@ -3998,6 +4000,13 @@ class BGPPathAttributeCommunities(_PathAttribute):
return buf
@staticmethod
+ def is_blackhole(comm_attr):
+ """Returns True if given value matches well-known community BLACKHOLE
+ attribute value.
+ """
+ return comm_attr == BGPPathAttributeCommunities.BLACKHOLE
+
+ @staticmethod
def is_no_export(comm_attr):
"""Returns True if given value matches well-known community NO_EXPORT
attribute value.
diff --git a/ryu/services/protocols/bgp/api/base.py b/ryu/services/protocols/bgp/api/base.py
index 598ee04b..33f2a7cc 100644
--- a/ryu/services/protocols/bgp/api/base.py
+++ b/ryu/services/protocols/bgp/api/base.py
@@ -58,6 +58,7 @@ FLOWSPEC_FAMILY = 'flowspec_family'
FLOWSPEC_RULES = 'rules'
FLOWSPEC_ACTIONS = 'actions'
AS_PATH = 'as_path'
+COMMUNITIES = 'communities'
# API call registry
_CALL_REGISTRY = {}
diff --git a/ryu/services/protocols/bgp/api/rtconf.py b/ryu/services/protocols/bgp/api/rtconf.py
index 82da22f0..54f89c27 100644
--- a/ryu/services/protocols/bgp/api/rtconf.py
+++ b/ryu/services/protocols/bgp/api/rtconf.py
@@ -273,9 +273,9 @@ def get_vrfs_conf():
@register(name='network.add')
-def add_network(prefix, next_hop=None, as_path=None):
+def add_network(prefix, next_hop=None, as_path=None, communities=None):
tm = CORE_MANAGER.get_core_service().table_manager
- tm.update_global_table(prefix, next_hop, as_path=as_path)
+ tm.update_global_table(prefix, next_hop, as_path=as_path, communities=communities)
return True
diff --git a/ryu/services/protocols/bgp/core_managers/table_manager.py b/ryu/services/protocols/bgp/core_managers/table_manager.py
index b60b785d..89dd3182 100644
--- a/ryu/services/protocols/bgp/core_managers/table_manager.py
+++ b/ryu/services/protocols/bgp/core_managers/table_manager.py
@@ -50,9 +50,11 @@ from ryu.lib.packet.bgp import RF_VPNv4_FLOWSPEC
from ryu.lib.packet.bgp import RF_VPNv6_FLOWSPEC
from ryu.lib.packet.bgp import RF_L2VPN_FLOWSPEC
from ryu.lib.packet.bgp import RF_RTC_UC
+from ryu.lib.packet.bgp import BGPPathAttributeCommunities
from ryu.lib.packet.bgp import BGPPathAttributeOrigin
from ryu.lib.packet.bgp import BGPPathAttributeAsPath
from ryu.lib.packet.bgp import BGPPathAttributeExtendedCommunities
+from ryu.lib.packet.bgp import BGP_ATTR_TYPE_COMMUNITIES
from ryu.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
from ryu.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
from ryu.lib.packet.bgp import BGP_ATTR_ORIGIN_IGP
@@ -772,7 +774,7 @@ class TableCoreManager(object):
nlri=prefix, communities=communities,
is_withdraw=is_withdraw)
- def update_global_table(self, prefix, next_hop=None, is_withdraw=False, as_path=None):
+ def update_global_table(self, prefix, next_hop=None, is_withdraw=False, as_path=None, communities=None):
"""Update a BGP route in the Global table for the given `prefix`
with the given `next_hop`.
@@ -792,6 +794,9 @@ class TableCoreManager(object):
pathattrs[BGP_ATTR_TYPE_ORIGIN] = origin
pathattrs[BGP_ATTR_TYPE_AS_PATH] = aspath
+ if communities:
+ pathattrs[BGP_ATTR_TYPE_COMMUNITIES] = BGPPathAttributeCommunities(communities)
+
net = netaddr.IPNetwork(prefix)
addr = str(net.ip)
masklen = net.prefixlen
diff --git a/ryu/tests/unit/packet/.test_bgp.py.swp b/ryu/tests/unit/packet/.test_bgp.py.swp
new file mode 100644
index 00000000..dd9b5b83
--- /dev/null
+++ b/ryu/tests/unit/packet/.test_bgp.py.swp
Binary files differ