Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_MVPN_MVPN_TABLE_H_ 6 : #define SRC_BGP_MVPN_MVPN_TABLE_H_ 7 : 8 : #include <map> 9 : #include <set> 10 : #include <string> 11 : 12 : #include "bgp/bgp_attr.h" 13 : #include "bgp/bgp_table.h" 14 : #include "bgp/mvpn/mvpn_route.h" 15 : #include "bgp/routing-instance/path_resolver.h" 16 : 17 : class BgpPath; 18 : class BgpRoute; 19 : class BgpServer; 20 : class MvpnManager; 21 : class MvpnProjectManager; 22 : class MvpnProjectManagerPartition; 23 : 24 : class MvpnTable : public BgpTable { 25 : public: 26 : static const int kPartitionCount = 1; 27 : 28 : struct RequestKey : BgpTable::RequestKey { 29 114027 : RequestKey(const MvpnPrefix &prefix, const IPeer *ipeer) 30 114027 : : prefix(prefix), peer(ipeer) { 31 114027 : } 32 : MvpnPrefix prefix; 33 : const IPeer *peer; 34 40134 : virtual const IPeer *GetPeer() const { return peer; } 35 : }; 36 : 37 : MvpnTable(DB *db, const std::string &name); 38 : 39 : virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *key) const; 40 : virtual std::unique_ptr<DBEntry> AllocEntryStr(const std::string &key) const; 41 : void CreateManager(); 42 : void DestroyManager(); 43 1739692 : virtual Address::Family family() const { return Address::MVPN; } 44 : bool IsMaster() const; 45 1027658 : virtual bool IsVpnTable() const { return IsMaster(); } 46 : 47 : virtual size_t Hash(const DBEntry *entry) const; 48 : virtual size_t Hash(const DBRequestKey *key) const; 49 395239 : virtual int PartitionCount() const { return kPartitionCount; } 50 : MvpnRoute *FindSPMSIRoute(MvpnRoute *leaf_ad_rt) { return NULL; } 51 : const ExtCommunity::ExtCommunityValue GetAutoVrfImportRouteTarget() const { 52 : return ExtCommunity::ExtCommunityValue(); 53 : } 54 : 55 : virtual BgpRoute *RouteReplicate(BgpServer *server, BgpTable *src_table, 56 : BgpRoute *src_rt, const BgpPath *path, 57 : ExtCommunityPtr ptr); 58 : virtual bool Export(RibOut *ribout, Route *route, 59 : const RibPeerSet &peerset, 60 : UpdateInfoSList &info_slist); 61 : static DBTableBase *CreateTable(DB *db, const std::string &name); 62 : size_t HashFunction(const MvpnPrefix &prefix) const; 63 : PathResolver *CreatePathResolver(); 64 454 : const MvpnManager *manager() const { return manager_; } 65 72266 : MvpnManager *manager() { return manager_; } 66 : 67 : bool RouteNotify(BgpServer *server, DBTablePartBase *root, DBEntryBase *e); 68 : const MvpnProjectManager *GetProjectManager() const; 69 : MvpnProjectManager *GetProjectManager(); 70 : const MvpnProjectManagerPartition *GetProjectManagerPartition( 71 : BgpRoute *route) const; 72 : void UpdateSecondaryTablesForReplication(BgpRoute *rt, 73 : TableSet *secondary_tables); 74 : MvpnPrefix CreateType4LeafADRoutePrefix(const MvpnRoute *type3_rt); 75 : MvpnPrefix CreateType3SPMSIRoutePrefix(const MvpnRoute *type7_rt); 76 : MvpnPrefix CreateType2ADRoutePrefix(); 77 : MvpnPrefix CreateType1ADRoutePrefix(const Ip4Address &originator_ip); 78 : MvpnPrefix CreateType1ADRoutePrefix(); 79 : MvpnPrefix CreateType7SourceTreeJoinRoutePrefix(MvpnRoute *rt) const; 80 : MvpnPrefix CreateLocalType7Prefix(MvpnRoute *rt) const; 81 : MvpnRoute *FindType1ADRoute(const Ip4Address &originator_ip); 82 : MvpnRoute *FindType1ADRoute(); 83 : const MvpnRoute *FindType7SourceTreeJoinRoute(MvpnRoute *rt) const; 84 : MvpnRoute *LocateType1ADRoute(); 85 : MvpnRoute *LocateType3SPMSIRoute(const MvpnRoute *type7_join_rt); 86 : MvpnRoute *LocateType4LeafADRoute(const MvpnRoute *type3_spmsi_rt); 87 : MvpnRoute *FindRoute(const MvpnPrefix &prefix); 88 : const MvpnRoute *FindRoute(const MvpnPrefix &prefix) const; 89 : void CreateMvpnManagers(); 90 : bool IsProjectManagerUsable() const; 91 : 92 : private: 93 : friend class BgpMulticastTest; 94 : typedef std::set<std::string> MvpnManagerNetworks; 95 : typedef std::map<std::string, MvpnManagerNetworks> 96 : MvpnProjectManagerNetworks; 97 : 98 : void DeleteMvpnManager(); 99 : virtual BgpRoute *TableFind(DBTablePartition *rtp, 100 : const DBRequestKey *prefix); 101 : MvpnRoute *LocateRoute(const MvpnPrefix &prefix); 102 : UpdateInfo *GetMvpnUpdateInfo(RibOut *ribout, MvpnRoute *route, 103 : const RibPeerSet &peerset); 104 : void GetPeerSet(RibOut *ribout, MvpnRoute *route, 105 : const RibPeerSet &peerset, RibPeerSet *new_peerset); 106 : BgpRoute *ReplicateType7SourceTreeJoin(BgpServer *server, 107 : MvpnTable *src_table, MvpnRoute *src_rt, const BgpPath *src_path, 108 : ExtCommunityPtr ext_community); 109 : BgpRoute *ReplicatePath(BgpServer *server, const MvpnPrefix &mprefix, 110 : MvpnTable *src_table, MvpnRoute *src_rt, const BgpPath *src_path, 111 : ExtCommunityPtr comm); 112 834300 : const MvpnTable *table() const { return this; } 113 : 114 : MvpnManager *manager_; 115 : 116 : DISALLOW_COPY_AND_ASSIGN(MvpnTable); 117 : }; 118 : 119 : #endif // SRC_BGP_MVPN_MVPN_TABLE_H_