OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qos_config.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <cmn/agent.h>
6 #include <vnc_cfg_types.h>
7 #include <agent_types.h>
8 #include <oper/agent_sandesh.h>
9 #include <cfg/cfg_init.h>
10 #include <oper_db.h>
11 #include <oper/config_manager.h>
12 #include <oper/interface_common.h>
13 #include <forwarding_class.h>
14 #include <qos_config.h>
18 
19 using namespace autogen;
21  uuid_(uuid), id_(AgentQosConfigTable::kInvalidIndex) {
22 }
23 
26  static_cast<AgentQosConfigTable *>(get_table())->ReleaseIndex(this);
27  }
28 }
29 
32  return DBEntryBase::KeyPtr(key);
33 }
34 
35 std::string AgentQosConfig::ToString() const {
36  std::ostringstream buffer;
37  buffer << uuid_;
38  return buffer.str();
39 }
40 
41 bool AgentQosConfig::DBEntrySandesh(Sandesh *sresp, std::string &name) const {
42  AgentQosConfigSandeshResp *resp =
43  static_cast<AgentQosConfigSandeshResp *>(sresp);
44  AgentQosConfigSandeshData data;
45 
46  data.set_uuid(UuidToString(uuid_));
47  data.set_name(name_);
48  data.set_id(id_);
49  if (type_ == VHOST) {
50  data.set_type("vhost");
51  } else if (type_ == FABRIC) {
52  data.set_type("fabric");
53  } else {
54  data.set_type("default");
55  }
56 
57  std::vector<QosForwardingClassSandeshPair> dscp_list;
58  AgentQosConfig::QosIdForwardingClassMap::const_iterator it =
59  dscp_map_.begin();
60  for(; it != dscp_map_.end(); it++) {
61  QosForwardingClassSandeshPair pair;
62  pair.set_qos_value(it->first);
63  pair.set_forwarding_class_id(it->second);
64  dscp_list.push_back(pair);
65  }
66 
67  std::vector<QosForwardingClassSandeshPair> vlan_priority_list;
68  it = vlan_priority_map_.begin();
69  for(; it != vlan_priority_map_.end(); it++) {
70  QosForwardingClassSandeshPair pair;
71  pair.set_qos_value(it->first);
72  pair.set_forwarding_class_id(it->second);
73  vlan_priority_list.push_back(pair);
74  }
75 
76  std::vector<QosForwardingClassSandeshPair> mpls_exp_list;
77  it = mpls_exp_map_.begin();
78  for(; it != mpls_exp_map_.end(); it++) {
79  QosForwardingClassSandeshPair pair;
80  pair.set_qos_value(it->first);
81  pair.set_forwarding_class_id(it->second);
82  mpls_exp_list.push_back(pair);
83  }
84 
85  data.set_dscp_list(dscp_list);
86  data.set_vlan_priority_list(vlan_priority_list);
87  data.set_mpls_exp_list(mpls_exp_list);
88  data.set_default_forwarding_class(default_forwarding_class_);
89 
90  std::vector<AgentQosConfigSandeshData> &list =
91  const_cast<std::vector<AgentQosConfigSandeshData>&>(resp->get_qc_list());
92  list.push_back(data);
93  return true;
94 }
95 
96 bool AgentQosConfig::IsLess(const DBEntry &rhs) const {
97  const AgentQosConfig &fc = static_cast<const AgentQosConfig &>(rhs);
98  return (uuid_ < fc.uuid_);
99 }
100 
103  const
105  &data_map) {
106 
107  QosIdForwardingClassMap new_map;
108  AgentQosIdForwardingClassMap::const_iterator it = data_map.begin();
109  for (; it != data_map.end(); it++) {
110  new_map.insert(QosIdForwardingClassPair(it->first, it->second));
111  }
112 
113  if (map != new_map) {
114  map = new_map;
115  return true;
116  }
117 
118  return false;
119 }
120 
122  const AgentQosConfigData *data) {
123  IFMapNode *node = data->ifmap_node();
124  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
125 
127  node->begin(table->GetGraph()); iter != node->end(table->GetGraph());
128  ++iter) {
129  const IFMapNode *adj_node = static_cast<const IFMapNode *>(iter.operator->());
130  if (adj_node->table() == agent->cfg()->cfg_global_qos_table()) {
131  return true;
132  }
133  }
134  return false;
135 }
136 
138  const AgentQosConfigData *data, bool deleted) {
139  if (deleted == false) {
140  //Verify that link to Global QoS config exists
141  if (VerifyLinkToGlobalQosConfig(agent, data) == false) {
142  deleted = true;
143  }
144  }
145 
146  AgentQosConfigTable *table =
147  static_cast<AgentQosConfigTable *>(agent->qos_config_table());
148 
149  if (deleted) {
150  table->EraseVhostQosConfig(uuid());
151  } else {
152  table->InsertVhostQosConfig(uuid());
153  }
154 
156  VmInterfaceKey *key =
157  new VmInterfaceKey(AgentKey::ADD_DEL_CHANGE, boost::uuids::nil_uuid(),
158  agent->vhost_interface_name());
159  key->sub_op_ = AgentKey::RESYNC;
160  boost::uuids::uuid qos_config_uuid = table->GetActiveVhostQosConfig();
161  InterfaceQosConfigData *qos_data =
162  new InterfaceQosConfigData(agent, NULL, qos_config_uuid);
163  req.key.reset(key);
164  req.data.reset(qos_data);
165  agent->interface_table()->Enqueue(&req);
166 }
167 
169  const AgentQosConfigData *data, bool deleted) {
170 
171  if (deleted == false) {
172  //Verify that link to Global QoS config exists
173  if (VerifyLinkToGlobalQosConfig(agent, data) == false) {
174  deleted = true;
175  }
176  }
177 
178  AgentQosConfigTable *table =
179  static_cast<AgentQosConfigTable *>(agent->qos_config_table());
180 
181  if (deleted) {
182  table->EraseFabricQosConfig(uuid());
183  } else {
184  table->InsertFabricQosConfig(uuid());
185  }
186 
188  PhysicalInterfaceKey *key =
190  key->sub_op_ = AgentKey::RESYNC;
191 
192  boost::uuids::uuid qos_config_uuid = table->GetActiveFabricQosConfig();
193  InterfaceQosConfigData *qos_data =
194  new InterfaceQosConfigData(agent, NULL, qos_config_uuid);
195  req.key.reset(key);
196  req.data.reset(qos_data);
197  agent->interface_table()->Enqueue(&req);
198 }
199 
201  if (data->ifmap_node() == NULL) {
202  return;
203  }
204  if (type_ == VHOST) {
205  HandleVhostQosConfig(data->agent(), data, false);
206  } else {
207  HandleFabricQosConfig(data->agent(), data, false);
208  }
209 }
210 
212  bool ret = false;
213  const AgentQosConfigData *data =
214  static_cast<const AgentQosConfigData *>(req->data.get());
215 
216  //Ignore change notification if entry node is marked for deletion
217  if ((data->ifmap_node() == NULL) || (data->ifmap_node()->IsDeleted())) {
218  return ret;
219  }
220 
221  if (name_ != data->name_) {
222  name_ = data->name_;
223  ret = true;
224  }
225 
226  if (HandleQosForwardingMapChange(data->agent(), dscp_map_, data->dscp_map_)) {
227  ret = true;
228  }
229 
231  data->vlan_priority_map_)) {
232  ret = true;
233  }
234 
236  data->mpls_exp_map_)) {
237  ret = true;
238  }
239 
240  if (type_ != data->type_) {
241  type_ = data->type_;
242  ret = true;
243  }
244 
245  if (type_ != DEFAULT) {
246  HandleGlobalQosConfig(data);
247  }
248 
251  ret = true;
252  }
253 
254  return ret;
255 }
256 
258  Agent *agent = (static_cast<AgentOperDBTable *>(get_table())->agent());
259  if (type_ == VHOST) {
260  HandleVhostQosConfig(agent, NULL, true);
261  } else if (type_ == FABRIC) {
262  HandleFabricQosConfig(agent, NULL, true);
263  }
264 }
265 
267  const AgentQosConfigKey *fc_key =
268  static_cast<const AgentQosConfigKey *>(key);
269  uuid_ = fc_key->uuid_;
270 }
271 
273  DB *db, const std::string &name):
274  AgentOperDBTable(db, name) {
275  set_agent(agent);
276 }
277 
279 }
280 
282 AgentQosConfigTable::CreateTable(Agent *agent, DB *db, const std::string &name) {
283  AgentQosConfigTable *qos_table = new AgentQosConfigTable(agent, db, name);
284  (static_cast<DBTable *>(qos_table))->Init();
285  return qos_table;
286 }
287 
288 std::unique_ptr<DBEntry>
290  const AgentQosConfigKey *key =
291  static_cast<const AgentQosConfigKey *>(k);
292  AgentQosConfig *fc = new AgentQosConfig(key->uuid_);
293  return std::unique_ptr<DBEntry>(static_cast<DBEntry *>(fc));
294 }
295 
297  const AgentQosConfigKey *key =
298  static_cast<const AgentQosConfigKey *>(req->key.get());
299  AgentQosConfig *qc = new AgentQosConfig(key->uuid_);
301  agent()->resource_manager(), key->uuid_));
302  int id = static_cast<IndexResourceData *>(agent()->resource_manager()->
303  Allocate(rkey).get())->index();
304  index_table_.InsertAtIndex(id, qc);
305  qc->set_id(id);
306  qc->Change(req);
307  name_map_.insert(AgentQosConfigNamePair(qc->name(), qc));
308  return static_cast<DBEntry *>(qc);
309 }
310 
312  AgentQosConfig *qc = static_cast<AgentQosConfig *>(entry);
313  return qc->Change(req);
314 }
315 
317  return OperDBOnChange(entry, req);
318 }
319 
321  AgentQosConfig *qc = static_cast<AgentQosConfig *>(entry);
322  qc->Delete(req);
323  name_map_.erase(qc->name());
324  return true;
325 }
326 
328  if (qc->id() != kInvalidIndex) {
330  index_table_.Remove(qc->id());
331  }
332 }
333 
335  const boost::uuids::uuid &u) {
336  assert(!u.is_nil());
337 
338  if ((req.oper == DBRequest::DB_ENTRY_DELETE) || node->IsDeleted()) {
339  req.key.reset(new AgentQosConfigKey(u));
341  Enqueue(&req);
342  return false;
343  }
344 
346  return false;
347 }
348 
350  autogen::QosConfig *cfg = static_cast <autogen::QosConfig *> (node->GetObject());
351  assert(cfg);
352  autogen::IdPermsType id_perms = cfg->id_perms();
353  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
354  return true;
355 }
356 
358  const boost::uuids::uuid &u) {
359  if (node->IsDeleted()) {
360  return false;
361  }
362 
364  req.key.reset(new AgentQosConfigKey(u));
365  req.data.reset(BuildData(node));
366  Enqueue(&req);
367  return false;
368 }
369 
372  AgentQosConfigData *qcd = new AgentQosConfigData(agent(), node);
373  autogen::QosConfig *cfg = static_cast <autogen::QosConfig *> (node->GetObject());
374 
375  std::vector<QosIdForwardingClassPair>::const_iterator it =
376  cfg->dscp_entries().begin();
377  for(; it != cfg->dscp_entries().end(); it++) {
378  qcd->dscp_map_[it->key] = it->forwarding_class_id;
379  }
380 
381  for(it = cfg->vlan_priority_entries().begin();
382  it != cfg->vlan_priority_entries().end(); it++) {
383  qcd->vlan_priority_map_[it->key] = it->forwarding_class_id;
384  }
385 
386  for(it = cfg->mpls_exp_entries().begin();
387  it != cfg->mpls_exp_entries().end(); it++) {
388  qcd->mpls_exp_map_[it->key] = it->forwarding_class_id;
389  }
390 
391  qcd->name_ = node->name();
392  if (cfg->type() == "vhost") {
394  } else if (cfg->type() == "fabric") {
396  } else {
398  }
399 
400  qcd->default_forwarding_class_ = cfg->default_forwarding_class_id();
401 
402  return qcd;
403 }
404 
407  const std::string &context) {
408  return AgentSandeshPtr(new AgentQosConfigSandesh(context,
409  args->GetString("uuid"), args->GetString("name"),
410  args->GetString("id")));
411 }
412 
413 void AgentQosConfigSandeshReq::HandleRequest() const {
414  AgentSandeshPtr sand(new AgentQosConfigSandesh(context(), get_uuid(),
415  get_name(), get_id()));
416  sand->DoSandesh(sand);
417 }
418 
419 void AddQosConfig::HandleRequest() const {
420  QosResponse *resp = new QosResponse();
421  resp->set_context(context());
422 
423  char str[50];
424  sprintf(str, "00000000-0000-0000-0000-00%010x", get_uuid());
425  boost::uuids::uuid u1 = StringToUuid(std::string(str));
426 
428 
429  data->dscp_map_.insert(AgentQosIdForwardingClassPair(get_dscp(),
430  get_dscp_forwarding_class_id()));
431  data->vlan_priority_map_.insert(AgentQosIdForwardingClassPair(get_vlan_priority(),
432  get_vlan_priority_forwarding_class_id()));
433  data->mpls_exp_map_.insert(AgentQosIdForwardingClassPair(get_mpls_exp(),
434  get_mpls_exp_forwarding_class_id()));
435  data->name_ = get_name();
436 
437  if (get_type() == "vhost") {
439  } else if (get_type() == "fabric") {
441  } else {
443  }
444 
445 
447  DBRequest req;
449  req.key.reset(new AgentQosConfigKey(u1));
450  req.data.reset(data);
451  table->Enqueue(&req);
452  resp->set_resp("Success");
453  resp->Response();
454 }
455 
456 void DeleteQosConfig::HandleRequest() const {
457  QosResponse *resp = new QosResponse();
458  resp->set_context(context());
459 
460  char str[50];
461  sprintf(str, "00000000-0000-0000-0000-00%010x", get_uuid());
462  boost::uuids::uuid u1 = StringToUuid(std::string(str));
463 
465  DBRequest req;
467  req.key.reset(new AgentQosConfigKey(u1));
468  req.data.reset(NULL);
469  table->Enqueue(&req);
470  resp->set_resp("Success");
471  resp->Response();
472 }
void EraseVhostQosConfig(const boost::uuids::uuid &uuid)
Definition: qos_config.h:202
AgentQosIdForwardingClassMap dscp_map_
Definition: qos_config.h:130
AgentQosConfigNameMap name_map_
Definition: qos_config.h:219
virtual bool IsLess(const DBEntry &rhs) const
Definition: qos_config.cc:96
static Agent * GetInstance()
Definition: agent.h:436
static boost::uuids::uuid StringToUuid(const std::string &str)
Definition: string_util.h:145
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
std::string GetString(const std::string &key) const
DBTableBase * get_table() const
Definition: db_entry.cc:119
IFMapAgentTable * cfg_global_qos_table() const
Definition: cfg_init.h:86
void Release(KeyPtr key)
bool IsDeleted() const
Definition: db_entry.h:49
ConfigManager * config_manager() const
Definition: agent.cc:889
AgentQosConfig(const boost::uuids::uuid uuid)
Definition: qos_config.cc:20
uint8_t sub_op_
Definition: agent_db.h:106
Agent * agent() const
Definition: agent_db.h:213
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
boost::shared_ptr< ResourceKey > KeyPtr
void HandleGlobalQosConfig(const AgentQosConfigData *data)
Definition: qos_config.cc:200
const std::string & vhost_interface_name() const
Definition: agent.cc:104
static const uint32_t kInvalidIndex
Definition: qos_config.h:144
InterfaceTable * interface_table() const
Definition: agent.h:465
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
uint32_t id() const
Definition: qos_config.h:73
boost::uuids::uuid uuid
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
Definition: qos_config.cc:349
KeyPtr GetDBRequestKey() const
Definition: qos_config.cc:30
virtual void SetKey(const DBRequestKey *key)
Definition: qos_config.cc:266
uint32_t default_forwarding_class_
Definition: qos_config.h:134
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: qos_config.cc:334
adjacency_iterator end(DBGraph *graph)
std::string ToString() const
Definition: qos_config.cc:35
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:138
IFMapTable * table()
Definition: ifmap_node.h:29
virtual bool Change(const DBRequest *req)
Definition: qos_config.cc:211
AgentQosIdForwardingClassMap vlan_priority_map_
Definition: qos_config.h:131
AgentQosConfigData * BuildData(IFMapNode *node)
Definition: qos_config.cc:371
std::pair< uint32_t, uint32_t > AgentQosIdForwardingClassPair
Definition: qos_config.h:31
virtual ~AgentQosConfig()
Definition: qos_config.cc:24
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
virtual bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: qos_config.cc:357
bool VerifyLinkToGlobalQosConfig(const Agent *agent, const AgentQosConfigData *data)
Definition: qos_config.cc:121
uint32_t id_
Definition: qos_config.h:116
std::pair< uint32_t, uint32_t > QosIdForwardingClassPair
Definition: qos_config.h:43
const DBGraph * GetGraph() const
void Remove(size_t index)
Definition: index_vector.h:78
Definition: db.h:24
uint32_t default_forwarding_class_
Definition: qos_config.h:121
virtual bool DBEntrySandesh(Sandesh *resp, std::string &name) const
Definition: qos_config.cc:41
void ReleaseIndex(AgentQosConfig *qc)
Definition: qos_config.cc:327
void InsertVhostQosConfig(const boost::uuids::uuid &uuid)
Definition: qos_config.h:206
Definition: agent.h:358
QosIdForwardingClassMap dscp_map_
Definition: qos_config.h:117
AgentQosIdForwardingClassMap mpls_exp_map_
Definition: qos_config.h:132
IndexVector< AgentQosConfig * > index_table_
Definition: qos_config.h:222
const std::string & fabric_interface_name() const
Definition: agent.h:1129
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
DBOperation oper
Definition: db_table.h:42
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
virtual bool OperDBResync(DBEntry *entry, const DBRequest *req)
Definition: qos_config.cc:316
boost::uuids::uuid uuid_
Definition: qos_config.h:114
const std::string & name() const
Definition: ifmap_node.h:48
std::string name_
Definition: qos_config.h:129
void HandleVhostQosConfig(const Agent *agent, const AgentQosConfigData *data, bool deleted)
Definition: qos_config.cc:137
void EraseFabricQosConfig(const boost::uuids::uuid &uuid)
Definition: qos_config.h:185
const boost::uuids::uuid GetActiveFabricQosConfig()
Definition: qos_config.h:193
IFMapNode * ifmap_node() const
Definition: oper_db.h:59
QosIdForwardingClassMap mpls_exp_map_
Definition: qos_config.h:119
void Delete()
Definition: db_entry.cc:131
virtual DBEntry * OperDBAdd(const DBRequest *req)
Definition: qos_config.cc:296
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
AgentQosConfigTable(Agent *agent, DB *db, const std::string &name)
Definition: qos_config.cc:272
std::string name() const
Definition: qos_config.h:77
const Agent * agent() const
Definition: oper_db.h:65
void AddQosConfigNode(IFMapNode *node)
void HandleFabricQosConfig(const Agent *agent, const AgentQosConfigData *data, bool deleted)
Definition: qos_config.cc:168
AgentQosConfigTable * qos_config_table() const
Definition: agent.h:554
virtual void Delete(const DBRequest *req)
Definition: qos_config.cc:257
boost::uuids::uuid uuid() const
Definition: qos_config.h:66
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
Definition: qos_config.cc:320
const boost::uuids::uuid GetActiveVhostQosConfig()
Definition: qos_config.h:210
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: qos_config.cc:406
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
Definition: qos_config.cc:311
std::map< uint32_t, uint32_t > AgentQosIdForwardingClassMap
Definition: qos_config.h:32
AgentConfig * cfg() const
Definition: agent.cc:865
static DBTableBase * CreateTable(Agent *agent, DB *db, const std::string &name)
Definition: qos_config.cc:282
std::string name_
Definition: qos_config.h:115
void InsertFabricQosConfig(const boost::uuids::uuid &uuid)
Definition: qos_config.h:189
virtual ~AgentQosConfigTable()
Definition: qos_config.cc:278
boost::uuids::uuid uuid_
Definition: qos_config.h:28
adjacency_iterator begin(DBGraph *graph)
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
Definition: qos_config.cc:289
void set_id(uint32_t id)
Definition: qos_config.h:70
bool HandleQosForwardingMapChange(const Agent *agent, QosIdForwardingClassMap &map, const AgentQosIdForwardingClassMap &data_map)
Definition: qos_config.cc:101
QosIdForwardingClassMap vlan_priority_map_
Definition: qos_config.h:118
AgentQosConfig::Type type_
Definition: qos_config.h:133
ResourceManager * resource_manager() const
Definition: agent.cc:1021
void set_agent(Agent *agent)
Definition: agent_db.h:212
size_t InsertAtIndex(uint32_t index, EntryType entry)
Definition: index_vector.h:54
std::pair< std::string, AgentQosConfig * > AgentQosConfigNamePair
Definition: qos_config.h:140
std::map< uint32_t, uint32_t > QosIdForwardingClassMap
Definition: qos_config.h:44