diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-12-24 13:32:23 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-12-25 10:03:52 +0900 |
commit | d9ecfccdc81f7d7258e4650ed5a5205a8c978b1a (patch) | |
tree | d3264da0fa15dd3723e347958bad2a50bebeb9a4 | |
parent | fede089e939ba9e193bb6a866cd0dfb6dd9f4de6 (diff) |
bgp: fix handling unknown and unsupported transitive path
attributes
we must forward optional transitive path attributes.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/bgp.py | 1 | ||||
-rw-r--r-- | ryu/services/protocols/bgp/peer.py | 8 | ||||
-rw-r--r-- | ryu/services/protocols/bgp/utils/bgp.py | 42 |
3 files changed, 31 insertions, 20 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index f5575c46..66dbc3c7 100644 --- a/ryu/lib/packet/bgp.py +++ b/ryu/lib/packet/bgp.py @@ -1558,6 +1558,7 @@ class BGPPathAttributeAsPath(_BGPPathAttributeAsPathCommon): @_PathAttribute.register_type(BGP_ATTR_TYPE_AS4_PATH) class BGPPathAttributeAs4Path(_BGPPathAttributeAsPathCommon): _AS_PACK_STR = '!I' + _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE | BGP_ATTR_FLAG_OPTIONAL @classmethod def _is_valid_16bit_as_path(cls, buf): diff --git a/ryu/services/protocols/bgp/peer.py b/ryu/services/protocols/bgp/peer.py index fc8ee558..f95836ce 100644 --- a/ryu/services/protocols/bgp/peer.py +++ b/ryu/services/protocols/bgp/peer.py @@ -847,7 +847,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity): extcomm_attr = None community_attr = None localpref_attr = None - unkown_opttrans_attrs = None + unknown_opttrans_attrs = None nlri_list = [path.nlri] # By default we use BGPS's interface IP with this peer as next_hop. @@ -995,7 +995,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity): # UNKOWN Attributes. # Get optional transitive path attributes - unkown_opttrans_attrs = bgp_utils.get_unknow_opttrans_attr(path) + unknown_opttrans_attrs = bgp_utils.get_unknown_opttrans_attr(path) # Ordering path attributes according to type as RFC says. We set # MPReachNLRI first as advised by experts as a new trend in BGP @@ -1015,8 +1015,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity): new_pathattr.append(community_attr) if extcomm_attr: new_pathattr.append(extcomm_attr) - if unkown_opttrans_attrs: - new_pathattr.extend(unkown_opttrans_attrs.values()) + if unknown_opttrans_attrs: + new_pathattr.extend(unknown_opttrans_attrs.values()) if isinstance(path, Ipv4Path): update = BGPUpdate(path_attributes=new_pathattr, diff --git a/ryu/services/protocols/bgp/utils/bgp.py b/ryu/services/protocols/bgp/utils/bgp.py index 28e010a2..43793570 100644 --- a/ryu/services/protocols/bgp/utils/bgp.py +++ b/ryu/services/protocols/bgp/utils/bgp.py @@ -19,17 +19,23 @@ import logging import socket -from ryu.lib.packet.bgp import BGPUpdate -from ryu.lib.packet.bgp import RF_IPv4_UC -from ryu.lib.packet.bgp import RF_IPv6_UC -from ryu.lib.packet.bgp import RF_IPv4_VPN -from ryu.lib.packet.bgp import RF_IPv6_VPN -from ryu.lib.packet.bgp import RF_RTC_UC -from ryu.lib.packet.bgp import RouteTargetMembershipNLRI -from ryu.lib.packet.bgp import BGP_ATTR_TYPE_MULTI_EXIT_DISC -from ryu.lib.packet.bgp import BGPPathAttributeMultiExitDisc -from ryu.lib.packet.bgp import BGPPathAttributeMpUnreachNLRI -from ryu.lib.packet.bgp import BGPPathAttributeUnknown +from ryu.lib.packet.bgp import ( + BGPUpdate, + RF_IPv4_UC, + RF_IPv6_UC, + RF_IPv4_VPN, + RF_IPv6_VPN, + RF_RTC_UC, + RouteTargetMembershipNLRI, + BGP_ATTR_TYPE_MULTI_EXIT_DISC, + BGPPathAttributeMultiExitDisc, + BGPPathAttributeMpUnreachNLRI, + BGPPathAttributeAs4Path, + BGPPathAttributeAs4Aggregator, + BGPPathAttributeUnknown, + BGP_ATTR_FLAG_OPTIONAL, + BGP_ATTR_FLAG_TRANSITIVE, +) from ryu.services.protocols.bgp.info_base.rtc import RtcPath from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path from ryu.services.protocols.bgp.info_base.ipv6 import Ipv6Path @@ -102,9 +108,9 @@ def from_inet_ptoi(bgp_id): return four_byte_id -def get_unknow_opttrans_attr(path): - """Utility method that gives a `dict` of unknown optional transitive - path attributes of `path`. +def get_unknown_opttrans_attr(path): + """Utility method that gives a `dict` of unknown and unsupported optional + transitive path attributes of `path`. Returns dict: <key> - attribute type code, <value> - unknown path-attr. """ @@ -112,8 +118,12 @@ def get_unknow_opttrans_attr(path): unknown_opt_tran_attrs = {} for _, attr in path_attrs.items(): if (isinstance(attr, BGPPathAttributeUnknown) and - attr.is_optional_transitive()): - unknown_opt_tran_attrs[attr.type_code] = attr + attr.flags & (BGP_ATTR_FLAG_OPTIONAL | + BGP_ATTR_FLAG_TRANSITIVE)) or \ + isinstance(attr, BGPPathAttributeAs4Path) or \ + isinstance(attr, BGPPathAttributeAs4Aggregator): + unknown_opt_tran_attrs[attr.type] = attr + return unknown_opt_tran_attrs |