OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
port_ipc_handler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  */
4 #include <ctype.h>
5 #include <stdio.h>
6 #include <sstream>
7 #include <fstream>
8 #include <net/if.h>
9 #include <boost/uuid/uuid.hpp>
10 #include <boost/filesystem.hpp>
11 #include <boost/foreach.hpp>
12 #include <rapidjson/document.h>
13 #include <rapidjson/prettywriter.h>
14 #include <rapidjson/stringbuffer.h>
15 #include "base/logging.h"
16 #include "base/task.h"
17 #include "base/string_util.h"
18 #include "db/db.h"
19 #include "db/db_entry.h"
20 #include "db/db_table.h"
21 #include "cmn/agent_cmn.h"
22 #include "init/agent_param.h"
23 #include "cfg/cfg_init.h"
24 #include "oper/interface_common.h"
25 #include "oper/vm.h"
26 #include "oper/vn.h"
28 #include "port_ipc/port_ipc_types.h"
30 
31 using boost::uuids::nil_uuid;
32 namespace fs = boost::filesystem;
33 
35 // Utility methods
37 static bool GetStringMember(const contrail_rapidjson::Value &d, const char *member,
38  std::string *data, std::string *err) {
39  if (!d.HasMember(member) || !d[member].IsString()) {
40  if (err) {
41  *err += "Invalid or missing field for <" + string(member) + ">";
42  }
43  return false;
44  }
45 
46  *data = d[member].GetString();
47  return true;
48 }
49 
50 static bool GetUint32Member(const contrail_rapidjson::Value &d, const char *member,
51  uint32_t *data, std::string *err) {
52  if (!d.HasMember(member) || !d[member].IsInt()) {
53  if (err) {
54  *err += "Invalid or missing field for <" + string(member) + ">";
55  }
56  return false;
57  }
58 
59  *data = d[member].GetInt();
60  return true;
61 }
62 
63 static bool GetUuidMember(const contrail_rapidjson::Value &d, const char *member,
64  boost::uuids::uuid *u, std::string *err) {
65  if (!d.HasMember(member) || !d[member].IsString()) {
66  if (err) {
67  *err += "Invalid or missing data for <" + string(member) + ">";
68  }
69  return false;
70  }
71 
72  *u = StringToUuid(d[member].GetString());
73  return true;
74 }
75 
76 static void InterfaceResync(Agent *agent, const boost::uuids::uuid &u,
77  const string &name, bool link_status) {
78  InterfaceTable *table = agent->interface_table();
80  req.key.reset(new VmInterfaceKey(AgentKey::RESYNC, u, name));
81  req.data.reset(new VmInterfaceOsOperStateData(link_status));
82  table->Enqueue(&req);
83 }
84 
86 // PortIpcHandler methods
88 PortIpcHandler::PortIpcHandler(Agent *agent, const std::string &dir)
89  : agent_(agent), ports_dir_(dir), vmvn_dir_(dir + "/vm"), version_(0),
90  interface_stale_cleaner_(new InterfaceConfigStaleCleaner(agent)),
91  port_subscribe_table_(new PortSubscribeTable(agent_)) {
92  interface_stale_cleaner_->set_callback(
94  interface_stale_cleaner_.get(), _1));
95  uint32_t timeout_secs = agent->params()->stale_interface_cleanup_timeout();
96  //Set timeout in milliseconds
97  interface_stale_cleaner_->set_timeout(timeout_secs * 1000);
98 
99  fs::path ports_dir(ports_dir_);
100  if (fs::exists(ports_dir) == false) {
101  if (!fs::create_directories(ports_dir)) {
102  string err_msg = "Creating directory " + ports_dir_ + " failed";
103  CONFIG_TRACE(PortInfo, err_msg.c_str());
104  }
105  }
106 
107  // Create directory for vm-vn subscription config files
108  fs::path vmvn_dir(vmvn_dir_);
109  if (fs::exists(vmvn_dir) == false) {
110  if (!fs::create_directories(vmvn_dir)) {
111  string err_msg = "Creating directory " + vmvn_dir_ + " failed";
112  CONFIG_TRACE(PortInfo, err_msg.c_str());
113  }
114  }
115 }
116 
118 }
119 
120 void PortIpcHandler::ReloadAllPorts(const std::string &dir, bool check_port,
121  bool vm_vn_ports) {
122  fs::path ports_dir(dir);
123  fs::directory_iterator end_iter;
124 
125  if (!fs::exists(ports_dir) || !fs::is_directory(ports_dir)) {
126  return;
127  }
128 
129  fs::directory_iterator it(ports_dir);
130  BOOST_FOREACH(fs::path const &p, std::make_pair(it, end_iter)) {
131  if (!fs::is_regular_file(p)) {
132  continue;
133  }
134  /* Skip if filename is not in UUID format */
135  if (!IsUUID(p.filename().string())) {
136  continue;
137  }
138 
139  ProcessFile(p.string(), check_port, vm_vn_ports);
140  }
141 }
142 
143 void PortIpcHandler::ReloadAllPorts(bool check_port) {
144  ReloadAllPorts(ports_dir_, check_port, false);
145 
146  /* Process each vm directory under vmvn_dir_ */
147  fs::path vmvn_dir(vmvn_dir_);
148  fs::directory_iterator end_iter;
149 
150  if (!fs::exists(vmvn_dir) || !fs::is_directory(vmvn_dir)) {
151  return;
152  }
153  fs::directory_iterator it(vmvn_dir);
154  BOOST_FOREACH(fs::path const &p, std::make_pair(it, end_iter)) {
155  if (!fs::is_directory(p)) {
156  continue;
157  }
158  ReloadAllPorts(p.string(), check_port, true);
159  }
160 }
161 
162 void PortIpcHandler::ProcessFile(const string &file, bool check_port,
163  bool vm_vn_ports) {
164  string err_msg;
165  std::ifstream f(file.c_str());
166  if (!f.good()) {
167  return;
168  }
169  std::ostringstream tmp;
170  tmp<<f.rdbuf();
171  string json = tmp.str();
172  f.close();
173 
174  if (vm_vn_ports == false)
175  AddPortFromJson(json, check_port, err_msg, false);
176  else
177  AddVmVnPort(json, check_port, err_msg, false);
178 }
179 
180 bool PortIpcHandler::AddPortArrayFromJson(const contrail_rapidjson::Value &d,
181  const string &json,
182  VmiSubscribeEntryPtrList &req_list,
183  bool check_port,
184  string &err_msg) {
185  for (size_t i = 0; i < d.Size(); i++) {
186  const contrail_rapidjson::Value& elem = d[i];
187  if (elem.IsObject() == false) {
188  err_msg = "Json Array has invalid element ==> " + json;
189  CONFIG_TRACE(PortInfo, err_msg.c_str());
190  return false;
191  }
192 
193  PortSubscribeEntry *entry =
194  MakeAddVmiUuidRequest(elem, check_port, err_msg);
195  if (entry == NULL) {
196  CONFIG_TRACE(PortInfo, err_msg.c_str());
197  return false;
198  }
199 
200  req_list.push_back(PortSubscribeEntryPtr(entry));
201  }
202  return true;
203 }
204 
205 bool PortIpcHandler::AddPortFromJson(const string &json, bool check_port,
206  string &err_msg, bool write_file) {
207  contrail_rapidjson::Document d;
208  if (d.Parse<0>(const_cast<char *>(json.c_str())).HasParseError()) {
209  err_msg = "Invalid Json string ==> " + json;
210  CONFIG_TRACE(PortInfo, err_msg.c_str());
211  return false;
212  }
213  if (!d.IsObject() && !d.IsArray()) {
214  err_msg = "Unexpected Json string ==> " + json;
215  CONFIG_TRACE(PortInfo, err_msg.c_str());
216  return false;
217  }
218 
219  if (d.IsArray()) {
220  /* When Json Array is passed, we do 'All or None'. We add all the
221  * elements of the array or none are added. So we do validation in
222  * first pass and addition in second pass */
223  VmiSubscribeEntryPtrList req_list;
224  if (AddPortArrayFromJson(d, json, req_list, check_port, err_msg)) {
225  for (size_t i = 0; i < req_list.size(); i++) {
226  AddVmiUuidEntry(req_list[i], d, write_file, err_msg);
227  }
228  }
229 
230  req_list.clear();
231  return true;
232  }
233 
234  PortSubscribeEntryPtr entry(MakeAddVmiUuidRequest(d, check_port, err_msg));
235  if (entry.get() == NULL) {
236  CONFIG_TRACE(PortInfo, err_msg.c_str());
237  return false;
238  }
239 
240  AddVmiUuidEntry(entry, d, write_file, err_msg);
241  return true;
242 }
243 
245 (const contrail_rapidjson::Value &d, bool check_port,
246 std::string &err_msg) const {
247  boost::uuids::uuid vmi_uuid;
248  if (GetUuidMember(d, "id", &vmi_uuid, &err_msg) == false) {
249  return NULL;
250  }
251 
252  boost::uuids::uuid instance_uuid;
253  if (GetUuidMember(d, "instance-id", &instance_uuid, &err_msg) == false) {
254  return NULL;
255  }
256 
257  boost::uuids::uuid vn_uuid;
258  if (GetUuidMember(d, "vn-id", &vn_uuid, &err_msg) == false) {
259  return NULL;
260  }
261 
262  boost::uuids::uuid project_uuid;
263  if (GetUuidMember(d, "vm-project-id", &project_uuid, &err_msg) == false) {
264  return NULL;
265  }
266 
267  string vm_name;
268  if (GetStringMember(d, "display-name", &vm_name, &err_msg) == false) {
269  return NULL;
270  }
271 
272  string ip4_str;
273  if (GetStringMember(d, "ip-address", &ip4_str, &err_msg) == false) {
274  return NULL;
275  }
276  boost::system::error_code ec;
277  Ip4Address ip4 = Ip4Address::from_string(ip4_str, ec);
278 
279  string ip6_str;
280  if (GetStringMember(d, "ip6-address", &ip6_str, &err_msg) == false) {
281  return NULL;
282  }
283  boost::system::error_code ec6;
284  Ip6Address ip6 = Ip6Address::from_string(ip6_str, ec6);
285 
286  uint32_t val;
287  if (GetUint32Member(d, "type", &val, &err_msg) == false) {
288  return NULL;
289  }
290 
292  uint32_t link_state = 1;
293  if (val == 1) {
295  } else if (val == 2) {
297  /* Default port-state is disabled for REMOTE_PORT */
298  link_state = 0;
299  }
300  if (vmi_type == PortSubscribeEntry::VMPORT) {
301  if (vn_uuid == nil_uuid()) {
302  err_msg = "Invalid VN uuid";
303  return NULL;
304  }
305  }
306 
307  string ifname;
308  if (GetStringMember(d, "system-name", &ifname, &err_msg) == false) {
309  return NULL;
310  }
311  // Verify that interface exists in OS
312  if (vmi_type != PortSubscribeEntry::REMOTE_PORT) {
313  if (check_port && !InterfaceExists(ifname)) {
314  err_msg = "Interface does not exist in OS";
315  return NULL;
316  }
317  }
318 
319  string mac;
320  if (GetStringMember(d, "mac-address", &mac, &err_msg) == false) {
321  return NULL;
322  }
323  if (ValidateMac(mac) == false) {
324  err_msg = "Invalid MAC, Use xx:xx:xx:xx:xx:xx format";
325  return NULL;
326  }
327 
328  // Sanity check. We should not have isolated_vlan_id set and vlan_id unset
329  uint32_t rx_vlan_id = VmInterface::kInvalidVlanId;
330  if (GetUint32Member(d, "rx-vlan-id", &rx_vlan_id, &err_msg) == false) {
331  return NULL;
332  }
333 
334  uint32_t tx_vlan_id = VmInterface::kInvalidVlanId;
335  if (GetUint32Member(d, "tx-vlan-id", &tx_vlan_id, &err_msg) == false) {
336  return NULL;
337  }
338 
339  if ((rx_vlan_id != VmInterface::kInvalidVlanId) &&
340  (tx_vlan_id == VmInterface::kInvalidVlanId-1)) {
341  err_msg += "Invalid request. RX (isolated) vlan set, "
342  "but TX vlan not set";
343  return NULL;
344  }
345 
346  // Dont return in case of error as this is an optional parameter for
347  // DPDK/vhostuser
348  uint32_t vhostuser_mode = 0;
349  GetUint32Member(d, "vhostuser-mode", &vhostuser_mode, &err_msg);
350  /* Don't return error in case link-state is not found. This is required
351  * for backward compatibility when old files are used with new
352  * vrouter-agent. If field is absent then value as initialized above
353  * for link_state gets used */
354  GetUint32Member(d, "link-state", &link_state, NULL);
355 
356  CONFIG_TRACE(AddPortEnqueue, "Add", UuidToString(vmi_uuid),
357  UuidToString(instance_uuid), UuidToString(vn_uuid),
358  ip4.to_string(), ifname, mac, vm_name, tx_vlan_id, rx_vlan_id,
359  UuidToString(project_uuid),
361  ip6.to_string(), version_, vhostuser_mode, link_state);
362  return new VmiSubscribeEntry(vmi_type, ifname, version_, vmi_uuid,
363  instance_uuid, vm_name, vn_uuid, project_uuid,
364  ip4, ip6, mac, tx_vlan_id, rx_vlan_id,
365  vhostuser_mode, link_state);
366 }
367 
369  const contrail_rapidjson::Value &d,
370  bool write_file, string &err_msg) const {
371  VmiSubscribeEntry *entry =
372  dynamic_cast<VmiSubscribeEntry *>(entry_ref.get());
373  // If Writing to file fails return error
374  if(write_file && WriteJsonToFile(entry, false) == false) {
375  err_msg += "Writing of Json string to file failed for " +
376  UuidToString(entry->vmi_uuid());
377  CONFIG_TRACE(PortInfo, err_msg.c_str());
378  return false;
379  }
380 
381  CONFIG_TRACE(AddPortEnqueue, "Add", UuidToString(entry->vmi_uuid()),
382  UuidToString(entry->vm_uuid()), UuidToString(entry->vn_uuid()),
383  entry->ip4_addr().to_string(), entry->ifname(),
384  entry->mac_addr(), entry->vm_name(), entry->tx_vlan_id(),
385  entry->rx_vlan_id(), UuidToString(entry->project_uuid()),
387  entry->ip6_addr().to_string(), entry->version(),
388  entry->vhostuser_mode(), entry->link_state());
389  port_subscribe_table_->AddVmi(entry->vmi_uuid(), entry_ref);
390  return true;
391 }
392 
394  const {
395  string filename = ports_dir_ + "/" + UuidToString(entry->vmi_uuid());
396  fs::path file_path(filename);
397 
398  bool remove = true;
399  /* Don't overwrite if the file already exists */
400  if (!overwrite) {
401  remove = !fs::exists(file_path);
402  if (!remove) {
403  return true;
404  }
405  }
406 
407  string info = MakeVmiUuidJson(entry, true);
408  if (info.empty()) {
409  LOG(ERROR, "Error producing entry JSON for port " << file_path.filename());
410  return false;
411  }
412  std::ofstream fs(filename.c_str());
413  if (fs.fail()) {
414  LOG(ERROR, "Cannot open file " << filename << " for writing");
415  return false;
416  }
417  bool output = (fs << info).good();
418  fs.close();
419  if (!output) {
420  LOG(ERROR, "Cannot write JSON to the file " << filename);
421  if (remove) {
422  fs::remove(file_path);
423  }
424  }
425 
426  return output;
427 }
428 
429 bool PortIpcHandler::ValidateMac(const string &mac) const {
430  size_t pos = 0;
431  int colon = 0;
432  if (mac.empty()) {
433  return false;
434  }
435  while ((pos = mac.find(':', pos)) != std::string::npos) {
436  colon++;
437  pos += 1;
438  }
439  if (colon != 5)
440  return false;
441 
442  if (MacAddress::FromString(mac).IsZero())
443  return false;
444 
445  return true;
446 }
447 
448 bool PortIpcHandler::DeletePort(const string &url, string &err_msg) {
449  boost::uuids::uuid vmi_uuid = StringToUuid(url);
450  if (vmi_uuid != nil_uuid()) {
451  DeleteVmiUuidEntry(vmi_uuid, err_msg);
452  return true;
453  }
454 
455  return true;
456 }
457 
459  const boost::uuids::uuid &u, string &err_msg) {
460  uint64_t version = 0;
461  PortSubscribeEntryPtr entry = port_subscribe_table_->GetVmi(u);
462  if (entry.get() != NULL) {
463  version = entry->version();
464  }
465  port_subscribe_table_->DeleteVmi(u);
466  CONFIG_TRACE(DeletePortEnqueue, "Delete", UuidToString(u), version);
467 
468  string file = ports_dir_ + "/" + UuidToString(u);
469  fs::path file_path(file);
470 
471  if (fs::exists(file_path) && fs::is_regular_file(file_path)) {
472  if (remove(file.c_str())) {
473  err_msg = "Error deleting file " + file;
474  }
475  }
476 }
477 
478 bool PortIpcHandler::EnablePort(const string &url, string &err_msg) {
480  if (u == nil_uuid()) {
481  err_msg = "Port Not found " + url;
482  return false;
483  }
484  PortSubscribeEntryPtr entry = port_subscribe_table_->GetVmi(u);
485  if (entry.get() == NULL) {
486  err_msg = "Port Not found " + url;
487  return false;
488  }
489  if (entry->type() != PortSubscribeEntry::REMOTE_PORT) {
490  err_msg = "Incorrect Port type for " + url;
491  return false;
492  }
493  VmiSubscribeEntry *ventry =
494  dynamic_cast<VmiSubscribeEntry *>(entry.get());
495  if (ventry == NULL) {
496  err_msg = "Invalid Port " + url;
497  return false;
498  }
499  int written_to_file = 0;
500  if (!ventry->link_state()) {
501  ventry->set_link_state(1);
502  written_to_file = 1;
503  if (WriteJsonToFile(ventry, true) == false) {
504  err_msg += "Writing of Json to file failed on enable for " +
505  UuidToString(ventry->vmi_uuid());
506  CONFIG_TRACE(PortInfo, err_msg.c_str());
507  written_to_file = 0;
508  }
509  }
510  InterfaceResync(agent_, u, entry->ifname(), true);
511  string msg = "Enable state for " + url + " version " +
512  integerToString(entry->version()) + " written to file : " +
513  integerToString(written_to_file);
514  CONFIG_TRACE(PortInfo, msg);
515  return true;
516 }
517 
518 bool PortIpcHandler::DisablePort(const string &url, string &err_msg) {
520  if (u == nil_uuid()) {
521  err_msg = "Port Not found " + url;
522  return false;
523  }
524  PortSubscribeEntryPtr entry = port_subscribe_table_->GetVmi(u);
525  if (entry.get() == NULL) {
526  err_msg = "Port Not found " + url;
527  return false;
528  }
529  if (entry->type() != PortSubscribeEntry::REMOTE_PORT) {
530  err_msg = "Incorrect Port type for " + url;
531  return false;
532  }
533  VmiSubscribeEntry *ventry =
534  dynamic_cast<VmiSubscribeEntry *>(entry.get());
535  if (ventry == NULL) {
536  err_msg = "Invalid Port " + url;
537  return false;
538  }
539  int written_to_file = 0;
540  if (ventry->link_state()) {
541  ventry->set_link_state(0);
542  written_to_file = 1;
543  if (WriteJsonToFile(ventry, true) == false) {
544  err_msg += "Writing of Json to file failed on disable for " +
545  UuidToString(ventry->vmi_uuid());
546  CONFIG_TRACE(PortInfo, err_msg.c_str());
547  written_to_file = 0;
548  }
549  }
550  InterfaceResync(agent_, u, entry->ifname(), false);
551  string msg = "Disable state for " + url + " version " +
552  integerToString(entry->version()) + " written to file : " +
553  integerToString(written_to_file);
554  CONFIG_TRACE(PortInfo, msg);
555  return true;
556 }
557 
558 bool PortIpcHandler::IsUUID(const string &uuid_str) const {
559  boost::uuids::uuid vmi_uuid = StringToUuid(uuid_str);
560  if (vmi_uuid == nil_uuid()) {
561  return false;
562  }
563  return true;
564 }
565 
566 void PortIpcHandler::AddMember(const char *key, const char *value,
567  contrail_rapidjson::Document *doc) const {
568  contrail_rapidjson::Document::AllocatorType &a = doc->GetAllocator();
569  contrail_rapidjson::Value v;
570  contrail_rapidjson::Value vk;
571  doc->AddMember(vk.SetString(key, a), v.SetString(value, a), a);
572 }
573 
575  bool meta_info) const {
576  contrail_rapidjson::Document doc;
577  doc.SetObject();
578  contrail_rapidjson::Document::AllocatorType &a = doc.GetAllocator();
579 
580  string str1 = UuidToString(entry->vmi_uuid());
581  AddMember("id", str1.c_str(), &doc);
582  string str2 = UuidToString(entry->vm_uuid());
583  AddMember("instance-id", str2.c_str(), &doc);
584  AddMember("display-name", entry->vm_name().c_str(), &doc);
585  string str3 = entry->ip4_addr().to_string();
586  AddMember("ip-address", str3.c_str(), &doc);
587  string str4 = entry->ip6_addr().to_string();
588  AddMember("ip6-address", str4.c_str(), &doc);
589  string str5 = UuidToString(entry->vn_uuid());
590  AddMember("vn-id", str5.c_str(), &doc);
591  string str6 = UuidToString(entry->project_uuid());
592  AddMember("vm-project-id", str6.c_str(), &doc);
593  AddMember("mac-address", entry->mac_addr().c_str(), &doc);
594  AddMember("system-name", entry->ifname().c_str(), &doc);
595  doc.AddMember("type", (int)entry->type(), a);
596  doc.AddMember("rx-vlan-id", (int)entry->rx_vlan_id(), a);
597  doc.AddMember("tx-vlan-id", (int)entry->tx_vlan_id(), a);
598  doc.AddMember("vhostuser-mode", (int)entry->vhostuser_mode(), a);
599  /* link-state has to be persisted for port-type of REMOTE_PORT.
600  * REMOTE_PORT will NOT have corresponding tap interface in OS to pick
601  * operational state. */
602  if (entry->type() == PortSubscribeEntry::REMOTE_PORT) {
603  doc.AddMember("link-state", (int)entry->link_state(), a);
604  }
605  if (meta_info) {
606  AddMember("author", agent_->program_name().c_str(), &doc);
608  AddMember("time", now.c_str(), &doc);
609  }
610 
611  contrail_rapidjson::StringBuffer buffer;
612  contrail_rapidjson::PrettyWriter<contrail_rapidjson::StringBuffer> writer(buffer);
613  doc.Accept(writer);
614 
615  return buffer.GetString();
616 }
617 
618 bool PortIpcHandler::GetPortInfo(const string &uuid_str, string &info) const {
619  boost::uuids::uuid vmi_uuid = StringToUuid(uuid_str);
620  if (vmi_uuid == nil_uuid()) {
621  return false;
622  }
623 
624  return MakeJsonFromVmi(vmi_uuid, info);
625 }
626 
628  ++version_;
629  interface_stale_cleaner_->StartStaleCleanTimer(version_);
630  string msg = " Sync " + integerToString(version_);
631  CONFIG_TRACE(PortInfo, msg);
632 }
633 
635  port_subscribe_table_->InitDone();
636 }
637 
639  port_subscribe_table_->Shutdown();
640 }
641 
643 (const contrail_rapidjson::Value &d, VirtualGatewayConfig::Subnet *entry) const {
644  if (!d.HasMember("ip-address") || !d["ip-address"].IsString()) {
645  return false;
646  }
647 
648  if (!d.HasMember("prefix-len") || !d["prefix-len"].IsInt()) {
649  return false;
650  }
651  boost::system::error_code ec;
652  entry->ip_ = Ip4Address::from_string(d["ip-address"].GetString(), ec);
653  if (ec.failed()) {
654  return false;
655  }
656  entry->plen_ = d["prefix-len"].GetInt();
657  return true;
658 }
659 
661 (const contrail_rapidjson::Value &d, VirtualGatewayConfig::SubnetList *list) const {
662  for (size_t i = 0; i < d.Size(); i++) {
663  const contrail_rapidjson::Value& elem = d[i];
664  if (!elem.IsObject()) {
665  return false;
666  }
668  if (!BuildGatewayArrayElement(elem, &entry)) {
669  return false;
670  }
671  list->push_back(entry);
672  }
673  return true;
674 }
675 
676 bool PortIpcHandler::HasAllGatewayFields(const contrail_rapidjson::Value &d,
677  std::string &member_err,
678  VirtualGatewayInfo *req) const {
679  if (!d.HasMember("interface") || !d["interface"].IsString()) {
680  member_err = "interface";
681  return false;
682  }
683 
684  if (!d.HasMember("routing-instance") || !d["routing-instance"].IsString()) {
685  member_err = "routing-instance";
686  return false;
687  }
688 
689  if (!d.HasMember("subnets") || !d["subnets"].IsArray()) {
690  member_err = "subnets";
691  return false;
692  }
693 
694  if (!ValidGatewayJsonString(d["subnets"], &req->subnets_)) {
695  member_err = "subnets value";
696  return false;
697  }
698 
699  if (!d.HasMember("routes") || !d["routes"].IsArray()) {
700  member_err = "routes";
701  return false;
702  }
703 
704  if (!ValidGatewayJsonString(d["routes"], &req->routes_)) {
705  member_err = "routes value";
706  return false;
707  }
708  req->interface_name_ = d["interface"].GetString();
709  req->vrf_name_ = d["routing-instance"].GetString();
710 
711  return true;
712 }
713 
714 bool PortIpcHandler::BuildGateway(const contrail_rapidjson::Value &d,
715  const string &json, string &err_msg,
716  VirtualGatewayInfo *req) const {
717  string member_err;
718  if (!HasAllGatewayFields(d, member_err, req)) {
719  err_msg = "Json string does not have all required members, "
720  + member_err + " is missing ==> "
721  + json;
722  CONFIG_TRACE(PortInfo, err_msg.c_str());
723  return false;
724  }
725  return true;
726 }
727 
728 bool PortIpcHandler::AddVgwFromJson(const string &json, string &err_msg) const {
729  contrail_rapidjson::Document d;
730  if (d.Parse<0>(const_cast<char *>(json.c_str())).HasParseError()) {
731  err_msg = "Invalid Json string ==> " + json;
732  CONFIG_TRACE(PortInfo, err_msg.c_str());
733  return false;
734  }
735  if (!d.IsArray()) {
736  err_msg = "Unexpected Json string (not an array) ==> " + json;
737  CONFIG_TRACE(PortInfo, err_msg.c_str());
738  return false;
739  }
740 
741  std::vector<VirtualGatewayInfo> req_list;
742  for (size_t i = 0; i < d.Size(); i++) {
743  const contrail_rapidjson::Value& elem = d[i];
744  if (elem.IsObject()) {
745  VirtualGatewayInfo req("");
746  if (!BuildGateway(elem, json, err_msg, &req)) {
747  return false;
748  }
749  req_list.push_back(req);
750  } else {
751  err_msg = "Json Array has invalid element ==> " + json;
752  CONFIG_TRACE(PortInfo, err_msg.c_str());
753  return false;
754  }
755  }
756 
757  if (!req_list.empty()) {
758  boost::shared_ptr<VirtualGatewayData>
759  vgw_data(new VirtualGatewayData(VirtualGatewayData::Add, req_list,
760  0));
761  agent_->params()->vgw_config_table()->Enqueue(vgw_data);
762  CONFIG_TRACE(VgwEnqueue, "Add", json);
763  }
764  return true;
765 }
766 
767 bool PortIpcHandler::DelVgwFromJson(const string &json, string &err_msg) const {
768  contrail_rapidjson::Document d;
769  if (d.Parse<0>(const_cast<char *>(json.c_str())).HasParseError()) {
770  err_msg = "Invalid Json string ==> " + json;
771  CONFIG_TRACE(PortInfo, err_msg.c_str());
772  return false;
773  }
774  if (!d.IsArray()) {
775  err_msg = "Unexpected Json string (not an array) ==> " + json;
776  CONFIG_TRACE(PortInfo, err_msg.c_str());
777  return false;
778  }
779 
780  std::vector<VirtualGatewayInfo> req_list;
781  for (size_t i = 0; i < d.Size(); i++) {
782  const contrail_rapidjson::Value& elem = d[i];
783  if (elem.IsObject()) {
784  if (!elem.HasMember("interface") || !elem["interface"].IsString()) {
785  err_msg = "Json string does not have or has invalid value for "
786  "member interface ==> " + json;
787  CONFIG_TRACE(PortInfo, err_msg.c_str());
788  return false;
789  }
790  VirtualGatewayInfo req(elem["interface"].GetString());
791  req_list.push_back(req);
792  } else {
793  err_msg = "Json Array has invalid element ==> " + json;
794  CONFIG_TRACE(PortInfo, err_msg.c_str());
795  return false;
796  }
797  }
798 
799  if (!req_list.empty()) {
800  boost::shared_ptr<VirtualGatewayData>
802  req_list, 0));
803  agent_->params()->vgw_config_table()->Enqueue(vgw_data);
804  CONFIG_TRACE(VgwEnqueue, "Del", json);
805  }
806  return true;
807 }
808 
810 // VM based message related methods
812 bool PortIpcHandler::AddVmVnPort(const string &json, bool check_port,
813  string &err_msg, bool write_file) {
814  contrail_rapidjson::Document d;
815  if (d.Parse<0>(const_cast<char *>(json.c_str())).HasParseError()) {
816  err_msg = "Invalid Json string ==> " + json;
817  CONFIG_TRACE(VmVnPortInfo, err_msg.c_str());
818  return false;
819  }
820 
821  if (!d.IsObject()) {
822  err_msg = "Unexpected Json string ==> " + json;
823  CONFIG_TRACE(VmVnPortInfo, err_msg.c_str());
824  return false;
825  }
826 
827  if (d.IsArray()) {
828  err_msg = "Arrays not supported in json for vm ==> " + json;
829  CONFIG_TRACE(VmVnPortInfo, err_msg.c_str());
830  return false;
831  }
832 
833  PortSubscribeEntryPtr entry(MakeAddVmVnPortRequest(d, check_port, err_msg));
834  if (entry.get() == NULL) {
835  CONFIG_TRACE(VmVnPortInfo, err_msg.c_str());
836  return false;
837  }
838 
839  AddVmVnPortEntry(entry, d, write_file, err_msg);
840  return true;
841 }
842 
844  const contrail_rapidjson::Value &d,
845  bool write_file, string &err_msg) const {
846  VmVnPortSubscribeEntry *entry =
847  dynamic_cast<VmVnPortSubscribeEntry *>(entry_ref.get());
848  // If Writing to file fails return error
849  if(write_file && WriteJsonToFile(entry) == false) {
850  err_msg += "Writing of Json string to file failed for Vm " +
851  UuidToString(entry->vm_uuid());
852  CONFIG_TRACE(VmVnPortInfo, err_msg.c_str());
853  return false;
854  }
855 
856  CONFIG_TRACE(AddVmVnPortEnqueue, "Add", UuidToString(entry->vm_uuid()),
857  UuidToString(entry->vn_uuid()), UuidToString(entry->vmi_uuid()),
858  entry->vm_name(), entry->vm_identifier(), entry->ifname(),
859  entry->vm_ifname(), entry->vm_namespace(), version_);
860  port_subscribe_table_->AddVmVnPort(entry->vm_uuid(),
861  entry->vn_uuid(), entry->vmi_uuid(), entry_ref);
862  return true;
863 }
864 
866 (const contrail_rapidjson::Value &d, bool check_port,
867 std::string &err_msg) const {
869  boost::uuids::uuid vm_uuid;
870  if (GetUuidMember(d, "vm-uuid", &vm_uuid, &err_msg) == false) {
871  return NULL;
872  }
873 
874  string host_ifname;
875  if (GetStringMember(d, "host-ifname", &host_ifname, &err_msg) == false) {
876  return NULL;
877  }
878  // Verify that interface exists in OS
879  if (vmi_type != PortSubscribeEntry::REMOTE_PORT) {
880  if (check_port && !InterfaceExists(host_ifname)) {
881  err_msg = "Interface does not exist in OS";
882  return NULL;
883  }
884  }
885 
886  string vm_name;
887  if (GetStringMember(d, "vm-name", &vm_name, &err_msg) == false) {
888  return NULL;
889  }
890 
891  string vm_identifier;
892  GetStringMember(d, "vm-id", &vm_identifier, NULL);
893 
894  string vm_ifname;
895  GetStringMember(d, "vm-ifname", &vm_ifname, NULL);
896 
897  string vm_namespace;
898  GetStringMember(d, "vm-namespace", &vm_namespace, NULL);
899 
900  boost::uuids::uuid vn_uuid;
901  if (GetUuidMember(d, "vn-uuid", &vn_uuid, &err_msg) == false) {
902  return NULL;
903  }
904 
905  boost::uuids::uuid vmi_uuid;
906  if (GetUuidMember(d, "vmi-uuid", &vmi_uuid, &err_msg) == false) {
907  return NULL;
908  }
909 
910  CONFIG_TRACE(AddVmVnPortEnqueue, "Add", UuidToString(vm_uuid),
911  UuidToString(vn_uuid), UuidToString(vmi_uuid),
912  vm_name, vm_identifier, host_ifname, vm_ifname,
913  vm_namespace, version_);
914 
915  return new VmVnPortSubscribeEntry(vmi_type, host_ifname, version_, vm_uuid,
916  vn_uuid, vmi_uuid, vm_name, vm_identifier,
917  vm_ifname, vm_namespace);
918 }
919 
921  string &info, bool meta_info) const {
922  contrail_rapidjson::Document doc;
923  doc.SetObject();
924 
925  string str2 = UuidToString(entry->vm_uuid());
926  AddMember("vm-uuid", str2.c_str(), &doc);
927  str2 = UuidToString(entry->vn_uuid());
928  AddMember("vn-uuid", str2.c_str(), &doc);
929  str2 = UuidToString(entry->vmi_uuid());
930  AddMember("vmi-uuid", str2.c_str(), &doc);
931  AddMember("vm-id", entry->vm_identifier().c_str(), &doc);
932  AddMember("vm-name", entry->vm_name().c_str(), &doc);
933  AddMember("host-ifname", entry->ifname().c_str(), &doc);
934  AddMember("vm-ifname", entry->vm_ifname().c_str(), &doc);
935  AddMember("vm-namespace", entry->vm_namespace().c_str(), &doc);
936 
937  if (meta_info) {
938  AddMember("author", agent_->program_name().c_str(), &doc);
940  AddMember("time", now.c_str(), &doc);
941  }
942 
943  contrail_rapidjson::StringBuffer buffer;
944  contrail_rapidjson::PrettyWriter<contrail_rapidjson::StringBuffer> writer(buffer);
945  doc.Accept(writer);
946  info = buffer.GetString();
947  return;
948 }
949 
951  string vmvn_dir = vmvn_dir_ + "/" + entry->vm_name();
952  fs::path base_dir(vmvn_dir);
953  if (fs::exists(base_dir) == false) {
954  if (!fs::create_directories(base_dir)) {
955  string err_msg = "Creating directory " + vmvn_dir + " failed";
956  CONFIG_TRACE(PortInfo, err_msg.c_str());
957  return false;
958  }
959  }
960 
961  string filename = vmvn_dir + "/" + UuidToString(entry->vmi_uuid());
962  fs::path file_path(filename);
963  /* Don't overwrite if the file already exists */
964  if (fs::exists(file_path)) {
965  return true;
966  }
967 
968  string info;
969  MakeVmVnPortJson(entry, info, true);
970  if (info.empty()) {
971  LOG(ERROR, "Error producing entry JSON for VM " << entry->vm_name());
972  return false;
973  }
974  std::ofstream fs(filename.c_str());
975  if (fs.fail()) {
976  LOG(ERROR, "Cannot open file " << filename << " for writing");
977  return false;
978  }
979  bool output = (fs << info).good();
980  fs.close();
981  if (!output) {
982  LOG(ERROR, "Cannot write JSON to the file " << filename);
983  fs::remove(file_path);
984  }
985 
986  return output;
987 }
988 
990  string &err_msg) {
991  uint64_t version;
992  bool failed = false;
993  string vmvn_dir = vmvn_dir_ + "/" + UuidToString(vm_uuid);
994  std::set<boost::uuids::uuid> vmi_uuid_set;
995 
996  if (!port_subscribe_table_->VmVnToVmiSet(vm_uuid, vmi_uuid_set))
997  return false;
998 
999  std::set<boost::uuids::uuid>::iterator it = vmi_uuid_set.begin();
1000  while (it != vmi_uuid_set.end()) {
1001  boost::uuids::uuid vmi_uuid = *it;
1002  const PortSubscribeTable::VmiEntry *vmi_entry =
1003  port_subscribe_table_->VmiToEntry(vmi_uuid);
1004  PortSubscribeEntryPtr entry =
1005  port_subscribe_table_->GetVmVnPort(vm_uuid,
1006  vmi_entry->vn_uuid_, vmi_uuid);
1007  if (entry.get() != NULL) {
1008  version = entry->version();
1009  } else {
1010  version = 0;
1011  }
1012 
1013  port_subscribe_table_->DeleteVmVnPort(vm_uuid,
1014  vmi_entry->vn_uuid_, vmi_uuid);
1015  CONFIG_TRACE(DeleteVmVnPortEnqueue, "Delete", UuidToString(vm_uuid),
1016  UuidToString(vmi_entry->vn_uuid_), version);
1017 
1018  string file = vmvn_dir + "/" + UuidToString(vmi_uuid);
1019  fs::path file_path(file);
1020  if (fs::exists(file_path) && fs::is_regular_file(file_path)) {
1021  if (remove(file.c_str())) {
1022  err_msg += " Error deleting file " + file;
1023  failed = true;
1024  }
1025  }
1026  it++;
1027  }
1028 
1029  if (failed)
1030  return false;
1031 
1032  /* remove vm directory in vmvn_dir_ */
1033  fs::path base_dir(vmvn_dir);
1034  if (!fs::remove_all(base_dir)) {
1035  string err_msg = "Deleting directory " + vmvn_dir + " failed";
1036  CONFIG_TRACE(PortInfo, err_msg.c_str());
1037  }
1038 
1039  return true;
1040 }
1041 
1042 bool PortIpcHandler::DeleteVmVnPort(const string &json, const string &vm,
1043  string &err_msg) {
1044  boost::uuids::uuid vm_uuid = StringToUuid(vm);
1045  if (vm_uuid == nil_uuid()) {
1046  return true;
1047  }
1048 
1049  DeleteVmVnPort(vm_uuid, err_msg);
1050  return true;
1051 }
1052 
1053 bool PortIpcHandler::GetVmVnCfgPort(const string &vm, string &info) const {
1054  VmTable *vm_table = agent_->vm_table();
1055  boost::uuids::uuid vm_uuid = vm_table->GetVmUuid(vm);
1056  if (vm_uuid == nil_uuid()) {
1057  return false;
1058  }
1059 
1060  std::set<boost::uuids::uuid> vmi_uuid_set;
1061  if (!port_subscribe_table_->VmVnToVmiSet(vm_uuid, vmi_uuid_set))
1062  return false;
1063 
1064  std::set<boost::uuids::uuid>::iterator it = vmi_uuid_set.begin();
1065  info = '[';
1066  do {
1067  boost::uuids::uuid vmi_uuid = *it;
1068  if (!MakeJsonFromVmiConfig(vmi_uuid, info))
1069  return false;
1070  it++;
1071  info += ',';
1072  } while (it != vmi_uuid_set.end());
1073  info.erase(info.size() - 1);
1074  info += ']';
1075 
1076  return true;
1077 
1078 }
1079 
1081  string &resp) const {
1082  const PortSubscribeTable::VmiEntry *vmi_entry =
1083  port_subscribe_table_->VmiToEntry(vmi_uuid);
1084 
1085  if (vmi_entry == NULL) {
1086  resp = "Interface Entry not found for request. Retry";
1087  return false;
1088  }
1089 
1090  const VnEntry *vn = agent_->vn_table()->Find(vmi_entry->vn_uuid_);
1091  if (vn == NULL) {
1092  resp = "VirtualNetwork not found for request. Retry";
1093  return false;
1094  }
1095 
1096  contrail_rapidjson::Document doc;
1097  doc.SetObject();
1098  contrail_rapidjson::Document::AllocatorType &a = doc.GetAllocator();
1099 
1100  string str1 = UuidToString(vmi_uuid);
1101  AddMember("id", str1.c_str(), &doc);
1102 
1103  string str2 = UuidToString(vmi_entry->vm_uuid_);
1104  AddMember("vm-uuid", str2.c_str(), &doc);
1105 
1106  string str5 = UuidToString(vmi_entry->vn_uuid_);
1107  AddMember("vn-id", str5.c_str(), &doc);
1108  AddMember("vn-name", vn->GetName().c_str(), &doc);
1109 
1110  AddMember("mac-address", vmi_entry->mac_.c_str(), &doc);
1111  doc.AddMember("sub-interface", (bool)vmi_entry->sub_interface_, a);
1112  doc.AddMember("vlan-id", (int)vmi_entry->vlan_tag_, a);
1113 
1114  if (vmi_entry->vmi_cfg != NULL) {
1115  const std::vector<autogen::KeyValuePair> annotations =
1116  vmi_entry->vmi_cfg->annotations();
1117  if (annotations.size()) {
1118  string str6;
1119  contrail_rapidjson::Value val(contrail_rapidjson::kStringType);
1120  contrail_rapidjson::Value array(contrail_rapidjson::kArrayType);
1121  std::vector<autogen::KeyValuePair>::const_iterator it =
1122  annotations.begin();
1123  while (it != annotations.end()) {
1124  str6 = "{" + it->key + ":" + it->value + "}";
1125  val.SetString(str6.c_str(), a);
1126  array.PushBack(val, a);
1127  it++;
1128  }
1129  doc.AddMember("annotations", array, a);
1130  }
1131  }
1132 
1133  contrail_rapidjson::StringBuffer buffer;
1134  contrail_rapidjson::PrettyWriter<contrail_rapidjson::StringBuffer>
1135  writer(buffer);
1136  doc.Accept(writer);
1137  resp += buffer.GetString();
1138  return true;
1139 }
1140 
1141 bool PortIpcHandler::GetVmVnPort(const string &vm, const string &vmi,
1142  string &info) const {
1143  boost::uuids::uuid vm_uuid = StringToUuid(vm);
1144  if (vm_uuid == nil_uuid()) {
1145  return false;
1146  }
1147 
1148  if (vmi.size() > 0) {
1149  info = '[';
1150  boost::uuids::uuid vmi_uuid = StringToUuid(vmi);
1151  if (!MakeJsonFromVmi(vmi_uuid, info))
1152  return false;
1153  info += ']';
1154  return true;
1155  }
1156 
1157  std::set<boost::uuids::uuid> vmi_uuid_set;
1158  if (!port_subscribe_table_->VmVnToVmiSet(vm_uuid, vmi_uuid_set))
1159  return false;
1160 
1161  std::set<boost::uuids::uuid>::iterator it = vmi_uuid_set.begin();
1162  info = '[';
1163  do {
1164  boost::uuids::uuid vmi_uuid = *it;
1165  if (!MakeJsonFromVmi(vmi_uuid, info))
1166  return false;
1167  it++;
1168  info += ',';
1169  } while (it != vmi_uuid_set.end());
1170  info.erase(info.size() - 1);
1171  info += ']';
1172 
1173  return true;
1174 }
1175 
1177  const boost::uuids::uuid &vmi_uuid, string &resp) const {
1178  InterfaceConstRef intf_ref = agent_->interface_table()->FindVmi(vmi_uuid);
1179  const VmInterface *vmi = static_cast<const VmInterface *>(intf_ref.get());
1180  if (vmi == NULL) {
1181  resp = "Interface not found for request. Retry";
1182  return false;
1183  }
1184 
1185  const VmEntry *vm = vmi->vm();
1186  if (vm == NULL) {
1187  resp = "VirtualMachine not found for request. Retry";
1188  return false;
1189  }
1190 
1191  const VnEntry *vn = vmi->vn();
1192  if (vn == NULL) {
1193  resp = "VirtualNetwork not found for request. Retry";
1194  return false;
1195  }
1196 
1197  const VnIpam *ipam_v4 = vn->GetIpam(vmi->primary_ip_addr());
1198  const VnIpam *ipam_v6 = vn->GetIpam(vmi->primary_ip6_addr());
1199  if ((ipam_v4 == NULL) && (ipam_v6 == NULL)) {
1200  resp = "Missing IPAM entry for request. Retry";
1201  return false;
1202  }
1203 
1204  contrail_rapidjson::Document doc;
1205  doc.SetObject();
1206  contrail_rapidjson::Document::AllocatorType &a = doc.GetAllocator();
1207 
1208  string str1 = UuidToString(vmi->GetUuid());
1209  AddMember("id", str1.c_str(), &doc);
1210 
1211  string str2 = UuidToString(vm->GetUuid());
1212  AddMember("instance-id", str2.c_str(), &doc);
1213 
1214  string str3 = UuidToString(vn->GetUuid());
1215  AddMember("vn-id", str3.c_str(), &doc);
1216 
1217  string str4 = UuidToString(vmi->vm_project_uuid());
1218  AddMember("vm-project-id", str4.c_str(), &doc);
1219 
1220  string str5 = vmi->vm_mac().ToString();
1221  AddMember("mac-address", str5.c_str(), &doc);
1222  AddMember("system-name", vmi->name().c_str(), &doc);
1223  doc.AddMember("rx-vlan-id", (int)vmi->rx_vlan_id(), a);
1224  doc.AddMember("tx-vlan-id", (int)vmi->tx_vlan_id(), a);
1225  doc.AddMember("vhostuser-mode", (int)vmi->vhostuser_mode(), a);
1226 
1227  if (ipam_v4) {
1228  string str6 = vmi->primary_ip_addr().to_string();
1229  AddMember("ip-address", str6.c_str(), &doc);
1230  doc.AddMember("plen", ipam_v4->plen, a);
1231  string str7 = ipam_v4->dns_server.to_v4().to_string();
1232  AddMember("dns-server", str7.c_str(), &doc);
1233  string str8 = ipam_v4->default_gw.to_v4().to_string();
1234  AddMember("gateway", str8.c_str(), &doc);
1235  }
1236 
1237  if (ipam_v6) {
1238  string str6 = vmi->primary_ip6_addr().to_string();
1239  AddMember("v6-ip-address", str6.c_str(), &doc);
1240  string str7 = ipam_v6->dns_server.to_v6().to_string();
1241  AddMember("v6-dns-server", str7.c_str(), &doc);
1242  string str8 = ipam_v6->default_gw.to_v6().to_string();
1243  AddMember("v6-gateway", str8.c_str(), &doc);
1244  }
1245 
1246  AddMember("author", agent_->program_name().c_str(), &doc);
1248  AddMember("time", now.c_str(), &doc);
1249 
1250  contrail_rapidjson::StringBuffer buffer;
1251  contrail_rapidjson::PrettyWriter<contrail_rapidjson::StringBuffer> writer(buffer);
1252  doc.Accept(writer);
1253  resp += buffer.GetString();
1254  return true;
1255 }
virtual const boost::uuids::uuid & vm_uuid() const
bool MakeJsonFromVmiConfig(const boost::uuids::uuid &vmi_uuid, string &resp) const
#define CONFIG_TRACE(obj,...)
Definition: cfg_init.h:236
static bool GetUint32Member(const contrail_rapidjson::Value &d, const char *member, uint32_t *data, std::string *err)
void AddMember(const char *key, const char *value, contrail_rapidjson::Document *doc) const
const MacAddress & vm_mac() const
static bool GetStringMember(const contrail_rapidjson::Value &d, const char *member, std::string *data, std::string *err)
static boost::uuids::uuid StringToUuid(const std::string &str)
Definition: string_util.h:145
void Enqueue(boost::shared_ptr< VirtualGatewayData > request)
Definition: cfg_vgw.cc:110
bool ValidateMac(const std::string &mac) const
bool DeletePort(const string &url, string &err_msg)
const std::string & vm_identifier() const
const boost::uuids::uuid & vm_project_uuid() const
bool WriteJsonToFile(VmiSubscribeEntry *entry, bool overwrite) const
const boost::uuids::uuid & vm_uuid() const
uint16_t rx_vlan_id() const
bool GetVmVnCfgPort(const string &vm, string &info) const
const boost::uuids::uuid & GetUuid() const
Definition: interface.h:113
uint32_t stale_interface_cleanup_timeout() const
Definition: agent_param.h:263
const VnIpam * GetIpam(const IpAddress &ip) const
Definition: vn.cc:651
Definition: vn.h:28
bool GetPortInfo(const std::string &uuid_str, std::string &info) const
boost::uuids::uuid GetVmUuid(const std::string &name)
Definition: vm.cc:144
bool DelVgwFromJson(const std::string &json, std::string &err_msg) const
PortIpcHandler(Agent *agent, const std::string &dir)
const boost::uuids::uuid & project_uuid() const
Definition: vm.h:32
Definition: vm.h:78
bool GetVmVnPort(const std::string &vm_uuid, const std::string &vmi_uuid, std::string &info) const
boost::scoped_ptr< InterfaceConfigStaleCleaner > interface_stale_cleaner_
bool MakeJsonFromVmi(const boost::uuids::uuid &vmi_uuid, std::string &resp) const
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
void ProcessFile(const std::string &file, bool check_port, bool vm_vn_port)
bool AddPortArrayFromJson(const contrail_rapidjson::Value &d, const std::string &json, VmiSubscribeEntryPtrList &req_list, bool check_port, std::string &err_msg)
bool AddVmiUuidEntry(PortSubscribeEntryPtr entry, const contrail_rapidjson::Value &d, bool write_file, std::string &err_msg) const
uint8_t vhostuser_mode() const
const boost::uuids::uuid & vmi_uuid() const
static bool InterfaceExists(std::string if_name)
InterfaceTable * interface_table() const
Definition: agent.h:465
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
boost::uuids::uuid uuid
VirtualGatewayConfig::SubnetList routes_
Definition: cfg_vgw.h:79
VnTable * vn_table() const
Definition: agent.h:495
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:138
bool EnablePort(const string &url, string &err_msg)
const boost::uuids::uuid & GetUuid() const
Definition: vm.h:46
std::string MakeVmiUuidJson(const VmiSubscribeEntry *entry, bool meta_info) const
uint16_t rx_vlan_id() const
std::string ports_dir_
bool AddVmVnPort(const std::string &json, bool check_port, std::string &err_msg, bool write_file)
uint8_t vhostuser_mode() const
std::string ToString() const
Definition: mac_address.cc:53
bool DeleteVmVnPort(const boost::uuids::uuid &vmi_uuid, string &err_msg)
InterfaceConstRef FindVmi(const boost::uuids::uuid &u)
Definition: interface.cc:419
void MakeVmVnPortJson(const VmVnPortSubscribeEntry *entry, string &info, bool meta_info) const
uint16_t tx_vlan_id() const
const std::string & program_name() const
Definition: agent.h:451
std::vector< PortSubscribeEntryPtr > VmiSubscribeEntryPtrList
static const char * TypeToString(Type type)
std::string vrf_name_
Definition: cfg_vgw.h:77
bool IsZero() const
Definition: mac_address.cc:29
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:19
const std::string & vm_ifname() const
const std::string & mac_addr() const
IpAddress default_gw
Definition: vn.h:31
static const uint32_t kInvalidVlanId
Definition: vm_interface.h:360
bool DisablePort(const string &url, string &err_msg)
Definition: agent.h:358
VmVnPortSubscribeEntry * MakeAddVmVnPortRequest(const contrail_rapidjson::Value &d, bool check_port, std::string &err_msg) const
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
bool AddVmVnPortEntry(PortSubscribeEntryPtr entry, const contrail_rapidjson::Value &d, bool write_file, std::string &err_msg) const
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
uint32_t plen
Definition: vn.h:30
static const std::string duration_usecs_to_string(const uint64_t usecs)
Definition: time_util.h:62
const std::string & vm_name() const
const std::string & ifname() const
boost::intrusive_ptr< const Interface > InterfaceConstRef
Definition: agent.h:51
const VnEntry * vn() const
boost::shared_ptr< PortSubscribeEntry > PortSubscribeEntryPtr
AgentParam * params() const
Definition: agent.h:1218
VnEntry * Find(const boost::uuids::uuid &vn_uuid)
Definition: vn.cc:759
std::unique_ptr< PortSubscribeTable > port_subscribe_table_
IpAddress dns_server
Definition: vn.h:33
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
const boost::uuids::uuid & vn_uuid() const
Definition: vn.h:151
const Ip4Address & primary_ip_addr() const
static void InterfaceResync(Agent *agent, const boost::uuids::uuid &u, const string &name, bool link_status)
const std::string & vm_namespace() const
std::string vmvn_dir_
const std::string & vm_name() const
autogen::VirtualMachineInterface * vmi_cfg
static bool GetUuidMember(const contrail_rapidjson::Value &d, const char *member, boost::uuids::uuid *u, std::string *err)
static uint64_t UTCTimestampUsec()
Definition: time_util.h:13
virtual const boost::uuids::uuid & vn_uuid() const
const Ip6Address & primary_ip6_addr() const
void set_link_state(uint8_t value)
uint32_t version() const
const boost::uuids::uuid & vmi_uuid() const
uint8_t link_state() const
#define LOG(_Level, _Msg)
Definition: logging.h:33
virtual ~PortIpcHandler()
void DeleteVmiUuidEntry(const boost::uuids::uuid &u, std::string &err_str)
const std::string & name() const
Definition: interface.h:114
std::vector< Subnet > SubnetList
Definition: cfg_vgw.h:30
const boost::uuids::uuid & GetUuid() const
Definition: vn.h:161
bool BuildGatewayArrayElement(const contrail_rapidjson::Value &d, VirtualGatewayConfig::Subnet *entry) const
const string & GetName() const
Definition: vn.h:162
bool AddPortFromJson(const string &json, bool check_port, string &err_msg, bool write_file)
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: mac_address.cc:71
const Ip6Address & ip6_addr() const
uint16_t tx_vlan_id() const
bool BuildGateway(const contrail_rapidjson::Value &d, const std::string &json, std::string &err_msg, VirtualGatewayInfo *req) const
VirtualGatewayConfig::SubnetList subnets_
Definition: cfg_vgw.h:78
bool ValidGatewayJsonString(const contrail_rapidjson::Value &d, VirtualGatewayConfig::SubnetList *list) const
VirtualGatewayConfigTable * vgw_config_table() const
Definition: agent_param.h:329
const Ip4Address & ip4_addr() const
bool IsUUID(const std::string &uuid_str) const
virtual bool OnInterfaceConfigStaleTimeout(int32_t version)
void ReloadAllPorts(const std::string &dir, bool check_port, bool vm_vn_port)
VmTable * vm_table() const
Definition: agent.h:490
const VmEntry * vm() const
bool HasAllGatewayFields(const contrail_rapidjson::Value &d, std::string &member_err, VirtualGatewayInfo *req) const
bool AddVgwFromJson(const std::string &json, std::string &err_msg) const
std::string interface_name_
Definition: cfg_vgw.h:76
VmiSubscribeEntry * MakeAddVmiUuidRequest(const contrail_rapidjson::Value &d, bool check_port, std::string &err_msg) const