OpenSDN source code
bgp_route.h
Go to the documentation of this file.
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  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 
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);
60  }
61 
62  void NotifyOrDelete();
63  BgpTable *table();
64  const BgpTable *table() const;
65 
66  virtual std::string ToXmppIdString() const { return ToString(); }
67 
68  virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
69  const BgpAttr *attr = NULL,
70  uint32_t label = 0,
71  uint32_t l3_label = 0) const {
72  }
73  virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
74  IpAddress nexthop) const {
75  }
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;
86  const std::set<std::string> &peer_sources() const { return peer_sources_; }
87  void add_peer_sources(std::string val) { peer_sources_.insert(val); }
88  void del_peer_sources(std::string val) {
89  if (peer_sources_.find(val) != peer_sources_.end()) {
90  peer_sources_.erase(val);
91  };
92  }
93 
94 private:
95  std::set<std::string> peer_sources_;
97 };
98 
99 #endif // SRC_BGP_BGP_ROUTE_H_
boost::asio::ip::address IpAddress
Definition: address.h:14
PathSource
Definition: bgp_path.h:38
BgpRoute()
Definition: bgp_route.cc:37
const BgpPath * FindPath(BgpPath::PathSource src) const
Definition: bgp_route.cc:147
void FillRouteInfo(const BgpTable *table, ShowRoute *show_route, const std::string &source="", const std::string &protocol="") const
DISALLOW_COPY_AND_ASSIGN(BgpRoute)
bool RemovePath(BgpPath::PathSource src, const IPeer *peer=NULL, uint32_t path_id=0)
Definition: bgp_route.cc:264
const BgpPath * BestPath() const
Definition: bgp_route.cc:48
virtual bool IsValid() const
Definition: bgp_route.cc:340
void add_peer_sources(std::string val)
Definition: bgp_route.h:87
const std::set< std::string > & peer_sources() const
Definition: bgp_route.h:86
virtual RouteDistinguisher GetRouteDistinguisher() const
Definition: bgp_route.h:58
void del_peer_sources(std::string val)
Definition: bgp_route.h:88
BgpTable * table()
Definition: bgp_route.cc:426
void DeletePath(BgpPath *path)
Definition: bgp_route.cc:128
bool RemoveSecondaryPath(const BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:399
bool IsUsable() const
Definition: bgp_route.cc:326
size_t count() const
Definition: bgp_route.cc:422
BgpPath * FindSecondaryPath(BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:374
virtual std::string ToXmppIdString() const
Definition: bgp_route.h:66
virtual void BuildProtoPrefix(BgpProtoPrefix *prefix, const BgpAttr *attr=NULL, uint32_t label=0, uint32_t l3_label=0) const
Definition: bgp_route.h:68
virtual void BuildBgpProtoNextHop(std::vector< uint8_t > &nh, IpAddress nexthop) const
Definition: bgp_route.h:73
~BgpRoute()
Definition: bgp_route.cc:40
uint32_t SubClusterId() const
Definition: bgp_route.cc:781
void FillRouteInfo(const BgpTable *table, ShowRouteBrief *show_route) const
Definition: bgp_route.cc:434
std::set< std::string > peer_sources_
Definition: bgp_route.h:95
void InsertPath(BgpPath *path)
Definition: bgp_route.cc:62
bool HasPaths() const
Definition: bgp_route.h:29
bool DuplicateForwardingPath(const BgpPath *in_path) const
Definition: bgp_route.cc:354
void AddExtCommunitySubCluster(BgpPath *path)
void NotifyOrDelete()
Definition: bgp_route.cc:773
virtual std::string ToString() const =0
Definition: ipeer.h:187
static RouteDistinguisher kZeroRd
Definition: rd.h:15
Definition: route.h:15
const Path * front() const
Definition: route.cc:17