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

Generated by: LCOV version 1.14