OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rtarget_group.h
Go to the documentation of this file.
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"
17 
18 class BgpPeer;
19 class BgpRoute;
20 class BgpTable;
21 class RTargetRoute;
22 class ShowRtGroupMemberTableList;
23 class ShowRtGroupInfo;
24 
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  std::string ToString() const { return rt_.ToString(); }
73  bool MayDelete() const;
74 
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 
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 
114 
116 };
117 
118 #endif // SRC_BGP_ROUTING_INSTANCE_RTARGET_GROUP_H_
void FillShowPeerInfo(ShowRtGroupInfo *info) const
std::map< const BgpPeer *, RTargetRouteList > InterestedPeerList
Definition: rtarget_group.h:68
std::set< RTargetRoute * > RTargetRouteList
Definition: rtarget_group.h:67
bool RemoveImportTable(Address::Family family, BgpTable *tbl)
void RemoveDepRoute(int part_id, BgpRoute *rt)
std::set< BgpTable * > RtGroupMemberList
Definition: rtarget_group.h:63
DISALLOW_COPY_AND_ASSIGN(RtGroup)
void FillShowInfoCommon(ShowRtGroupInfo *info, bool fill_peers, bool fill_routes) const
void FillMemberTables(const RtGroupMembers &rt_members, std::vector< ShowRtGroupMemberTableList > *member_list) const
bool AddExportTable(Address::Family family, BgpTable *tbl)
const RtGroupMemberList & GetExportTables(Address::Family family) const
bool HasDepRoutes() const
Family
Definition: address.h:24
RouteTarget rt_
const RtGroupMemberList & GetImportTables(Address::Family family) const
void FillInterestedPeers(std::vector< std::string > *interested_peers) const
InterestedPeerList peer_list_
RtGroupInterestedPeerSet interested_peers_
void AddDepRoute(int part_id, BgpRoute *rt)
const RtGroupInterestedPeerSet & GetInterestedPeers() const
void FillShowSummaryInfo(ShowRtGroupInfo *info) const
bool HasVrfTables(Address::Family family) const
void FillDependentRoutes(std::vector< std::string > *rtlist) const
bool MayDelete() const
bool HasInterestedPeers() const
bool AddImportTable(Address::Family family, BgpTable *tbl)
Definition: bitset.h:17
bool HasInterestedPeer(const std::string &name) const
RtGroupMembers export_
RtGroupMembers import_
bool HasImportExportTables() const
std::string ToString() const
Definition: rtarget_group.h:72
std::vector< RouteList > RTargetDepRouteList
Definition: rtarget_group.h:66
RtGroup(const RouteTarget &rt)
void NotifyDepRoutes(int part_id)
std::string ToString() const
std::map< Address::Family, RtGroupMemberList > RtGroupMembers
Definition: rtarget_group.h:64
void AddInterestedPeer(const BgpPeer *peer, RTargetRoute *rt)
RTargetDepRouteList dep_
bool RemoveExportTable(Address::Family family, BgpTable *tbl)
const RouteTarget & rt()
void FillShowInfo(ShowRtGroupInfo *info) const
std::set< BgpRoute * > RouteList
Definition: rtarget_group.h:65
void RemoveInterestedPeer(const BgpPeer *peer, RTargetRoute *rt)