FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
qos_mark.c
Go to the documentation of this file.
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/ip/ip.h>
17 #include <vnet/feature/feature.h>
19 #include <vnet/qos/qos_mark.h>
20 
21 /**
22  * per-interface vector of which MAP is used by which interface
23  * for each output source
24  */
26 
27 void
29 {
30  vnet_feature_enable_disable ("ip6-output", "ip6-qos-mark",
31  sw_if_index, enable, NULL, 0);
32  vnet_feature_enable_disable ("ip4-output", "ip4-qos-mark",
33  sw_if_index, enable, NULL, 0);
34 }
35 
36 void
38 {
39  /*
40  * one cannot run a feature on a sub-interface, so we need
41  * to enable a feature on all the L3 output paths
42  */
43  vnet_feature_enable_disable ("ip6-output", "vlan-ip6-qos-mark",
44  sw_if_index, enable, NULL, 0);
45  vnet_feature_enable_disable ("ip4-output", "vlan-ip4-qos-mark",
46  sw_if_index, enable, NULL, 0);
47  vnet_feature_enable_disable ("mpls-output", "vlan-mpls-qos-mark",
48  sw_if_index, enable, NULL, 0);
49 }
50 
51 void
53 {
54  vnet_feature_enable_disable ("mpls-output", "mpls-qos-mark",
55  sw_if_index, enable, NULL, 0);
56 }
57 
58 static void
60 {
61  switch (qs)
62  {
63  case QOS_SOURCE_EXT:
64  ASSERT (0);
65  break;
66  case QOS_SOURCE_VLAN:
67  qos_mark_vlan_enable_disable (sw_if_index, enable);
68  break;
69  case QOS_SOURCE_MPLS:
70  qos_mark_mpls_enable_disable (sw_if_index, enable);
71  break;
72  case QOS_SOURCE_IP:
73  qos_mark_ip_enable_disable (sw_if_index, enable);
74  break;
75  }
76 }
77 
78 int
80  qos_source_t output_source, qos_egress_map_id_t mid)
81 {
82  index_t qemi;
83 
85  sw_if_index, INDEX_INVALID);
86 
87  qemi = qos_egress_map_find (mid);
88 
89  if (INDEX_INVALID == qemi)
90  return VNET_API_ERROR_NO_SUCH_TABLE;
91 
92  if (INDEX_INVALID == qos_mark_configs[output_source][sw_if_index])
93  {
94  qos_egress_map_feature_config (sw_if_index, output_source, 1);
95  }
96 
97  qos_mark_configs[output_source][sw_if_index] = qemi;
98 
99  return (0);
100 }
101 
102 int
104 {
105  if (vec_len (qos_mark_configs[output_source]) <= sw_if_index)
106  return VNET_API_ERROR_NO_MATCHING_INTERFACE;
107  if (INDEX_INVALID == qos_mark_configs[output_source][sw_if_index])
108  return VNET_API_ERROR_VALUE_EXIST;
109 
110  if (INDEX_INVALID != qos_mark_configs[output_source][sw_if_index])
111  {
112  qos_egress_map_feature_config (sw_if_index, output_source, 0);
113  }
114 
115  qos_mark_configs[output_source][sw_if_index] = INDEX_INVALID;
116 
117  return (0);
118 }
119 
120 static clib_error_t *
122  unformat_input_t * input, vlib_cli_command_t * cmd)
123 {
124  qos_egress_map_id_t map_id;
125  u32 sw_if_index, qs;
126  vnet_main_t *vnm;
127  int rv, enable;
128 
129  vnm = vnet_get_main ();
130  map_id = ~0;
131  qs = 0xff;
132  enable = 1;
133 
135  {
136  if (unformat (input, "id %d", &map_id))
137  ;
138  else if (unformat (input, "disable"))
139  enable = 0;
140  else if (unformat (input, "%U", unformat_qos_source, &qs))
141  ;
142  else if (unformat (input, "%U",
143  unformat_vnet_sw_interface, vnm, &sw_if_index))
144  ;
145  else
146  break;
147  }
148 
149  if (~0 == sw_if_index)
150  return clib_error_return (0, "interface must be specified");
151  if (0xff == qs)
152  return clib_error_return (0, "output location must be specified");
153 
154  if (enable)
155  rv = qos_mark_enable (sw_if_index, qs, map_id);
156  else
157  rv = qos_mark_disable (sw_if_index, qs);
158 
159  if (0 == rv)
160  return (NULL);
161 
162  return clib_error_return (0, "Failed to map interface");
163 }
164 
165 /*?
166  * Apply a QoS egress mapping table to an interface for QoS marking packets
167  * at the given output protocol.
168  *
169  * @cliexpar
170  * @cliexcmd{qos egress interface GigEthernet0/9/0 id 0 output ip}
171  ?*/
172 /* *INDENT-OFF* */
173 VLIB_CLI_COMMAND (qos_egress_map_interface_command, static) = {
174  .path = "qos mark",
175  .short_help = "qos mark <SOURCE> <INTERFACE> id <MAP>",
176  .function = qos_mark_cli,
177  .is_mp_safe = 1,
178 };
179 /* *INDENT-ON* */
180 
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184 * Local Variables:
185 * eval: (c-set-style "gnu")
186 * End:
187 *
188 */
u32 sw_if_index
Definition: ipsec_gre.api:37
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
index_t qos_egress_map_find(qos_egress_map_id_t mid)
Get the VPP QoS map index from the user&#39;s map-ID.
#define NULL
Definition: clib.h:58
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
void qos_mark_vlan_enable_disable(u32 sw_if_index, u8 enable)
Definition: qos_mark.c:37
void qos_mark_ip_enable_disable(u32 sw_if_index, u8 enable)
Definition: qos_mark.c:28
unformat_function_t unformat_vnet_sw_interface
unsigned char u8
Definition: types.h:56
int qos_mark_disable(u32 sw_if_index, qos_source_t output_source)
Definition: qos_mark.c:103
Some external source, e.g.
Definition: qos_types.h:35
#define clib_error_return(e, args...)
Definition: error.h:99
int qos_mark_enable(u32 sw_if_index, qos_source_t output_source, qos_egress_map_id_t mid)
enable QoS marking by associating a MAP with an interface.
Definition: qos_mark.c:79
unsigned int u32
Definition: types.h:88
struct _unformat_input_t unformat_input_t
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:312
enum qos_source_t_ qos_source_t
QoS types.
static void qos_egress_map_feature_config(u32 sw_if_index, qos_source_t qs, u8 enable)
Definition: qos_mark.c:59
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
index_t * qos_mark_configs[QOS_N_SOURCES]
per-interface vector of which MAP is used by which interface for each output source ...
Definition: qos_mark.c:25
#define ASSERT(truth)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
static clib_error_t * qos_mark_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: qos_mark.c:121
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:486
void qos_mark_mpls_enable_disable(u32 sw_if_index, u8 enable)
Definition: qos_mark.c:52
uword unformat_qos_source(unformat_input_t *input, va_list *args)
Definition: qos_types.c:35
u32 qos_egress_map_id_t
A QOS egress map translates from the COS bits stored in the packet&#39;s meta-data into a per-protocol CO...
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:274
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
#define QOS_N_SOURCES
The maximum number of sources.
Definition: qos_types.h:45