OpenSDN source code
logical_switch_ovsdb.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_LOGICAL_SWITCH_OVSDB_H_
7 #define SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_LOGICAL_SWITCH_OVSDB_H_
8 
9 #include <ovsdb_entry.h>
10 #include <ovsdb_object.h>
11 #include <ovsdb_client_idl.h>
14 
15 class PhysicalDeviceVn;
16 
17 namespace OVSDB {
18 class LogicalSwitchEntry;
19 class OvsdbResourceVxLanId;
20 
21 // Logical Switch reference pointer to maintain active references
22 // in OVSDB database that needs to be deleted before triggering
23 // delete of a logical switch
25 
27 public:
28  typedef std::map<struct ovsdb_idl_row *, LogicalSwitchEntry *> OvsdbIdlRowMap;
30  virtual ~LogicalSwitchTable();
31 
32  void OvsdbNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *);
33  void OvsdbMcastLocalMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *);
34  void OvsdbMcastRemoteMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *);
35  void OvsdbUcastLocalMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *);
36 
37  KSyncEntry *Alloc(const KSyncEntry *key, uint32_t index);
39  OvsdbDBEntry *AllocOvsEntry(struct ovsdb_idl_row *row);
41  const OvsdbDBEntry *ovsdb_entry);
42  void ProcessDeleteTableReq();
43 
44 private:
46  public:
47  static const int kEntriesPerIteration = 32;
50 
51  bool Run();
52  std::string Description() const {
53  return "LogicalSwitchTable::ProcessDeleteTableReqTask";
54  }
55 
56  private:
60  };
61 
64 };
65 
67 public:
68  typedef std::set<struct ovsdb_idl_row *> OvsdbIdlRowList;
69  enum Trace {
75  };
76  LogicalSwitchEntry(OvsdbDBObject *table, const std::string &name);
79  const PhysicalDeviceVn *entry);
81  struct ovsdb_idl_row *entry);
82 
83  virtual ~LogicalSwitchEntry();
84 
86  void AddMsg(struct ovsdb_idl_txn *);
87  void ChangeMsg(struct ovsdb_idl_txn *);
88  void DeleteMsg(struct ovsdb_idl_txn *);
89  virtual void NotifyDelete(struct ovsdb_idl_row *);
90 
91  void OvsdbChange();
92 
93  const std::string &name() const;
94  const std::string &device_name() const;
95  int64_t vxlan_id() const;
96  std::string tor_service_node() const;
98  bool IsDeleteOvsInProgress() const;
99 
100  bool Sync(DBEntry*);
101  bool IsLess(const KSyncEntry&) const;
102  std::string ToString() const {return "Logical Switch";}
104 
105  bool IsLocalMacsRef() const;
106 
107  // Override Ack api to get trigger on Ack
108  void Ack(bool success);
109 
110  // Override TxnDoneNoMessage to get triggers for no message
111  // transaction complete
112  void TxnDoneNoMessage();
113 
114  // API used to remove Logical Switch from OVSDB-database
115  // this can be triggered when the relevance of logical switch
116  // in OVSDB database is either not required (when physical
117  // device VN doesnot exist) or when it is incomplete due to
118  // unavailability of logical switch resource like VxLAN ID
119  //
120  // To trigger delete of Logical Switch from OVSDB server, we
121  // must remove the vlan-port bindings and unicast/multicast
122  // remote routes before triggering delete of logical switch
123  // Logical Switch uses intrusive pointer back reference infra
124  // to maintain back references to the objects that needs to be
125  // deleted.
126  // This API works with an assumption that while this API is
127  // triggered Logical switch is either delete marked or deferred
128  // so that DELADD_REQ triggers done on dependent entries will
129  // release backreference pointer till the Logical switch becomes
130  // active again and remains in deferred state
131  // Once logical switch is available again in OVSDB-server
132  // we program back all the deferred entries
133  void DeleteOvs(bool add_change_in_progress);
134 
135  virtual void StaleTimerExpired();
136 
137  //Sandesh helpers
138  uint32_t mcast_local_row_list_size() const {
139  return mcast_local_row_list_.size();
140  }
141  uint32_t ucast_local_row_list_size() const {
142  return ucast_local_row_list_.size();
143  }
145  return old_mcast_remote_row_list_.size();
146  }
147  bool is_local_mac_ref_set() const {
148  return local_mac_ref_ != NULL;
149  }
150  bool is_mcast_remote_set() const {
151  return mcast_remote_row_ != NULL;
152  }
153 private:
154  class ProcessDeleteOvsReqTask : public Task {
155  public:
156  static const int kEntriesPerIteration = 32;
158  virtual ~ProcessDeleteOvsReqTask();
159 
160  bool Run();
161  std::string Description() const {
162  return "LogicalSwitchEntry::ProcessDeleteOvsReqTask";
163  }
164 
165  private:
167  // back reference to the reffer from which process
168  // should start triggering DelAdd OP
171  };
172 
173  // API used to stop running Delete OVS task, this is always
174  // called in conjuction with activation or free of the entry
175  void CancelDeleteOvs();
176  void SendTrace(Trace event) const;
178 
180 
181  friend class LogicalSwitchTable;
182  // not defining ref add and ref release for LogicalSwitchEntry
183  // will endup calling functions for KSyncEntry class, thus
184  // provide base refence infra along with local back ref info
186  LogicalSwitchEntry *p);
188  LogicalSwitchEntry *p);
189 
190  std::string name_;
191  std::string device_name_;
193  // self ref to account for local mac from ToR, we hold
194  // the reference till timeout or when all the local
195  // macs are withdrawn
197 
198  // physical_locator create ref
200 
201  int64_t vxlan_id_;
203  struct ovsdb_idl_row *mcast_remote_row_;
206 
207  // indicates deleting logical switch from ovsdb is in process
208  // used to identify operation while Logical switch is waiting
209  // for local macs to be deleted
213 
214  // set of back reference, which needs to be deleted before
215  // triggering delete of logical switch
216  std::set<IntrusiveReferrer> back_ref_set_;
217 
219 };
220 };
221 
222 #endif //SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_LOGICAL_SWITCH_OVSDB_H_
223 
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
boost::intrusive_ptr< KSyncEntry > KSyncEntryPtr
Definition: ksync_entry.h:69
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
std::string Description() const
Gives a description of the task.
void SendTrace(Trace event) const
OvsdbResourceVxLanId res_vxlan_id_
void DeleteOvs(bool add_change_in_progress)
friend void intrusive_ptr_add_back_ref(IntrusiveReferrer ref, LogicalSwitchEntry *p)
uint32_t ucast_local_row_list_size() const
void AddMsg(struct ovsdb_idl_txn *)
const std::string & device_name() const
OvsdbResourceVxLanId & res_vxlan_id()
void DeleteMsg(struct ovsdb_idl_txn *)
void ChangeMsg(struct ovsdb_idl_txn *)
ProcessDeleteOvsReqTask * del_task_
const std::string & name() const
std::string tor_service_node() const
bool IsLess(const KSyncEntry &) const
DISALLOW_COPY_AND_ASSIGN(LogicalSwitchEntry)
struct ovsdb_idl_row * mcast_remote_row_
uint32_t old_mcast_remote_row_list_size() const
Ip4Address & physical_switch_tunnel_ip()
std::set< struct ovsdb_idl_row * > OvsdbIdlRowList
LogicalSwitchEntry(OvsdbDBObject *table, const std::string &name)
virtual void NotifyDelete(struct ovsdb_idl_row *)
uint32_t mcast_local_row_list_size() const
friend void intrusive_ptr_del_back_ref(IntrusiveReferrer ref, LogicalSwitchEntry *p)
OvsdbIdlRowList old_mcast_remote_row_list_
std::set< IntrusiveReferrer > back_ref_set_
std::string Description() const
Gives a description of the task.
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
KSyncEntry * DBToKSyncEntry(const DBEntry *)
void OvsdbUcastLocalMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
std::map< struct ovsdb_idl_row *, LogicalSwitchEntry * > OvsdbIdlRowMap
LogicalSwitchTable(OvsdbClientIdl *idl)
void OvsdbMcastRemoteMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)
void OvsdbMcastLocalMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
OvsdbDBEntry * AllocOvsEntry(struct ovsdb_idl_row *row)
DBFilterResp OvsdbDBEntryFilter(const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry)
DISALLOW_COPY_AND_ASSIGN(LogicalSwitchTable)
void OvsdbNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
OvsdbDBObject * table()
Definition: ovsdb_entry.h:97
Task is a class to describe a computational task within OpenSDN control plane applications....
Definition: task.h:82
Definition: trace.h:289
std::pair< void *, void * > IntrusiveReferrer
Definition: agent.h:44
IntrusivePtrRef< LogicalSwitchEntry > LogicalSwitchRef