OpenSDN source code
forwarding_class_ksync.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 <base/logging.h>
7 #include <ksync/ksync_index.h>
8 #include <ksync/ksync_entry.h>
9 #include <ksync/ksync_object.h>
10 #include <ksync/ksync_netlink.h>
11 #include <ksync/ksync_sock.h>
13 #include <init/agent_param.h>
16 
19  KSyncNetlinkDBEntry(), ksync_obj_(obj), id_(fc->id()),
20  qos_queue_ksync_(NULL) {
21 }
22 
25  KSyncNetlinkDBEntry(), ksync_obj_(obj), id_(fc->id()),
26  qos_queue_ksync_(NULL) {
27 }
28 
30  ForwardingClassKSyncObject *obj, uint32_t id):
31  KSyncNetlinkDBEntry(), ksync_obj_(obj), id_(id),
32  qos_queue_ksync_(NULL) {
33 }
34 
36 }
37 
39  return ksync_obj_;
40 }
41 
43  const ForwardingClassKSyncEntry &entry = static_cast<const ForwardingClassKSyncEntry &>(rhs);
44  return id_ < entry.id_;
45 }
46 
48  std::stringstream s;
49  s << "Forwarding class id " << id_;
50  return s.str();
51 }
52 
54  ForwardingClass *fc = static_cast<ForwardingClass *>(e);
55 
56  bool ret = false;
57  if (dscp_ != fc->dscp()) {
58  dscp_ = fc->dscp();
59  ret = true;
60  }
61 
62  if (vlan_priority_ != fc->vlan_priority()) {
64  ret = true;
65  }
66 
67  if (mpls_exp_ != fc->mpls_exp()) {
68  mpls_exp_ = fc->mpls_exp();
69  ret = true;
70  }
71 
72  QosQueueKSyncObject *qos_queue_object =
73  (static_cast<QosQueueKSyncObject *>(ksync_obj_))->
74  ksync()->qos_queue_ksync_obj();
75 
76  KSyncEntry *qos_queue_ksync_ptr = NULL;
77  if (fc->qos_queue_ref()) {
78  QosQueueKSyncEntry qos_queue_ksync(qos_queue_object,
79  fc->qos_queue_ref());
80  qos_queue_ksync_ptr = qos_queue_object->GetReference(&qos_queue_ksync);
81  }
82 
83  if (qos_queue_ksync_ptr != qos_queue_ksync_) {
84  qos_queue_ksync_ = qos_queue_ksync_ptr;
85  ret = true;
86  }
87 
88  uint16_t nic_queue = Agent::kInvalidQueueId;
89  if (fc->qos_queue_ref()) {
90  nic_queue = fc->qos_queue_ref()->nic_queue_id();
91  } else {
92  nic_queue = (static_cast<QosQueueKSyncObject *>(ksync_obj_))->ksync()->
93  agent()->params()->default_nic_queue();
94  }
95 
96  if (nic_queue_id_ != nic_queue) {
97  nic_queue_id_ = nic_queue;
98  ret = true;
99  }
100 
101  return ret;
102 }
103 
104 int ForwardingClassKSyncEntry::Encode(sandesh_op::type op, char *buf, int buf_len) {
105  vr_fc_map_req encoder;
106  encoder.set_h_op(op);
107  encoder.set_fmr_rid(0);
108 
109  std::vector<int16_t> id_list;
110  id_list.push_back((int16_t)id_);
111  encoder.set_fmr_id(id_list);
112 
113  std::vector<int8_t> dscp_list;
114  dscp_list.push_back(dscp_);
115  encoder.set_fmr_dscp(dscp_list);
116 
117  std::vector<int8_t> vlan_priority_list;
118  vlan_priority_list.push_back(vlan_priority_);
119  encoder.set_fmr_dotonep(vlan_priority_list);
120 
121  std::vector<int8_t> mpls_exp_list;
122  mpls_exp_list.push_back(mpls_exp_);
123  encoder.set_fmr_mpls_qos(mpls_exp_list);
124 
125  std::vector<int8_t> qos_queue_list;
126  qos_queue_list.push_back(nic_queue_id_);
127  encoder.set_fmr_queue_id(qos_queue_list);
128 
129  int error = 0;
130  int encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
131  assert(error == 0);
132  assert(encode_len <= buf_len);
133  return encode_len;
134 }
135 
136 int ForwardingClassKSyncEntry::AddMsg(char *buf, int buf_len) {
137  return Encode(sandesh_op::ADD, buf, buf_len);
138 }
139 
140 int ForwardingClassKSyncEntry::ChangeMsg(char *buf, int buf_len) {
141  return Encode(sandesh_op::ADD, buf, buf_len);
142 }
143 
144 int ForwardingClassKSyncEntry::DeleteMsg(char *buf, int buf_len) {
145  return Encode(sandesh_op::DEL, buf, buf_len);
146 }
147 
149  if (qos_queue_ksync() && qos_queue_ksync()->IsResolved() == false) {
150  return qos_queue_ksync();
151  }
152 
153  return NULL;
154 }
155 
157  KSyncDBObject("KSync Forwarding class object"), ksync_(ksync) {
158 }
159 
161 
162 }
163 
166 }
167 
168 KSyncEntry*
170  const ForwardingClassKSyncEntry *entry =
171  static_cast<const ForwardingClassKSyncEntry *>(e);
172  ForwardingClassKSyncEntry *new_entry =
173  new ForwardingClassKSyncEntry(this, entry);
174  return static_cast<KSyncEntry *>(new_entry);
175 }
176 
178  const ForwardingClass *fc = static_cast<const ForwardingClass *>(e);
180  return static_cast<KSyncEntry *>(entry);
181 }
182 
183 void vr_fc_map_req::Process(SandeshContext *context) {
184  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
185  ioc->ForwardingClassMsgHandler(this);
186 }
187 
190  const KSyncDBEntry *ksync) {
191  const ForwardingClass *fc = static_cast<const ForwardingClass *>(entry);
192  if (ksync) {
193  const ForwardingClassKSyncEntry *ksync_entry =
194  static_cast<const ForwardingClassKSyncEntry *>(ksync);
195  if (fc->id() != ksync_entry->id()) {
196  return DBFilterDelAdd;
197  }
198  }
199  return DBFilterAccept;
200 }
virtual void ForwardingClassMsgHandler(vr_fc_map_req *req)=0
ForwardingClassTable * forwarding_class_table() const
Definition: agent.h:543
static const uint8_t kInvalidQueueId
Definition: agent.h:392
virtual int ChangeMsg(char *buf, int buf_len)
KSyncEntry * qos_queue_ksync() const
KSyncDBObject * GetObject() const
int Encode(sandesh_op::type op, char *buf, int buf_len)
virtual int AddMsg(char *buf, int buf_len)
virtual bool Sync(DBEntry *e)
virtual std::string ToString() const
virtual KSyncEntry * UnresolvedReference()
virtual int DeleteMsg(char *buf, int buf_len)
virtual bool IsLess(const KSyncEntry &rhs) const
ForwardingClassKSyncEntry(ForwardingClassKSyncObject *obj, const ForwardingClassKSyncEntry *entry)
virtual KSyncEntry * DBToKSyncEntry(const DBEntry *e)
virtual KSyncEntry * Alloc(const KSyncEntry *entry, uint32_t index)
virtual KSyncDBObject::DBFilterResp DBEntryFilter(const DBEntry *entry, const KSyncDBEntry *ksync)
const QosQueue * qos_queue_ref() const
uint32_t id() const
uint32_t vlan_priority() const
uint32_t mpls_exp() const
uint32_t dscp() const
void RegisterDb(DBTableBase *table)
bool IsResolved()
KSyncEntry * GetReference(const KSyncEntry *key)
Agent * agent() const
Definition: ksync_init.h:40
uint16_t nic_queue_id() const
Definition: qos_queue.h:75
uint8_t type
Definition: load_balance.h:2