OpenSDN source code
forwarding_class.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <cmn/agent.h>
7 #include <oper_db.h>
8 #include <vnc_cfg_types.h>
9 #include <agent_types.h>
10 #include <oper_db.h>
11 #include <oper/config_manager.h>
12 #include <oper/agent_sandesh.h>
13 #include <qos_queue.h>
14 #include <forwarding_class.h>
16 #include <cfg/cfg_init.h>
17 
19  uuid_(uuid) {
20 }
21 
23 }
24 
27  return DBEntryBase::KeyPtr(key);
28 }
29 
30 std::string ForwardingClass::ToString() const {
31  std::ostringstream buffer;
32  buffer << uuid_;
33  buffer << "id : " << id_;
34  return buffer.str();
35 }
36 
37 bool ForwardingClass::DBEntrySandesh(Sandesh *sresp, std::string &name) const {
38  ForwardingClassSandeshResp *resp = static_cast<ForwardingClassSandeshResp *>(sresp);
39  ForwardingClassSandeshData data;
40  data.set_uuid(UuidToString(uuid_));
41  data.set_id(id_);
42  data.set_dscp(dscp_);
43  data.set_vlan_priority(vlan_priority_);
44  data.set_mpls_exp(mpls_exp_);
45  if (qos_queue_ref_.get()) {
46  data.set_qos_queue(qos_queue_ref_->id());
47  }
48  data.set_name(name_);
49 
50  std::vector<ForwardingClassSandeshData> &list =
51  const_cast<std::vector<ForwardingClassSandeshData>&>(resp->get_fc_list());
52  list.push_back(data);
53  return true;
54 }
55 
56 bool ForwardingClass::IsLess(const DBEntry &rhs) const {
57  const ForwardingClass &fc = static_cast<const ForwardingClass &>(rhs);
58  return (uuid_ < fc.uuid_);
59 }
60 
62  bool ret = false;
63  const ForwardingClassData *data =
64  static_cast<const ForwardingClassData *>(req->data.get());
65  const Agent *agent = data->agent();
66 
67  if (id_ != data->id_) {
68  id_ = data->id_;
69  ret = true;
70  }
71 
72  if (dscp_ != data->dscp_) {
73  dscp_ = data->dscp_;
74  ret = true;
75  }
76 
77  if (vlan_priority_ != data->vlan_priority_) {
79  ret = true;
80  }
81 
82  if (mpls_exp_ != data->mpls_exp_) {
83  mpls_exp_ = data->mpls_exp_;
84  ret = true;
85  }
86 
87  if (name_ != data->name_) {
88  name_ = data->name_;
89  ret = true;
90  }
91 
92  const QosQueueKey key(data->qos_queue_uuid_);
93  const QosQueue *queue = static_cast<const QosQueue *>(
94  agent->qos_queue_table()->FindActiveEntry(&key));
95  if (queue != qos_queue_ref_.get()) {
96  qos_queue_ref_ = queue;
97  ret = true;
98  }
99 
100  if (qos_queue_ref_.get()) {
101  if (nic_queue_id_ != qos_queue_ref_->nic_queue_id()) {
102  nic_queue_id_ = qos_queue_ref_->nic_queue_id();
103  ret = true;
104  }
105  }
106  return ret;
107 }
108 
110 }
111 
113  const ForwardingClassKey *fc_key =
114  static_cast<const ForwardingClassKey *>(key);
115  uuid_ = fc_key->uuid_;
116 }
117 
119  DB *db, const std::string &name):
120  AgentOperDBTable(db, name) {
121  set_agent(agent);
122 }
123 
125 }
126 
128 ForwardingClassTable::CreateTable(Agent *agent, DB *db, const std::string &name) {
129  ForwardingClassTable *fc_table = new ForwardingClassTable(agent, db, name);
130  (static_cast<DBTable *>(fc_table))->Init();
131  return fc_table;
132 }
133 
134 std::unique_ptr<DBEntry>
136  const ForwardingClassKey *key =
137  static_cast<const ForwardingClassKey *>(k);
138  ForwardingClass *fc = new ForwardingClass(key->uuid_);
139  return std::unique_ptr<DBEntry>(static_cast<DBEntry *>(fc));
140 }
141 
143  const ForwardingClassKey *key =
144  static_cast<const ForwardingClassKey *>(req->key.get());
145  ForwardingClass *fc = new ForwardingClass(key->uuid_);
146  fc->Change(req);
147  return static_cast<DBEntry *>(fc);
148 }
149 
151  ForwardingClass *fc = static_cast<ForwardingClass *>(entry);
152  return fc->Change(req);
153 }
154 
156  return OperDBOnChange(entry, req);
157 }
158 
160  return true;
161 }
162 
164  const boost::uuids::uuid &u) {
165  assert(!u.is_nil());
166  if ((req.oper == DBRequest::DB_ENTRY_DELETE) || node->IsDeleted()) {
167  req.key.reset(new ForwardingClassKey(u));
169  Enqueue(&req);
170  return false;
171  }
172 
174  return false;
175 }
176 
178  autogen::ForwardingClass *cfg =
179  static_cast <autogen::ForwardingClass *> (node->GetObject());
180  assert(cfg);
181  autogen::IdPermsType id_perms = cfg->id_perms();
182  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
183  return true;
184 }
185 
187  const boost::uuids::uuid &u) {
188  if (node->IsDeleted()) {
189  return false;
190  }
191 
193  req.key.reset(new ForwardingClassKey(u));
194  req.data.reset(BuildData(node));
195  Enqueue(&req);
196  return false;
197 }
198 
201  autogen::ForwardingClass *data =
202  static_cast<autogen::ForwardingClass *>(node->GetObject());
203  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
204 
205  boost::uuids::uuid qos_queue_uuid = boost::uuids::nil_uuid();
206  for (DBGraphVertex::adjacency_iterator iter = node->begin(table->GetGraph());
207  iter != node->end(table->GetGraph()); ++iter) {
208 
209  IFMapNode *adj_node = static_cast<IFMapNode *>(iter.operator->());
210  if (agent()->config_manager()->SkipNode(adj_node)) {
211  continue;
212  }
213 
214  if (adj_node->table() == agent()->cfg()->cfg_qos_queue_table()) {
215  autogen::QosQueue *qos_queue =
216  static_cast<autogen::QosQueue *>(adj_node->GetObject());
217  autogen::IdPermsType id_perms = qos_queue->id_perms();
218  CfgUuidSet(id_perms.uuid.uuid_mslong,
219  id_perms.uuid.uuid_lslong, qos_queue_uuid);
220  }
221  }
222 
223  ForwardingClassData *fc_data =
224  new ForwardingClassData(agent(), node, data->dscp(), data->vlan_priority(),
225  data->mpls_exp(), data->id(), qos_queue_uuid,
226  node->name());
227  return fc_data;
228 }
229 
232  const std::string &context) {
233  return AgentSandeshPtr(new ForwardingClassSandesh(context,
234  args->GetString("uuid"), args->GetString("id"),
235  args->GetString("name")));
236 }
237 
238 void ForwardingClassSandeshReq::HandleRequest() const {
239  AgentSandeshPtr sand(new ForwardingClassSandesh(context(), get_uuid(),
240  get_name(), get_id()));
241  sand->DoSandesh(sand);
242 }
243 
244 void AddForwardingClass::HandleRequest() const {
245  QosResponse *resp = new QosResponse();
246  resp->set_context(context());
247 
248  if (get_id() > 255 || get_dscp_value() > 63 || get_mpls_exp() > 7 ||
249  get_vlan_priority() > 7) {
250  resp->set_resp("Error");
251  resp->Response();
252  return;
253  }
254 
255  char str[50];
256  sprintf(str, "00000000-0000-0000-0000-00%010x", get_uuid());
257  boost::uuids::uuid u1 = StringToUuid(std::string(str));
258 
259  char str1[50];
260  sprintf(str1, "00000000-0000-0000-0000-00%010x", get_qos_queue_uuid());
261  boost::uuids::uuid u2 = StringToUuid(std::string(str1));
262 
264  DBRequest req;
266  req.key.reset(new ForwardingClassKey(u1));
267  req.data.reset(new ForwardingClassData(Agent::GetInstance(), NULL,
268  get_dscp_value(), get_vlan_priority(),
269  get_mpls_exp(), get_id(),
270  u2, get_name()));
271  table->Enqueue(&req);
272  resp->set_resp("Success");
273  resp->Response();
274 }
275 
276 void DeleteForwardingClass::HandleRequest() const {
277  QosResponse *resp = new QosResponse();
278  resp->set_context(context());
279 
280  char str[50];
281  sprintf(str, "00000000-0000-0000-0000-00%010x", get_uuid());
282  boost::uuids::uuid u1 = StringToUuid(std::string(str));
283 
285  DBRequest req;
287  req.key.reset(new ForwardingClassKey(u1));
288  req.data.reset(NULL);
289  table->Enqueue(&req);
290  resp->set_resp("Success");
291  resp->Response();
292 }
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:21
IFMapAgentTable * cfg_qos_queue_table() const
Definition: cfg_init.h:91
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
Agent * agent() const
Definition: agent_db.h:216
void set_agent(Agent *agent)
Definition: agent_db.h:215
std::string GetString(const std::string &key) const
Definition: agent.h:361
ConfigManager * config_manager() const
Definition: agent.cc:893
ForwardingClassTable * forwarding_class_table() const
Definition: agent.h:543
QosQueueTable * qos_queue_table() const
Definition: agent.h:565
AgentConfig * cfg() const
Definition: agent.cc:869
static Agent * GetInstance()
Definition: agent.h:439
void AddForwardingClassNode(IFMapNode *node)
bool SkipNode(IFMapNode *node)
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
adjacency_iterator end(DBGraph *graph)
adjacency_iterator begin(DBGraph *graph)
bool Enqueue(DBRequest *req)
Definition: db_table.cc:221
const std::string & name() const
Definition: db_table.h:111
Definition: db.h:25
virtual DBEntry * OperDBAdd(const DBRequest *req)
ForwardingClassData * BuildData(IFMapNode *node)
static DBTableBase * CreateTable(Agent *agent, DB *db, const std::string &name)
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
ForwardingClassTable(Agent *agent, DB *db, const std::string &name)
virtual bool OperDBResync(DBEntry *entry, const DBRequest *req)
virtual bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
std::string name_
boost::uuids::uuid uuid_
uint16_t nic_queue_id_
virtual void SetKey(const DBRequestKey *key)
virtual ~ForwardingClass()
virtual bool DBEntrySandesh(Sandesh *resp, std::string &name) const
KeyPtr GetDBRequestKey() const
virtual bool Change(const DBRequest *req)
QosQueueConstRef qos_queue_ref_
virtual bool IsLess(const DBEntry &rhs) const
std::string ToString() const
ForwardingClass(const boost::uuids::uuid &uuid)
uint32_t vlan_priority_
const DBGraph * GetGraph() const
IFMapTable * table()
Definition: ifmap_node.h:30
const std::string & name() const
Definition: ifmap_node.h:49
IFMapObject * GetObject()
Definition: ifmap_node.cc:64
static boost::uuids::uuid StringToUuid(const std::string &str)
Definition: string_util.h:146
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:139
const Agent * agent() const
Definition: oper_db.h:66
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
boost::uuids::uuid qos_queue_uuid_
boost::uuids::uuid uuid_
boost::uuids::uuid uuid