TEST: link-state up/down notifications on FIB forwarding
[vpp.git] / src / plugins / unittest / interface_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/vnet.h>
17
18 static clib_error_t *
19 test_interface_command_fn (vlib_main_t * vm,
20                            unformat_input_t * input, vlib_cli_command_t * cmd)
21 {
22   vnet_hw_interface_flags_t flags;
23   vnet_main_t *vnm;
24   u32 sw_if_index;
25
26   flags = VNET_HW_INTERFACE_FLAG_NONE;
27   sw_if_index = ~0;
28   vnm = vnet_get_main ();
29
30   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
31     {
32       if (unformat
33           (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
34         ;
35       else if (unformat (input, "up"))
36         flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
37       else if (unformat (input, "down"))
38         ;
39       else
40         break;
41     }
42
43   if (~0 != sw_if_index)
44     {
45       vnet_sw_interface_t *sw;
46
47       sw = vnet_get_sw_interface (vnm, sw_if_index);
48
49       vnet_hw_interface_set_flags (vnm, sw->hw_if_index, flags);
50     }
51   else
52     {
53       return clib_error_return (0, "unknown interface `%U'",
54                                 format_unformat_error, input);
55     }
56
57   return (NULL);
58 }
59
60 /* *INDENT-OFF* */
61 VLIB_CLI_COMMAND (test_interface_command, static) =
62 {
63   .path = "test interface link-state",
64   .short_help = "test interface link-state <interface> [up] [down]",
65   .function = test_interface_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  */