summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/vom/arp_proxy_config_cmds.hpp
blob: ac0e1fd170219678cef90bd015a5d6c7031c87a5 (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
/*
 * 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.
 */

#ifndef __VOM_ARP_PROXY_CONFIG_CMDS_H__
#define __VOM_ARP_PROXY_CONFIG_CMDS_H__

#include "vom/arp_proxy_config.hpp"
#include "vom/dump_cmd.hpp"
#include "vom/rpc_cmd.hpp"

#include <vapi/ip.api.vapi.hpp>

namespace VOM {
namespace arp_proxy_config_cmds {
/**
 * A command class that adds the ARP Proxy config
 */
class config_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::Proxy_arp_add_del>
{
public:
  /**
   * Constructor
   */
  config_cmd(HW::item<bool>& item,
             const boost::asio::ip::address_v4& lo,
             const boost::asio::ip::address_v4& high);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const config_cmd& i) const;

private:
  /**
   * Address range
   */
  const boost::asio::ip::address_v4 m_low;
  const boost::asio::ip::address_v4 m_high;
};

/**
 * A cmd class that Unconfigs ArpProxy Config from an interface
 */
class unconfig_cmd
  : public rpc_cmd<HW::item<bool>, rc_t, vapi::Proxy_arp_add_del>
{
public:
  /**
   * Constructor
   */
  unconfig_cmd(HW::item<bool>& item,
               const boost::asio::ip::address_v4& lo,
               const boost::asio::ip::address_v4& hig);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const unconfig_cmd& i)
/*
 * Copyright (c) 2016 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.
 */

#include "svm_fifo_segment.h"

clib_error_t 
"n">u8 *retrieved_data = 0; clib_error_t *error = 0; memset (a, 0, sizeof (*a)); a->segment_name = "fifo-test1"; a->segment_size = 256 << 10; a->rx_fifo_size = 4096; a->tx_fifo_size = 4096; a->preallocated_fifo_pairs = 4; rv = svm_fifo_segment_create (a); if (rv) return clib_error_return (0, "svm_fifo_segment_create returned %d", rv); sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]); f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST); if (f == 0) return clib_error_return (0, "svm_fifo_segment_alloc_fifo failed"); test_data = format (0, "Hello world%c", 0); vec_validate (retrieved_data, vec_len (test_data) - 1); while (svm_fifo_max_enqueue (f) >= vec_len (test_data)) svm_fifo_enqueue_nowait (f, vec_len (test_data), test_data); while (svm_fifo_max_dequeue (f) >= vec_len (test_data)) svm_fifo_dequeue_nowait (f, vec_len (retrieved_data), retrieved_data); while (svm_fifo_max_enqueue (f) >= vec_len (test_data)) svm_fifo_enqueue_nowait (f, vec_len (test_data), test_data); while (svm_fifo_max_dequeue (f) >= vec_len (test_data)) svm_fifo_dequeue_nowait (f, vec_len (retrieved_data), retrieved_data); if (!memcmp (retrieved_data, test_data, vec_len (test_data))) error = clib_error_return (0, "data test OK, got '%s'", retrieved_data); else error = clib_error_return (0, "data test FAIL!"); svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST); return error; } clib_error_t * master (int verbose) { svm_fifo_segment_create_args_t _a, *a = &_a; svm_fifo_segment_private_t *sp; svm_fifo_t *f; int rv; u8 *test_data; u8 *retrieved_data = 0; int i; memset (a, 0, sizeof (*a)); a->segment_name = "fifo-test1"; a->segment_size = 256 << 10; rv = svm_fifo_segment_create (a); if (rv) return clib_error_return (0, "svm_fifo_segment_create returned %d", rv); sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]); f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST); if (f == 0) return clib_error_return (0, "svm_fifo_segment_alloc_fifo failed"); test_data = format (0, "Hello world%c", 0); vec_validate (retrieved_data, vec_len (test_data) - 1); for (i = 0; i < 1000; i++) svm_fifo_enqueue_nowait (f, vec_len (test_data), test_data); return clib_error_return (0, "master (enqueue) done"); } clib_error_t * mempig (int verbose) { svm_fifo_segment_create_args_t _a, *a = &_a; svm_fifo_segment_private_t *sp; svm_fifo_t *f; svm_fifo_t **flist = 0; int rv; int i; memset (a, 0, sizeof (*a)); a->segment_name = "fifo-test1"; a->segment_size = 256 << 10; rv = svm_fifo_segment_create (a); if (rv) return clib_error_return (0, "svm_fifo_segment_create returned %d", rv); sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]); for (i = 0; i < 1000; i++) { f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST); if (f == 0) break; vec_add1 (flist, f); } fformat (stdout, "Try #1: created %d fifos...\n", vec_len (flist)); for (i = 0; i < vec_len (flist); i++) { f = flist[i]; svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST); } _vec_len (flist) = 0; for (i = 0; i < 1000; i++) { f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST); if (f == 0) break; vec_add1 (flist, f); } fformat (stdout, "Try #2: created %d fifos...\n", vec_len (flist)); for (i = 0; i < vec_len (flist); i++) { f = flist[i]; svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST); } return 0; } clib_error_t * offset (int verbose) { svm_fifo_segment_create_args_t _a, *a = &_a; svm_fifo_segment_private_t *sp; svm_fifo_t *f; int rv; u32 *test_data = 0; u32 *recovered_data = 0; int i; memset (a, 0, sizeof (*a)); a->segment_name = "fifo-test1"; a->segment_size = 256 << 10; rv = svm_fifo_segment_create (a); if (rv) return clib_error_return (0, "svm_fifo_segment_create returned %d", rv); sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]); f = svm_fifo_segment_alloc_fifo (sp, 200 << 10, FIFO_SEGMENT_RX_FREELIST); if (f == 0) return clib_error_return (0, "svm_fifo_segment_alloc_fifo failed"); for (i = 0; i < (3 * 1024); i++) vec_add1 (test_data, i); /* Enqueue the first 1024 u32's */ svm_fifo_enqueue_nowait (f, 4096 /* bytes to enqueue */ , (u8 *) test_data); /* Enqueue the third 1024 u32's 2048 ahead of the current tail */ svm_fifo_enqueue_with_offset (f, 4096, 4096, (u8 *) & test_data[2048]); /* Enqueue the second 1024 u32's at the current tail */ svm_fifo_enqueue_nowait (f, 4096 /* bytes to enqueue */ , (u8 *) & test_data[1024]); vec_validate (recovered_data, (3 * 1024) - 1); svm_fifo_dequeue_nowait (f, 3 * 4096, (u8 *) recovered_data); for (i = 0; i < (3 * 1024); i++) { if (recovered_data[i] != test_data[i]) { clib_warning ("[%d] expected %d recovered %d", i, test_data[i], recovered_data[i]); return clib_error_return (0, "offset test FAILED"); } } return clib_error_return (0, "offset test OK"); } clib_error_t * slave (int verbose) { svm_fifo_segment_create_args_t _a, *a = &_a; svm_fifo_segment_private_t *sp; svm_fifo_t *f; ssvm_shared_header_t *sh; svm_fifo_segment_header_t *fsh; int rv; u8 *test_data; u8 *retrieved_data = 0; int i; memset (a, 0, sizeof (*a)); a->segment_name = "fifo-test1"; rv = svm_fifo_segment_attach (a); if (rv) return clib_error_return (0, "svm_fifo_segment_attach returned %d", rv); sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]); sh = sp->ssvm.sh; fsh = (svm_fifo_segment_header_t *) sh->opaque[0]; /* might wanna wait.. */ f = fsh->fifos; /* Lazy bastards united */ test_data = format (0, "Hello world%c", 0); vec_validate (retrieved_data, vec_len (test_data) - 1); for (i = 0; i < 1000; i++) { svm_fifo_dequeue_nowait (f, vec_len (retrieved_data), retrieved_data); if (memcmp (retrieved_data, test_data, vec_len (retrieved_data))) return clib_error_return (0, "retrieved data incorrect, '%s'", retrieved_data); } return clib_error_return (0, "slave (dequeue) done"); } int test_ssvm_fifo1 (unformat_input_t * input) { clib_error_t *error = 0; int verbose = 0; int test_id = 0; svm_fifo_segment_init (0x200000000ULL, 20); while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "verbose %d", &verbose)) ; else if (unformat (input, "verbose")) verbose = 1; else if (unformat (input, "master")) test_id = 1; else if (unformat (input, "slave")) test_id = 2; else if (unformat (input, "mempig")) test_id = 3; else if (unformat (input, "offset")) test_id = 4; else { error = clib_error_create ("unknown input `%U'\n", format_unformat_error, input); goto out; } } switch (test_id) { case 0: error = hello_world (verbose); break; case 1: error = master (verbose); break; case 2: error = slave (verbose); break; case 3: error = mempig (verbose); break; case 4: error = offset (verbose); break; default: error = clib_error_return (0, "test id %d unknown", test_id); break; } out: if (error) clib_error_report (error); return 0; } int main (int argc, char *argv[]) { unformat_input_t i; int r; unformat_init_command_line (&i, argv); r = test_ssvm_fifo1 (&i); unformat_free (&i); return r; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */