Line data Source code
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 : *------------------------------------------------------------------
17 : * ioam_export.c - ioam export API / debug CLI handling
18 : *------------------------------------------------------------------
19 : */
20 :
21 : #include <vnet/vnet.h>
22 : #include <vnet/plugin/plugin.h>
23 : #include <ioam/export-common/ioam_export.h>
24 :
25 : #include <vlibapi/api.h>
26 : #include <vlibmemory/api.h>
27 : #include <vnet/ip/ip6_hop_by_hop.h>
28 : #include <vnet/format_fns.h>
29 :
30 : /* define message IDs */
31 : #include <ioam/export/ioam_export.api_enum.h>
32 : #include <ioam/export/ioam_export.api_types.h>
33 :
34 : #define REPLY_MSG_ID_BASE sm->msg_id_base
35 : #include <vlibapi/api_helper_macros.h>
36 :
37 : ioam_export_main_t ioam_export_main;
38 :
39 : extern vlib_node_registration_t export_node;
40 :
41 : /* Action function shared between message handler and debug CLI */
42 :
43 : int
44 0 : ioam_export_ip6_enable_disable (ioam_export_main_t * em,
45 : u8 is_disable,
46 : ip4_address_t * collector_address,
47 : ip4_address_t * src_address)
48 : {
49 0 : vlib_main_t *vm = em->vlib_main;
50 :
51 0 : if (is_disable == 0)
52 : {
53 0 : if (1 == ioam_export_header_create (em, collector_address, src_address))
54 : {
55 0 : ioam_export_thread_buffer_init (em, vm);
56 0 : ip6_hbh_set_next_override (em->my_hbh_slot);
57 : /* Turn on the export buffer check process */
58 0 : vlib_process_signal_event (vm, em->export_process_node_index, 1, 0);
59 :
60 : }
61 : else
62 : {
63 0 : return (-2);
64 : }
65 : }
66 : else
67 : {
68 0 : ip6_hbh_set_next_override (IP6_LOOKUP_NEXT_POP_HOP_BY_HOP);
69 0 : ioam_export_header_cleanup (em, collector_address, src_address);
70 0 : ioam_export_thread_buffer_free (em);
71 : /* Turn off the export buffer check process */
72 0 : vlib_process_signal_event (vm, em->export_process_node_index, 2, 0);
73 :
74 : }
75 :
76 0 : return 0;
77 : }
78 :
79 : /* API message handler */
80 0 : static void vl_api_ioam_export_ip6_enable_disable_t_handler
81 : (vl_api_ioam_export_ip6_enable_disable_t * mp)
82 : {
83 : vl_api_ioam_export_ip6_enable_disable_reply_t *rmp;
84 0 : ioam_export_main_t *sm = &ioam_export_main;
85 : int rv;
86 :
87 0 : rv = ioam_export_ip6_enable_disable (sm, (int) (mp->is_disable),
88 : (ip4_address_t *)
89 0 : mp->collector_address,
90 0 : (ip4_address_t *) mp->src_address);
91 :
92 0 : REPLY_MACRO (VL_API_IOAM_EXPORT_IP6_ENABLE_DISABLE_REPLY);
93 : }
94 :
95 : static clib_error_t *
96 0 : set_ioam_export_ipfix_command_fn (vlib_main_t * vm,
97 : unformat_input_t * input,
98 : vlib_cli_command_t * cmd)
99 : {
100 0 : ioam_export_main_t *em = &ioam_export_main;
101 : ip4_address_t collector, src;
102 0 : u8 is_disable = 0;
103 :
104 0 : collector.as_u32 = 0;
105 0 : src.as_u32 = 0;
106 :
107 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
108 : {
109 0 : if (unformat (input, "collector %U", unformat_ip4_address, &collector))
110 : ;
111 0 : else if (unformat (input, "src %U", unformat_ip4_address, &src))
112 : ;
113 0 : else if (unformat (input, "disable"))
114 0 : is_disable = 1;
115 : else
116 0 : break;
117 : }
118 :
119 0 : if (collector.as_u32 == 0)
120 0 : return clib_error_return (0, "collector address required");
121 :
122 0 : if (src.as_u32 == 0)
123 0 : return clib_error_return (0, "src address required");
124 :
125 0 : em->ipfix_collector.as_u32 = collector.as_u32;
126 0 : em->src_address.as_u32 = src.as_u32;
127 :
128 0 : vlib_cli_output (vm, "Collector %U, src address %U",
129 : format_ip4_address, &em->ipfix_collector,
130 : format_ip4_address, &em->src_address);
131 :
132 : /* Turn on the export timer process */
133 : // vlib_process_signal_event (vm, flow_report_process_node.index,
134 : //1, 0);
135 0 : ioam_export_ip6_enable_disable (em, is_disable, &collector, &src);
136 :
137 0 : return 0;
138 : }
139 :
140 : /* *INDENT-OFF* */
141 176567 : VLIB_CLI_COMMAND (set_ipfix_command, static) =
142 : {
143 : .path = "set ioam export ipfix",.short_help =
144 : "set ioam export ipfix collector <ip4-address> src <ip4-address>",.
145 : function = set_ioam_export_ipfix_command_fn,};
146 : /* *INDENT-ON* */
147 :
148 : #include <ioam/export/ioam_export.api.c>
149 : static clib_error_t *
150 559 : ioam_export_init (vlib_main_t * vm)
151 : {
152 559 : ioam_export_main_t *em = &ioam_export_main;
153 559 : u32 node_index = export_node.index;
154 559 : vlib_node_t *ip6_hbyh_node = NULL;
155 :
156 559 : em->vlib_main = vm;
157 559 : em->vnet_main = vnet_get_main ();
158 559 : em->set_id = IPFIX_IOAM_EXPORT_ID;
159 559 : ioam_export_reset_next_node (em);
160 :
161 : /* Ask for a correctly-sized block of API message decode slots */
162 559 : em->msg_id_base = setup_message_id_table ();
163 :
164 559 : em->unix_time_0 = (u32) time (0); /* Store starting time */
165 559 : em->vlib_time_0 = vlib_time_now (vm);
166 :
167 : /* Hook this export node to ip6-hop-by-hop */
168 559 : ip6_hbyh_node = vlib_get_node_by_name (vm, (u8 *) "ip6-hop-by-hop");
169 559 : em->my_hbh_slot = vlib_node_add_next (vm, ip6_hbyh_node->index, node_index);
170 :
171 559 : return 0;
172 : }
173 :
174 1679 : VLIB_INIT_FUNCTION (ioam_export_init);
175 :
176 : /*
177 : * fd.io coding-style-patch-verification: ON
178 : *
179 : * Local Variables:
180 : * eval: (c-set-style "gnu")
181 : * End:
182 : */
|