blob: 6ff86e32f67918662fd3468986f836436844a2a2 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Neale Ranns1357f3b2016-10-16 12:01:42 -07002 * pg.c: packet generator mpls interface
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 *
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/gre/gre.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010021#include <vnet/mpls/mpls.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070022
23typedef struct {
24 pg_edit_t label;
25} pg_mpls_header_t;
26
27static inline void
28pg_mpls_header_init (pg_mpls_header_t * e)
29{
30 pg_edit_init (&e->label, mpls_unicast_header_t, label_exp_s_ttl);
31}
32
33uword
34unformat_pg_mpls_header (unformat_input_t * input, va_list * args)
35{
36 pg_stream_t * s = va_arg (*args, pg_stream_t *);
37 pg_mpls_header_t * h;
38 vlib_main_t * vm = vlib_get_main();
39 u32 group_index, error;
40
41 h = pg_create_edit_group (s, sizeof (h[0]), sizeof (mpls_unicast_header_t),
42 &group_index);
43 pg_mpls_header_init (h);
44
45 error = 1;
46 if (! unformat (input, "%U",
47 unformat_pg_edit,
48 unformat_mpls_label_net_byte_order, &h->label))
49 goto done;
50
51 {
52 pg_node_t * pg_node = 0;
53 vlib_node_t * ip_lookup_node;
54
55 ip_lookup_node = vlib_get_node_by_name (vm, (u8 *)"ip4-input");
56 ASSERT (ip_lookup_node);
57
58 pg_node = pg_get_node (ip_lookup_node->index);
59
60 if (pg_node && pg_node->unformat_edit
61 && unformat_user (input, pg_node->unformat_edit, s))
62 ;
63 }
64
65 error = 0;
66 done:
67 if (error)
68 pg_free_edit_group (s);
69 return error == 0;
70}
71