OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_route.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_BGP_ROUTE_H_
6 #define SRC_BGP_BGP_ROUTE_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "bgp/bgp_path.h"
12 #include "base/address.h"
13 #include "route/route.h"
14 
15 class BgpAttr;
16 struct BgpProtoPrefix;
17 class IPeer;
18 class BgpTable;
19 class ShowRoute;
20 class ShowRouteBrief;
21 
22 class BgpRoute : public Route {
23 public:
24  BgpRoute();
25  ~BgpRoute();
26 
27  bool HasPaths() const { return front() != NULL; }
28  const BgpPath *BestPath() const;
29 
30  void InsertPath(BgpPath *path);
31  void DeletePath(BgpPath *path);
32 
33  const BgpPath *FindPath(BgpPath::PathSource src) const;
34  const BgpPath *FindPath(const IPeer *peer,
35  bool include_secondary = false) const;
36  BgpPath *FindPath(const IPeer *peer, bool include_secondary = false);
37  BgpPath *FindPath(const IpAddress &nexthop);
38  BgpPath *FindPath(BgpPath::PathSource src, const IPeer *peer,
39  uint32_t path_id);
40  BgpPath *FindPath(BgpPath::PathSource src, uint32_t path_id);
41  bool RemovePath(BgpPath::PathSource src, const IPeer *peer = NULL,
42  uint32_t path_id = 0);
43  bool RemovePath(BgpPath::PathSource src, uint32_t path_id);
44  bool RemovePath(const IPeer *peer);
45 
46  bool IsUsable() const;
47  virtual bool IsValid() const;
48 
49  // Check if there's a better path with the same forwarding information.
50  bool DuplicateForwardingPath(const BgpPath *in_path) const;
51 
53  const IPeer *peer, uint32_t path_id);
54  bool RemoveSecondaryPath(const BgpRoute *src_rt, BgpPath::PathSource src,
55  const IPeer *peer, uint32_t path_id);
58  }
59 
60  void NotifyOrDelete();
61  BgpTable *table();
62  const BgpTable *table() const;
63 
64  virtual std::string ToXmppIdString() const { return ToString(); }
65 
66  virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
67  const BgpAttr *attr = NULL,
68  uint32_t label = 0,
69  uint32_t l3_label = 0) const {
70  }
71  virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
72  IpAddress nexthop) const {
73  }
74 
75  // number of paths
76  size_t count() const;
77 
78  // Fill info needed for introspect
79  void FillRouteInfo(const BgpTable *table, ShowRouteBrief *show_route) const;
80  void FillRouteInfo(const BgpTable *table, ShowRoute *show_route,
81  const std::string &source = "", const std::string &protocol = "") const;
82  uint32_t SubClusterId() const;
84 
85 private:
87 };
88 
89 #endif // SRC_BGP_BGP_ROUTE_H_
void FillRouteInfo(const BgpTable *table, ShowRouteBrief *show_route) const
Definition: bgp_route.cc:432
virtual std::string ToXmppIdString() const
Definition: bgp_route.h:64
const BgpPath * BestPath() const
Definition: bgp_route.cc:46
void NotifyOrDelete()
Definition: bgp_route.cc:747
bool RemoveSecondaryPath(const BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:397
BgpRoute()
Definition: bgp_route.cc:35
boost::asio::ip::address IpAddress
Definition: address.h:13
virtual void BuildProtoPrefix(BgpProtoPrefix *prefix, const BgpAttr *attr=NULL, uint32_t label=0, uint32_t l3_label=0) const
Definition: bgp_route.h:66
Definition: route.h:14
const BgpPath * FindPath(BgpPath::PathSource src) const
Definition: bgp_route.cc:145
Definition: ipeer.h:186
bool IsUsable() const
Definition: bgp_route.cc:324
PathSource
Definition: bgp_path.h:37
virtual void BuildBgpProtoNextHop(std::vector< uint8_t > &nh, IpAddress nexthop) const
Definition: bgp_route.h:71
virtual std::string ToString() const =0
static RouteDistinguisher kZeroRd
Definition: rd.h:14
uint32_t SubClusterId() const
Definition: bgp_route.cc:755
void InsertPath(BgpPath *path)
Definition: bgp_route.cc:60
bool DuplicateForwardingPath(const BgpPath *in_path) const
Definition: bgp_route.cc:352
bool RemovePath(BgpPath::PathSource src, const IPeer *peer=NULL, uint32_t path_id=0)
Definition: bgp_route.cc:262
const Path * front() const
Definition: route.cc:16
BgpPath * FindSecondaryPath(BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:372
BgpTable * table()
Definition: bgp_route.cc:424
bool HasPaths() const
Definition: bgp_route.h:27
size_t count() const
Definition: bgp_route.cc:420
void DeletePath(BgpPath *path)
Definition: bgp_route.cc:126
~BgpRoute()
Definition: bgp_route.cc:38
DISALLOW_COPY_AND_ASSIGN(BgpRoute)
void AddExtCommunitySubCluster(BgpPath *path)
virtual bool IsValid() const
Definition: bgp_route.cc:338
virtual RouteDistinguisher GetRouteDistinguisher() const
Definition: bgp_route.h:56