OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qos_config_ksync.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <base/logging.h>
6 #include <ksync/ksync_index.h>
7 #include <ksync/ksync_entry.h>
8 #include <ksync/ksync_object.h>
9 #include <ksync/ksync_netlink.h>
10 #include <ksync/ksync_sock.h>
14 
17  KSyncNetlinkDBEntry(), ksync_obj_(obj), uuid_(qc->uuid()), id_(qc->id()) {
18 }
19 
21  const AgentQosConfig *qc):
22  KSyncNetlinkDBEntry(), ksync_obj_(obj), uuid_(qc->uuid()), id_(qc->id()) {
23 }
24 
26 }
27 
29  return ksync_obj_;
30 }
31 
32 bool QosConfigKSyncEntry::IsLess(const KSyncEntry &rhs) const {
33  const QosConfigKSyncEntry &entry = static_cast<const QosConfigKSyncEntry &>(rhs);
34  return uuid_ < entry.uuid_;
35 }
36 
37 std::string QosConfigKSyncEntry::ToString() const {
38  std::stringstream s;
39  s << "Qos Config class id " << uuid_;
40  return s.str();
41 }
42 
44  const AgentQosConfig::
45  QosIdForwardingClassMap *map) {
46 
47  bool ret = false;
48  ForwardingClassKSyncObject *fc_object =
50  ->ksync()->forwarding_class_ksync_obj();
51 
52  KSyncQosFcMap new_ksync_map;
53  AgentQosConfig::QosIdForwardingClassMap::const_iterator it = map->begin();
54  for (; it != map->end(); it++) {
55  KSyncEntryPtr ptr(NULL);
56  ForwardingClassKSyncEntry fc_key(fc_object, it->second);
57  ptr = fc_object->GetReference(&fc_key);
58  new_ksync_map.insert(KSyncQosFcPair(it->first, ptr));
59  }
60 
61  if (ksync_map != new_ksync_map) {
62  ksync_map = new_ksync_map;
63  ret = true;
64  }
65 
66  return ret;
67 }
68 
70  AgentQosConfig *qc = static_cast<AgentQosConfig *>(e);
71  bool ret = false;
72 
73 
74  if (CopyQosMap(dscp_map_, &(qc->dscp_map()))) {
75  ret = true;
76  }
77 
79  ret = true;
80  }
81 
82  if (CopyQosMap(mpls_exp_map_, &(qc->mpls_exp_map()))) {
83  ret = true;
84  }
85 
88  ret = true;
89  }
90 
91  return ret;
92 }
93 
94 int QosConfigKSyncEntry::Encode(sandesh_op::type op, char *buf, int buf_len) {
95  vr_qos_map_req encoder;
96 
97  encoder.set_h_op(op);
98  encoder.set_qmr_id(id_);
99  encoder.set_qmr_rid(0);
100 
101  std::vector<int8_t> key;
102  std::vector<int8_t> data;
103  KSyncQosFcMap::const_iterator it = dscp_map_.begin();
104  for (uint32_t index = 0;
105  index <= AgentQosConfigTable::kDscpEntries; index++) {
106  it = dscp_map_.find(index);
107  if (it != dscp_map_.end()) {
109  static_cast<ForwardingClassKSyncEntry *>(it->second.get());
110  key.push_back(index);
111  data.push_back(fc->id());
112  } else {
113  key.push_back(index);
114  data.push_back(default_forwarding_class_);
115  }
116  }
117 
118  encoder.set_qmr_dscp(key);
119  encoder.set_qmr_dscp_fc_id(data);
120 
121  std::vector<int8_t> vlan_key;
122  std::vector<int8_t> vlan_data;
123  it = vlan_priority_map_.begin();
124  for (uint32_t index = 0;
125  index <= AgentQosConfigTable::k801pEntries; index++) {
126  it = vlan_priority_map_.find(index);
127  if (it != vlan_priority_map_.end()) {
129  static_cast<ForwardingClassKSyncEntry *>(it->second.get());
130  vlan_key.push_back(index);
131  vlan_data.push_back(fc->id());
132  } else {
133  vlan_key.push_back(index);
134  vlan_data.push_back(default_forwarding_class_);
135  }
136  }
137  encoder.set_qmr_dotonep(vlan_key);
138  encoder.set_qmr_dotonep_fc_id(vlan_data);
139 
140  std::vector<int8_t> mpls_key;
141  std::vector<int8_t> mpls_data;
142  it = mpls_exp_map_.begin();
143  for (uint32_t index = 0;
144  index <= AgentQosConfigTable::kExpEntries; index++) {
145  it = mpls_exp_map_.find(index);
146  if (it != mpls_exp_map_.end()) {
148  static_cast<ForwardingClassKSyncEntry *>(it->second.get());
149  mpls_key.push_back(index);
150  mpls_data.push_back(fc->id());
151  } else {
152  mpls_key.push_back(index);
153  mpls_data.push_back(default_forwarding_class_);
154  }
155  }
156  encoder.set_qmr_mpls_qos(mpls_key);
157  encoder.set_qmr_mpls_qos_fc_id(mpls_data);
158 
159  int error = 0;
160  int encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
161  assert(error == 0);
162  assert(encode_len <= buf_len);
163  return encode_len;
164 }
165 
166 int QosConfigKSyncEntry::AddMsg(char *buf, int buf_len) {
167  return Encode(sandesh_op::ADD, buf, buf_len);
168 }
169 
170 int QosConfigKSyncEntry::ChangeMsg(char *buf, int buf_len) {
171  return Encode(sandesh_op::ADD, buf, buf_len);
172 }
173 
174 int QosConfigKSyncEntry::DeleteMsg(char *buf, int buf_len) {
175  return Encode(sandesh_op::DEL, buf, buf_len);
176 }
177 
179 
180  //QOS config has forwarding-class ID
181  //And qos-config may have a forwarding-class ID which
182  //is not present, in that case unresolved dependency
183  //would never resolve and all dependent object like
184  //VMI also would not be programmed. vrouter also
185  //doesnt cross check for forwarding-class
186  //Hence not checking for any forwarding class reference
187  return NULL;
188 
189  KSyncQosFcMap::const_iterator it = dscp_map_.begin();
190  for (; it != dscp_map_.end(); it++) {
191  if (it->second.get()->IsResolved() == false) {
192  return it->second.get();
193  }
194  }
195 
196  it = vlan_priority_map_.begin();
197  for (; it != vlan_priority_map_.end(); it++) {
198  if (it->second.get()->IsResolved() == false) {
199  return it->second.get();
200  }
201  }
202 
203  it = mpls_exp_map_.begin();
204  for (; it != mpls_exp_map_.end(); it++) {
205  if (it->second.get()->IsResolved() == false) {
206  return it->second.get();
207  }
208  }
209 
211  ForwardingClassKSyncObject *fc_object =
212  static_cast<ForwardingClassKSyncObject *>(ksync_obj_)
213  ->ksync()->forwarding_class_ksync_obj();
214  ForwardingClassKSyncEntry fc_key(fc_object,
216  KSyncEntryPtr ptr = fc_object->GetReference(&fc_key);
217  if (ptr && ptr->IsResolved() == false) {
218  return ptr.get();
219  }
220  }
221 
222  return NULL;
223 }
224 
226  KSyncDBObject("KSync Qos Config class object"), ksync_(ksync) {
227 }
228 
230 
231 }
232 
235 }
236 
237 KSyncEntry*
238 QosConfigKSyncObject::Alloc(const KSyncEntry *e, uint32_t index) {
239  const QosConfigKSyncEntry *entry =
240  static_cast<const QosConfigKSyncEntry *>(e);
241  QosConfigKSyncEntry *new_entry =
242  new QosConfigKSyncEntry(this, entry);
243  return static_cast<KSyncEntry *>(new_entry);
244 }
245 
247  const AgentQosConfig *qc = static_cast<const AgentQosConfig *>(e);
248  QosConfigKSyncEntry *entry = new QosConfigKSyncEntry(this, qc);
249  return static_cast<KSyncEntry *>(entry);
250 }
251 
252 void vr_qos_map_req::Process(SandeshContext *context) {
253  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
254  ioc->QosConfigMsgHandler(this);
255 }
const QosIdForwardingClassMap & dscp_map() const
Definition: qos_config.h:81
virtual bool Sync(DBEntry *e)
void RegisterDb(DBTableBase *table)
uint32_t default_forwarding_class() const
Definition: qos_config.h:97
KSyncQosFcMap vlan_priority_map_
Agent * agent() const
Definition: ksync_init.h:39
QosConfigKSyncEntry(QosConfigKSyncObject *obj, const QosConfigKSyncEntry *entry)
virtual KSyncEntry * DBToKSyncEntry(const DBEntry *e)
bool CopyQosMap(KSyncQosFcMap &ksync_map, const AgentQosConfig::QosIdForwardingClassMap *map)
KSyncQosFcMap dscp_map_
uint32_t default_forwarding_class_
boost::uuids::uuid uuid
const QosIdForwardingClassMap & mpls_exp_map() const
Definition: qos_config.h:89
virtual int ChangeMsg(char *buf, int buf_len)
boost::uuids::uuid uuid_
QosConfigKSyncObject(KSync *ksync)
static const uint32_t kDscpEntries
Definition: qos_config.h:145
uint8_t type
Definition: load_balance.h:109
int Encode(sandesh_op::type op, char *buf, int buf_len)
boost::intrusive_ptr< KSyncEntry > KSyncEntryPtr
Definition: ksync_entry.h:68
virtual KSyncEntry * Alloc(const KSyncEntry *entry, uint32_t index)
virtual ~QosConfigKSyncEntry()
KSyncEntry * GetReference(const KSyncEntry *key)
const QosIdForwardingClassMap & vlan_priority_map() const
Definition: qos_config.h:85
virtual bool IsLess(const KSyncEntry &rhs) const
virtual void QosConfigMsgHandler(vr_qos_map_req *req)=0
std::pair< uint32_t, KSyncEntryPtr > KSyncQosFcPair
static const uint32_t kExpEntries
Definition: qos_config.h:147
KSyncDBObject * GetObject() const
AgentQosConfigTable * qos_config_table() const
Definition: agent.h:554
KSyncQosFcMap mpls_exp_map_
virtual int AddMsg(char *buf, int buf_len)
virtual int DeleteMsg(char *buf, int buf_len)
static const uint32_t k801pEntries
Definition: qos_config.h:146
KSyncDBObject * ksync_obj_
virtual std::string ToString() const
std::map< uint32_t, KSyncEntryPtr > KSyncQosFcMap
virtual KSyncEntry * UnresolvedReference()