LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-analytics/contrail-collector - vizd_table_desc.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 107 139 77.0 %
Date: 2026-08-03 02:19:58 Functions: 2 2 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 "vizd_table_desc.h"
       6             : 
       7             : #include <boost/assign/list_of.hpp>
       8             : #include <analytics/viz_constants.h>
       9             : #include <database/gendb_constants.h>
      10             : 
      11             : std::vector<GenDb::NewCf> vizd_tables;
      12             : std::vector<GenDb::NewCf> vizd_stat_tables;
      13             : std::vector<GenDb::NewCf> vizd_session_tables;
      14             : SessionTypeMap session_msg2type_map;
      15             : 
      16         135 : void init_tables(std::vector<GenDb::NewCf>& table,
      17             :                 std::map<std::string, table_schema> schema) {
      18             : 
      19             :     GenDb::DbDataTypeVec flow_series_value_thrift = boost::assign::list_of
      20         135 :         (GenDb::DbDataType::Unsigned64Type)
      21         135 :         (GenDb::DbDataType::Unsigned64Type)
      22         135 :         (GenDb::DbDataType::Unsigned8Type)
      23         135 :         (GenDb::DbDataType::LexicalUUIDType)
      24         135 :         (GenDb::DbDataType::UTF8Type)
      25         135 :         (GenDb::DbDataType::UTF8Type)
      26         135 :         (GenDb::DbDataType::UTF8Type)
      27         135 :         (GenDb::DbDataType::Unsigned32Type)
      28         135 :         (GenDb::DbDataType::Unsigned32Type)
      29         135 :         (GenDb::DbDataType::Unsigned8Type)
      30         135 :         (GenDb::DbDataType::Unsigned16Type)
      31         135 :         (GenDb::DbDataType::Unsigned16Type)
      32         135 :         (GenDb::DbDataType::UTF8Type);
      33             : 
      34         135 :     for (std::map<std::string, table_schema>::const_iterator it = schema.begin();
      35         360 :          it != schema.end(); ++it) {
      36             : 
      37         225 :         GenDb::DbDataTypeVec key_types;
      38         225 :         GenDb::DbDataTypeVec clustering_columns;
      39         225 :         GenDb::DbDataTypeVec columns;
      40         225 :         GenDb::DbDataTypeVec values;
      41         225 :         GenDb::NewCf::ColumnMap cols;
      42         225 :         if (it->second.is_static) {
      43         450 :             for(size_t j = 0; j < it->second.columns.size(); j++) {
      44         405 :                 if (it->second.columns[j].key) {
      45          45 :                     key_types.push_back(it->second.columns[j].datatype);
      46             :                 } else {
      47         360 :                     cols[it->second.columns[j].name] =
      48             :                         static_cast<GenDb::DbDataType::type>(
      49         360 :                                 it->second.columns[j].datatype);
      50             :                 }
      51             :             }
      52          45 :             table.push_back(GenDb::NewCf(it->first,
      53             :                             key_types, cols));
      54             :         } else {
      55        3690 :             for(size_t j = 0; j < it->second.columns.size(); j++) {
      56        3510 :                 if(boost::starts_with(it->second.columns[j].name, "key")) {
      57         540 :                     key_types.push_back(it->second.columns[j].datatype);
      58        2970 :                 } else if (it->second.columns[j].name == "value") {
      59         180 :                     values.push_back(it->second.columns[j].datatype);
      60        2790 :                 } else if (it->second.columns[j].clustering) {
      61         450 :                     clustering_columns.push_back(it->second.columns[j].datatype);
      62             :                 } else {
      63        2340 :                     columns.push_back(it->second.columns[j].datatype);
      64             :                 }
      65             :             }
      66         180 :             table.push_back(GenDb::NewCf(it->first,
      67             :                         key_types, clustering_columns, columns, values));
      68             :         }
      69         225 :     }
      70         135 : }
      71             : 
      72          45 : void init_vizd_tables() {
      73             :     static bool init_done = false;
      74             : 
      75          45 :     if (init_done)
      76           0 :         return;
      77          45 :     init_done = true;
      78             : 
      79             : // usage of GenDb::_DbDataType_VALUES_TO_NAMES[GenDb::DbDataType::LexicalUUIDType])) didn't
      80             : // compile, hence using raw values
      81          45 :     init_tables(vizd_tables, g_viz_constants._VIZD_TABLE_SCHEMA);
      82             : 
      83          45 :     init_tables(vizd_stat_tables, g_viz_constants._VIZD_STAT_TABLE_SCHEMA);
      84             : 
      85          45 :     init_tables(vizd_session_tables, g_viz_constants._VIZD_SESSION_TABLE_SCHEMA);
      86             : 
      87             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
      88          45 :             SessionRecordFields::SESSION_IS_CLIENT_SESSION]] =
      89           0 :         SessionTypeInfo(SessionRecordFields::SESSION_IS_CLIENT_SESSION,
      90          90 :             GenDb::DbDataType::Unsigned8Type);
      91             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
      92          45 :             SessionRecordFields::SESSION_IS_SI]] =
      93           0 :         SessionTypeInfo(SessionRecordFields::SESSION_IS_SI,
      94          90 :             GenDb::DbDataType::Unsigned8Type);
      95             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
      96          45 :             SessionRecordFields::SESSION_PROTOCOL]] =
      97           0 :         SessionTypeInfo(SessionRecordFields::SESSION_PROTOCOL,
      98          90 :             GenDb::DbDataType::Unsigned16Type);
      99             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     100          45 :             SessionRecordFields::SESSION_SPORT]] =
     101           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SPORT,
     102          90 :             GenDb::DbDataType::Unsigned16Type);
     103             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     104          45 :             SessionRecordFields::SESSION_DEPLOYMENT]] =
     105           0 :         SessionTypeInfo(SessionRecordFields::SESSION_DEPLOYMENT,
     106          90 :             GenDb::DbDataType::UTF8Type);
     107             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     108          45 :             SessionRecordFields::SESSION_TIER]] =
     109           0 :         SessionTypeInfo(SessionRecordFields::SESSION_TIER,
     110          90 :             GenDb::DbDataType::UTF8Type);
     111             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     112          45 :             SessionRecordFields::SESSION_APPLICATION]] =
     113           0 :         SessionTypeInfo(SessionRecordFields::SESSION_APPLICATION,
     114          90 :             GenDb::DbDataType::UTF8Type);
     115             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     116          45 :             SessionRecordFields::SESSION_SITE]] =
     117           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SITE,
     118          90 :             GenDb::DbDataType::UTF8Type);
     119             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     120          45 :             SessionRecordFields::SESSION_LABELS]] =
     121           0 :         SessionTypeInfo(SessionRecordFields::SESSION_LABELS,
     122          90 :             GenDb::DbDataType::UTF8Type);
     123             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     124          45 :             SessionRecordFields::SESSION_CUSTOM_TAGS]] =
     125           0 :         SessionTypeInfo(SessionRecordFields::SESSION_CUSTOM_TAGS,
     126          90 :             GenDb::DbDataType::UTF8Type);
     127             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     128          45 :             SessionRecordFields::SESSION_REMOTE_DEPLOYMENT]] =
     129           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_DEPLOYMENT,
     130          90 :             GenDb::DbDataType::UTF8Type);
     131             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     132          45 :             SessionRecordFields::SESSION_REMOTE_TIER]] =
     133           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_TIER,
     134          90 :             GenDb::DbDataType::UTF8Type);
     135             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     136          45 :             SessionRecordFields::SESSION_REMOTE_APPLICATION]] =
     137           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_APPLICATION,
     138          90 :             GenDb::DbDataType::UTF8Type);
     139             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     140          45 :             SessionRecordFields::SESSION_REMOTE_SITE]] =
     141           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_SITE,
     142          90 :             GenDb::DbDataType::UTF8Type);
     143             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     144          45 :             SessionRecordFields::SESSION_REMOTE_LABELS]] =
     145           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_LABELS,
     146          90 :             GenDb::DbDataType::UTF8Type);
     147             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     148          45 :             SessionRecordFields::SESSION_REMOTE_CUSTOM_TAGS]] =
     149           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_CUSTOM_TAGS,
     150          90 :             GenDb::DbDataType::UTF8Type);
     151             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     152          45 :             SessionRecordFields::SESSION_SECURITY_POLICY_RULE]] =
     153           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SECURITY_POLICY_RULE,
     154          90 :             GenDb::DbDataType::UTF8Type);
     155             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     156          45 :             SessionRecordFields::SESSION_REMOTE_PREFIX]] =
     157           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_PREFIX,
     158          90 :             GenDb::DbDataType::UTF8Type);
     159             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     160          45 :             SessionRecordFields::SESSION_VMI]] =
     161           0 :         SessionTypeInfo(SessionRecordFields::SESSION_VMI,
     162          90 :             GenDb::DbDataType::AsciiType);
     163             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     164          45 :             SessionRecordFields::SESSION_IP]] =
     165           0 :         SessionTypeInfo(SessionRecordFields::SESSION_IP,
     166          90 :             GenDb::DbDataType::AsciiType);
     167             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     168          45 :             SessionRecordFields::SESSION_VROUTER_IP]] =
     169           0 :         SessionTypeInfo(SessionRecordFields::SESSION_VROUTER_IP,
     170          90 :             GenDb::DbDataType::InetType);
     171             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     172          45 :             SessionRecordFields::SESSION_VN]] =
     173           0 :         SessionTypeInfo(SessionRecordFields::SESSION_VN,
     174          90 :             GenDb::DbDataType::UTF8Type);
     175             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     176          45 :             SessionRecordFields::SESSION_REMOTE_VN]] =
     177           0 :         SessionTypeInfo(SessionRecordFields::SESSION_REMOTE_VN,
     178          90 :             GenDb::DbDataType::UTF8Type);
     179             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     180          45 :             SessionRecordFields::SESSION_SAMPLED_FORWARD_BYTES]] =
     181           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SAMPLED_FORWARD_BYTES,
     182          90 :             GenDb::DbDataType::Unsigned64Type);
     183             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     184          45 :             SessionRecordFields::SESSION_SAMPLED_FORWARD_PKTS]] =
     185           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SAMPLED_FORWARD_PKTS,
     186          90 :             GenDb::DbDataType::Unsigned64Type);
     187             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     188          45 :             SessionRecordFields::SESSION_SAMPLED_REVERSE_BYTES]] =
     189           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SAMPLED_REVERSE_BYTES,
     190          90 :             GenDb::DbDataType::Unsigned64Type);
     191             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     192          45 :             SessionRecordFields::SESSION_SAMPLED_REVERSE_PKTS]] =
     193           0 :         SessionTypeInfo(SessionRecordFields::SESSION_SAMPLED_REVERSE_PKTS,
     194          90 :             GenDb::DbDataType::Unsigned64Type);
     195             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     196          45 :             SessionRecordFields::SESSION_LOGGED_FORWARD_BYTES]] =
     197           0 :         SessionTypeInfo(SessionRecordFields::SESSION_LOGGED_FORWARD_BYTES,
     198          90 :             GenDb::DbDataType::Unsigned64Type);
     199             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     200          45 :             SessionRecordFields::SESSION_LOGGED_FORWARD_PKTS]] =
     201           0 :         SessionTypeInfo(SessionRecordFields::SESSION_LOGGED_FORWARD_PKTS,
     202          90 :             GenDb::DbDataType::Unsigned64Type);
     203             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     204          45 :             SessionRecordFields::SESSION_LOGGED_REVERSE_BYTES]] =
     205           0 :         SessionTypeInfo(SessionRecordFields::SESSION_LOGGED_REVERSE_BYTES,
     206          90 :             GenDb::DbDataType::Unsigned64Type);
     207             :     session_msg2type_map[g_viz_constants.SessionRecordNames[
     208          45 :             SessionRecordFields::SESSION_LOGGED_REVERSE_PKTS]] =
     209           0 :         SessionTypeInfo(SessionRecordFields::SESSION_LOGGED_REVERSE_PKTS,
     210          90 :             GenDb::DbDataType::Unsigned64Type);
     211             : }

Generated by: LCOV version 1.14