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