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_ROUTE_H_ 7 : #define SRC_BGP_BGP_ROUTE_H_ 8 : 9 : #include <string> 10 : #include <vector> 11 : #include <set> 12 : 13 : #include "bgp/bgp_path.h" 14 : #include "base/address.h" 15 : #include "route/route.h" 16 : 17 : class BgpAttr; 18 : struct BgpProtoPrefix; 19 : class IPeer; 20 : class BgpTable; 21 : class ShowRoute; 22 : class ShowRouteBrief; 23 : 24 : class BgpRoute : public Route { 25 : public: 26 : BgpRoute(); 27 : ~BgpRoute(); 28 : 29 73318 : bool HasPaths() const { return front() != NULL; } 30 : const BgpPath *BestPath() const; 31 : 32 : void InsertPath(BgpPath *path); 33 : void DeletePath(BgpPath *path); 34 : 35 : const BgpPath *FindPath(BgpPath::PathSource src) const; 36 : const BgpPath *FindPath(const IPeer *peer, 37 : bool include_secondary = false) const; 38 : BgpPath *FindPath(const IPeer *peer, bool include_secondary = false); 39 : BgpPath *FindPath(const IpAddress &nexthop); 40 : BgpPath *FindPath(BgpPath::PathSource src, const IPeer *peer, 41 : uint32_t path_id); 42 : BgpPath *FindPath(BgpPath::PathSource src, uint32_t path_id); 43 : bool RemovePath(BgpPath::PathSource src, const IPeer *peer = NULL, 44 : uint32_t path_id = 0); 45 : bool RemovePath(BgpPath::PathSource src, uint32_t path_id); 46 : bool RemovePath(const IPeer *peer); 47 : 48 : bool IsUsable() const; 49 : virtual bool IsValid() const; 50 : 51 : // Check if there's a better path with the same forwarding information. 52 : bool DuplicateForwardingPath(const BgpPath *in_path) const; 53 : 54 : BgpPath *FindSecondaryPath(BgpRoute *src_rt, BgpPath::PathSource src, 55 : const IPeer *peer, uint32_t path_id); 56 : bool RemoveSecondaryPath(const BgpRoute *src_rt, BgpPath::PathSource src, 57 : const IPeer *peer, uint32_t path_id); 58 1 : virtual RouteDistinguisher GetRouteDistinguisher() const { 59 1 : return RouteDistinguisher::kZeroRd; 60 : } 61 : 62 : void NotifyOrDelete(); 63 : BgpTable *table(); 64 : const BgpTable *table() const; 65 : 66 778918 : virtual std::string ToXmppIdString() const { return ToString(); } 67 : 68 0 : virtual void BuildProtoPrefix(BgpProtoPrefix *prefix, 69 : const BgpAttr *attr = NULL, 70 : uint32_t label = 0, 71 : uint32_t l3_label = 0) const { 72 0 : } 73 0 : virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh, 74 : IpAddress nexthop) const { 75 0 : } 76 : 77 : // number of paths 78 : size_t count() const; 79 : 80 : // Fill info needed for introspect 81 : void FillRouteInfo(const BgpTable *table, ShowRouteBrief *show_route) const; 82 : void FillRouteInfo(const BgpTable *table, ShowRoute *show_route, 83 : const std::string &source = "", const std::string &protocol = "") const; 84 : uint32_t SubClusterId() const; 85 : void AddExtCommunitySubCluster(BgpPath *path); 86 10519 : const std::set<std::string> &peer_sources() const { return peer_sources_; } 87 2735 : void add_peer_sources(std::string val) { peer_sources_.insert(val); } 88 154092 : void del_peer_sources(std::string val) { 89 154092 : if (peer_sources_.find(val) != peer_sources_.end()) { 90 1232 : peer_sources_.erase(val); 91 : }; 92 154096 : } 93 : 94 : private: 95 : std::set<std::string> peer_sources_; 96 : DISALLOW_COPY_AND_ASSIGN(BgpRoute); 97 : }; 98 : 99 : #endif // SRC_BGP_BGP_ROUTE_H_