FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
packet.h
Go to the documentation of this file.
1 #ifndef included_vnet_mpls_packet_h
2 #define included_vnet_mpls_packet_h
3 
4 /*
5  * MPLS packet format
6  *
7  * Copyright (c) 2012 Cisco and/or its affiliates.
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at:
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 /**
22  * A label value only, i.e. 20bits.
23  */
24 typedef u32 mpls_label_t;
25 
26 typedef struct {
27  /* Label: top 20 bits [in network byte order] */
28  /* Experimental: 3 bits ... */
29  /* S (bottom of label stack): 1 bit */
30  /* TTL: 8 bits */
33 
34 typedef enum mpls_eos_bit_t_
35 {
37  MPLS_EOS = 1,
39 
40 #define MPLS_EOS_BITS { \
41  [MPLS_NON_EOS] = "neos", \
42  [MPLS_EOS] = "eos", \
43 }
44 
45 #define FOR_EACH_MPLS_EOS_BIT(_eos) \
46  for (_eos = MPLS_NON_EOS; _eos <= MPLS_EOS; _eos++)
47 
48 #define MPLS_ENTRY_LABEL_OFFSET 0
49 #define MPLS_ENTRY_LABEL_SHIFT 12
50 #define MPLS_ENTRY_LABEL_MASK 0x000fffff
51 #define MPLS_ENTRY_LABEL_BITS \
52  (MPLS_ENTRY_LABEL_MASK << MPLS_ENTRY_LABEL_SHIFT)
53 
54 #define MPLS_ENTRY_EXP_OFFSET 2 /* byte offset to EXP bits */
55 #define MPLS_ENTRY_EXP_SHIFT 9
56 #define MPLS_ENTRY_EXP_MASK 0x07
57 #define MPLS_ENTRY_EXP(mpls) \
58  (((mpls)>>MPLS_ENTRY_EXP_SHIFT) & MPLS_ENTRY_EXP_MASK)
59 #define MPLS_ENTRY_EXP_BITS \
60  (MPLS_ENTRY_EXP_MASK << MPLS_ENTRY_EXP_SHIFT)
61 
62 #define MPLS_ENTRY_EOS_OFFSET 2 /* byte offset to EOS bit */
63 #define MPLS_ENTRY_EOS_SHIFT 8
64 #define MPLS_ENTRY_EOS_MASK 0x01 /* EOS bit in its byte */
65 #define MPLS_ENTRY_EOS(mpls) \
66  (((mpls) >> MPLS_ENTRY_EOS_SHIFT) & MPLS_ENTRY_EOS_MASK)
67 #define MPLS_ENTRY_EOS_BIT (MPLS_ENTRY_EOS_MASK << MPLS_ENTRY_EOS_SHIFT)
68 
69 #define MPLS_ENTRY_TTL_OFFSET 3 /* byte offset to ttl field */
70 #define MPLS_ENTRY_TTL_SHIFT 0
71 #define MPLS_ENTRY_TTL_MASK 0xff
72 #define MPLS_ENTRY_TTL(mpls) \
73  (((mpls) >> MPLS_ENTRY_TTL_SHIFT) & MPLS_ENTRY_TTL_MASK)
74 #define MPLS_ENTRY_TTL_BITS \
75  (MPLS_ENTRY_TTL_MASK << MPLS_ENTRY_TTL_SHIFT)
76 
77 static inline u32 vnet_mpls_uc_get_label (mpls_label_t label_exp_s_ttl)
78 {
79  return (label_exp_s_ttl>>MPLS_ENTRY_LABEL_SHIFT);
80 }
81 
82 static inline u32 vnet_mpls_uc_get_exp (mpls_label_t label_exp_s_ttl)
83 {
84  return (MPLS_ENTRY_EXP(label_exp_s_ttl));
85 }
86 
87 static inline u32 vnet_mpls_uc_get_s (mpls_label_t label_exp_s_ttl)
88 {
89  return (MPLS_ENTRY_EOS(label_exp_s_ttl));
90 }
91 
92 static inline u32 vnet_mpls_uc_get_ttl (mpls_label_t label_exp_s_ttl)
93 {
94  return (MPLS_ENTRY_TTL(label_exp_s_ttl));
95 }
96 
97 static inline void vnet_mpls_uc_set_label (mpls_label_t *label_exp_s_ttl,
98  u32 value)
99 {
100  *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_LABEL_BITS)) |
102 }
103 
104 static inline void vnet_mpls_uc_set_exp (mpls_label_t *label_exp_s_ttl,
105  u32 exp)
106 {
107  *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_EXP_BITS)) |
109 }
110 
111 static inline void vnet_mpls_uc_set_s (mpls_label_t *label_exp_s_ttl,
112  u32 eos)
113 {
114  *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_EOS_BIT)) |
116 }
117 
118 static inline void vnet_mpls_uc_set_ttl (mpls_label_t *label_exp_s_ttl,
119  u32 ttl)
120 {
121  *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_TTL_BITS)) |
122  ((ttl & MPLS_ENTRY_TTL_MASK)));
123 }
124 
125 #endif /* included_vnet_mpls_packet_h */
mpls_eos_bit_t_
Definition: packet.h:34
#define MPLS_ENTRY_LABEL_SHIFT
Definition: packet.h:49
#define MPLS_ENTRY_EOS_MASK
Definition: packet.h:64
#define MPLS_ENTRY_TTL_MASK
Definition: packet.h:71
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
#define MPLS_ENTRY_LABEL_BITS
Definition: packet.h:51
#define MPLS_ENTRY_EXP_MASK
Definition: packet.h:56
#define MPLS_ENTRY_EOS_SHIFT
Definition: packet.h:63
static u32 vnet_mpls_uc_get_ttl(mpls_label_t label_exp_s_ttl)
Definition: packet.h:92
static void vnet_mpls_uc_set_label(mpls_label_t *label_exp_s_ttl, u32 value)
Definition: packet.h:97
static void vnet_mpls_uc_set_exp(mpls_label_t *label_exp_s_ttl, u32 exp)
Definition: packet.h:104
#define MPLS_ENTRY_EOS_BIT
Definition: packet.h:67
static u32 vnet_mpls_uc_get_label(mpls_label_t label_exp_s_ttl)
Definition: packet.h:77
#define MPLS_ENTRY_LABEL_MASK
Definition: packet.h:50
#define MPLS_ENTRY_EXP_BITS
Definition: packet.h:59
#define MPLS_ENTRY_EOS(mpls)
Definition: packet.h:65
#define MPLS_ENTRY_TTL(mpls)
Definition: packet.h:72
unsigned int u32
Definition: types.h:88
mpls_label_t label_exp_s_ttl
Definition: packet.h:31
static void vnet_mpls_uc_set_s(mpls_label_t *label_exp_s_ttl, u32 eos)
Definition: packet.h:111
#define MPLS_ENTRY_EXP_SHIFT
Definition: packet.h:55
static u32 vnet_mpls_uc_get_s(mpls_label_t label_exp_s_ttl)
Definition: packet.h:87
static void vnet_mpls_uc_set_ttl(mpls_label_t *label_exp_s_ttl, u32 ttl)
Definition: packet.h:118
static u32 vnet_mpls_uc_get_exp(mpls_label_t label_exp_s_ttl)
Definition: packet.h:82
#define MPLS_ENTRY_EXP(mpls)
Definition: packet.h:57
#define MPLS_ENTRY_TTL_BITS
Definition: packet.h:74
enum mpls_eos_bit_t_ mpls_eos_bit_t