LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/sandesh/library/cpp - sandesh_uve.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 22 85 25.9 %
Date: 2026-11-09 02:10:49 Functions: 2 7 28.6 %
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             : //
       7             : // sandesh_uve.cc
       8             : //
       9             : // file to handle requests for Sending Sandesh UVEs
      10             : //
      11             : 
      12             : #include "sandesh_uve.h"
      13             : #include "../common/sandesh_uve_types.h"
      14             : #include "sandesh_session.h"
      15             : #include "sandesh_http.h"
      16             : #include "sandesh_client_sm.h"
      17             : 
      18             : using std::string;
      19             : using std::map;
      20             : 
      21             : SandeshUVETypeMaps::uve_global_map* SandeshUVETypeMaps::map_ = NULL;
      22             : int PullSandeshUVE = 0;
      23             : 
      24             : 
      25             : bool
      26          86 : SandeshUVETypeMaps::InitDerivedStats(
      27             :         const std::map<std::string, ds_conf_elem> &dsmap) {
      28          86 :     bool success = true;
      29             :     // For all (per UVE Struct) elements of the DerivedStats config,
      30             :     // call the InitDerivedStats functions on that UVE Struct's Cache
      31          86 :     for (map<string, ds_conf_elem>::const_iterator cit = dsmap.begin();
      32          86 :             cit != dsmap.end(); cit++) {
      33           0 :         uve_global_map::iterator it = map_->find(cit->first);
      34           0 :         if (it==map_->end()) {
      35           0 :             success = false;
      36             :         } else {
      37           0 :             if (!(it->second.second)->InitDerivedStats(cit->second))
      38           0 :                 success = false;
      39             :         }
      40             :     }
      41          86 :     return success;
      42             : }
      43             : 
      44             : uint32_t
      45           0 : SandeshUVETypeMaps::Clear(const std::string& proxy, int partition) {
      46           0 :     int count=0;
      47           0 :     for (uve_global_map::iterator it = map_->begin();
      48           0 :             it != map_->end(); it++) {
      49           0 :         uint32_t subcount = it->second.second->ClearUVEs(proxy, partition);
      50           0 :         if (subcount !=0) {
      51           0 :             SANDESH_LOG(INFO, __func__ << " for " << it->first << " partition " <<
      52             :                 partition << " proxy " << proxy << " cleared " <<
      53             :                 subcount);
      54           0 :             count += subcount;
      55             :         }
      56             :     }
      57           0 :     return count;
      58             : }
      59             : 
      60             : void
      61          93 : SandeshUVETypeMaps::SyncAllMaps(const map<string,uint32_t> & inpMap, bool periodic) {
      62             :     static uint64_t periodic_count = 0;
      63          93 :     if (periodic) periodic_count++;
      64          93 :     for (uve_global_map::iterator it = map_->begin();
      65         540 :             it != map_->end(); it++) {
      66         447 :         map<string,uint32_t>::const_iterator iit = inpMap.find(it->first);
      67         447 :         uint32_t cycle = 0;
      68         447 :         if (periodic) {
      69             :             uint64_t target_count =
      70          28 :                     (it->second.first * 1000) / SandeshClientSM::kTickInterval;
      71          34 :             if (target_count == 0) continue;
      72           7 :             if ((periodic_count % target_count) != 0) continue;
      73           1 :             cycle = (uint32_t) (periodic_count / target_count);
      74           1 :             assert(inpMap.size() == 0);
      75             :         }
      76         420 :         SandeshUVE::SendType stype = (periodic ? SandeshUVE::ST_PERIODIC : SandeshUVE::ST_SYNC);
      77         420 :         if (iit == inpMap.end()) {
      78         420 :             uint count = it->second.second->SyncUVE("", stype, 0, cycle, "");
      79         420 :             SANDESH_LOG(INFO, __func__ << " for " << it->first << ":" << stype <<
      80             :                 " period " << it->second.first << " cycle " << cycle <<
      81             :                 " without seqno , total = " << count);
      82             :         } else {
      83           0 :             uint count = it->second.second->SyncUVE("", stype, iit->second, cycle, "");
      84           0 :             SANDESH_LOG(INFO, __func__ << " for " << it->first << ":" << stype <<
      85             :                 " period " << it->second.first << " cycle " << cycle <<
      86             :                 " with seqno " << iit->second <<
      87             :                 ", total = " << count);
      88             :         }
      89             :     }
      90          93 : }
      91             : 
      92             : void
      93           0 : SandeshUVETypeMaps::SyncIntrospect(
      94             :        std::string tname, std::string table, std::string key) {
      95           0 :     const SandeshUVETypeMaps::uve_global_elem um = TypeMap(tname);
      96           0 :     um.second->SendUVE(table, key, "");
      97           0 : }
      98             : 
      99             : void
     100           0 : SandeshUVETypesReq::HandleRequest() const {
     101           0 :     std::vector<SandeshUVETypeInfo> stv;
     102             : 
     103             :     SandeshUVETypeMaps::uve_global_map::const_iterator it =
     104           0 :         SandeshUVETypeMaps::Begin();
     105           0 :     for(; it!= SandeshUVETypeMaps::End(); it++) {
     106           0 :         SandeshUVETypeInfo sti;
     107           0 :         sti.set_type_name(it->first);
     108           0 :         sti.set_seq_num(it->second.second->TypeSeq());
     109           0 :         sti.set_period(it->second.first);
     110           0 :         sti.set_dsconf(it->second.second->GetDSConf());
     111           0 :         sti.set_timeout(it->second.second->GetTimeout());
     112           0 :         stv.push_back(sti);
     113           0 :     }
     114           0 :     SandeshUVETypesResp *sur = new SandeshUVETypesResp();
     115           0 :     sur->set_type_info(stv);
     116           0 :     sur->set_context(context());
     117           0 :     sur->Response();
     118           0 : }
     119             : void
     120           0 : SandeshUVEDSConfReq::HandleRequest() const {
     121             :     const SandeshUVETypeMaps::uve_global_elem um =
     122           0 :         SandeshUVETypeMaps::TypeMap(get_tname());
     123             : 
     124           0 :     map<string,string> dsconf;
     125           0 :     bool success = false;
     126           0 :     if (um.second) {
     127           0 :         dsconf.insert(std::make_pair(get_dsattr(), get_dsconf()));
     128           0 :         success = um.second->InitDerivedStats(dsconf);
     129             :     }
     130           0 :     SandeshUVEDSConfResp *sur = new SandeshUVEDSConfResp();
     131           0 :     sur->set_success(success);
     132           0 :     if (success) sur->set_dsconf(um.second->GetDSConf());
     133           0 :     sur->set_context(context());
     134           0 :     sur->Response();
     135           0 : }
     136             : 
     137             : void
     138           0 : SandeshUVECacheReq::HandleRequest() const {
     139           0 :     uint32_t returned = 0;
     140             : 
     141           0 :     const SandeshUVETypeMaps::uve_global_elem um = SandeshUVETypeMaps::TypeMap(get_tname());
     142             : 
     143           0 :     if (um.second) {
     144           0 :         if (__isset.key) {
     145           0 :             returned = um.second->SendUVE("", get_key(), context());
     146             :         } else {
     147           0 :             returned += um.second->SyncUVE("", SandeshUVE::ST_INTROSPECT, 0, 0, context());
     148             :         }
     149             :     }
     150             : 
     151           0 :     SandeshUVECacheResp *sur = new SandeshUVECacheResp();
     152           0 :     sur->set_returned(returned);
     153           0 :     if (um.second) sur->set_period(um.first);
     154           0 :     sur->set_context(context());
     155           0 :     sur->Response();
     156           0 : }

Generated by: LCOV version 1.14