OpenSDN source code
vm_interface_ksync.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 #include <vm_interface_ksync.h>
10 
11 #include <oper/vn.h>
12 #include <oper/interface.h>
13 #include <oper/vm_interface.h>
14 #include <oper/vrf.h>
15 #include <ovsdb_types.h>
16 #include <ovsdb_route_data.h>
17 #include <ovsdb_route_peer.h>
18 
22 
23 VMInterfaceKSyncEntry::VMInterfaceKSyncEntry(VMInterfaceKSyncObject *table,
24  const VmInterface *entry) : OvsdbDBEntry(table),
25  uuid_(entry->GetUuid()) {
26 }
27 
29  const VMInterfaceKSyncEntry *key) : OvsdbDBEntry(table),
30  uuid_(key->uuid_) {
31 }
32 
34  boost::uuids::uuid uuid) : OvsdbDBEntry(table), uuid_(uuid) {
35 }
36 
37 void VMInterfaceKSyncEntry::AddMsg(struct ovsdb_idl_txn *txn) {
38 }
39 
40 void VMInterfaceKSyncEntry::ChangeMsg(struct ovsdb_idl_txn *txn) {
41 }
42 
43 void VMInterfaceKSyncEntry::DeleteMsg(struct ovsdb_idl_txn *txn) {
44 }
45 
47  VmInterface *entry = static_cast<VmInterface *>(db_entry);
48  bool ret = false;
49 
50  std::string vn_name;
51  if (entry->vn()) {
52  vn_name = UuidToString(entry->vn()->GetUuid());
53  }
54 
55  SecurityGroupList sg_list;
56  entry->CopySgIdList(&sg_list);
57  if (sg_list != sg_list_) {
58  // Enqueue a RESYNC on the route with new VN-Name and SG-ID
59  const VrfEntry *vrf = entry->vrf();
60  const VnEntry *vn = entry->vn();
61  const VxLanId *vxlan = NULL;
62  if (vn)
63  vxlan = vn->vxlan_id_ref();
64  if (vrf != NULL && vn != NULL && vxlan != NULL &&
65  !table_->client_idl()->IsDeleted() &&
66  table_->client_idl()->route_peer() != NULL) {
67  EvpnAgentRouteTable *evpn_table = static_cast<EvpnAgentRouteTable *>
68  (vrf->GetEvpnRouteTable());
69 
70  // SG-ID changed, update OVSDB Route for VMI with new SG-ID
71  sg_list_ = sg_list;
72  OvsdbRouteResyncData *data = new OvsdbRouteResyncData(sg_list);
73  evpn_table->ResyncVmRoute(table_->client_idl()->route_peer(),
74  vrf->GetName(), entry->vm_mac(), IpAddress(),
75  vxlan->vxlan_id(), data);
76  ret = true;
77  }
78  }
79 
80  if (vn_name_ != vn_name) {
81  vn_name_ = vn_name;
82  ret = true;
83  }
84  return ret;
85 }
86 
87 bool VMInterfaceKSyncEntry::IsLess(const KSyncEntry &entry) const {
88  const VMInterfaceKSyncEntry &intf_entry =
89  static_cast<const VMInterfaceKSyncEntry&>(entry);
90  return uuid_ < intf_entry.uuid_;
91 }
92 
94  if (vn_name_.empty()) {
96  }
97  return NULL;
98 }
99 
100 const std::string &VMInterfaceKSyncEntry::vn_name() const {
101  return vn_name_;
102 }
103 
105  OvsdbDBObject(idl, table, false) {
106 }
107 
109 }
110 
112  const VMInterfaceKSyncEntry *k_entry =
113  static_cast<const VMInterfaceKSyncEntry *>(key);
114  VMInterfaceKSyncEntry *entry = new VMInterfaceKSyncEntry(this, k_entry);
115  return entry;
116 }
117 
119  const VmInterface *entry = static_cast<const VmInterface *>(db_entry);
120  VMInterfaceKSyncEntry *key = new VMInterfaceKSyncEntry(this, entry);
121  return static_cast<KSyncEntry *>(key);
122 }
123 
125  const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry) {
126  const Interface *intf = static_cast<const Interface *>(entry);
127  // only accept vm interfaces
128  if (intf->type() != Interface::VM_INTERFACE) {
129  return DBFilterIgnore;
130  }
131  return DBFilterAccept;
132 }
133 
boost::asio::ip::address IpAddress
Definition: address.h:14
std::vector< int > SecurityGroupList
Definition: agent.h:202
static void ResyncVmRoute(const Peer *peer, const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag, AgentRouteData *data)
@ VM_INTERFACE
Definition: interface.h:38
VrfEntry * vrf() const
Definition: interface.h:118
Type type() const
Definition: interface.h:115
static KSyncEntry * default_defer_entry()
KSyncObjectManager * ksync_obj_manager()
OvsdbDBObject * table_
Definition: ovsdb_entry.h:111
OvsdbClientIdl * client_idl()
Definition: ovsdb_object.h:77
void DeleteMsg(struct ovsdb_idl_txn *)
const std::string & vn_name() const
void AddMsg(struct ovsdb_idl_txn *)
bool IsLess(const KSyncEntry &) const
VMInterfaceKSyncEntry(VMInterfaceKSyncObject *table, const VMInterfaceKSyncEntry *key)
void ChangeMsg(struct ovsdb_idl_txn *)
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)
KSyncEntry * DBToKSyncEntry(const DBEntry *)
DBFilterResp OvsdbDBEntryFilter(const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry)
VMInterfaceKSyncObject(OvsdbClientIdl *idl, DBTable *table)
const MacAddress & vm_mac() const
const VnEntry * vn() const
void CopySgIdList(SecurityGroupList *sg_id_list) const
Definition: vn.h:152
const boost::uuids::uuid & GetUuid() const
Definition: vn.h:162
const VxLanId * vxlan_id_ref() const
Definition: vn.h:193
Definition: vrf.h:90
const string & GetName() const
Definition: vrf.h:104
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:331
Definition: vxlan.h:14
uint32_t vxlan_id() const
Definition: vxlan.h:27
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:139
boost::uuids::uuid uuid