LCOV - code coverage report
Current view: top level - vnsw/agent/vrouter/ksync - mpls_ksync.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 99 102 97.1 %
Date: 2026-11-09 02:10:49 Functions: 21 21 100.0 %
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 <oper/nexthop.h>
       8             : #include <oper/mirror_table.h>
       9             : #include <ksync/ksync_index.h>
      10             : #include <vrouter/ksync/interface_ksync.h>
      11             : #include <vrouter/ksync/nexthop_ksync.h>
      12             : #include <vrouter/ksync/mpls_ksync.h>
      13             : #include <vrouter/ksync/ksync_init.h>
      14             : #include <ksync/ksync_sock.h>
      15             : 
      16        1027 : MplsKSyncEntry::MplsKSyncEntry(MplsKSyncObject* obj, const MplsKSyncEntry *me,
      17        1027 :                                uint32_t index) :
      18        1027 :     KSyncNetlinkDBEntry(index), ksync_obj_(obj), label_(me->label_),
      19        1027 :     nh_(NULL)  {
      20        1027 : }
      21             : 
      22        1027 : MplsKSyncEntry::MplsKSyncEntry(MplsKSyncObject* obj, const MplsLabel *mpls) :
      23        1027 :     KSyncNetlinkDBEntry(kInvalidIndex), ksync_obj_(obj),
      24        1027 :     label_(mpls->label()), nh_(NULL) {
      25        1027 : }
      26             : 
      27        4108 : MplsKSyncEntry::~MplsKSyncEntry() {
      28        4108 : }
      29             : 
      30       11478 : KSyncDBObject *MplsKSyncEntry::GetObject() const {
      31       11478 :     return ksync_obj_;
      32             : }
      33             : 
      34       26135 : bool MplsKSyncEntry::IsLess(const KSyncEntry &rhs) const {
      35       26135 :     const MplsKSyncEntry &entry = static_cast<const MplsKSyncEntry &>(rhs);
      36       26135 :     return label_ < entry.label_;
      37             : }
      38             : 
      39        6528 : std::string MplsKSyncEntry::ToString() const {
      40        6528 :     std::stringstream s;
      41        6528 :     NHKSyncEntry *next_hop = nh();
      42             : 
      43        6528 :     s << "Mpls : " << label_ << " Index : " << GetIndex();
      44        6528 :     if (next_hop) {
      45        6528 :         s << next_hop->ToString();
      46             :     } else {
      47           0 :         s << "NextHop :  NULL";
      48             :     }
      49       13056 :     return s.str();
      50        6528 : }
      51             : 
      52        1334 : bool MplsKSyncEntry::Sync(DBEntry *e) {
      53        1334 :     bool ret = false;
      54        1334 :     const MplsLabel *mpls = static_cast<MplsLabel *>(e);
      55             : 
      56        1334 :     NHKSyncObject *nh_object = ksync_obj_->ksync()->nh_ksync_obj();
      57        1334 :     if (mpls->nexthop() == NULL) {
      58           0 :         LOG(DEBUG, "nexthop in mpls label is null");
      59           0 :         assert(0);
      60             :     }
      61        1334 :     NHKSyncEntry next_hop(nh_object, mpls->nexthop());
      62        1334 :     NHKSyncEntry *old_nh = nh();
      63             : 
      64        1334 :     nh_ = nh_object->GetReference(&next_hop);
      65        1334 :     if (old_nh != nh()) {
      66        1334 :         ret = true;
      67             :     }
      68             : 
      69        1334 :     return ret;
      70        1334 : };
      71             : 
      72        2359 : int MplsKSyncEntry::Encode(sandesh_op::type op, char *buf, int buf_len) {
      73        2359 :     vr_mpls_req encoder;
      74             :     int encode_len;
      75        2359 :     NHKSyncEntry *next_hop = nh();
      76             : 
      77        2359 :     encoder.set_h_op(op);
      78        2359 :     encoder.set_mr_label(label_);
      79        2359 :     encoder.set_mr_rid(0);
      80        2359 :     encoder.set_mr_nhid(next_hop->nh_id());
      81        2359 :     int error = 0;
      82        2359 :     encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
      83        2359 :     assert(error == 0);
      84        2359 :     assert(encode_len <= buf_len);
      85        2359 :     return encode_len;
      86        2359 : }
      87             : 
      88        2359 : void MplsKSyncEntry::FillObjectLog(sandesh_op::type op,
      89             :                                    KSyncMplsInfo &info) const {
      90        2359 :     info.set_label(label_);
      91        2359 :     info.set_nh(nh()->nh_id());
      92             : 
      93        2359 :     if (op == sandesh_op::ADD) {
      94        1332 :         info.set_operation("ADD/CHANGE");
      95             :     } else {
      96        1027 :         info.set_operation("DELETE");
      97             :     }
      98        2359 : }
      99             : 
     100        1027 : int MplsKSyncEntry::AddMsg(char *buf, int buf_len) {
     101        1027 :     KSyncMplsInfo info;
     102        1027 :     FillObjectLog(sandesh_op::ADD, info);
     103        1027 :     KSYNC_TRACE(Mpls, GetObject(), info);
     104             : 
     105        2054 :     return Encode(sandesh_op::ADD, buf, buf_len);
     106        1027 : }
     107             : 
     108         305 : int MplsKSyncEntry::ChangeMsg(char *buf, int buf_len){
     109         305 :     KSyncMplsInfo info;
     110         305 :     FillObjectLog(sandesh_op::ADD, info);
     111         305 :     KSYNC_TRACE(Mpls, GetObject(), info);
     112             : 
     113         610 :     return Encode(sandesh_op::ADD, buf, buf_len);
     114         305 : }
     115             : 
     116        1027 : int MplsKSyncEntry::DeleteMsg(char *buf, int buf_len) {
     117        1027 :     KSyncMplsInfo info;
     118        1027 :     FillObjectLog(sandesh_op::DEL, info);
     119        1027 :     KSYNC_TRACE(Mpls, GetObject(), info);
     120             : 
     121        2054 :     return Encode(sandesh_op::DEL, buf, buf_len);
     122        1027 : }
     123             : 
     124        3142 : KSyncEntry *MplsKSyncEntry::UnresolvedReference() {
     125        3142 :     NHKSyncEntry *next_hop = nh();
     126        3142 :     if (!next_hop->IsResolvedAndInSync()) {
     127        1810 :         return next_hop;
     128             :     }
     129        1332 :     return NULL;
     130             : }
     131             : 
     132           2 : MplsKSyncObject::MplsKSyncObject(KSync *ksync) :
     133           2 :     KSyncDBObject("KSync Mpls"), ksync_(ksync) {
     134           2 : }
     135             : 
     136           4 : MplsKSyncObject::~MplsKSyncObject() {
     137           4 : }
     138             : 
     139           2 : void MplsKSyncObject::RegisterDBClients() {
     140           2 :     RegisterDb(ksync_->agent()->mpls_table());
     141           2 : }
     142             : 
     143        1027 : KSyncEntry *MplsKSyncObject::Alloc(const KSyncEntry *entry, uint32_t index) {
     144        1027 :     const MplsKSyncEntry *mpls = static_cast<const MplsKSyncEntry *>(entry);
     145        1027 :     MplsKSyncEntry *ksync = new MplsKSyncEntry(this, mpls, index);
     146        1027 :     return static_cast<KSyncEntry *>(ksync);
     147             : };
     148             : 
     149        1027 : KSyncEntry *MplsKSyncObject::DBToKSyncEntry(const DBEntry *e) {
     150        1027 :     const MplsLabel *mpls = static_cast<const MplsLabel *>(e);
     151        1027 :     MplsKSyncEntry *key = new MplsKSyncEntry(this, mpls);
     152        1027 :     return static_cast<KSyncEntry *>(key);
     153             : }
     154             : 
     155        2359 : void vr_mpls_req::Process(SandeshContext *context) {
     156        2359 :     AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
     157        2359 :     ioc->MplsMsgHandler(this);
     158        2359 : }
     159             : 

Generated by: LCOV version 1.14