FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
police_inlines.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #ifndef __POLICE_INLINES_H__
16 #define __POLICE_INLINES_H__
17 
18 #include <vnet/policer/police.h>
19 #include <vnet/vnet.h>
20 #include <vnet/ip/ip.h>
21 
22 #define IP4_NON_DSCP_BITS 0x03
23 #define IP4_DSCP_SHIFT 2
24 #define IP6_NON_DSCP_BITS 0xf03fffff
25 #define IP6_DSCP_SHIFT 22
26 
29 {
31  ip4_header_t *ip4h;
32  ip6_header_t *ip6h;
33  u16 type;
34 
35  eh = (ethernet_header_t *) b->data;
36  type = clib_net_to_host_u16 (eh->type);
37 
38  if (PREDICT_TRUE (type == ETHERNET_TYPE_IP4))
39  {
40  ip4h = (ip4_header_t *) & (b->data[sizeof (ethernet_header_t)]);;
41  ip4h->tos &= IP4_NON_DSCP_BITS;
42  ip4h->tos |= dscp << IP4_DSCP_SHIFT;
43  ip4h->checksum = ip4_header_checksum (ip4h);
44  }
45  else
46  {
47  if (PREDICT_TRUE (type == ETHERNET_TYPE_IP6))
48  {
49  ip6h = (ip6_header_t *) & (b->data[sizeof (ethernet_header_t)]);
51  clib_host_to_net_u32 (IP6_NON_DSCP_BITS);
53  clib_host_to_net_u32 (dscp << IP6_DSCP_SHIFT);
54  }
55  }
56 }
57 
60  vlib_buffer_t * b,
61  u32 policer_index,
62  u64 time_in_policer_periods,
63  policer_result_e packet_color)
64 {
65  u8 act;
66  u32 len;
67  u32 col;
70 
71  len = vlib_buffer_length_in_chain (vm, b);
72  pol = &pm->policers[policer_index];
73  col = vnet_police_packet (pol, len, packet_color, time_in_policer_periods);
74  act = pol->action[col];
76  vnet_policer_mark (b, pol->mark_dscp[col]);
77 
78  return act;
79 }
80 
81 #endif // __POLICE_INLINES_H__
82 
83 /*
84  * fd.io coding-style-patch-verification: ON
85  *
86  * Local Variables:
87  * eval: (c-set-style "gnu")
88  * End:
89  */
#define PREDICT_TRUE(x)
Definition: clib.h:113
unsigned long u64
Definition: types.h:89
#define IP6_DSCP_SHIFT
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:366
unsigned char u8
Definition: types.h:56
vnet_policer_main_t vnet_policer_main
Definition: policer.c:19
static_always_inline void vnet_policer_mark(vlib_buffer_t *b, u8 dscp)
#define static_always_inline
Definition: clib.h:100
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
static policer_result_e vnet_police_packet(policer_read_response_type_st *policer, u32 packet_length, policer_result_e packet_color, u64 time)
Definition: police.h:90
unsigned short u16
Definition: types.h:57
policer_read_response_type_st * policers
Definition: policer.h:27
u8 len
Definition: ip_types.api:90
vlib_main_t * vm
Definition: buffer.c:323
u8 data[]
Packet data.
Definition: buffer.h:181
#define IP6_NON_DSCP_BITS
#define IP4_NON_DSCP_BITS
ip_dscp_t tos
Definition: ip4_packet.h:141
static_always_inline u8 vnet_policer_police(vlib_main_t *vm, vlib_buffer_t *b, u32 policer_index, u64 time_in_policer_periods, policer_result_e packet_color)
#define IP4_DSCP_SHIFT
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:370
VLIB buffer representation.
Definition: buffer.h:102
policer_result_e
Definition: police.h:18
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247