aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ioam/udp-ping/udp_ping_test.c
blob: 84b878cffa79ed17ed20d3473b18c6cc86c4afc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *------------------------------------------------------------------
 * udp_ping_test.c - test harness for udp ping plugin
 *------------------------------------------------------------------
 */

#include <vat/vat.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>

#include <vppinfra/error.h>
#include <vnet/ip/ip.h>
#include <vnet/format_fns.h>
#include <vnet/ip/ip_types_api.h>

#define __plugin_msg_base udp_ping_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>

/* Declare message IDs */
#include <ioam/udp-ping/udp_ping.api_enum.h>
#include <ioam/udp-ping/udp_ping.api_types.h>

typedef struct
{
  /* API message ID base */
  u16 msg_id_base;
  vat_main_t *vat_main;
} udp_ping_test_main_t;

udp_ping_test_main_t udp_ping_test_main;

static int
api_udp_ping_add_del (vat_main_t * vam)
{
  unformat_input_t *input = vam->input;
  vl_api_udp_ping_add_del_t *mp;
  int rv = 0;
  ip46_address_t dst, src;
  u32 start_src_port, end_src_port;
  u32 start_dst_port, end_dst_port;
  u32 interval;
  u8 is_disable = 0;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "src %U", unformat_ip46_address, &src))
	;
      else if (unformat (input, "start-src-port %d", &start_src_port))
	;
      else if (unformat (input, "end-src-port %d", &end_src_port))
	;
      else if (unformat (input, "start-dst-port %d", &start_dst_port))
	;
      else if (unformat (input, "end-dst-port %d", &end_dst_port))
	;
      else if (unformat (input, "dst %U", unformat_ip46_address, &dst))
	;
      else if (unformat (input, "interval %d", &interval))
	;
      else if (unformat (input, "disable"))
	is_disable = 1;
      else
	break;
    }

  M (UDP_PING_ADD_DEL, mp);

  ip_address_encode (&src, IP46_TYPE_IP6, &mp->src_ip_address);
  ip_address_encode (&dst, IP46_TYPE_IP6, &mp->dst_ip_address);
  mp->start_src_port = (u16) start_src_port;
  mp->end_src_port = (u16) end_src_port;
  mp->start_dst_port = (u16) start_dst_port;
  mp->end_dst_port = (u16) end_dst_port;
  mp->interval = (u16) interval;
  mp->dis = is_disable;

  S (mp);
  W (rv);

  return (rv);
}

static int
api_udp_ping_export (vat_main_t * vam)
{
  unformat_input_t *input = vam->input;
  vl_api_udp_ping_export_t *mp;
  int rv = 0;
  int is_add = 1;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "export"))
	is_add = 1;
      else if (unformat (input, "disable"))
	is_add = 0;
      else
	break;
    }

  M (UDP_PING_EXPORT, mp);

  mp->enable = is_add;

  S (mp);
  W (rv);

  return (rv);
}

/* Override generated plugin register symbol */
#define vat_plugin_register udp_ping_vat_plugin_register
#include <ioam/udp-ping/udp_ping.api_test.c>

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */