LCOV - code coverage report
Current view: top level - vnsw/agent/vrouter/ksync - forwarding_class_ksync.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 5 120 4.2 %
Date: 2026-11-09 02:10:49 Functions: 3 22 13.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14