ipsec: move the IPSec SA pool out of ipsec_main
[vpp.git] / src / plugins / unittest / ipsec_test.c
1 /*
2  * Copyright (c) 2018 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/ipsec/ipsec.h>
17 #include <vnet/ipsec/ipsec_sa.h>
18
19 static clib_error_t *
20 test_ipsec_command_fn (vlib_main_t * vm,
21                        unformat_input_t * input, vlib_cli_command_t * cmd)
22 {
23   u64 seq_num;
24   u32 sa_id;
25
26   sa_id = ~0;
27   seq_num = 0;
28
29   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
30     {
31       if (unformat (input, "sa %d", &sa_id))
32         ;
33       else if (unformat (input, "seq 0x%llx", &seq_num))
34         ;
35       else
36         break;
37     }
38
39   if (~0 != sa_id)
40     {
41       ipsec_sa_t *sa;
42       u32 sa_index;
43
44       sa_index = ipsec_sa_find_and_lock (sa_id);
45       sa = ipsec_sa_get (sa_index);
46
47       sa->seq = seq_num & 0xffffffff;
48       sa->seq_hi = seq_num >> 32;
49
50       ipsec_sa_unlock (sa_index);
51     }
52   else
53     {
54       return clib_error_return (0, "unknown SA `%U'",
55                                 format_unformat_error, input);
56     }
57
58   return (NULL);
59 }
60
61 /* *INDENT-OFF* */
62 VLIB_CLI_COMMAND (test_ipsec_command, static) =
63 {
64   .path = "test ipsec",
65   .short_help = "test ipsec sa <ID> seq-num <VALUE>",
66   .function = test_ipsec_command_fn,
67 };
68 /* *INDENT-ON* */
69
70 /*
71  * fd.io coding-style-patch-verification: ON
72  *
73  * Local Variables:
74  * eval: (c-set-style "gnu")
75  * End:
76  */