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

Generated by: LCOV version 1.14