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