OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical_locator_ovsdb.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 extern "C" {
6 #include <ovsdb_wrapper.h>
7 };
8 
9 #include <ovsdb_client_idl.h>
10 #include <physical_locator_ovsdb.h>
11 #include <ovsdb_types.h>
12 
15 
16 PhysicalLocatorEntry::PhysicalLocatorEntry(PhysicalLocatorTable *table,
17  const std::string &dip_str) : OvsdbEntry(table), dip_(dip_str),
18  create_req_owner_(NULL) {
19 }
20 
22  assert(create_req_owner_ == NULL);
23 }
24 
25 bool PhysicalLocatorEntry::IsLess(const KSyncEntry &entry) const {
26  const PhysicalLocatorEntry &pl_entry =
27  static_cast<const PhysicalLocatorEntry&>(entry);
28  return (dip_ < pl_entry.dip_);
29 }
30 
32  return NULL;
33 }
34 
36  if (create_req_owner_ == NULL) {
37  create_req_owner_ = creator;
38  return true;
39  }
40  return false;
41 }
42 
44  assert(create_req_owner_ == creator);
45  if (!IsResolved() && create_req_owner_ != NULL) {
46  // if entry is not resolved before clear Create Request
47  table_->BackRefReEval(this);
48  }
49  create_req_owner_ = NULL;
50 }
51 
53  OvsdbObject(idl) {
55  boost::bind(&PhysicalLocatorTable::OvsdbNotify, this, _1, _2));
56 }
57 
59 }
60 
62  struct ovsdb_idl_row *row) {
63  const char *dip_str = ovsdb_wrapper_physical_locator_dst_ip(row);
64  PhysicalLocatorEntry key(this, dip_str);
65  PhysicalLocatorEntry *entry =
66  static_cast<PhysicalLocatorEntry *>(Find(&key));
67  if (op == OvsdbClientIdl::OVSDB_DEL) {
68  if (entry != NULL && entry->IsActive()) {
69  OVSDB_TRACE(Trace, "Delete received for Physical Locator " +
70  entry->dip_);
71  Delete(entry);
72  }
73  } else if (op == OvsdbClientIdl::OVSDB_ADD) {
74  if (entry == NULL) {
75  entry = static_cast<PhysicalLocatorEntry *>(Create(&key));
76  entry->ovs_entry_ = row;
77  } else if (!entry->IsActive()) {
78  entry->ovs_entry_ = row;
79  // Activate entry by triggering change
80  Change(entry);
81  }
82  OVSDB_TRACE(Trace, "Add received for Physical Locator " +
83  entry->dip_);
84  } else {
85  assert(0);
86  }
87 }
88 
89 KSyncEntry *PhysicalLocatorTable::Alloc(const KSyncEntry *key, uint32_t index) {
90  const PhysicalLocatorEntry *k_entry =
91  static_cast<const PhysicalLocatorEntry *>(key);
92  PhysicalLocatorEntry *entry = new PhysicalLocatorEntry(this, k_entry->dip_);
93  return entry;
94 }
95 
void OvsdbNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
#define OVSDB_TRACE(obj,...)
void Change(KSyncEntry *entry)
bool IsResolved()
char * ovsdb_wrapper_physical_locator_dst_ip(struct ovsdb_idl_row *row)
bool IsLess(const KSyncEntry &) const
PhysicalLocatorTable(OvsdbClientIdl *idl)
void Delete(KSyncEntry *entry)
bool AcquireCreateRequest(KSyncEntry *creator)
void Register(EntryType type, NotifyCB cb)
struct ovsdb_idl_row * ovs_entry_
Definition: ovsdb_entry.h:53
Definition: trace.h:220
KSyncEntry * Find(const KSyncEntry *key)
Definition: ksync_object.cc:99
bool IsActive()
Definition: ksync_entry.h:172
KSyncEntry * Create(const KSyncEntry *key)
void BackRefReEval(KSyncEntry *key)
OvsdbObject * table_
Definition: ovsdb_entry.h:52
void ReleaseCreateRequest(KSyncEntry *creator)
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)