Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_ROUTING_INSTANCE_RTARGET_GROUP_H_ 6 : #define SRC_BGP_ROUTING_INSTANCE_RTARGET_GROUP_H_ 7 : 8 : #include <map> 9 : #include <set> 10 : #include <string> 11 : #include <vector> 12 : 13 : #include "base/bitset.h" 14 : #include "base/util.h" 15 : #include "base/address.h" 16 : #include "bgp/rtarget/rtarget_address.h" 17 : 18 : class BgpPeer; 19 : class BgpRoute; 20 : class BgpTable; 21 : class RTargetRoute; 22 : class ShowRtGroupMemberTableList; 23 : class ShowRtGroupInfo; 24 : 25 : class RtGroupInterestedPeerSet : public BitSet { 26 : }; 27 : 28 : // 29 : // This class keeps track of state per RouteTarget. It maintains three main 30 : // pieces of information. 31 : // 32 : // 1. The RtGroupMembers map and the RtGroupMemberList set are used to keep 33 : // per address family lists of import and export BgpTables. The lists are 34 : // updated from the RoutePathReplicator. 35 : // 36 : // 2. The RTargetDepRouteList and the RouteList are used to maintain a per 37 : // partition list of dependent BgpRoutes i.e. routes with the RouteTarget 38 : // as one of their route targets. Each entry in the RTargetDepRouteList 39 : // vector corresponds to a DB partition. 40 : // 41 : // The list of dependent BgpRoutes is updated from DB task when handling 42 : // notifications for BgpRoutes in various VPN tables e.g. bgp.l3vpn.0 and 43 : // bgp.evpn.0. Since we could be processing multiple notifications (each 44 : // from a different partition) in parallel, we keep a separate RouteList 45 : // per partition id. The RouteLists are accessed from the RTFilter task 46 : // to trigger re-evaluation of export policy for dependent BgpRoutes based 47 : // on receiving advertisements/withdrawals for RTargetRoutes. 48 : // 49 : // 3. The InterestedPeerList map and RTargetRouteList set are used to keep a 50 : // list of peers interested in this RouteTarget. Since a peer could send 51 : // multiple RTargetRoutes for a given RouteTarget, we maintain a set of 52 : // RTargetRoutes per peer. A peer is added to the InterestedPeerList map 53 : // when the first RTargetRoute is added and removed from the map when the 54 : // last RTargetRoute is removed. 55 : // 56 : // Note that this class does not take any references on dependent BgpRoutes 57 : // or RTargetRoutes. It is the RTargetGroupManager's job to do that. Note 58 : // that each dependent BgpRoute may have multiple RouteTargets, so it doesn't 59 : // make sense to take a reference to the dependent route for each RouteTarget. 60 : // 61 : class RtGroup { 62 : public: 63 : typedef std::set<BgpTable *> RtGroupMemberList; 64 : typedef std::map<Address::Family, RtGroupMemberList> RtGroupMembers; 65 : typedef std::set<BgpRoute *> RouteList; 66 : typedef std::vector<RouteList> RTargetDepRouteList; 67 : typedef std::set<RTargetRoute *> RTargetRouteList; 68 : typedef std::map<const BgpPeer *, RTargetRouteList> InterestedPeerList; 69 : 70 : explicit RtGroup(const RouteTarget &rt); 71 : const RouteTarget &rt(); 72 5824 : std::string ToString() const { return rt_.ToString(); } 73 : bool MayDelete() const; 74 : 75 : const RtGroupMemberList &GetImportTables(Address::Family family) const; 76 : const RtGroupMemberList &GetExportTables(Address::Family family) const; 77 : 78 : bool AddImportTable(Address::Family family, BgpTable *tbl); 79 : bool AddExportTable(Address::Family family, BgpTable *tbl); 80 : bool RemoveImportTable(Address::Family family, BgpTable *tbl); 81 : bool RemoveExportTable(Address::Family family, BgpTable *tbl); 82 : bool HasImportExportTables() const; 83 : bool HasVrfTables(Address::Family family) const; 84 : 85 : void AddDepRoute(int part_id, BgpRoute *rt); 86 : void RemoveDepRoute(int part_id, BgpRoute *rt); 87 : void NotifyDepRoutes(int part_id); 88 : bool HasDepRoutes() const; 89 : 90 : const RtGroupInterestedPeerSet &GetInterestedPeers() const; 91 : void AddInterestedPeer(const BgpPeer *peer, RTargetRoute *rt); 92 : void RemoveInterestedPeer(const BgpPeer *peer, RTargetRoute *rt); 93 : bool HasInterestedPeers() const; 94 : bool HasInterestedPeer(const std::string &name) const; 95 : 96 : void FillShowInfo(ShowRtGroupInfo *info) const; 97 : void FillShowPeerInfo(ShowRtGroupInfo *info) const; 98 : void FillShowSummaryInfo(ShowRtGroupInfo *info) const; 99 : 100 : private: 101 : void FillMemberTables(const RtGroupMembers &rt_members, 102 : std::vector<ShowRtGroupMemberTableList> *member_list) const; 103 : void FillInterestedPeers(std::vector<std::string> *interested_peers) const; 104 : void FillDependentRoutes(std::vector<std::string> *rtlist) const; 105 : void FillShowInfoCommon( 106 : ShowRtGroupInfo *info, bool fill_peers, bool fill_routes) const; 107 : 108 : RouteTarget rt_; 109 : RtGroupMembers import_; 110 : RtGroupMembers export_; 111 : RTargetDepRouteList dep_; 112 : InterestedPeerList peer_list_; 113 : RtGroupInterestedPeerSet interested_peers_; 114 : 115 : DISALLOW_COPY_AND_ASSIGN(RtGroup); 116 : }; 117 : 118 : #endif // SRC_BGP_ROUTING_INSTANCE_RTARGET_GROUP_H_