FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pg.c
Go to the documentation of this file.
1 /*
2  * pg.c: packet generator mpls interface
3  *
4  * Copyright (c) 2012 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vnet/pg/pg.h>
20 #include <vnet/mpls/mpls.h>
21 
22 typedef struct {
25 
26 static inline void
28 {
29  pg_edit_init (&e->label, mpls_unicast_header_t, label_exp_s_ttl);
30 }
31 
32 uword
33 unformat_pg_mpls_header (unformat_input_t * input, va_list * args)
34 {
35  pg_stream_t * s = va_arg (*args, pg_stream_t *);
38  u32 group_index, error;
39 
40  h = pg_create_edit_group (s, sizeof (h[0]), sizeof (mpls_unicast_header_t),
41  &group_index);
43 
44  error = 1;
45  if (! unformat (input, "%U",
48  goto done;
49 
50  {
51  pg_node_t * pg_node = 0;
52  vlib_node_t * ip_lookup_node;
53 
54  ip_lookup_node = vlib_get_node_by_name (vm, (u8 *)"ip4-input");
55  ASSERT (ip_lookup_node);
56 
57  pg_node = pg_get_node (ip_lookup_node->index);
58 
59  if (pg_node && pg_node->unformat_edit
60  && unformat_user (input, pg_node->unformat_edit, s))
61  ;
62  }
63 
64  error = 0;
65  done:
66  if (error)
68  return error == 0;
69 }
70 
vlib.h
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_pg_mpls_header
uword unformat_pg_mpls_header(unformat_input_t *input, va_list *args)
Definition: pg.c:33
pg.h
unformat_mpls_label_net_byte_order
unformat_function_t unformat_mpls_label_net_byte_order
Definition: mpls.h:80
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
mpls_unicast_header_t
Definition: packet.h:28
mpls.h
unformat_input_t
struct _unformat_input_t unformat_input_t
h
h
Definition: flowhash_template.h:372
error
Definition: cJSON.c:88
pg_node_t
Definition: pg.h:324
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vlib_node_t::index
u32 index
Definition: node.h:269
pg_node_t::unformat_edit
unformat_function_t * unformat_edit
Definition: pg.h:327
uword
u64 uword
Definition: types.h:112
pg_get_node
static pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:381
pg_free_edit_group
static void pg_free_edit_group(pg_stream_t *s)
Definition: pg.h:292
unformat_pg_edit
uword unformat_pg_edit(unformat_input_t *input, va_list *args)
Definition: edit.c:106
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
pg_create_edit_group
static void * pg_create_edit_group(pg_stream_t *s, int n_edit_bytes, int n_packet_bytes, u32 *group_index)
Definition: pg.h:239
pg_mpls_header_t
Definition: pg.c:22
u32
unsigned int u32
Definition: types.h:88
pg_edit_init
#define pg_edit_init(e, type, field)
Definition: edit.h:116
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
pg_mpls_header_t::label
pg_edit_t label
Definition: pg.c:23
pg_edit_t
Definition: edit.h:64
pg_mpls_header_init
static void pg_mpls_header_init(pg_mpls_header_t *e)
Definition: pg.c:27
pg_stream_t
Definition: pg.h:96