blob: 9f66e04d88e1011619dadb8ffa308c540bae126f [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 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 * counter.c: simple and packet/byte counters
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#include <vlib/vlib.h>
41
Dave Barach9b8ffd92016-07-08 08:13:45 -040042void
43vlib_clear_simple_counters (vlib_simple_counter_main_t * cm)
Ed Warnickecb9cada2015-12-08 15:45:58 -070044{
45 uword i, j;
Dave Barach9b8ffd92016-07-08 08:13:45 -040046 u16 *my_minis;
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
Dave Barach9b8ffd92016-07-08 08:13:45 -040048 for (i = 0; i < vec_len (cm->minis); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -070049 {
50 my_minis = cm->minis[i];
Dave Barach9b8ffd92016-07-08 08:13:45 -040051
Ed Warnickecb9cada2015-12-08 15:45:58 -070052 for (j = 0; j < vec_len (my_minis); j++)
Dave Barach9b8ffd92016-07-08 08:13:45 -040053 {
54 cm->maxi[j] += my_minis[j];
55 my_minis[j] = 0;
56 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070057 }
58
59 j = vec_len (cm->maxi);
60 if (j > 0)
61 vec_validate (cm->value_at_last_clear, j - 1);
62 for (i = 0; i < j; i++)
63 cm->value_at_last_clear[i] = cm->maxi[i];
64}
65
Dave Barach9b8ffd92016-07-08 08:13:45 -040066void
67vlib_clear_combined_counters (vlib_combined_counter_main_t * cm)
Ed Warnickecb9cada2015-12-08 15:45:58 -070068{
69 uword i, j;
Dave Barach9b8ffd92016-07-08 08:13:45 -040070 vlib_mini_counter_t *my_minis;
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
Dave Barach9b8ffd92016-07-08 08:13:45 -040072 for (i = 0; i < vec_len (cm->minis); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -070073 {
74 my_minis = cm->minis[i];
Dave Barach9b8ffd92016-07-08 08:13:45 -040075
Ed Warnickecb9cada2015-12-08 15:45:58 -070076 for (j = 0; j < vec_len (my_minis); j++)
Dave Barach9b8ffd92016-07-08 08:13:45 -040077 {
78 cm->maxi[j].packets += my_minis[j].packets;
79 cm->maxi[j].bytes += my_minis[j].bytes;
80 my_minis[j].packets = 0;
81 my_minis[j].bytes = 0;
82 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 }
84
85 j = vec_len (cm->maxi);
86 if (j > 0)
87 vec_validate (cm->value_at_last_clear, j - 1);
88
89 for (i = 0; i < j; i++)
90 {
Dave Barach9b8ffd92016-07-08 08:13:45 -040091 vlib_counter_t *c = vec_elt_at_index (cm->value_at_last_clear, i);
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
93 c[0] = cm->maxi[i];
94 }
95}
96
Dave Barach9b8ffd92016-07-08 08:13:45 -040097void
98vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
Damjan Marioncfb2d802016-02-06 00:54:12 +010099{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400100 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marioncfb2d802016-02-06 00:54:12 +0100101 int i;
102
103 vec_validate (cm->minis, tm->n_vlib_mains - 1);
104 for (i = 0; i < tm->n_vlib_mains; i++)
105 vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES);
106 vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES);
107}
108
Dave Barach9b8ffd92016-07-08 08:13:45 -0400109void
110vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index)
Damjan Marioncfb2d802016-02-06 00:54:12 +0100111{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400112 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marioncfb2d802016-02-06 00:54:12 +0100113 int i;
114
115 vec_validate (cm->minis, tm->n_vlib_mains - 1);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400116 for (i = 0; i < tm->n_vlib_mains; i++)
Damjan Marioncfb2d802016-02-06 00:54:12 +0100117 vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES);
118 vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES);
119}
120
Dave Barach9b8ffd92016-07-08 08:13:45 -0400121void
122serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123{
124 clib_warning ("unimplemented");
125}
126
Dave Barach9b8ffd92016-07-08 08:13:45 -0400127void
128unserialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129{
130 clib_warning ("unimplemented");
131}
132
Dave Barach9b8ffd92016-07-08 08:13:45 -0400133void
134serialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135{
136 clib_warning ("unimplemented");
137}
138
Dave Barach9b8ffd92016-07-08 08:13:45 -0400139void
140unserialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141{
142 clib_warning ("unimplemented");
143}
Dave Barach9b8ffd92016-07-08 08:13:45 -0400144
145/*
146 * fd.io coding-style-patch-verification: ON
147 *
148 * Local Variables:
149 * eval: (c-set-style "gnu")
150 * End:
151 */