1/*
2 * Copyright (c) 2017 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 *------------------------------------------------------------------
17 * udp_ping_test.c - test harness for udp ping plugin
18 *------------------------------------------------------------------
19 */
20
21#include <vat/vat.h>
22#include <vlibapi/api.h>
23#include <vlibmemory/api.h>
24
25#include <vppinfra/error.h>
26#include <vnet/ip/ip.h>
27#include <vnet/format_fns.h>
28#include <vnet/ip/ip_types_api.h>
29
30#define __plugin_msg_base udp_ping_test_main.msg_id_base
31#include <vlibapi/vat_helper_macros.h>
32
33/* Declare message IDs */
34#include <ioam/udp-ping/udp_ping.api_enum.h>
35#include <ioam/udp-ping/udp_ping.api_types.h>
36
37typedef struct
38{
39  /* API message ID base */
40  u16 msg_id_base;
41  vat_main_t *vat_main;
42} udp_ping_test_main_t;
43
44udp_ping_test_main_t udp_ping_test_main;
45
46static int
47api_udp_ping_add_del (vat_main_t * vam)
48{
49  unformat_input_t *input = vam->input;
50  vl_api_udp_ping_add_del_t *mp;
51  int rv = 0;
52  ip46_address_t dst, src;
53  u32 start_src_port, end_src_port;
54  u32 start_dst_port, end_dst_port;
55  u32 interval;
56  u8 is_disable = 0;
57
58  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
59    {
60      if (unformat (input, "src %U", unformat_ip46_address, &src))
61	;
62      else if (unformat (input, "start-src-port %d", &start_src_port))
63	;
64      else if (unformat (input, "end-src-port %d", &end_src_port))
65	;
66      else if (unformat (input, "start-dst-port %d", &start_dst_port))
67	;
68      else if (unformat (input, "end-dst-port %d", &end_dst_port))
69	;
70      else if (unformat (input, "dst %U", unformat_ip46_address, &dst))
71	;
72      else if (unformat (input, "interval %d", &interval))
73	;
74      else if (unformat (input, "disable"))
75	is_disable = 1;
76      else
77	break;
78    }
79
80  M (UDP_PING_ADD_DEL, mp);
81
82  ip_address_encode (&src, IP46_TYPE_IP6, &mp->src_ip_address);
83  ip_address_encode (&dst, IP46_TYPE_IP6, &mp->dst_ip_address);
84  mp->start_src_port = (u16) start_src_port;
85  mp->end_src_port = (u16) end_src_port;
86  mp->start_dst_port = (u16) start_dst_port;
87  mp->end_dst_port = (u16) end_dst_port;
88  mp->interval = (u16) interval;
89  mp->dis = is_disable;
90
91  S (mp);
92  W (rv);
93
94  return (rv);
95}
96
97static int
98api_udp_ping_export (vat_main_t * vam)
99{
100  unformat_input_t *input = vam->input;
101  vl_api_udp_ping_export_t *mp;
102  int rv = 0;
103  int is_add = 1;
104
105  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
106    {
107      if (unformat (input, "export"))
108	is_add = 1;
109      else if (unformat (input, "disable"))
110	is_add = 0;
111      else
112	break;
113    }
114
115  M (UDP_PING_EXPORT, mp);
116
117  mp->enable = is_add;
118
119  S (mp);
120  W (rv);
121
122  return (rv);
123}
124
125/* Override generated plugin register symbol */
126#define vat_plugin_register udp_ping_vat_plugin_register
127#include <ioam/udp-ping/udp_ping.api_test.c>
128
129/*
130 * fd.io coding-style-patch-verification: ON
131 *
132 * Local Variables:
133 * eval: (c-set-style "gnu")
134 * End:
135 */
136