OpenSDN source code
remote_physical_interface.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 #include <boost/uuid/uuid_io.hpp>
7 #include <vnc_cfg_types.h>
8 #include <cmn/agent_cmn.h>
9 
10 #include <ifmap/ifmap_node.h>
11 #include <cfg/cfg_init.h>
12 #include <oper/agent_sandesh.h>
14 #include <oper/interface_common.h>
15 #include <oper/physical_device.h>
16 #include <oper/nexthop.h>
17 #include <oper/config_manager.h>
18 
19 #include <vector>
20 #include <string>
21 
22 using std::string;
23 using boost::uuids::uuid;
24 
26 // RemotePhysicalInterface routines
29  Interface(Interface::REMOTE_PHYSICAL, boost::uuids::nil_uuid(), name,
30  NULL, true, boost::uuids::nil_uuid()),
31  display_name_(), physical_device_(NULL) {
32 }
33 
35 }
36 
38  return "Remote-PORT <" + name() + ">";
39 }
40 
42  const RemotePhysicalInterface &a =
43  static_cast<const RemotePhysicalInterface &>(rhs);
44  return name() < a.name();
45 }
46 
51 }
52 
55  return DBEntryBase::KeyPtr(key);
56 }
57 
59  const RemotePhysicalInterfaceData *data){
60  bool ret = false;
61 
62  // Handle VRF Change
63  VrfKey key(data->vrf_name_);
64  VrfEntry *new_vrf = static_cast<VrfEntry *>
65  (table->agent()->vrf_table()->FindActiveEntry(&key));
66  if (new_vrf != vrf_.get()) {
67  vrf_.reset(new_vrf);
68  ret = true;
69  }
70 
71  PhysicalDevice *dev =
72  table->agent()->physical_device_table()->Find(data->device_uuid_);
73  if (dev != physical_device_.get()) {
74  physical_device_.reset(dev);
75  ret = true;
76  }
77 
78  if (display_name_ != data->display_name_) {
80  ret = true;
81  }
82 
83  return ret;
84 }
85 
87 // RemotePhysicalInterfaceKey routines
90  InterfaceKey(AgentKey::ADD_DEL_CHANGE, Interface::REMOTE_PHYSICAL,
91  boost::uuids::nil_uuid(), name, false) {
92 }
93 
95 }
96 
98  const {
99  return new RemotePhysicalInterface(name_);
100 }
101 
103  const InterfaceData *data)
104  const {
106 
107  const RemotePhysicalInterfaceData *phy_data =
108  static_cast<const RemotePhysicalInterfaceData *>(data);
109 
110  intf->OnChange(table, phy_data);
111  return intf;
112 }
113 
115  return new RemotePhysicalInterfaceKey(name_);
116 }
117 
119 // RemotePhysicalInterfaceData routines
122  (Agent *agent, IFMapNode *node, const string &display_name,
123  const string &vrf_name, const uuid &device_uuid) :
124  InterfaceData(agent, node, Interface::TRANSPORT_INVALID),
125  display_name_(display_name),
126  device_uuid_(device_uuid) {
127  RemotePhysicalPortInit(vrf_name);
128 }
129 
131 }
132 
134 // Config handling routines
137  return new RemotePhysicalInterfaceKey(node->name());
138 }
139 
141 (Agent *agent, IFMapNode *node, const autogen::PhysicalInterface *port) {
142  boost::uuids::uuid dev_uuid = boost::uuids::nil_uuid();
143  // Find link with physical-router adjacency
144  IFMapNode *adj_node = NULL;
145  adj_node = agent->config_manager()->FindAdjacentIFMapNode(node,
146  "physical-router");
147  if (adj_node) {
148  autogen::PhysicalRouter *router =
149  static_cast<autogen::PhysicalRouter *>(adj_node->GetObject());
150  autogen::IdPermsType id_perms = router->id_perms();
151  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
152  dev_uuid);
153  }
154 
155  return new RemotePhysicalInterfaceData(agent, node, port->display_name(),
156  agent->fabric_vrf_name(), dev_uuid);
157 }
158 
160  DBRequest &req,
161  const boost::uuids::uuid &u) {
162  autogen::PhysicalInterface *port =
163  static_cast <autogen::PhysicalInterface *>(node->GetObject());
164  assert(port);
165 
166  req.key.reset(BuildKey(node));
167  if (req.oper == DBRequest::DB_ENTRY_DELETE || node->IsDeleted()) {
169  return true;
170  }
171 
173  req.data.reset(BuildData(agent(), node, port));
175  return true;
176 }
177 
179 // Utility methods
181 static void SetReq(DBRequest *req, const string &fqdn,
182  const string &display_name, const string &vrf_name,
183  const uuid &device_uuid) {
184  req->key.reset(new RemotePhysicalInterfaceKey(fqdn));
185  req->data.reset(new RemotePhysicalInterfaceData(NULL, NULL, display_name,
186  vrf_name, device_uuid));
187 }
188 
190  const string &fqdn,
191  const string &display_name,
192  const string &vrf_name,
193  const uuid &device_uuid) {
195  SetReq(&req, fqdn, display_name, vrf_name, device_uuid);
196  table->Enqueue(&req);
197 }
198 
199 void RemotePhysicalInterface::Create(InterfaceTable *table, const string &fqdn,
200  const string &display_name,
201  const string &vrf_name,
202  const uuid &device_uuid) {
204  SetReq(&req, fqdn, display_name, vrf_name, device_uuid);
205  table->Process(req);
206 }
207 
208 // Enqueue DBRequest to delete a Host Interface
210  const string &fqdn) {
212  req.key.reset(new RemotePhysicalInterfaceKey(fqdn));
213  req.data.reset(NULL);
214  table->Enqueue(&req);
215 }
216 
218  const string &fqdn) {
220  req.key.reset(new RemotePhysicalInterfaceKey(fqdn));
221  req.data.reset(NULL);
222  table->Process(req);
223 }
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
virtual void Process(DBRequest &req)
Definition: agent_db.cc:232
Definition: agent.h:361
ConfigManager * config_manager() const
Definition: agent.cc:893
VrfTable * vrf_table() const
Definition: agent.h:488
PhysicalDeviceTable * physical_device_table() const
Definition: agent.h:631
const std::string & fabric_vrf_name() const
Definition: agent.h:906
IFMapNode * FindAdjacentIFMapNode(IFMapNode *node, const char *type)
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
bool IsDeleted() const
Definition: db_entry.h:49
void Delete()
Definition: db_entry.cc:132
bool Enqueue(DBRequest *req)
Definition: db_table.cc:221
const std::string & name() const
Definition: ifmap_node.h:49
IFMapObject * GetObject()
Definition: ifmap_node.cc:64
bool RemotePhysicalInterfaceIFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
uint32_t pi_ifnode_to_req_
Definition: interface.h:500
Agent * agent() const
Definition: interface.h:450
const std::string & name() const
Definition: interface.h:117
VrfEntryRef vrf_
Definition: interface.h:166
struct InterfaceOsParams os_params_
Definition: interface.h:191
static const uint32_t kInvalidIndex
Definition: interface.h:73
void Zero()
Definition: mac_address.h:132
PhysicalDevice * Find(const boost::uuids::uuid &u)
virtual std::string ToString() const
RemotePhysicalInterface(const std::string &name)
static void CreateReq(InterfaceTable *table, const std::string &fqdn, const std::string &display_name, const std::string &vrf_name, const boost::uuids::uuid &device_uuid)
virtual bool OnChange(const InterfaceTable *table, const RemotePhysicalInterfaceData *data)
virtual KeyPtr GetDBRequestKey() const
static void DeleteReq(InterfaceTable *table, const std::string &ifname)
const std::string & display_name() const
static void Create(InterfaceTable *table, const std::string &fqdn, const std::string &display_name, const std::string &vrf_name, const boost::uuids::uuid &device_uuid)
virtual bool CmpInterface(const DBEntry &rhs) const
virtual void GetOsParams(Agent *agent)
Definition: vrf.h:90
static void SetReq(DBRequest *req, const string &fqdn, const string &display_name, const string &vrf_name, const uuid &device_uuid)
static RemotePhysicalInterfaceKey * BuildKey(IFMapNode *node)
static RemotePhysicalInterfaceData * BuildData(Agent *agent, IFMapNode *node, const autogen::PhysicalInterface *port)
DBOperation oper
Definition: db_table.h:43
@ DB_ENTRY_DELETE
Definition: db_table.h:40
@ DB_ENTRY_ADD_CHANGE
Definition: db_table.h:39
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:49
std::unique_ptr< DBRequestData > data
Definition: db_table.h:50
void RemotePhysicalPortInit(const std::string &vrf_name)
Definition: interface.h:263
std::string vrf_name_
Definition: interface.h:268
std::string name_
Definition: interface.h:248
RemotePhysicalInterfaceData(Agent *agent, IFMapNode *node, const std::string &display_name, const std::string &vrf_name, const boost::uuids::uuid &device_uuid)
RemotePhysicalInterfaceKey(const std::string &name)
Interface * AllocEntry(const InterfaceTable *table) const
Definition: vrf.h:26
boost::uuids::uuid uuid