LCOV - code coverage report
Current view: top level - bgp - bgp_table.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 44 47 93.6 %
Date: 2026-11-09 02:10:49 Functions: 24 25 96.0 %
Legend: Lines: hit not hit

          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_BGP_TABLE_H_
       7             : #define SRC_BGP_BGP_TABLE_H_
       8             : 
       9             : #include <map>
      10             : #include <string>
      11             : #include <vector>
      12             : #include <atomic>
      13             : 
      14             : #include "base/lifetime.h"
      15             : #include "bgp/bgp_rib_policy.h"
      16             : #include "db/db_table_walker.h"
      17             : #include "route/table.h"
      18             : #include "bgp/bgp_ribout.h"
      19             : 
      20             : class BgpServer;
      21             : class BgpRoute;
      22             : class BgpPath;
      23             : class BgpUpdateSender;
      24             : class IPeer;
      25             : class Path;
      26             : class PathResolver;
      27             : class RibOut;
      28             : class RibPeerSet;
      29             : class Route;
      30             : class RoutingInstance;
      31             : class ShowRibOutStatistics;
      32             : class UpdateInfoSList;
      33             : struct UpdateInfo;
      34             : 
      35             : class BgpTable : public RouteTable {
      36             : public:
      37             :     typedef std::map<RibExportPolicy, RibOut *> RibOutMap;
      38             :     typedef std::set<BgpTable *> TableSet;
      39             : 
      40             :     struct RequestKey : DBRequestKey {
      41             :         virtual const IPeer *GetPeer() const = 0;
      42             :     };
      43             : 
      44             :     struct RequestData : DBRequestData {
      45             :         struct NextHop {
      46             :             NextHop()
      47             :                 : flags_(0),
      48             :                   address_(Ip4Address(0)),
      49             :                   label_(0),
      50             :                   l3_label_(0) {
      51             :             }
      52      296232 :             NextHop(uint32_t flags, IpAddress address, uint32_t label,
      53             :                     uint32_t l3_label = 0)
      54      296232 :                 : flags_(flags),
      55      296232 :                   address_(address),
      56      296233 :                   label_(label),
      57      296233 :                   l3_label_(l3_label) {
      58      296233 :             }
      59             : 
      60             :             uint32_t flags_;
      61             :             IpAddress address_;
      62             :             uint32_t label_;
      63             :             uint32_t l3_label_;
      64             :         };
      65             : 
      66      210478 :         RequestData(const BgpAttrPtr &attrs, uint32_t flags, uint32_t label,
      67             :             uint32_t l3_label, uint64_t subscription_gen_id)
      68      420956 :             : attrs_(attrs),
      69      210494 :               nexthop_(flags, attrs ? attrs->nexthop() : Ip4Address(0),
      70             :                        label, l3_label),
      71      210478 :               subscription_gen_id_(subscription_gen_id) {
      72      210484 :         }
      73             : 
      74       85747 :         RequestData(const BgpAttrPtr &attrs, uint32_t flags, uint32_t label,
      75             :             uint32_t l3_label = 0)
      76      171494 :             : attrs_(attrs),
      77       85747 :               nexthop_(flags, attrs ? attrs->nexthop() : Ip4Address(0),
      78             :                        label, l3_label),
      79       85747 :               subscription_gen_id_(0) {
      80       85747 :         }
      81             : 
      82      273365 :         const NextHop &nexthop() { return nexthop_; }
      83      280616 :         BgpAttrPtr &attrs() { return attrs_; }
      84             :         void set_attrs(BgpAttrPtr attrs) { attrs_ = attrs; }
      85        1052 :         void set_subscription_gen_id(uint64_t subscription_gen_id) {
      86        1052 :             subscription_gen_id_ = subscription_gen_id;
      87        1052 :         }
      88       27024 :         uint64_t subscription_gen_id() const { return subscription_gen_id_; }
      89             : 
      90             :     private:
      91             :         BgpAttrPtr attrs_;
      92             :         NextHop nexthop_;
      93             :         uint64_t subscription_gen_id_;
      94             :     };
      95             : 
      96             :     BgpTable(DB *db, const std::string &name);
      97             :     ~BgpTable();
      98             : 
      99          24 :     const RibOutMap &ribout_map() { return ribout_map_; }
     100             :     RibOut *RibOutFind(const RibExportPolicy &policy);
     101             :     RibOut *RibOutLocate(BgpUpdateSender *sender,
     102             :                          const RibExportPolicy &policy);
     103             :     void RibOutDelete(const RibExportPolicy &policy);
     104             : 
     105             :     virtual bool Export(RibOut *ribout, Route *route,
     106             :                         const RibPeerSet &peerset,
     107             :                         UpdateInfoSList &uinfo_slist) = 0;
     108             : 
     109             :     virtual Address::Family family() const = 0;
     110      599199 :     virtual bool IsVpnTable() const { return false; }
     111      514552 :     virtual bool IsRoutingPolicySupported() const { return false; }
     112     1264529 :     virtual bool IsRouteAggregationSupported() const { return false; }
     113             :     virtual std::unique_ptr<DBEntry> AllocEntryStr(
     114             :         const std::string &key) const = 0;
     115             : 
     116             :     virtual BgpRoute *RouteReplicate(BgpServer *server, BgpTable *table,
     117             :                                      BgpRoute *src, const BgpPath *path,
     118             :                                      ExtCommunityPtr community) = 0;
     119             : 
     120             :     static bool PathSelection(const Path &path1, const Path &path2);
     121             :     void CheckAggregatorAttr(BgpAttr *attr) const;
     122             :     void CreateAsPath4Byte(BgpAttr *attr, as_t local_as) const;
     123             :     void CreateAsPath2Byte(BgpAttr *attr) const;
     124             :     void CreateAs4Path(BgpAttr *attr) const;
     125             :     bool Has4ByteAsn(BgpAttr *attr) const;
     126             :     void PrependAsToAsPath4Byte(BgpAttr *attr, as_t asn) const;
     127             :     void PrependAsToAsPath2Byte(BgpAttr *attr, as_t asn) const;
     128             :     void PrependAsToAsPath2Byte(BgpAttr *attr, as2_t asn) const;
     129             :     void PrependAsToAs4Path(BgpAttr* attr, as_t asn) const;
     130             :     UpdateInfo *GetUpdateInfo(RibOut *ribout, BgpRoute *route,
     131             :                               const RibPeerSet &peerset);
     132             :     void ProcessDefaultTunnelEncapsulation(const RibOut *ribout,
     133             :         ExtCommunityDB *extcomm_db, BgpAttr *attr) const;
     134             : 
     135      320238 :     virtual void UpdateSecondaryTablesForReplication(BgpRoute *rt,
     136             :                      TableSet *secondary_tables) {
     137      320238 :     }
     138             : 
     139             :     void ManagedDelete();
     140             :     virtual void RetryDelete();
     141             :     void Shutdown();
     142             :     virtual bool MayDelete() const;
     143      282406 :     bool IsDeleted() const { return deleter()->IsDeleted(); }
     144             :     virtual PathResolver *CreatePathResolver();
     145             :     void LocatePathResolver();
     146             :     void DestroyPathResolver();
     147             : 
     148     6514072 :     RoutingInstance *routing_instance() { return rtinstance_; }
     149     7321168 :     const RoutingInstance *routing_instance() const { return rtinstance_; }
     150             :     virtual void set_routing_instance(RoutingInstance *rtinstance);
     151             :     BgpServer *server();
     152             :     const BgpServer *server() const;
     153        9156 :     PathResolver *path_resolver() { return path_resolver_; }
     154          80 :     const PathResolver *path_resolver() const { return path_resolver_; }
     155             : 
     156             :     LifetimeActor *deleter();
     157             :     const LifetimeActor *deleter() const;
     158             :     size_t GetPendingRiboutsCount(size_t *markers) const;
     159             : 
     160             :     void UpdatePathCount(const BgpPath *path, int count);
     161       21386 :     const uint64_t GetPrimaryPathCount() const { return primary_path_count_; }
     162       21380 :     const uint64_t GetSecondaryPathCount() const {
     163       21380 :         return secondary_path_count_;
     164             :     }
     165       21376 :     const uint64_t GetInfeasiblePathCount() const {
     166       21376 :         return infeasible_path_count_;
     167             :     }
     168       16881 :     const uint64_t GetStalePathCount() const { return stale_path_count_; }
     169       16876 :     const uint64_t GetLlgrStalePathCount() const {
     170       16876 :         return llgr_stale_path_count_;
     171             :     }
     172        3110 :     void UpdateStalePathCount(int count) { stale_path_count_ += count; }
     173           0 :     void UpdateLlgrStalePathCount(int count) {
     174           0 :         llgr_stale_path_count_ += count;
     175           0 :     }
     176             : 
     177             :     // Check whether the route is aggregate route
     178             :     bool IsAggregateRoute(const BgpRoute *route) const;
     179             : 
     180             :     // Check whether the route is contributing route to aggregate route
     181             :     bool IsContributingRoute(const BgpRoute *route) const;
     182             : 
     183             :     bool DeletePath(DBTablePartBase *root, BgpRoute *rt, BgpPath *path);
     184             :     virtual void Input(DBTablePartition *root, DBClient *client,
     185             :                        DBRequest *req);
     186             :     bool InputCommon(DBTablePartBase *root, BgpRoute *rt, BgpPath *path,
     187             :                      const IPeer *peer, DBRequest *req,
     188             :                      DBRequest::DBOperation oper, BgpAttrPtr attrs,
     189             :                      uint32_t path_id, uint32_t flags, uint32_t label,
     190             :                      uint32_t l3_label);
     191             :     void InputCommonPostProcess(DBTablePartBase *root, BgpRoute *rt,
     192             :                                 bool notify_rt);
     193             : 
     194             :     void FillRibOutStatisticsInfo(
     195             :         std::vector<ShowRibOutStatistics> *sros_list) const;
     196             : 
     197      242836 :     virtual BgpAttrPtr GetAttributes(BgpRoute *rt, BgpAttrPtr attrp,
     198             :                                      const IPeer *peer) {
     199      242836 :         return attrp;
     200             :     };
     201             : private:
     202             :     friend class BgpTableTest;
     203             : 
     204             :     class DeleteActor;
     205             : 
     206             :     void PrependLocalAs(const RibOut *ribout, BgpAttr *attr, const IPeer*) const;
     207             :     void ProcessAsOverride(const RibOut *ribout, BgpAttr *attr) const;
     208             :     void ProcessRemovePrivate(const RibOut *ribout, BgpAttr *attr) const;
     209             :     void RemovePrivateAs(const RibOut *ribout, BgpAttr *attr) const;
     210             :     void RemovePrivate4ByteAs(const RibOut *ribout, BgpAttr *attr) const;
     211             :     void RemovePrivateAs4(const RibOut *ribout, BgpAttr *attr) const;
     212             :     void ProcessLlgrState(const RibOut *ribout, const BgpPath *path,
     213             :                           BgpAttr *attr, bool llgr_stale_comm);
     214             :     virtual BgpRoute *TableFind(DBTablePartition *rtp,
     215             :             const DBRequestKey *prefix) = 0;
     216             : 
     217             :     RoutingInstance *rtinstance_;
     218             :     PathResolver *path_resolver_;
     219             :     RibOutMap ribout_map_;
     220             : 
     221             :     boost::scoped_ptr<DeleteActor> deleter_;
     222             :     LifetimeRef<BgpTable> instance_delete_ref_;
     223             :     std::atomic<uint64_t> primary_path_count_;
     224             :     std::atomic<uint64_t> secondary_path_count_;
     225             :     std::atomic<uint64_t> infeasible_path_count_;
     226             :     std::atomic<uint64_t> stale_path_count_;
     227             :     std::atomic<uint64_t> llgr_stale_path_count_;
     228             : 
     229             :     DISALLOW_COPY_AND_ASSIGN(BgpTable);
     230             : };
     231             : 
     232             : #endif  // SRC_BGP_BGP_TABLE_H_

Generated by: LCOV version 1.14