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

Generated by: LCOV version 1.14