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