LCOV - code coverage report
Current view: top level - vnsw/agent/vrouter/ksync - vxlan_ksync.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 93 104 89.4 %
Date: 2026-11-09 02:10:49 Functions: 20 21 95.2 %
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 <boost/asio.hpp>
       7             : #include <boost/bind/bind.hpp>
       8             : 
       9             : #include <base/logging.h>
      10             : #include <db/db_entry.h>
      11             : #include <db/db_table.h>
      12             : #include <db/db_table_partition.h>
      13             : #include <ksync/ksync_index.h>
      14             : #include <ksync/ksync_entry.h>
      15             : #include <ksync/ksync_object.h>
      16             : #include <ksync/ksync_netlink.h>
      17             : #include <ksync/ksync_sock.h>
      18             : 
      19             : #include "oper/interface_common.h"
      20             : #include "oper/nexthop.h"
      21             : #include "oper/vxlan.h"
      22             : #include "oper/mirror_table.h"
      23             : 
      24             : #include "vrouter/ksync/interface_ksync.h"
      25             : #include "vrouter/ksync/nexthop_ksync.h"
      26             : #include "vrouter/ksync/vxlan_ksync.h"
      27             : 
      28             : #include "ksync_init.h"
      29             : 
      30             : using namespace boost::placeholders;
      31             : 
      32          67 : VxLanIdKSyncEntry::VxLanIdKSyncEntry(VxLanKSyncObject *obj,
      33             :                                      const VxLanIdKSyncEntry *entry,
      34          67 :                                      uint32_t index) :
      35          67 :     KSyncNetlinkDBEntry(index), ksync_obj_(obj), label_(entry->label_),
      36          67 :     nh_(NULL) {
      37          67 : }
      38             : 
      39          67 : VxLanIdKSyncEntry::VxLanIdKSyncEntry(VxLanKSyncObject *obj,
      40          67 :                                      const VxLanId *vxlan_id) :
      41          67 :     KSyncNetlinkDBEntry(kInvalidIndex), ksync_obj_(obj),
      42          67 :     label_(vxlan_id->vxlan_id()), nh_(NULL) {
      43          67 : }
      44             : 
      45         268 : VxLanIdKSyncEntry::~VxLanIdKSyncEntry() {
      46         268 : }
      47             : 
      48         335 : KSyncDBObject *VxLanIdKSyncEntry::GetObject() const {
      49         335 :     return ksync_obj_;
      50             : }
      51             : 
      52         456 : bool VxLanIdKSyncEntry::IsLess(const KSyncEntry &rhs) const {
      53         456 :     const VxLanIdKSyncEntry &entry =
      54             :         static_cast<const VxLanIdKSyncEntry &>(rhs);
      55             : 
      56         456 :     return label_ < entry.label_;
      57             : }
      58             : 
      59         268 : std::string VxLanIdKSyncEntry::ToString() const {
      60         268 :     std::stringstream s;
      61         268 :     NHKSyncEntry *nexthop = nh();
      62             : 
      63         268 :     if (nexthop) {
      64         268 :         s << "VXLAN Label: " << label_ << " Index : "
      65         268 :             << GetIndex() << nexthop->ToString();
      66             :     } else {
      67           0 :         s << "VXLAN Label: " << label_ << " Index : "
      68           0 :             << GetIndex() << " NextHop : <null>";
      69             :     }
      70         536 :     return s.str();
      71         268 : }
      72             : 
      73          67 : bool VxLanIdKSyncEntry::Sync(DBEntry *e) {
      74          67 :     bool ret = false;
      75          67 :     const VxLanId *vxlan_id = static_cast<VxLanId *>(e);
      76             : 
      77          67 :     NHKSyncObject *nh_object = ksync_obj_->ksync()->nh_ksync_obj();
      78          67 :     if (vxlan_id->nexthop() == NULL) {
      79           0 :         LOG(DEBUG, "nexthop in network-id label is null");
      80           0 :         assert(0);
      81             :     }
      82          67 :     NHKSyncEntry nexthop(nh_object, vxlan_id->nexthop());
      83          67 :     NHKSyncEntry *old_nh = nh();
      84             : 
      85          67 :     nh_ = nh_object->GetReference(&nexthop);
      86          67 :     if (old_nh != nh()) {
      87          67 :         ret = true;
      88             :     }
      89             : 
      90          67 :     return ret;
      91          67 : };
      92             : 
      93         134 : int VxLanIdKSyncEntry::Encode(sandesh_op::type op, char *buf, int buf_len) {
      94         134 :     vr_vxlan_req encoder;
      95             :     int encode_len;
      96         134 :     NHKSyncEntry *nexthop = nh();
      97             : 
      98         134 :     encoder.set_h_op(op);
      99         134 :     encoder.set_vxlanr_rid(0);
     100         134 :     encoder.set_vxlanr_vnid(label_);
     101         134 :     encoder.set_vxlanr_nhid(nexthop->nh_id());
     102         134 :     int error = 0;
     103         134 :     encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
     104         134 :     assert(error == 0);
     105         134 :     assert(encode_len <= buf_len);
     106         134 :     return encode_len;
     107         134 : }
     108             : 
     109         134 : void VxLanIdKSyncEntry::FillObjectLog(sandesh_op::type op,
     110             :                                       KSyncVxLanInfo &info) const {
     111         134 :     info.set_label(label_);
     112         134 :     info.set_nh(nh()->nh_id());
     113             : 
     114         134 :     if (op == sandesh_op::ADD) {
     115          67 :         info.set_operation("ADD/CHANGE");
     116             :     } else {
     117          67 :         info.set_operation("DELETE");
     118             :     }
     119         134 : }
     120             : 
     121          67 : int VxLanIdKSyncEntry::AddMsg(char *buf, int buf_len) {
     122          67 :     KSyncVxLanInfo info;
     123          67 :     FillObjectLog(sandesh_op::ADD, info);
     124          67 :     KSYNC_TRACE(VxLan, GetObject(), info);
     125             : 
     126         134 :     return Encode(sandesh_op::ADD, buf, buf_len);
     127          67 : }
     128             : 
     129           0 : int VxLanIdKSyncEntry::ChangeMsg(char *buf, int buf_len) {
     130           0 :     KSyncVxLanInfo info;
     131           0 :     FillObjectLog(sandesh_op::ADD, info);
     132           0 :     KSYNC_TRACE(VxLan, GetObject(), info);
     133             : 
     134           0 :     return Encode(sandesh_op::ADD, buf, buf_len);
     135           0 : }
     136             : 
     137          67 : int VxLanIdKSyncEntry::DeleteMsg(char *buf, int buf_len) {
     138          67 :     KSyncVxLanInfo info;
     139          67 :     FillObjectLog(sandesh_op::DEL, info);
     140          67 :     KSYNC_TRACE(VxLan, GetObject(), info);
     141             : 
     142         134 :     return Encode(sandesh_op::DEL, buf, buf_len);
     143          67 : }
     144             : 
     145          67 : KSyncEntry *VxLanIdKSyncEntry::UnresolvedReference() {
     146          67 :     NHKSyncEntry *nexthop = nh();
     147          67 :     if (!nexthop->IsResolved()) {
     148           0 :         return nexthop;
     149             :     }
     150          67 :     return NULL;
     151             : }
     152             : 
     153           2 : VxLanKSyncObject::VxLanKSyncObject(KSync *ksync)
     154           2 :     : KSyncDBObject("KSync VxLan"), ksync_(ksync) {
     155           2 : }
     156             : 
     157           4 : VxLanKSyncObject::~VxLanKSyncObject() {
     158           4 : }
     159             : 
     160           2 : void VxLanKSyncObject::RegisterDBClients() {
     161           2 :     RegisterDb(ksync_->agent()->vxlan_table());
     162           2 : }
     163             : 
     164          67 : KSyncEntry *VxLanKSyncObject::Alloc(const KSyncEntry *entry, uint32_t index) {
     165          67 :     const VxLanIdKSyncEntry *vxlan =
     166             :         static_cast<const VxLanIdKSyncEntry *>(entry);
     167          67 :     VxLanIdKSyncEntry *ksync = new VxLanIdKSyncEntry(this, vxlan, index);
     168          67 :     return static_cast<KSyncEntry *>(ksync);
     169             : }
     170             : 
     171          67 : KSyncEntry *VxLanKSyncObject::DBToKSyncEntry(const DBEntry *e) {
     172          67 :     const VxLanId *vxlan = static_cast<const VxLanId *>(e);
     173          67 :     VxLanIdKSyncEntry *key = new VxLanIdKSyncEntry(this, vxlan);
     174          67 :     return static_cast<KSyncEntry *>(key);
     175             : }
     176             : 
     177         134 : void vr_vxlan_req::Process(SandeshContext *context) {
     178         134 :     AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
     179         134 :     ioc->VxLanMsgHandler(this);
     180         134 : }
     181             : 

Generated by: LCOV version 1.14