OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
path_preference.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 #ifndef __ROUTE_PREFERENCE_H__
5 #define __ROUTE_PREFERENCE_H__
6 
7 #include <boost/statechart/custom_reaction.hpp>
8 #include <boost/statechart/event.hpp>
9 #include <boost/statechart/simple_state.hpp>
10 #include <boost/statechart/state.hpp>
11 #include <boost/statechart/state_machine.hpp>
12 
13 namespace sc = boost::statechart;
14 struct Init;
15 struct WaitForTraffic;
16 struct TrafficSeen;
17 struct ActiveActiveState;
19 
20 #define PATH_PREFERENCE_TRACE(...) \
21 do { \
22  PathPreferenceTrace::TraceMsg(PathPreferenceTraceBuf, __FILE__, __LINE__,\
23  ##__VA_ARGS__); \
24 } while (false) \
25 
26 //Per Path state machine to determine preference of a path based on
27 //traffic(GARP or flow from VM)
29  public sc::state_machine<PathPreferenceSM, Init> {
31 public:
32  static const uint32_t kMinInterval = 4 * 1000;
33  static const uint32_t kMaxInterval = 32 * 1000;
34  static const uint32_t kMaxFlapCount = 5;
35  PathPreferenceSM(Agent *agent, const Peer *peer,
36  AgentRoute *rt, bool dependent_rt,
37  const PathPreference &pref);
39  uint32_t sequence() const {return path_preference_.sequence();}
40  uint32_t preference() const {return path_preference_.preference();}
42  bool ecmp() const {return path_preference_.ecmp();}
43  uint32_t timeout() const { return timeout_;}
44 
47  }
48  uint32_t flap_count() const { return flap_count_;}
49 
50  bool is_dependent_rt() const { return is_dependent_rt_;}
51  void set_sequence(uint32_t seq_no) {
53  }
54 
55  void set_preference(uint32_t preference) {
56  path_preference_.set_preference(preference);
57  }
58 
60  path_preference_.set_wait_for_traffic(wait_for_traffic);
61  }
62 
63  void set_ecmp(bool ecmp) {
65  }
66 
67  void set_seen(bool seen) {
68  seen_ = seen;
69  }
70 
71  void set_max_sequence(uint32_t seq) {
72  max_sequence_ = seq;
73  }
74 
75  void set_timeout(uint32_t timeout) {
76  timeout_ = timeout;
77  }
78 
79  void set_last_stable_high_priority_change_at(uint64_t timestamp) {
81  }
82 
84  dependent_rt_.reset(sm);
85  }
86 
87  void set_is_dependent_rt(bool dependent_path) {
88  is_dependent_rt_ = dependent_path;
89  }
90 
91  void set_dependent_ip(const IpAddress &ip) {
93  }
94 
97  }
98 
99  bool IsFlap() const;
100  bool seen() { return seen_; }
101  uint32_t max_sequence() const { return max_sequence_;}
102  void Process();
103  void Delete();
104  void Log(std::string state);
105  void EnqueuePathChange();
106  bool Retry();
107  void StartRetryTimer();
108  void CancelRetryTimer();
109  bool RetryTimerRunning();
110  void IncreaseRetryTimeout();
111  void DecreaseRetryTimeout();
112  bool IsPathFlapping() const;
113  bool IsPathStable() const;
114  void UpdateFlapTime();
115  void UpdateDependentRoute();
116 private:
118  const Peer *peer_;
121  uint32_t max_sequence_;
122  bool seen_;
124  uint32_t timeout_;
127  uint32_t flap_count_;
131 };
132 
133 //Per Route state machine containing a map for all
134 //local path state machine data
136 public:
137  typedef std::map<const Peer *, PathPreferenceSM *> PeerPathPreferenceMap;
140  void Process(bool &should_resolve);
141  PathPreferenceSM *GetSM(const Peer *);
142  PathPreferenceSM* GetDependentPath(const AgentPath *path) const;
143 private:
144  bool GetRouteListenerId(const VrfEntry *vrf,
145  const Agent::RouteTableType &table,
146  DBTableBase::ListenerId &rt_id) const;
150 };
151 
152 //Per VM interface state, containing floating IP
153 //and static route a interface contains
156  struct RouteAddrList {
157  RouteAddrList();
158  RouteAddrList(const Address::Family &family, const IpAddress &ip,
159  uint32_t plen, const std::string &vrf);
160  bool operator<(const RouteAddrList &rhs) const;
161  bool operator==(const RouteAddrList &rhs) const;
162 
165  uint32_t plen_;
166  std::string vrf_name_;
167  mutable bool seen_;
168  };
169  uint32_t DependentRouteListSize() const { return dependent_rt_.size(); }
170 private:
173  std::set<RouteAddrList> dependent_rt_;
174 };
175 
178  DBTableBase::ListenerId evpn_rt_id,
179  DBTableBase::ListenerId uc6_rt_id,
180  DBTableBase::ListenerId mpls_rt_id):
181  uc_rt_id_(uc_rt_id), evpn_rt_id_(evpn_rt_id),
182  uc6_rt_id_(uc6_rt_id),mpls_rt_id_(mpls_rt_id) {}
187 };
188 
191  virtual void Delete();
192 
193  void Notify(DBTablePartBase *partition, DBEntryBase *e);
194  void Init();
195  bool DeleteState(DBTablePartBase *partition, DBEntryBase *e);
196  void Walkdone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition,
198  DBTableBase::ListenerId id() const { return id_;}
199  void ManagedDelete();
200  void set_deleted() {deleted_ = true;}
201  bool deleted() const {return deleted_;}
202 private:
207  bool deleted_;
209 };
210 
212 public:
215  uint32_t plen_;
218  uint32_t vrf_index_;
219  uint32_t vxlan_id_;
220  boost::intrusive_ptr<const sc::event_base> event;
221  };
222 
224  void Init();
225  void Shutdown();
226  void VrfNotify(DBTablePartBase *partition, DBEntryBase *e);
227  void EnqueueTrafficSeen(IpAddress ip, uint32_t plen,
228  uint32_t interface_index, uint32_t vrf_index,
229  const MacAddress &mac);
231  Agent *agent() { return agent_;}
236  void Resolve();
237 private:
242  std::set<PathPreferenceState *> unresolved_paths_;
243 };
244 #endif
void set_sequence(uint32_t sequence)
Definition: agent_path.h:79
static const uint32_t kMinInterval
Definition: vrf.h:86
DependencyList< PathPreferenceSM, PathPreferenceSM > PathDependencyList
static const uint32_t kMaxInterval
DependencyRef< PathPreferenceSM, PathPreferenceSM > dependent_rt_
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge, EVPN (Type2/Type5). This base class contains common code for all types of route tables.
Definition: agent_route.h:109
uint32_t preference() const
Definition: agent_path.h:41
Family
Definition: address.h:24
boost::asio::ip::address IpAddress
Definition: address.h:13
void Notify(DBTablePartBase *partition, DBEntryBase *e)
static const uint32_t kMaxFlapCount
DBTableBase::ListenerId uc6_rt_id_
boost::intrusive_ptr< const sc::event_base > event
void set_last_stable_high_priority_change_at(uint64_t timestamp)
int ListenerId
Definition: db_table.h:62
DBTableBase::ListenerId evpn_rt_id_
void Log(std::string state)
void VrfNotify(DBTablePartBase *partition, DBEntryBase *e)
bool IsPathStable() const
PathPreferenceSM * GetDependentPath(const AgentPath *path) const
DBTableBase::ListenerId mpls_rt_id_
DBTableBase::ListenerId uc_rt_id_
bool GetRouteListenerId(const VrfEntry *vrf, const Agent::RouteTableType &table, DBTableBase::ListenerId &rt_id) const
uint32_t DependentRouteListSize() const
PathPreferenceModule(Agent *agent)
Base class for all Route entries in agent.
Definition: agent_route.h:224
WorkQueue< PathPreferenceEventContainer > work_queue_
std::set< RouteAddrList > dependent_rt_
uint32_t flap_count() const
void set_timeout(uint32_t timeout)
void set_is_dependent_rt(bool dependent_path)
DBTableBase::ListenerId vrf_id_
PeerPathPreferenceMap path_preference_peer_map_
bool operator==(const RouteAddrList &rhs) const
bool ecmp() const
Definition: agent_path.h:45
std::map< const Peer *, PathPreferenceSM * > PeerPathPreferenceMap
uint64_t last_stable_high_priority_change_at() const
DBTableBase::ListenerId id() const
DBTableBase::ListenerId vrf_id() const
void set_dependent_ip(const IpAddress &ip)
Definition: agent_path.h:96
Definition: agent.h:358
void set_dependent_ip(const IpAddress &ip)
DBTableBase::ListenerId intf_id() const
void set_preference(uint32_t preference)
PathPreferenceIntfState(const VmInterface *intf)
PathPreference path_preference_
void set_wait_for_traffic(bool wait_for_traffic)
Definition: agent_path.h:85
void set_preference(uint32_t preference)
Definition: agent_path.h:82
void EnqueueTrafficSeen(IpAddress ip, uint32_t plen, uint32_t interface_index, uint32_t vrf_index, const MacAddress &mac)
void set_sequence(uint32_t seq_no)
bool DequeueEvent(PathPreferenceEventContainer e)
void AddUnresolvedPath(PathPreferenceState *sm)
Definition: peer.h:44
bool IsPathFlapping() const
PathPreferenceSM(Agent *agent, const Peer *peer, AgentRoute *rt, bool dependent_rt, const PathPreference &pref)
uint32_t max_sequence() const
PathPreferenceVrfState(DBTableBase::ListenerId uc_rt_id, DBTableBase::ListenerId evpn_rt_id, DBTableBase::ListenerId uc6_rt_id, DBTableBase::ListenerId mpls_rt_id)
void set_max_sequence(uint32_t seq)
uint32_t preference() const
LifetimeRef< PathPreferenceRouteListener > table_delete_ref_
std::set< PathPreferenceState * > unresolved_paths_
const Peer * peer_
bool DeleteState(DBTablePartBase *partition, DBEntryBase *e)
void Walkdone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition, PathPreferenceRouteListener *state)
uint32_t sequence() const
bool IsFlap() const
const VmInterface * intf_
void set_seen(bool seen)
uint64_t backoff_timer_fired_time_
void DeleteUnresolvedPath(PathPreferenceState *sm)
DBTable::DBTableWalkRef managed_delete_walk_ref_
PathPreferenceSM * GetSM(const Peer *)
DBTableBase::ListenerId id_
DEPENDENCY_LIST(PathPreferenceSM, PathPreferenceSM, dependent_routes_)
bool wait_for_traffic() const
Definition: agent_path.h:42
void Process(bool &should_resolve)
IpAddress dependent_ip()
void set_ecmp(bool ecmp)
void set_ecmp(bool ecmp)
Definition: agent_path.h:88
const IpAddress & dependent_ip() const
Definition: agent_path.h:68
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:169
DBTableBase::ListenerId intf_id_
void set_dependent_rt(PathPreferenceSM *sm)
RouteTableType
Definition: agent.h:415
Definition: timer.h:54
void reset(ObjectType *ptr)
Definition: dependency.h:32
uint32_t timeout() const
AgentRoute * rt_
bool wait_for_traffic() const
bool is_dependent_rt() const
uint64_t last_stable_high_priority_change_at_
PathPreferenceState(Agent *agent, AgentRoute *rt_)
uint32_t sequence() const
Definition: agent_path.h:40
void set_wait_for_traffic(bool wait_for_traffic)
PathPreferenceRouteListener(Agent *agent, AgentRouteTable *table)
bool ecmp() const
bool operator<(const RouteAddrList &rhs) const