OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_path.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_PATH_H_
6 #define SRC_BGP_BGP_PATH_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/util.h"
12 #include "route/path.h"
13 #include "bgp/bgp_attr.h"
14 
15 class BgpTable;
16 class BgpRoute;
17 class IPeer;
18 
19 class BgpPath : public Path {
20 public:
21  enum PathFlag {
22  AsPathLooped = 1 << 0,
23  NoNeighborAs = 1 << 1,
24  Stale = 1 << 2,
25  NoTunnelEncap = 1 << 3,
27  ResolveNexthop = 1 << 5,
28  ResolvedPath = 1 << 6,
30  LlgrStale = 1 << 8,
32  AliasedPath = 1 << 10,
34  };
35 
36  // Ordered in the ascending order of path preference
37  enum PathSource {
38  None = 0,
39  BGP_XMPP = 1,
42  Aggregate = 4,
43  Local = 5
44  };
45 
46  static const uint32_t INFEASIBLE_MASK = (AsPathLooped |
49 
50  static std::string PathIdString(uint32_t path_id);
51 
52  BgpPath(const IPeer *peer, uint32_t path_id, PathSource src,
53  const BgpAttrPtr ptr, uint32_t flags, uint32_t label,
54  uint32_t l3_label = 0);
55  BgpPath(const IPeer *peer, PathSource src, const BgpAttrPtr attr,
56  uint32_t flags, uint32_t label, uint32_t l3_label = 0);
57  BgpPath(uint32_t path_id, PathSource src, const BgpAttrPtr attr,
58  uint32_t flags = 0, uint32_t label = 0, uint32_t l3_label = 0);
59  BgpPath(PathSource src, const BgpAttrPtr attr,
60  uint32_t flags = 0, uint32_t label = 0, uint32_t l3_label = 0);
61  virtual ~BgpPath() {
62  }
63 
64  void AddExtCommunitySubCluster(uint32_t subcluster_id);
65 
67 
68  bool IsVrfOriginated() const {
69  if (IsReplicated())
70  return false;
71  if (source_ != Aggregate && source_ != BGP_XMPP && source_ != Local)
72  return false;
73  return true;
74  }
75 
76  IPeer *GetPeer() { return const_cast<IPeer *>(peer_); }
77  const IPeer *GetPeer() const { return peer_; }
78  const uint32_t GetPathId() const { return path_id_; }
79 
80  void UpdatePeerRefCount(int count, Address::Family family) const;
81 
82  void SetAttr(const BgpAttrPtr attr, const BgpAttrPtr original_attr) {
83  attr_ = attr;
84  original_attr_ = original_attr;
85  }
86 
87  const BgpAttr *GetAttr() const { return attr_.get(); }
88  const BgpAttr *GetOriginalAttr() const { return original_attr_.get(); }
89  uint32_t GetLabel() const { return label_; }
90  uint32_t GetL3Label() const { return l3_label_; }
91  virtual bool IsReplicated() const { return false; }
92  bool IsFeasible() const { return ((flags_ & INFEASIBLE_MASK) == 0); }
93 
94  bool IsResolutionFeasible() const {
95  return ((flags_ & (INFEASIBLE_MASK & ~ResolveNexthop)) == 0);
96  }
97 
98  bool IsAliased() const { return ((flags_ & AliasedPath) != 0); }
99  bool IsResolved() const { return ((flags_ & ResolvedPath) != 0); }
100  uint32_t GetFlags() const { return flags_; }
101  std::vector<std::string> GetFlagsStringList() const;
102 
103  PathSource GetSource() const { return source_; }
104  std::string GetSourceString(bool combine_bgp_and_xmpp = false) const;
105 
106  // Check if the path is stale
107  bool IsStale() const { return ((flags_ & Stale) != 0); }
108 
109  // Check if the path is stale
110  bool IsLlgrStale() const { return ((flags_ & LlgrStale) != 0); }
111 
112  // Mark a path as rejected by Routing policy
114 
115  // Reset a path as active from Routing Policy
117 
118  bool IsPolicyReject() const {
119  return ((flags_ & RoutingPolicyReject) != 0);
120  }
121 
122  // Mark a path as stale
123  void SetStale() { flags_ |= Stale; }
124 
125  // Reset a path as active (not stale)
126  void ResetStale() { flags_ &= ~Stale; }
127 
128  // Mark/Reset a path as needing resolution
131 
134 
135  bool NeedsResolution() const { return ((flags_ & ResolveNexthop) != 0); }
136  bool CheckErmVpn() const {
137  return ((flags_ & CheckGlobalErmVpnRoute) != 0);
138  }
141 
142  virtual std::string ToString() const;
143 
144  // Select one path over other
145  int PathCompare(const BgpPath &rhs, bool allow_ecmp) const;
146  bool PathSameNeighborAs(const BgpPath &rhs) const;
147 
148 private:
149  const IPeer *peer_;
150  const uint32_t path_id_;
152  // Attribute for the BgpPath. If routing policy updates the path attribute,
153  // this member contains the attribute after policy update
155  // Original path attribute before applying routing policy
157  uint32_t flags_;
158  uint32_t label_;
159  uint32_t l3_label_;
160 };
161 
162 class BgpSecondaryPath : public BgpPath {
163 public:
164  BgpSecondaryPath(const IPeer *peer, uint32_t path_id, PathSource src,
165  const BgpAttrPtr attr, uint32_t flags, uint32_t label,
166  uint32_t l3_label = 0);
167 
168  virtual bool IsReplicated() const {
169  return true;
170  }
171 
172  void SetReplicateInfo(const BgpTable *table, const BgpRoute *rt) {
173  src_table_ = table;
174  src_entry_ = rt;
175  }
176 
177  virtual ~BgpSecondaryPath() {
178  }
179 
181 
182  const BgpTable *src_table() const {
183  return src_table_;
184  }
185 
186  const BgpRoute *src_rt() const {
187  return src_entry_;
188  }
189 
190 private:
193 
195 };
196 
197 #endif // SRC_BGP_BGP_PATH_H_
void SetCheckErmVpn()
Definition: bgp_path.h:140
void ResetPolicyReject()
Definition: bgp_path.h:116
uint32_t l3_label_
Definition: bgp_path.h:159
uint32_t flags_
Definition: bgp_path.h:157
BgpPath(const IPeer *peer, uint32_t path_id, PathSource src, const BgpAttrPtr ptr, uint32_t flags, uint32_t label, uint32_t l3_label=0)
Definition: bgp_path.cc:23
bool CheckErmVpn() const
Definition: bgp_path.h:136
void SetPolicyReject()
Definition: bgp_path.h:113
void ResetLlgrStale()
Definition: bgp_path.h:133
static std::string PathIdString(uint32_t path_id)
Definition: bgp_path.cc:18
virtual ~BgpSecondaryPath()
Definition: bgp_path.h:177
Family
Definition: address.h:24
bool IsStale() const
Definition: bgp_path.h:107
const uint32_t path_id_
Definition: bgp_path.h:150
const uint32_t GetPathId() const
Definition: bgp_path.h:78
void SetLlgrStale()
Definition: bgp_path.h:132
uint32_t label_
Definition: bgp_path.h:158
void ResetResolveNextHop()
Definition: bgp_path.h:130
bool IsResolutionFeasible() const
Definition: bgp_path.h:94
virtual std::string ToString() const
Definition: bgp_path.cc:177
uint32_t GetFlags() const
Definition: bgp_path.h:100
Definition: ipeer.h:186
void ResetStale()
Definition: bgp_path.h:126
RouteDistinguisher GetPrimaryRouteDistinguisher() const
Definition: bgp_path.cc:300
uint32_t GetL3Label() const
Definition: bgp_path.h:90
std::string GetSourceString(bool combine_bgp_and_xmpp=false) const
Definition: bgp_path.cc:270
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:991
void SetReplicateInfo(const BgpTable *table, const BgpRoute *rt)
Definition: bgp_path.h:172
PathSource
Definition: bgp_path.h:37
BgpSecondaryPath(const IPeer *peer, uint32_t path_id, PathSource src, const BgpAttrPtr attr, uint32_t flags, uint32_t label, uint32_t l3_label=0)
Definition: bgp_path.cc:294
bool IsFeasible() const
Definition: bgp_path.h:92
PathSource GetSource() const
Definition: bgp_path.h:103
const IPeer * peer_
Definition: bgp_path.h:149
Definition: path.h:10
static const uint32_t INFEASIBLE_MASK
Definition: bgp_path.h:46
BgpAttrPtr original_attr_
Definition: bgp_path.h:156
virtual bool IsReplicated() const
Definition: bgp_path.h:168
IPeer * GetPeer()
Definition: bgp_path.h:76
void UpdatePeerRefCount(int count, Address::Family family) const
Definition: bgp_path.cc:168
void ResetCheckErmVpn()
Definition: bgp_path.h:139
bool IsVrfOriginated() const
Definition: bgp_path.h:68
uint32_t GetLabel() const
Definition: bgp_path.h:89
void SetResolveNextHop()
Definition: bgp_path.h:129
int PathCompare(const BgpPath &rhs, bool allow_ecmp) const
Definition: bgp_path.cc:58
bool IsResolved() const
Definition: bgp_path.h:99
const BgpAttr * GetOriginalAttr() const
Definition: bgp_path.h:88
DISALLOW_COPY_AND_ASSIGN(BgpSecondaryPath)
const PathSource source_
Definition: bgp_path.h:151
BgpAttrPtr attr_
Definition: bgp_path.h:154
const BgpRoute * src_rt() const
Definition: bgp_path.h:186
bool IsPolicyReject() const
Definition: bgp_path.h:118
void AddExtCommunitySubCluster(uint32_t subcluster_id)
Definition: bgp_path.cc:304
bool IsLlgrStale() const
Definition: bgp_path.h:110
const BgpRoute * src_entry_
Definition: bgp_path.h:192
const BgpTable * src_table_
Definition: bgp_path.h:191
const BgpAttr * GetAttr() const
Definition: bgp_path.h:87
std::vector< std::string > GetFlagsStringList() const
Definition: bgp_path.cc:191
bool IsAliased() const
Definition: bgp_path.h:98
bool NeedsResolution() const
Definition: bgp_path.h:135
void SetStale()
Definition: bgp_path.h:123
const BgpTable * src_table() const
Definition: bgp_path.h:182
virtual ~BgpPath()
Definition: bgp_path.h:61
const IPeer * GetPeer() const
Definition: bgp_path.h:77
RouteDistinguisher GetSourceRouteDistinguisher() const
Definition: bgp_path.cc:181
virtual bool IsReplicated() const
Definition: bgp_path.h:91
PathFlag
Definition: bgp_path.h:21
void SetAttr(const BgpAttrPtr attr, const BgpAttrPtr original_attr)
Definition: bgp_path.h:82
bool PathSameNeighborAs(const BgpPath &rhs) const
Definition: bgp_path.cc:159