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