OpenSDN source code
path_preference.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 #ifndef __ROUTE_PREFERENCE_H__
6 #define __ROUTE_PREFERENCE_H__
7 
8 #include <boost/statechart/custom_reaction.hpp>
9 #include <boost/statechart/event.hpp>
10 #include <boost/statechart/simple_state.hpp>
11 #include <boost/statechart/state.hpp>
12 #include <boost/statechart/state_machine.hpp>
13 
14 namespace sc = boost::statechart;
15 struct Init;
16 struct WaitForTraffic;
17 struct TrafficSeen;
18 struct ActiveActiveState;
20 
21 #define PATH_PREFERENCE_TRACE(...) \
22 do { \
23  PathPreferenceTrace::TraceMsg(PathPreferenceTraceBuf, __FILE__, __LINE__,\
24  ##__VA_ARGS__); \
25 } while (false) \
26 
27 //Per Path state machine to determine preference of a path based on
28 //traffic(GARP or flow from VM)
30  public sc::state_machine<PathPreferenceSM, Init> {
32 public:
33  static const uint32_t kMinInterval = 4 * 1000;
34  static const uint32_t kMaxInterval = 32 * 1000;
35  static const uint32_t kMaxFlapCount = 5;
36  PathPreferenceSM(Agent *agent, const Peer *peer,
37  AgentRoute *rt, bool dependent_rt,
38  const PathPreference &pref);
40  uint32_t sequence() const {return path_preference_.sequence();}
41  uint32_t preference() const {return path_preference_.preference();}
43  bool ecmp() const {return path_preference_.ecmp();}
44  uint32_t timeout() const { return timeout_;}
45 
48  }
49  uint32_t flap_count() const { return flap_count_;}
50 
51  bool is_dependent_rt() const { return is_dependent_rt_;}
52  void set_sequence(uint32_t seq_no) {
54  }
55 
56  void set_preference(uint32_t preference) {
58  }
59 
62  }
63 
64  void set_ecmp(bool ecmp) {
66  }
67 
68  void set_seen(bool seen) {
69  seen_ = seen;
70  }
71 
72  void set_max_sequence(uint32_t seq) {
73  max_sequence_ = seq;
74  }
75 
76  void set_timeout(uint32_t timeout) {
77  timeout_ = timeout;
78  }
79 
80  void set_last_stable_high_priority_change_at(uint64_t timestamp) {
82  }
83 
85  dependent_rt_.reset(sm);
86  }
87 
88  void set_is_dependent_rt(bool dependent_path) {
89  is_dependent_rt_ = dependent_path;
90  }
91 
92  void set_dependent_ip(const IpAddress &ip) {
94  }
95 
98  }
99 
100  bool IsFlap() const;
101  bool seen() { return seen_; }
102  uint32_t max_sequence() const { return max_sequence_;}
103  void Process();
104  void Delete();
105  void Log(std::string state);
106  void EnqueuePathChange();
107  bool Retry();
108  void StartRetryTimer();
109  void CancelRetryTimer();
110  bool RetryTimerRunning();
111  void IncreaseRetryTimeout();
112  void DecreaseRetryTimeout();
113  bool IsPathFlapping() const;
114  bool IsPathStable() const;
115  void UpdateFlapTime();
116  void UpdateDependentRoute();
117 private:
119  const Peer *peer_;
122  uint32_t max_sequence_;
123  bool seen_;
125  uint32_t timeout_;
128  uint32_t flap_count_;
132 };
133 
134 //Per Route state machine containing a map for all
135 //local path state machine data
137 public:
138  typedef std::map<const Peer *, PathPreferenceSM *> PeerPathPreferenceMap;
141  void Process(bool &should_resolve);
142  PathPreferenceSM *GetSM(const Peer *);
143  PathPreferenceSM* GetDependentPath(const AgentPath *path) const;
144 private:
145  bool GetRouteListenerId(const VrfEntry *vrf,
146  const Agent::RouteTableType &table,
147  DBTableBase::ListenerId &rt_id) const;
151 };
152 
153 //Per VM interface state, containing floating IP
154 //and static route a interface contains
157  struct RouteAddrList {
158  RouteAddrList();
159  RouteAddrList(const Address::Family &family, const IpAddress &ip,
160  uint32_t plen, const std::string &vrf);
161  bool operator<(const RouteAddrList &rhs) const;
162  bool operator==(const RouteAddrList &rhs) const;
163 
166  uint32_t plen_;
167  std::string vrf_name_;
168  mutable bool seen_;
169  };
170  uint32_t DependentRouteListSize() const { return dependent_rt_.size(); }
171 private:
174  std::set<RouteAddrList> dependent_rt_;
175 };
176 
179  DBTableBase::ListenerId evpn_rt_id,
180  DBTableBase::ListenerId uc6_rt_id,
181  DBTableBase::ListenerId mpls_rt_id):
182  uc_rt_id_(uc_rt_id), evpn_rt_id_(evpn_rt_id),
183  uc6_rt_id_(uc6_rt_id),mpls_rt_id_(mpls_rt_id) {}
188 };
189 
192  virtual void Delete();
193 
194  void Notify(DBTablePartBase *partition, DBEntryBase *e);
195  void Init();
196  bool DeleteState(DBTablePartBase *partition, DBEntryBase *e);
197  void Walkdone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition,
199  DBTableBase::ListenerId id() const { return id_;}
200  void ManagedDelete();
201  void set_deleted() {deleted_ = true;}
202  bool deleted() const {return deleted_;}
203 private:
208  bool deleted_;
210 };
211 
213 public:
216  uint32_t plen_;
219  uint32_t vrf_index_;
220  uint32_t vxlan_id_;
221  boost::intrusive_ptr<const sc::event_base> event;
222  };
223 
225  void Init();
226  void Shutdown();
227  void VrfNotify(DBTablePartBase *partition, DBEntryBase *e);
228  void EnqueueTrafficSeen(IpAddress ip, uint32_t plen,
229  uint32_t interface_index, uint32_t vrf_index,
230  const MacAddress &mac);
232  Agent *agent() { return agent_;}
237  void Resolve();
238 private:
243  std::set<PathPreferenceState *> unresolved_paths_;
244 };
245 #endif
boost::asio::ip::address IpAddress
Definition: address.h:14
Family
Definition: address.h:25
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:110
Base class for all Route entries in agent.
Definition: agent_route.h:225
Definition: agent.h:361
RouteTableType
Definition: agent.h:418
int ListenerId
Definition: db_table.h:63
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:170
void reset(ObjectType *ptr)
Definition: dependency.h:33
bool DequeueEvent(PathPreferenceEventContainer e)
void VrfNotify(DBTablePartBase *partition, DBEntryBase *e)
DBTableBase::ListenerId vrf_id_
void DeleteUnresolvedPath(PathPreferenceState *sm)
std::set< PathPreferenceState * > unresolved_paths_
PathPreferenceModule(Agent *agent)
DBTableBase::ListenerId intf_id_
DBTableBase::ListenerId intf_id() const
void AddUnresolvedPath(PathPreferenceState *sm)
DBTableBase::ListenerId vrf_id() const
void EnqueueTrafficSeen(IpAddress ip, uint32_t plen, uint32_t interface_index, uint32_t vrf_index, const MacAddress &mac)
WorkQueue< PathPreferenceEventContainer > work_queue_
uint32_t sequence() const
uint64_t backoff_timer_fired_time_
uint32_t timeout() const
uint32_t flap_count() const
AgentRoute * rt_
bool wait_for_traffic() const
uint64_t last_stable_high_priority_change_at_
bool IsPathStable() const
void set_dependent_ip(const IpAddress &ip)
DEPENDENCY_LIST(PathPreferenceSM, PathPreferenceSM, dependent_routes_)
bool ecmp() const
static const uint32_t kMaxInterval
PathPreferenceSM(Agent *agent, const Peer *peer, AgentRoute *rt, bool dependent_rt, const PathPreference &pref)
void set_is_dependent_rt(bool dependent_path)
void set_ecmp(bool ecmp)
uint32_t max_sequence() const
const Peer * peer_
void Log(std::string state)
PathPreference path_preference_
void set_max_sequence(uint32_t seq)
static const uint32_t kMinInterval
void set_wait_for_traffic(bool wait_for_traffic)
DependencyList< PathPreferenceSM, PathPreferenceSM > PathDependencyList
bool is_dependent_rt() const
DependencyRef< PathPreferenceSM, PathPreferenceSM > dependent_rt_
bool IsPathFlapping() const
static const uint32_t kMaxFlapCount
void set_sequence(uint32_t seq_no)
void set_timeout(uint32_t timeout)
IpAddress dependent_ip()
void set_seen(bool seen)
void set_dependent_rt(PathPreferenceSM *sm)
bool IsFlap() const
uint64_t last_stable_high_priority_change_at() const
void set_last_stable_high_priority_change_at(uint64_t timestamp)
void set_preference(uint32_t preference)
uint32_t preference() const
PathPreferenceSM * GetSM(const Peer *)
bool GetRouteListenerId(const VrfEntry *vrf, const Agent::RouteTableType &table, DBTableBase::ListenerId &rt_id) const
PathPreferenceSM * GetDependentPath(const AgentPath *path) const
PeerPathPreferenceMap path_preference_peer_map_
PathPreferenceState(Agent *agent, AgentRoute *rt_)
std::map< const Peer *, PathPreferenceSM * > PeerPathPreferenceMap
void Process(bool &should_resolve)
bool ecmp() const
Definition: agent_path.h:46
const IpAddress & dependent_ip() const
Definition: agent_path.h:69
void set_wait_for_traffic(bool wait_for_traffic)
Definition: agent_path.h:86
uint32_t preference() const
Definition: agent_path.h:42
uint32_t sequence() const
Definition: agent_path.h:41
void set_ecmp(bool ecmp)
Definition: agent_path.h:89
void set_sequence(uint32_t sequence)
Definition: agent_path.h:80
void set_dependent_ip(const IpAddress &ip)
Definition: agent_path.h:97
void set_preference(uint32_t preference)
Definition: agent_path.h:83
bool wait_for_traffic() const
Definition: agent_path.h:43
Definition: peer.h:45
Definition: timer.h:58
Definition: vrf.h:90
bool operator<(const RouteAddrList &rhs) const
bool operator==(const RouteAddrList &rhs) const
uint32_t DependentRouteListSize() const
const VmInterface * intf_
PathPreferenceIntfState(const VmInterface *intf)
std::set< RouteAddrList > dependent_rt_
boost::intrusive_ptr< const sc::event_base > event
bool DeleteState(DBTablePartBase *partition, DBEntryBase *e)
DBTable::DBTableWalkRef managed_delete_walk_ref_
PathPreferenceRouteListener(Agent *agent, AgentRouteTable *table)
DBTableBase::ListenerId id() const
DBTableBase::ListenerId id_
LifetimeRef< PathPreferenceRouteListener > table_delete_ref_
void Notify(DBTablePartBase *partition, DBEntryBase *e)
void Walkdone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition, PathPreferenceRouteListener *state)
DBTableBase::ListenerId uc_rt_id_
DBTableBase::ListenerId evpn_rt_id_
PathPreferenceVrfState(DBTableBase::ListenerId uc_rt_id, DBTableBase::ListenerId evpn_rt_id, DBTableBase::ListenerId uc6_rt_id, DBTableBase::ListenerId mpls_rt_id)
DBTableBase::ListenerId mpls_rt_id_
DBTableBase::ListenerId uc6_rt_id_