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-24 02:06:43 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         229 : MplsKSyncEntry::MplsKSyncEntry(MplsKSyncObject* obj, const MplsKSyncEntry *me,
      16         229 :                                uint32_t index) :
      17         229 :     KSyncNetlinkDBEntry(index), ksync_obj_(obj), label_(me->label_),
      18         229 :     nh_(NULL)  {
      19         229 : }
      20             : 
      21         229 : MplsKSyncEntry::MplsKSyncEntry(MplsKSyncObject* obj, const MplsLabel *mpls) :
      22         229 :     KSyncNetlinkDBEntry(kInvalidIndex), ksync_obj_(obj),
      23         229 :     label_(mpls->label()), nh_(NULL) {
      24         229 : }
      25             : 
      26         916 : MplsKSyncEntry::~MplsKSyncEntry() {
      27         916 : }
      28             : 
      29        2579 : KSyncDBObject *MplsKSyncEntry::GetObject() const {
      30        2579 :     return ksync_obj_;
      31             : }
      32             : 
      33        4242 : bool MplsKSyncEntry::IsLess(const KSyncEntry &rhs) const {
      34        4242 :     const MplsKSyncEntry &entry = static_cast<const MplsKSyncEntry &>(rhs);
      35        4242 :     return label_ < entry.label_;
      36             : }
      37             : 
      38        1474 : std::string MplsKSyncEntry::ToString() const {
      39        1474 :     std::stringstream s;
      40        1474 :     NHKSyncEntry *next_hop = nh();
      41             : 
      42        1474 :     s << "Mpls : " << label_ << " Index : " << GetIndex();
      43        1474 :     if (next_hop) {
      44        1474 :         s << next_hop->ToString();
      45             :     } else {
      46           0 :         s << "NextHop :  NULL";
      47             :     }
      48        2948 :     return s.str();
      49        1474 : }
      50             : 
      51         309 : bool MplsKSyncEntry::Sync(DBEntry *e) {
      52         309 :     bool ret = false;
      53         309 :     const MplsLabel *mpls = static_cast<MplsLabel *>(e);
      54             : 
      55         309 :     NHKSyncObject *nh_object = ksync_obj_->ksync()->nh_ksync_obj();
      56         309 :     if (mpls->nexthop() == NULL) {
      57           0 :         LOG(DEBUG, "nexthop in mpls label is null");
      58           0 :         assert(0);
      59             :     }
      60         309 :     NHKSyncEntry next_hop(nh_object, mpls->nexthop());
      61         309 :     NHKSyncEntry *old_nh = nh();
      62             : 
      63         309 :     nh_ = nh_object->GetReference(&next_hop);
      64         309 :     if (old_nh != nh()) {
      65         309 :         ret = true;
      66             :     }
      67             : 
      68         309 :     return ret;
      69         309 : };
      70             : 
      71         538 : int MplsKSyncEntry::Encode(sandesh_op::type op, char *buf, int buf_len) {
      72         538 :     vr_mpls_req encoder;
      73             :     int encode_len;
      74         538 :     NHKSyncEntry *next_hop = nh();
      75             : 
      76         538 :     encoder.set_h_op(op);
      77         538 :     encoder.set_mr_label(label_);
      78         538 :     encoder.set_mr_rid(0);
      79         538 :     encoder.set_mr_nhid(next_hop->nh_id());
      80         538 :     int error = 0;
      81         538 :     encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
      82         538 :     assert(error == 0);
      83         538 :     assert(encode_len <= buf_len);
      84         538 :     return encode_len;
      85         538 : }
      86             : 
      87         538 : void MplsKSyncEntry::FillObjectLog(sandesh_op::type op,
      88             :                                    KSyncMplsInfo &info) const {
      89         538 :     info.set_label(label_);
      90         538 :     info.set_nh(nh()->nh_id());
      91             : 
      92         538 :     if (op == sandesh_op::ADD) {
      93         309 :         info.set_operation("ADD/CHANGE");
      94             :     } else {
      95         229 :         info.set_operation("DELETE");
      96             :     }
      97         538 : }
      98             : 
      99         229 : int MplsKSyncEntry::AddMsg(char *buf, int buf_len) {
     100         229 :     KSyncMplsInfo info;
     101         229 :     FillObjectLog(sandesh_op::ADD, info);
     102         229 :     KSYNC_TRACE(Mpls, GetObject(), info);
     103             : 
     104         458 :     return Encode(sandesh_op::ADD, buf, buf_len);
     105         229 : }
     106             : 
     107          80 : int MplsKSyncEntry::ChangeMsg(char *buf, int buf_len){
     108          80 :     KSyncMplsInfo info;
     109          80 :     FillObjectLog(sandesh_op::ADD, info);
     110          80 :     KSYNC_TRACE(Mpls, GetObject(), info);
     111             : 
     112         160 :     return Encode(sandesh_op::ADD, buf, buf_len);
     113          80 : }
     114             : 
     115         229 : int MplsKSyncEntry::DeleteMsg(char *buf, int buf_len) {
     116         229 :     KSyncMplsInfo info;
     117         229 :     FillObjectLog(sandesh_op::DEL, info);
     118         229 :     KSYNC_TRACE(Mpls, GetObject(), info);
     119             : 
     120         458 :     return Encode(sandesh_op::DEL, buf, buf_len);
     121         229 : }
     122             : 
     123         707 : KSyncEntry *MplsKSyncEntry::UnresolvedReference() {
     124         707 :     NHKSyncEntry *next_hop = nh();
     125         707 :     if (!next_hop->IsResolvedAndInSync()) {
     126         398 :         return next_hop;
     127             :     }
     128         309 :     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         229 : KSyncEntry *MplsKSyncObject::Alloc(const KSyncEntry *entry, uint32_t index) {
     143         229 :     const MplsKSyncEntry *mpls = static_cast<const MplsKSyncEntry *>(entry);
     144         229 :     MplsKSyncEntry *ksync = new MplsKSyncEntry(this, mpls, index);
     145         229 :     return static_cast<KSyncEntry *>(ksync);
     146             : };
     147             : 
     148         229 : KSyncEntry *MplsKSyncObject::DBToKSyncEntry(const DBEntry *e) {
     149         229 :     const MplsLabel *mpls = static_cast<const MplsLabel *>(e);
     150         229 :     MplsKSyncEntry *key = new MplsKSyncEntry(this, mpls);
     151         229 :     return static_cast<KSyncEntry *>(key);
     152             : }
     153             : 
     154         538 : void vr_mpls_req::Process(SandeshContext *context) {
     155         538 :     AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
     156         538 :     ioc->MplsMsgHandler(this);
     157         538 : }
     158             : 

Generated by: LCOV version 1.14