diff --git a/ryu/services/protocols/bgp/peer.py b/ryu/services/protocols/bgp/peer.py index 70b486c0..2a0e2a9f 100644 --- a/ryu/services/protocols/bgp/peer.py +++ b/ryu/services/protocols/bgp/peer.py @@ -989,37 +989,32 @@ class Peer(Source, Sink, NeighborConfListener, Activity): elif self.is_route_server_client: nlri_list = [path.nlri] new_pathattr.extend(pathattr_map.values()) - elif self.is_route_reflector_client: - nlri_list = [path.nlri] + else: + if self.is_route_reflector_client: + # Append ORIGINATOR_ID attribute if not already exist. + if BGP_ATTR_TYPE_ORIGINATOR_ID not in pathattr_map: + originator_id = path.source + if originator_id is None: + originator_id = self._common_conf.router_id + elif isinstance(path.source, Peer): + originator_id = path.source.ip_address + new_pathattr.append( + BGPPathAttributeOriginatorId(value=originator_id)) - # Append ORIGINATOR_ID attribute if not already exists. - if BGP_ATTR_TYPE_ORIGINATOR_ID not in pathattr_map: - originator_id = path.source - if originator_id is None: - originator_id = self._common_conf.router_id - elif isinstance(path.source, Peer): - originator_id = path.source.ip_address - new_pathattr.append( - BGPPathAttributeOriginatorId(value=originator_id)) - - # Append CLUSTER_LIST attribute if not already exists. - if BGP_ATTR_TYPE_CLUSTER_LIST not in pathattr_map: - new_pathattr.append( - BGPPathAttributeClusterList( - [self._common_conf.cluster_id])) - - for t, path_attr in pathattr_map.items(): - if t == BGP_ATTR_TYPE_CLUSTER_LIST: - # Append own CLUSTER_ID into CLUSTER_LIST attribute - # if already exists. - cluster_list = list(path_attr.value) + # Preppend own CLUSTER_ID into CLUSTER_LIST attribute if exist. + # Otherwise append CLUSTER_LIST attribute. + cluster_lst_attr = pathattr_map.get(BGP_ATTR_TYPE_CLUSTER_LIST) + if cluster_lst_attr: + cluster_list = list(cluster_lst_attr.value) if self._common_conf.cluster_id not in cluster_list: - cluster_list.append(self._common_conf.cluster_id) + cluster_list.insert(0, self._common_conf.cluster_id) new_pathattr.append( BGPPathAttributeClusterList(cluster_list)) else: - new_pathattr.append(path_attr) - else: + new_pathattr.append( + BGPPathAttributeClusterList( + [self._common_conf.cluster_id])) + # Supported and un-supported/unknown attributes. origin_attr = None nexthop_attr = None