ec39a2e9042945c1e6dfe16e3ccd029764b2a435
[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_main_t *im = &ipsec_main;
42       ipsec_sa_t *sa;
43       u32 sa_index;
44
45       sa_index = ipsec_get_sa_index_by_sa_id (sa_id);
46       sa = pool_elt_at_index (im->sad, sa_index);
47
48       sa->seq = seq_num & 0xffffffff;
49       sa->seq_hi = seq_num >> 32;
50     }
51   else
52     {
53       return clib_error_return (0, "unknown SA `%U'",
54                                 format_unformat_error, input);
55     }
56
57   return (NULL);
58 }
59
60 /* *INDENT-OFF* */
61 VLIB_CLI_COMMAND (test_ipsec_command, static) =
62 {
63   .path = "test ipsec",
64   .short_help = "test ipsec sa <ID> seq-num <VALUE>",
65   .function = test_ipsec_command_fn,
66 };
67 /* *INDENT-ON* */
68
69 /*
70  * fd.io coding-style-patch-verification: ON
71  *
72  * Local Variables:
73  * eval: (c-set-style "gnu")
74  * End:
75  */