Tests: Example duplicate code refactoring.
[vpp.git] / src / plugins / gbp / gbp_sclass.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 <plugins/gbp/gbp_sclass.h>
17 #include <vnet/l2/l2_input.h>
18 #include <vnet/l2/l2_output.h>
19
20 gbp_sclass_main_t gbp_sclass_main;
21
22 void
23 gbp_sclass_enable_l2 (u32 sw_if_index)
24 {
25   l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_GBP_SCLASS_2_ID, 1);
26   l2output_intf_bitmap_enable (sw_if_index, L2OUTPUT_FEAT_GBP_ID_2_SCLASS, 1);
27 }
28
29 void
30 gbp_sclass_disable_l2 (u32 sw_if_index)
31 {
32   l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_GBP_SCLASS_2_ID, 0);
33   l2output_intf_bitmap_enable (sw_if_index, L2OUTPUT_FEAT_GBP_ID_2_SCLASS, 0);
34 }
35
36 void
37 gbp_sclass_enable_ip (u32 sw_if_index)
38 {
39   vnet_feature_enable_disable ("ip4-unicast",
40                                "ip4-gbp-sclass-2-id", sw_if_index, 1, 0, 0);
41   vnet_feature_enable_disable ("ip6-unicast",
42                                "ip6-gbp-sclass-2-id", sw_if_index, 1, 0, 0);
43   vnet_feature_enable_disable ("ip4-output",
44                                "ip4-gbp-id-2-sclass", sw_if_index, 1, 0, 0);
45   vnet_feature_enable_disable ("ip6-output",
46                                "ip6-gbp-id-2-sclass", sw_if_index, 1, 0, 0);
47 }
48
49 void
50 gbp_sclass_disable_ip (u32 sw_if_index)
51 {
52   vnet_feature_enable_disable ("ip4-unicast",
53                                "ip4-gbp-sclass-2-id", sw_if_index, 0, 0, 0);
54   vnet_feature_enable_disable ("ip6-unicast",
55                                "ip6-gbp-sclass-2-id", sw_if_index, 0, 0, 0);
56   vnet_feature_enable_disable ("ip4-output",
57                                "ip4-gbp-id-2-sclass", sw_if_index, 0, 0, 0);
58   vnet_feature_enable_disable ("ip6-output",
59                                "ip6-gbp-id-2-sclass", sw_if_index, 0, 0, 0);
60 }
61
62 static clib_error_t *
63 gbp_sclass_init (vlib_main_t * vm)
64 {
65   gbp_sclass_main_t *glm = &gbp_sclass_main;
66   vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "l2-gbp-sclass-2-id");
67
68   /* Initialize the feature next-node indices */
69   feat_bitmap_init_next_nodes (vm,
70                                node->index,
71                                L2INPUT_N_FEAT,
72                                l2input_get_feat_names (),
73                                glm->gel_l2_input_feat_next);
74
75   node = vlib_get_node_by_name (vm, (u8 *) "l2-gbp-id-2-sclass");
76   feat_bitmap_init_next_nodes (vm,
77                                node->index,
78                                L2OUTPUT_N_FEAT,
79                                l2output_get_feat_names (),
80                                glm->gel_l2_output_feat_next);
81
82   return (NULL);
83 }
84
85 VLIB_INIT_FUNCTION (gbp_sclass_init);
86
87
88 /*
89  * fd.io coding-style-patch-verification: ON
90  *
91  * Local Variables:
92  * eval: (c-set-style "gnu")
93  * End:
94  */