Line data Source code
1 : /*
2 : * Copyright (c) 2017 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 <vnet/ethernet/ethernet.h>
17 : #include <ioam/analyse/ioam_analyse.h>
18 : #include <ioam/export-common/ioam_export.h>
19 : #include <ioam/analyse/ip6/ip6_ioam_analyse.h>
20 : #include <ioam/analyse/ioam_summary_export.h>
21 : #include <vnet/ip/ip.h>
22 : #include <ioam/ipfixcollector/ipfixcollector.h>
23 :
24 : extern ioam_export_main_t ioam_export_main;
25 : static clib_error_t *
26 0 : ioam_analyse_enable_disable (vlib_main_t * vm,
27 : int is_add, int is_export, int remote_listen)
28 : {
29 : ipfix_client_add_del_t ipfix_reg;
30 0 : clib_error_t *rv = 0;
31 :
32 0 : ipfix_reg.client_name = format (0, "ip6-hbh-analyse-remote");
33 0 : ipfix_reg.client_node = analyse_node_remote.index;
34 0 : ipfix_reg.ipfix_setid = IPFIX_IOAM_EXPORT_ID;
35 :
36 0 : if (is_export)
37 : {
38 0 : rv = ioam_flow_create (!is_add);
39 0 : if (rv)
40 0 : goto ret;
41 : }
42 :
43 0 : if (is_add)
44 : {
45 0 : ip6_ioam_analyse_register_handlers ();
46 0 : if (remote_listen)
47 : {
48 0 : ipfix_reg.del = 0;
49 0 : ipfix_collector_reg_setid (vm, &ipfix_reg);
50 : }
51 : else
52 : {
53 0 : ioam_export_set_next_node (&ioam_export_main,
54 : (u8 *) "ip6-hbh-analyse-local");
55 : }
56 : }
57 : else
58 : {
59 0 : ip6_ioam_analyse_unregister_handlers ();
60 0 : if (remote_listen)
61 : {
62 0 : ipfix_reg.del = 1;
63 0 : ipfix_collector_reg_setid (vm, &ipfix_reg);
64 : }
65 : else
66 0 : ioam_export_reset_next_node (&ioam_export_main);
67 : }
68 :
69 0 : ret:
70 0 : vec_free (ipfix_reg.client_name);
71 0 : return rv;
72 : }
73 :
74 : static clib_error_t *
75 0 : set_ioam_analyse_command_fn (vlib_main_t * vm, unformat_input_t * input,
76 : vlib_cli_command_t * cmd)
77 : {
78 0 : int is_export = 0;
79 0 : int is_add = 1;
80 0 : int remote_listen = 0;
81 :
82 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
83 : {
84 0 : if (unformat (input, "export-ipfix-collector"))
85 0 : is_export = 1;
86 0 : else if (unformat (input, "disable"))
87 0 : is_add = 0;
88 0 : else if (unformat (input, "listen-ipfix"))
89 0 : remote_listen = 1;
90 : else
91 0 : break;
92 : }
93 :
94 0 : return (ioam_analyse_enable_disable (vm, is_add, is_export, remote_listen));
95 : }
96 :
97 : /* *INDENT-OFF* */
98 176567 : VLIB_CLI_COMMAND (set_ioam_analyse_command, static) = {
99 : .path = "set ioam analyse",
100 : .short_help = "set ioam analyse [export-ipfix-collector] [disable] [listen-ipfix]",
101 : .function = set_ioam_analyse_command_fn,
102 : };
103 : /* *INDENT-ON* */
104 :
105 : static clib_error_t *
106 0 : show_ioam_analyse_cmd_fn (vlib_main_t * vm, unformat_input_t * input,
107 : vlib_cli_command_t * cmd)
108 : {
109 0 : ip6_ioam_analyser_main_t *am = &ioam_analyser_main;
110 0 : ioam_analyser_data_t *record = NULL;
111 : u8 i;
112 0 : u8 *s = 0;
113 :
114 0 : vec_reset_length (s);
115 0 : s = format (0, "iOAM Analyse Information: \n");
116 0 : vec_foreach_index (i, am->aggregated_data)
117 : {
118 0 : record = am->aggregated_data + i;
119 0 : if (record->is_free)
120 0 : continue;
121 :
122 0 : s = format (s, "Flow Number: %u\n", i);
123 0 : s = print_analyse_flow (s, record);
124 0 : s = format (s, "\n");
125 : }
126 0 : vlib_cli_output (vm, "%v", s);
127 :
128 0 : vec_free (s);
129 :
130 0 : return 0;
131 : }
132 :
133 : /* *INDENT-OFF* */
134 176567 : VLIB_CLI_COMMAND (ip6_show_ioam_ipfix_cmd, static) = {
135 : .path = "show ioam analyse ",
136 : .short_help = "show ioam analyser information",
137 : .function = show_ioam_analyse_cmd_fn,
138 : };
139 : /* *INDENT-ON* */
140 :
141 : static clib_error_t *
142 559 : ioam_analyse_init (vlib_main_t * vm)
143 : {
144 559 : ip6_ioam_analyser_main_t *am = &ioam_analyser_main;
145 : u16 i;
146 :
147 559 : vec_validate_aligned (am->aggregated_data, 50, CLIB_CACHE_LINE_BYTES);
148 29068 : vec_foreach_index (i, am->aggregated_data)
149 : {
150 28509 : ioam_analyse_init_data (am->aggregated_data + i);
151 : }
152 :
153 559 : return 0;
154 : }
155 :
156 6159 : VLIB_INIT_FUNCTION (ioam_analyse_init);
157 :
158 : /*
159 : * fd.io coding-style-patch-verification: ON
160 : *
161 : * Local Variables:
162 : * eval: (c-set-style "gnu")
163 : * End:
164 : */
|