OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
logical_interface.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <boost/uuid/uuid_io.hpp>
6 #include <vnc_cfg_types.h>
7 #include <cmn/agent_cmn.h>
8 
9 #include <ifmap/ifmap_node.h>
10 #include <cfg/cfg_init.h>
11 #include <oper/agent_sandesh.h>
13 #include <oper/interface_common.h>
14 #include <oper/physical_device.h>
15 #include <oper/logical_interface.h>
16 #include <oper/vm_interface.h>
17 #include <oper/config_manager.h>
18 #include <oper/vn.h>
19 
20 #include <vector>
21 #include <string>
22 
23 using std::string;
24 using std::unique_ptr;
25 using boost::uuids::uuid;
26 
28 // LogicalInterface routines
31  const std::string &name,
32  const boost::uuids::uuid &logical_router_uuid) :
33  Interface(Interface::LOGICAL, uuid, name, NULL, true, logical_router_uuid),
34  display_name_(),
35  physical_interface_(),
36  vm_interface_(),
37  physical_device_(NULL),
38  phy_dev_display_name_(),
39  phy_intf_display_name_(),
40  vn_uuid_() {
41 }
42 
44 }
45 
47  return physical_device_.get();
48 }
49 
51  return UuidToString(uuid_);
52 }
53 
54 bool LogicalInterface::CmpInterface(const DBEntry &rhs) const {
55  const LogicalInterface &a = static_cast<const LogicalInterface &>(rhs);
56  return (uuid_ < a.uuid_);
57 }
58 
60  const LogicalInterfaceData *data) {
61  bool ret = false;
62 
63  if (display_name_ != data->display_name_) {
65  ret = true;
66  }
67 
69  Interface *intf = static_cast<PhysicalInterface *>
70  (table->agent()->interface_table()->FindActiveEntry(&phy_key));
71  if (intf == NULL) {
73  intf = static_cast<RemotePhysicalInterface *>
74  (table->agent()->interface_table()->FindActiveEntry(&rem_key));
75  }
76 
77  if (intf != physical_interface_.get()) {
78  physical_interface_.reset(intf);
79  ret = true;
80  }
81 
83  OPER_TRACE_ENTRY(Trace, table,
84  "Changing Physical Interface display name from " \
85  + phy_intf_display_name_ + " to " +
88  ret = true;
89  }
90 
92  Interface *intrface = static_cast<Interface *>
93  (table->agent()->interface_table()->FindActiveEntry(&vmi_key));
94  if (intrface != vm_interface_.get()) {
95  vm_interface_.reset(intrface);
96  ret = true;
97  }
98 
99  boost::uuids::uuid old_vn_uuid = vn_uuid_;
100  VmInterface *vmi = static_cast<VmInterface *>(vm_interface_.get());
101  if (vm_interface_.get() && vmi->vn()) {
102  vn_uuid_ = vmi->vn()->GetUuid();
103  } else {
104  vn_uuid_ = boost::uuids::nil_uuid();
105  }
106  if (old_vn_uuid != vn_uuid_)
107  ret = true;
108 
109  vm_uuid_ = data->vm_interface_;
110 
111  PhysicalDevice *dev = table->agent()->physical_device_table()->
112  Find(data->device_uuid_);
113  if (dev != physical_device_.get()) {
114  physical_device_.reset(dev);
115  ret = true;
116  }
117 
119  OPER_TRACE_ENTRY(Trace, table,
120  "Changing Physical Device display name from " \
121  + phy_dev_display_name_ + " to " +
122  data->phy_dev_display_name_);
124  ret = true;
125  }
126 
127  return ret;
128 }
129 
131  return true;
132 }
133 
136  os_params_.mac_.Zero();
137  os_params_.os_oper_state_ = true;
138 }
139 
141  return static_cast<VmInterface *>(vm_interface_.get());
142 }
143 
145  return static_cast<Interface *>(physical_interface_.get());
146 }
147 
149 // LogicalInterfaceKey routines
151 
153  const std::string &name) :
154  InterfaceKey(AgentKey::ADD_DEL_CHANGE, Interface::LOGICAL, uuid, name,
155  false) {
156 }
157 
159 }
160 
162 // LogicalInterfaceData routines
165  const std::string &display_name,
166  const std::string &port,
167  const boost::uuids::uuid &vif,
168  const uuid &device_uuid,
169  const std::string &phy_dev_display_name,
170  const std::string &phy_intf_display_name) :
171  InterfaceData(agent, node, Interface::TRANSPORT_INVALID),
172  display_name_(display_name),
173  physical_interface_(port), vm_interface_(vif), device_uuid_(device_uuid),
174  phy_dev_display_name_(phy_dev_display_name),
175  phy_intf_display_name_(phy_intf_display_name) {
176 }
177 
179 }
180 
182 // VlanLogicalInterface routines
185  const std::string &name,
186  uint16_t vlan,
187  const boost::uuids::uuid &logical_router_uuid) :
188  LogicalInterface(uuid, name, logical_router_uuid), vlan_(vlan) {
189 }
190 
192 }
193 
196  return DBEntryBase::KeyPtr(key);
197 }
198 
200 // VlanLogicalInterfaceKey routines
203  const std::string &name) :
204  LogicalInterfaceKey(uuid, name) {
205 }
206 
208 }
209 
212  const {
213  return new VlanLogicalInterface(uuid_, name_, 0, boost::uuids::nil_uuid());
214 }
215 
218  const InterfaceData *d) const {
219  const VlanLogicalInterfaceData *data =
220  static_cast<const VlanLogicalInterfaceData *>(d);
222  data->vlan_,
223  data->logical_router_uuid_);
224 
225  intf->OnChange(table, data);
226  return intf;
227 }
228 
230  return new VlanLogicalInterfaceKey(uuid_, name_);
231 }
232 
234 (Agent *agent, IFMapNode *node, const std::string &display_name,
235  const std::string &physical_interface,
236  const boost::uuids::uuid &vif, const boost::uuids::uuid &u,
237  const std::string &phy_dev_display_name,
238  const std::string &phy_intf_display_name, uint16_t vlan) :
239  LogicalInterfaceData(agent, node, display_name, physical_interface, vif, u,
240  phy_dev_display_name, phy_intf_display_name),
241  vlan_(vlan) {
242 }
243 
245 }
246 
247 #if 0
248 void VlanLogicalInterface::SetSandeshData(SandeshLogicalInterface *data) const {
249  data->set_vlan_tag(vlan_);
250 }
251 #endif
252 // Config handling routines
256  const boost::uuids::uuid &u) {
257  return new VlanLogicalInterfaceKey(u, node->name());
258 }
259 
261  const uuid &u,
262  const autogen::LogicalInterface *port) {
263  // Find link with physical-interface adjacency
264  string physical_interface;
265  string phy_dev_display_name;
266  string phy_intf_display_name;
267  IFMapNode *adj_node = NULL;
268  boost::uuids::uuid dev_uuid = boost::uuids::nil_uuid();
269  adj_node = agent->config_manager()->FindAdjacentIFMapNode(node,
270  "physical-interface");
271  IFMapNode *prouter_node = NULL;
272 
273  if (adj_node) {
274  physical_interface = adj_node->name();
275  autogen::PhysicalInterface *port =
276  static_cast <autogen::PhysicalInterface *>(adj_node->GetObject());
277  assert(port);
278  phy_intf_display_name = port->display_name();
279  prouter_node = agent->config_manager()->
280  FindAdjacentIFMapNode(adj_node, "physical-router");
281  if (prouter_node) {
282  autogen::PhysicalRouter *router =
283  static_cast<autogen::PhysicalRouter *>(prouter_node->GetObject());
284  phy_dev_display_name = router->display_name();
285  autogen::IdPermsType id_perms = router->id_perms();
286  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
287  dev_uuid);
288  }
289  }
290 
291  // Find link with virtual-machine-interface adjacency
292  boost::uuids::uuid vmi_uuid = boost::uuids::nil_uuid();
293  adj_node = agent->config_manager()->FindAdjacentIFMapNode
294  (node, "virtual-machine-interface");
295  if (adj_node) {
296  autogen::VirtualMachineInterface *vmi =
297  static_cast<autogen::VirtualMachineInterface *>
298  (adj_node->GetObject());
299  autogen::IdPermsType id_perms = vmi->id_perms();
300  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
301  vmi_uuid);
302  }
303 
304  string dev_name;
305  adj_node = agent->config_manager()->FindAdjacentIFMapNode
306  (node, "physical-router");
307  if (adj_node) {
308  dev_name = adj_node->name();
309  if (dev_uuid != boost::uuids::nil_uuid()) {
310  IFMAP_ERROR(LogicalInterfaceConfiguration,
311  "Both physical-router and physical-interface links for "
312  "interface:", node->name(),
313  "physical interface", physical_interface,
314  "prouter name", dev_name);
315  }
316  autogen::PhysicalRouter *router =
317  static_cast<autogen::PhysicalRouter *>(adj_node->GetObject());
318  autogen::IdPermsType id_perms = router->id_perms();
319  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
320  dev_uuid);
321  }
322 
323  // Logical-Interface must have VLAN-Tag field. Ignore the interface if
324  // VLAN-Tag is not yet present
325  if (port->IsPropertySet(autogen::LogicalInterface::VLAN_TAG) == false) {
326  OperConfigInfo t;
327  t.set_name(node->name());
328  t.set_uuid(UuidToString(u));
329  t.set_message("VLAN-Tag property not set. Ignoring node");
330 
331  OPER_IFMAP_TRACE(Config, t);
332  return NULL;
333  }
334 
335  return new VlanLogicalInterfaceData(agent, node, port->display_name(),
336  physical_interface, vmi_uuid, dev_uuid,
337  phy_dev_display_name,
338  phy_intf_display_name,
339  port->vlan_tag());
340 }
341 
343  boost::uuids::uuid &u) {
344 
345  autogen::LogicalInterface *port =
346  static_cast <autogen::LogicalInterface *>(node->GetObject());
347  assert(port);
348 
349  autogen::IdPermsType id_perms = port->id_perms();
350  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
351  return true;
352 }
353 
355  DBRequest &req,
356  const boost::uuids::uuid &u) {
357  autogen::LogicalInterface *port =
358  static_cast <autogen::LogicalInterface *>(node->GetObject());
359  assert(port);
360 
361  req.key.reset(BuildKey(node, u));
362  if (node->IsDeleted()) {
364  return true;
365  }
366 
368  req.data.reset(BuildData(agent(), node, u, port));
369 
370  if (req.data.get() != NULL) {
372  Enqueue(&req);
373  }
374  return false;
375 }
376 
378  DBRequest &req,
379  const boost::uuids::uuid &u) {
380  autogen::LogicalInterface *port =
381  static_cast <autogen::LogicalInterface *>(node->GetObject());
382  assert(port);
383 
384  req.key.reset(BuildKey(node, u));
385  if (req.oper == DBRequest::DB_ENTRY_DELETE || node->IsDeleted()) {
387  return true;
388  }
389 
391  return false;
392 }
boost::uuids::uuid uuid_
Definition: interface.h:162
static LogicalInterfaceData * BuildData(Agent *agent, IFMapNode *node, const uuid &u, const autogen::LogicalInterface *port)
static LogicalInterfaceKey * BuildKey(IFMapNode *node, const boost::uuids::uuid &u)
PhysicalDevice * physical_device() const
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
std::string display_name_
#define OPER_IFMAP_TRACE(obj,...)
Definition: agent_cmn.h:90
virtual DBEntryBase::KeyPtr GetDBRequestKey() const
virtual LogicalInterface * AllocEntry(const InterfaceTable *table) const
uint32_t li_ifnode_to_req_
Definition: interface.h:496
VlanLogicalInterfaceKey(const boost::uuids::uuid &uuid, const std::string &name)
std::string phy_intf_display_name_
PhysicalDeviceTable * physical_device_table() const
Definition: agent.h:628
bool IsDeleted() const
Definition: db_entry.h:49
ConfigManager * config_manager() const
Definition: agent.cc:889
virtual ~LogicalInterface()
VlanLogicalInterface(const boost::uuids::uuid &uuid, const std::string &name, uint16_t vlan, const boost::uuids::uuid &lr_uuid)
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
virtual void GetOsParams(Agent *agent)
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:110
InterfaceTable * interface_table() const
Definition: agent.h:465
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
boost::uuids::uuid uuid
Interface * physical_interface() const
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:138
void AddLogicalInterfaceNode(IFMapNode *node)
virtual std::string ToString() const
Agent * agent() const
Definition: interface.h:447
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
boost::uuids::uuid logical_router_uuid_
Definition: interface.h:267
std::string name_
Definition: interface.h:245
IFMapNode * FindAdjacentIFMapNode(IFMapNode *node, const char *type)
LogicalInterfaceData(Agent *agent, IFMapNode *node, const std::string &display_name, const std::string &physical_interface, const boost::uuids::uuid &vif, const boost::uuids::uuid &device_uuid, const std::string &phy_dev_display_name, const std::string &phy_intf_display_name)
#define IFMAP_ERROR(obj,...)
Definition: agent_cmn.h:95
boost::uuids::uuid vn_uuid_
Definition: agent.h:358
bool LogicalInterfaceProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual InterfaceKey * Clone() const
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
DBOperation oper
Definition: db_table.h:42
Definition: trace.h:220
std::string physical_interface_
#define OPER_TRACE_ENTRY(obj, table,...)
Definition: agent_db.h:234
const VnEntry * vn() const
const std::string & name() const
Definition: ifmap_node.h:48
void Delete()
Definition: db_entry.cc:131
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
std::string phy_intf_display_name_
virtual bool CmpInterface(const DBEntry &rhs) const
virtual bool OnChange(const InterfaceTable *table, const LogicalInterfaceData *data)
static const uint32_t kInvalidIndex
Definition: interface.h:70
InterfaceRef vm_interface_
VmInterface * vm_interface() const
PhysicalDeviceRef physical_device_
struct InterfaceOsParams os_params_
Definition: interface.h:188
const std::string & name() const
Definition: interface.h:114
boost::uuids::uuid device_uuid_
const boost::uuids::uuid & GetUuid() const
Definition: vn.h:161
std::string phy_dev_display_name_
bool LogicalInterfaceIFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
LogicalInterface(const boost::uuids::uuid &uuid, const std::string &name, const boost::uuids::uuid &logical_router_uuid)
std::string phy_dev_display_name_
void Zero()
Definition: mac_address.h:131
VlanLogicalInterfaceData(Agent *agent, IFMapNode *node, const std::string &display_name, const std::string &physical_interface, const boost::uuids::uuid &vif, const boost::uuids::uuid &device_uuid, const std::string &phy_dev_display_name, const std::string &phy_intf_display_name, uint16_t vlan)
InterfaceRef physical_interface_
boost::uuids::uuid vm_uuid_
LogicalInterfaceKey(const boost::uuids::uuid &uuid, const std::string &name)
boost::uuids::uuid uuid_
Definition: interface.h:244
boost::uuids::uuid vm_interface_
bool LogicalInterfaceIFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)