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