OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
remote_physical_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/nexthop.h>
16 #include <oper/config_manager.h>
17 
18 #include <vector>
19 #include <string>
20 
21 using std::string;
22 using boost::uuids::uuid;
23 
25 // RemotePhysicalInterface routines
28  Interface(Interface::REMOTE_PHYSICAL, boost::uuids::nil_uuid(), name,
29  NULL, true, boost::uuids::nil_uuid()),
30  display_name_(), physical_device_(NULL) {
31 }
32 
34 }
35 
37  return "Remote-PORT <" + name() + ">";
38 }
39 
41  const RemotePhysicalInterface &a =
42  static_cast<const RemotePhysicalInterface &>(rhs);
43  return name() < a.name();
44 }
45 
50 }
51 
54  return DBEntryBase::KeyPtr(key);
55 }
56 
58  const RemotePhysicalInterfaceData *data){
59  bool ret = false;
60 
61  // Handle VRF Change
62  VrfKey key(data->vrf_name_);
63  VrfEntry *new_vrf = static_cast<VrfEntry *>
64  (table->agent()->vrf_table()->FindActiveEntry(&key));
65  if (new_vrf != vrf_.get()) {
66  vrf_.reset(new_vrf);
67  ret = true;
68  }
69 
70  PhysicalDevice *dev =
71  table->agent()->physical_device_table()->Find(data->device_uuid_);
72  if (dev != physical_device_.get()) {
73  physical_device_.reset(dev);
74  ret = true;
75  }
76 
77  if (display_name_ != data->display_name_) {
79  ret = true;
80  }
81 
82  return ret;
83 }
84 
86 // RemotePhysicalInterfaceKey routines
89  InterfaceKey(AgentKey::ADD_DEL_CHANGE, Interface::REMOTE_PHYSICAL,
90  boost::uuids::nil_uuid(), name, false) {
91 }
92 
94 }
95 
97  const {
98  return new RemotePhysicalInterface(name_);
99 }
100 
102  const InterfaceData *data)
103  const {
105 
106  const RemotePhysicalInterfaceData *phy_data =
107  static_cast<const RemotePhysicalInterfaceData *>(data);
108 
109  intf->OnChange(table, phy_data);
110  return intf;
111 }
112 
114  return new RemotePhysicalInterfaceKey(name_);
115 }
116 
118 // RemotePhysicalInterfaceData routines
121  (Agent *agent, IFMapNode *node, const string &display_name,
122  const string &vrf_name, const uuid &device_uuid) :
124  display_name_(display_name),
125  device_uuid_(device_uuid) {
126  RemotePhysicalPortInit(vrf_name);
127 }
128 
130 }
131 
133 // Config handling routines
136  return new RemotePhysicalInterfaceKey(node->name());
137 }
138 
140 (Agent *agent, IFMapNode *node, const autogen::PhysicalInterface *port) {
141  boost::uuids::uuid dev_uuid = boost::uuids::nil_uuid();
142  // Find link with physical-router adjacency
143  IFMapNode *adj_node = NULL;
144  adj_node = agent->config_manager()->FindAdjacentIFMapNode(node,
145  "physical-router");
146  if (adj_node) {
147  autogen::PhysicalRouter *router =
148  static_cast<autogen::PhysicalRouter *>(adj_node->GetObject());
149  autogen::IdPermsType id_perms = router->id_perms();
150  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
151  dev_uuid);
152  }
153 
154  return new RemotePhysicalInterfaceData(agent, node, port->display_name(),
155  agent->fabric_vrf_name(), dev_uuid);
156 }
157 
159  DBRequest &req,
160  const boost::uuids::uuid &u) {
161  autogen::PhysicalInterface *port =
162  static_cast <autogen::PhysicalInterface *>(node->GetObject());
163  assert(port);
164 
165  req.key.reset(BuildKey(node));
166  if (req.oper == DBRequest::DB_ENTRY_DELETE || node->IsDeleted()) {
168  return true;
169  }
170 
172  req.data.reset(BuildData(agent(), node, port));
174  return true;
175 }
176 
178 // Utility methods
180 static void SetReq(DBRequest *req, const string &fqdn,
181  const string &display_name, const string &vrf_name,
182  const uuid &device_uuid) {
183  req->key.reset(new RemotePhysicalInterfaceKey(fqdn));
184  req->data.reset(new RemotePhysicalInterfaceData(NULL, NULL, display_name,
185  vrf_name, device_uuid));
186 }
187 
189  const string &fqdn,
190  const string &display_name,
191  const string &vrf_name,
192  const uuid &device_uuid) {
194  SetReq(&req, fqdn, display_name, vrf_name, device_uuid);
195  table->Enqueue(&req);
196 }
197 
198 void RemotePhysicalInterface::Create(InterfaceTable *table, const string &fqdn,
199  const string &display_name,
200  const string &vrf_name,
201  const uuid &device_uuid) {
203  SetReq(&req, fqdn, display_name, vrf_name, device_uuid);
204  table->Process(req);
205 }
206 
207 // Enqueue DBRequest to delete a Host Interface
209  const string &fqdn) {
211  req.key.reset(new RemotePhysicalInterfaceKey(fqdn));
212  req.data.reset(NULL);
213  table->Enqueue(&req);
214 }
215 
217  const string &fqdn) {
219  req.key.reset(new RemotePhysicalInterfaceKey(fqdn));
220  req.data.reset(NULL);
221  table->Process(req);
222 }
RemotePhysicalInterfaceKey(const std::string &name)
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
Definition: vrf.h:86
static void DeleteReq(InterfaceTable *table, const std::string &ifname)
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
static void SetReq(DBRequest *req, const string &fqdn, const string &display_name, const string &vrf_name, const uuid &device_uuid)
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:110
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
boost::uuids::uuid uuid
virtual KeyPtr GetDBRequestKey() const
Agent * agent() const
Definition: interface.h:447
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
static RemotePhysicalInterfaceKey * BuildKey(IFMapNode *node)
std::string name_
Definition: interface.h:245
const std::string & fabric_vrf_name() const
Definition: agent.h:903
PhysicalDevice * Find(const boost::uuids::uuid &u)
IFMapNode * FindAdjacentIFMapNode(IFMapNode *node, const char *type)
Definition: agent.h:358
std::string vrf_name_
Definition: interface.h:265
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)
Definition: vrf.h:22
RemotePhysicalInterface(const std::string &name)
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
DBOperation oper
Definition: db_table.h:42
uint32_t pi_ifnode_to_req_
Definition: interface.h:497
virtual void GetOsParams(Agent *agent)
virtual void Process(DBRequest &req)
Definition: agent_db.cc:231
const std::string & name() const
Definition: ifmap_node.h:48
VrfTable * vrf_table() const
Definition: agent.h:485
void Delete()
Definition: db_entry.cc:131
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
RemotePhysicalInterfaceData(Agent *agent, IFMapNode *node, const std::string &display_name, const std::string &vrf_name, const boost::uuids::uuid &device_uuid)
Interface * AllocEntry(const InterfaceTable *table) const
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 std::string ToString() const
static const uint32_t kInvalidIndex
Definition: interface.h:70
VrfEntryRef vrf_
Definition: interface.h:163
struct InterfaceOsParams os_params_
Definition: interface.h:188
const std::string & name() const
Definition: interface.h:114
bool RemotePhysicalInterfaceIFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual bool OnChange(const InterfaceTable *table, const RemotePhysicalInterfaceData *data)
static RemotePhysicalInterfaceData * BuildData(Agent *agent, IFMapNode *node, const autogen::PhysicalInterface *port)
void Zero()
Definition: mac_address.h:131
virtual bool CmpInterface(const DBEntry &rhs) const