Line data Source code
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,
26 : OriginatorIdLooped = 1 << 4,
27 : ResolveNexthop = 1 << 5,
28 : ResolvedPath = 1 << 6,
29 : RoutingPolicyReject = 1 << 7,
30 : LlgrStale = 1 << 8,
31 : ClusterListLooped = 1 << 9,
32 : AliasedPath = 1 << 10,
33 : CheckGlobalErmVpnRoute = 1 << 11,
34 : };
35 :
36 : // Ordered in the ascending order of path preference
37 : enum PathSource {
38 : None = 0,
39 : BGP_XMPP = 1,
40 : ServiceChain = 2,
41 : StaticRoute = 3,
42 : Aggregate = 4,
43 : Local = 5
44 : };
45 :
46 : static const uint32_t INFEASIBLE_MASK = (AsPathLooped |
47 : NoNeighborAs | NoTunnelEncap | OriginatorIdLooped | ResolveNexthop |
48 : RoutingPolicyReject | ClusterListLooped | CheckGlobalErmVpnRoute);
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 1352813 : virtual ~BgpPath() {
62 1352813 : }
63 :
64 : void AddExtCommunitySubCluster(uint32_t subcluster_id);
65 :
66 : RouteDistinguisher GetSourceRouteDistinguisher() const;
67 :
68 723969 : bool IsVrfOriginated() const {
69 723969 : if (IsReplicated())
70 408598 : return false;
71 315433 : if (source_ != Aggregate && source_ != BGP_XMPP && source_ != Local)
72 1991 : return false;
73 313442 : return true;
74 : }
75 :
76 7259112 : IPeer *GetPeer() { return const_cast<IPeer *>(peer_); }
77 2182537 : const IPeer *GetPeer() const { return peer_; }
78 5226476 : const uint32_t GetPathId() const { return path_id_; }
79 :
80 : void UpdatePeerRefCount(int count, Address::Family family) const;
81 :
82 710859 : void SetAttr(const BgpAttrPtr attr, const BgpAttrPtr original_attr) {
83 710859 : attr_ = attr;
84 710858 : original_attr_ = original_attr;
85 710873 : }
86 :
87 5753188 : const BgpAttr *GetAttr() const { return attr_.get(); }
88 2311134 : const BgpAttr *GetOriginalAttr() const { return original_attr_.get(); }
89 1940632 : uint32_t GetLabel() const { return label_; }
90 889120 : uint32_t GetL3Label() const { return l3_label_; }
91 1656169 : virtual bool IsReplicated() const { return false; }
92 14601435 : bool IsFeasible() const { return ((flags_ & INFEASIBLE_MASK) == 0); }
93 :
94 3051 : bool IsResolutionFeasible() const {
95 3051 : return ((flags_ & (INFEASIBLE_MASK & ~ResolveNexthop)) == 0);
96 : }
97 :
98 5051999 : bool IsAliased() const { return ((flags_ & AliasedPath) != 0); }
99 945576 : bool IsResolved() const { return ((flags_ & ResolvedPath) != 0); }
100 10605494 : uint32_t GetFlags() const { return flags_; }
101 : std::vector<std::string> GetFlagsStringList() const;
102 :
103 11581412 : 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 3728521 : bool IsStale() const { return ((flags_ & Stale) != 0); }
108 :
109 : // Check if the path is stale
110 8538184 : bool IsLlgrStale() const { return ((flags_ & LlgrStale) != 0); }
111 :
112 : // Mark a path as rejected by Routing policy
113 19 : void SetPolicyReject() { flags_ |= RoutingPolicyReject; }
114 :
115 : // Reset a path as active from Routing Policy
116 3 : void ResetPolicyReject() { flags_ &= ~RoutingPolicyReject; }
117 :
118 447753 : bool IsPolicyReject() const {
119 447753 : return ((flags_ & RoutingPolicyReject) != 0);
120 : }
121 :
122 : // Mark a path as stale
123 5 : void SetStale() { flags_ |= Stale; }
124 :
125 : // Reset a path as active (not stale)
126 3124 : void ResetStale() { flags_ &= ~Stale; }
127 :
128 : // Mark/Reset a path as needing resolution
129 106 : void SetResolveNextHop() { flags_ |= ResolveNexthop; }
130 : void ResetResolveNextHop() { flags_ &= ~ResolveNexthop; }
131 :
132 26 : void SetLlgrStale() { flags_ |= LlgrStale; }
133 38 : void ResetLlgrStale() { flags_ &= ~LlgrStale; }
134 :
135 1138984 : bool NeedsResolution() const { return ((flags_ & ResolveNexthop) != 0); }
136 516039 : bool CheckErmVpn() const {
137 516039 : return ((flags_ & CheckGlobalErmVpnRoute) != 0);
138 : }
139 625 : void ResetCheckErmVpn() { flags_ &= ~CheckGlobalErmVpnRoute; }
140 176 : void SetCheckErmVpn() { flags_ |= CheckGlobalErmVpnRoute; }
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_;
151 : const PathSource source_;
152 : // Attribute for the BgpPath. If routing policy updates the path attribute,
153 : // this member contains the attribute after policy update
154 : BgpAttrPtr attr_;
155 : // Original path attribute before applying routing policy
156 : BgpAttrPtr original_attr_;
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 3604987 : virtual bool IsReplicated() const {
169 3604987 : return true;
170 : }
171 :
172 578820 : void SetReplicateInfo(const BgpTable *table, const BgpRoute *rt) {
173 578820 : src_table_ = table;
174 578820 : src_entry_ = rt;
175 578820 : }
176 :
177 1157063 : virtual ~BgpSecondaryPath() {
178 1157063 : }
179 :
180 : RouteDistinguisher GetPrimaryRouteDistinguisher() const;
181 :
182 17320 : const BgpTable *src_table() const {
183 17320 : return src_table_;
184 : }
185 :
186 1811352 : const BgpRoute *src_rt() const {
187 1811352 : return src_entry_;
188 : }
189 :
190 : private:
191 : const BgpTable *src_table_;
192 : const BgpRoute *src_entry_;
193 :
194 : DISALLOW_COPY_AND_ASSIGN(BgpSecondaryPath);
195 : };
196 :
197 : #endif // SRC_BGP_BGP_PATH_H_
|