FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
mod_vpp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gm_metric.h>
17 
18 #include <stdlib.h>
19 #include <strings.h>
20 #include <time.h>
21 #include <vppinfra/clib.h>
22 #include <vppinfra/vec.h>
23 #include <vppinfra/hash.h>
24 #include <svm/svmdb.h>
25 #include <errno.h>
26 
27 mmodule vpp_module;
29 
30 static int vpp_metric_init (apr_pool_t *p)
31 {
32  const char* str_params = vpp_module.module_params;
33  apr_array_header_t *list_params = vpp_module.module_params_list;
34  mmparam *params;
35  char *chroot_path = 0;
36  svmdb_map_args_t _ma, *ma= &_ma;
37  int i;
38 
39  if (str_params) {
40  clib_warning("[mod_vpp]Received string params: %s", str_params);
41  }
42  /* Multiple name/value pair parameters. */
43  if (list_params) {
44  clib_warning("[mod_vpp]Received following params list: ");
45  params = (mmparam*) list_params->elts;
46  for(i=0; i< list_params->nelts; i++) {
47  clib_warning("\tParam: %s = %s", params[i].name, params[i].value);
48  }
49  }
50 
51  memset (ma, 0, sizeof (*ma));
52  ma->root_path = (char *)chroot_path;
53 
54  svmdb_client = svmdb_map (ma);
55 
56 
57  /* Initialize the metadata storage for each of the metrics and then
58  * store one or more key/value pairs. The define MGROUPS defines
59  * the key for the grouping attribute. */
60  for (i = 0; vpp_module.metrics_info[i].name != NULL; i++) {
61  MMETRIC_INIT_METADATA(&(vpp_module.metrics_info[i]),p);
62  MMETRIC_ADD_METADATA(&(vpp_module.metrics_info[i]),MGROUP,"VPP");
63  }
64 
65  return 0;
66 }
67 
68 static void vpp_metric_cleanup (void)
69 {
71 }
72 
73 static g_val_t vpp_metric_handler (int metric_index)
74 {
75  g_val_t val;
76  pid_t *vpp_pidp;
77  f64 *vector_ratep, *vpp_rx_ratep, *sig_error_ratep;
78 
79  switch (metric_index) {
80  case 0:
81  vector_ratep = svmdb_local_get_vec_variable
82  (svmdb_client, "vpp_vector_rate", sizeof (*vector_ratep));
83  if (vector_ratep) {
84  val.d = *vector_ratep;
85  vec_free (vector_ratep);
86  }
87  else
88  val.d = 0.0;
89  break;
90  case 1:
92  (svmdb_client,
93  "vpp_pid", sizeof (*vpp_pidp));
94  if (vpp_pidp && *vpp_pidp) {
95  if (kill(*vpp_pidp, 0) == 0 || errno != ESRCH) {
96  val.d = 1.0;
97  } else {
98  val.d = 0.0;
99  }
100  vec_free (vpp_pidp);
101  } else
102  val.d = 0;
103  break;
104 
105  case 2:
106  vpp_rx_ratep = svmdb_local_get_vec_variable
107  (svmdb_client, "vpp_input_rate", sizeof (*vector_ratep));
108  if (vpp_rx_ratep) {
109  val.d = *vpp_rx_ratep;
110  vec_free (vpp_rx_ratep);
111  } else
112  val.d = 0.0;
113  break;
114 
115  case 3:
116  sig_error_ratep = svmdb_local_get_vec_variable
117  (svmdb_client, "vpp_sig_error_rate", sizeof (*vector_ratep));
118  if (sig_error_ratep) {
119  val.d = *sig_error_ratep;
120  vec_free (sig_error_ratep);
121  } else
122  val.d = 0.0;
123  break;
124 
125  default:
126  val.d = 0.0;
127  }
128 
129  return val;
130 }
131 
132 static Ganglia_25metric vpp_metric_info[] =
133 {
134  {0, "Vector_Rate", 100, GANGLIA_VALUE_DOUBLE, "Packets/Frame",
135  "both", "%.1f",
136  UDP_HEADER_SIZE+8, "VPP Vector Rate"},
137  {0, "VPP_State", 100, GANGLIA_VALUE_DOUBLE, "Run=1", "both", "%.0f",
138  UDP_HEADER_SIZE+8, "VPP State"},
139  {0, "Input_Rate", 100, GANGLIA_VALUE_DOUBLE, "5 sec RX rate",
140  "both", "%.1f",
141  UDP_HEADER_SIZE+8, "VPP Aggregate RX Rate"},
142  {0, "Sig_Error_Rate", 100, GANGLIA_VALUE_DOUBLE,
143  "5 sec significant error rate",
144  "both", "%.1f",
145  UDP_HEADER_SIZE+8, "VPP Significant Error Rate"},
146  {0, NULL}
147 };
148 
149 mmodule vpp_module =
150 {
151  STD_MMODULE_STUFF,
156 };
svmdb_map_args_t::root_path
const char * root_path
Definition: svmdb.h:86
svmdb_unmap
void svmdb_unmap(svmdb_client_t *client)
Definition: svmdb.c:138
svmdb_client_t
Definition: svmdb.h:65
name
string name[64]
Definition: fib.api:25
vpp_metric_handler
static g_val_t vpp_metric_handler(int metric_index)
Definition: mod_vpp.c:73
clib.h
vpp_metric_info
static Ganglia_25metric vpp_metric_info[]
Definition: mod_vpp.c:132
vpp_metric_cleanup
static void vpp_metric_cleanup(void)
Definition: mod_vpp.c:68
svmdb_client
static svmdb_client_t * svmdb_client
Definition: mod_vpp.c:28
time.h
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
f64
double f64
Definition: types.h:142
svmdb.h
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vpp_metric_init
static int vpp_metric_init(apr_pool_t *p)
Definition: mod_vpp.c:30
svmdb_map
svmdb_client_t * svmdb_map(svmdb_map_args_t *dba)
Definition: svmdb.c:70
svmdb_local_get_vec_variable
void * svmdb_local_get_vec_variable(svmdb_client_t *client, char *var, u32 elsize)
Definition: svmdb.c:578
vpp_module
mmodule vpp_module
Definition: mod_vpp.c:27
value
u8 value
Definition: qos.api:54
vec.h
hash.h
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
svmdb_map_args_t
Definition: svmdb.h:84