OpenSDN source code
physical_locator_ovsdb.cc
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 extern "C" {
7 #include <ovsdb_wrapper.h>
8 };
9 
10 #include <ovsdb_client_idl.h>
11 #include <physical_locator_ovsdb.h>
12 #include <ovsdb_types.h>
13 
16 
17 PhysicalLocatorEntry::PhysicalLocatorEntry(PhysicalLocatorTable *table,
18  const std::string &dip_str) : OvsdbEntry(table), dip_(dip_str),
19  create_req_owner_(NULL) {
20 }
21 
23  assert(create_req_owner_ == NULL);
24 }
25 
26 bool PhysicalLocatorEntry::IsLess(const KSyncEntry &entry) const {
27  const PhysicalLocatorEntry &pl_entry =
28  static_cast<const PhysicalLocatorEntry&>(entry);
29  return (dip_ < pl_entry.dip_);
30 }
31 
33  return NULL;
34 }
35 
37  if (create_req_owner_ == NULL) {
38  create_req_owner_ = creator;
39  return true;
40  }
41  return false;
42 }
43 
45  assert(create_req_owner_ == creator);
46  if (!IsResolved() && create_req_owner_ != NULL) {
47  // if entry is not resolved before clear Create Request
48  table_->BackRefReEval(this);
49  }
50  create_req_owner_ = NULL;
51 }
52 
54  OvsdbObject(idl) {
56  boost::bind(&PhysicalLocatorTable::OvsdbNotify, this, _1, _2));
57 }
58 
60 }
61 
63  struct ovsdb_idl_row *row) {
64  const char *dip_str = ovsdb_wrapper_physical_locator_dst_ip(row);
65  PhysicalLocatorEntry key(this, dip_str);
66  PhysicalLocatorEntry *entry =
67  static_cast<PhysicalLocatorEntry *>(Find(&key));
68  if (op == OvsdbClientIdl::OVSDB_DEL) {
69  if (entry != NULL && entry->IsActive()) {
70  OVSDB_TRACE(Trace, "Delete received for Physical Locator " +
71  entry->dip_);
72  Delete(entry);
73  }
74  } else if (op == OvsdbClientIdl::OVSDB_ADD) {
75  if (entry == NULL) {
76  entry = static_cast<PhysicalLocatorEntry *>(Create(&key));
77  entry->ovs_entry_ = row;
78  } else if (!entry->IsActive()) {
79  entry->ovs_entry_ = row;
80  // Activate entry by triggering change
81  Change(entry);
82  }
83  OVSDB_TRACE(Trace, "Add received for Physical Locator " +
84  entry->dip_);
85  } else {
86  assert(0);
87  }
88 }
89 
90 KSyncEntry *PhysicalLocatorTable::Alloc(const KSyncEntry *key, uint32_t index) {
91  const PhysicalLocatorEntry *k_entry =
92  static_cast<const PhysicalLocatorEntry *>(key);
93  PhysicalLocatorEntry *entry = new PhysicalLocatorEntry(this, k_entry->dip_);
94  return entry;
95 }
96 
bool IsActive()
Definition: ksync_entry.h:191
bool IsResolved()
void BackRefReEval(KSyncEntry *key)
KSyncEntry * Find(const KSyncEntry *key)
void Change(KSyncEntry *entry)
KSyncEntry * Create(const KSyncEntry *key)
void Delete(KSyncEntry *entry)
void Register(EntryType type, NotifyCB cb)
OvsdbObject * table_
Definition: ovsdb_entry.h:53
struct ovsdb_idl_row * ovs_entry_
Definition: ovsdb_entry.h:54
bool AcquireCreateRequest(KSyncEntry *creator)
void ReleaseCreateRequest(KSyncEntry *creator)
bool IsLess(const KSyncEntry &) const
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)
void OvsdbNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
PhysicalLocatorTable(OvsdbClientIdl *idl)
Definition: trace.h:289
#define OVSDB_TRACE(obj,...)
char * ovsdb_wrapper_physical_locator_dst_ip(struct ovsdb_idl_row *row)