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