summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/xy.h
blob: fb562161a629c7b8b07d4b024e33050dba8518ec (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
/* (X,Y) coordinates. */

/*
  Copyright (c) 2008 Eliot Dresselhaus

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef included_clib_xy_h
#define included_clib_xy_h

#include <vppinfra/types.h>

/* Basic definitions: coordinates and points. */
typedef double xy_float_t;
typedef __complex__ double xy_t;
typedef __complex__ int ixy_t;

typedef __complex__ char i8xy_t;
typedef __complex__ short i16xy_t;
typedef __complex__ int i32xy_t;

/* X/Y components of a point: can be used as either rvalue/lvalue. */
#define xy_x(x) __real__ (x)
#define xy_y(x) __imag__ (x)

/* Unit vectors in x/y directions. */
#define xy_x_unit_vector (1)
#define xy_y_unit_vector (1I)

#endif /* included_clib_xy_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
class="n">d in dump: _test.vapi.memif_delete(d.sw_if_index) dump = _test.vapi.memif_socket_filename_dump() for d in dump: if d.socket_id != 0: _test.vapi.memif_socket_filename_add_del( 0, d.socket_id, d.socket_filename) class VppSocketFilename(VppObject): def __init__(self, test, socket_id, socket_filename, add_default_folder=False): self._test = test self.socket_id = socket_id self.socket_filename = socket_filename # if True insert default socket folder before socket filename, # after adding vpp config self.add_default_folder = add_default_folder def add_vpp_config(self): rv = self._test.vapi.memif_socket_filename_add_del( 1, self.socket_id, self.socket_filename) if self.add_default_folder: self.socket_filename = "%s/%s" % (self._test.tempdir, self.socket_filename) return rv def remove_vpp_config(self): return self._test.vapi.memif_socket_filename_add_del( 0, self.socket_id, self.socket_filename) def query_vpp_config(self): return self._test.vapi.memif_socket_filename_dump() def object_id(self): return "socket-filename-%d-%s" % (self.socket_id, self.socket_filename) class VppMemif(VppObject): def __init__(self, test, role, mode, rx_queues=0, tx_queues=0, if_id=0, socket_id=0, secret="", ring_size=0, buffer_size=0, hw_addr=""): self._test = test self.role = role self.mode = mode self.rx_queues = rx_queues self.tx_queues = tx_queues self.if_id = if_id self.socket_id = socket_id self.secret = secret self.ring_size = ring_size self.buffer_size = buffer_size self.hw_addr = hw_addr self.sw_if_index = None self.ip_prefix = IPv4Network("192.168.%d.%d/24" % (self.if_id + 1, self.role + 1), strict=False) def add_vpp_config(self): rv = self._test.vapi.memif_create( role=self.role, mode=self.mode, rx_queues=self.rx_queues, tx_queues=self.tx_queues, id=self.if_id, socket_id=self.socket_id, secret=self.secret, ring_size=self.ring_size, buffer_size=self.buffer_size, hw_addr=self.hw_addr) try: self.sw_if_index = rv.sw_if_index except AttributeError: # rv doesn't have .sw_if_index attribute raise AttributeError("%s %s" % (self, rv)) return self.sw_if_index def admin_up(self): if self.sw_if_index: return self._test.vapi.sw_interface_set_flags( sw_if_index=self.sw_if_index, flags=1) def admin_down(self): if self.sw_if_index: return self._test.vapi.sw_interface_set_flags( sw_if_index=self.sw_if_index, flags=0) def wait_for_link_up(self, timeout, step=1): if not self.sw_if_index: return False while True: dump = self.query_vpp_config() f = VppEnum.vl_api_if_status_flags_t.IF_STATUS_API_FLAG_LINK_UP if dump.flags & f: return True self._test.sleep(step) timeout -= step if timeout <= 0: return False def config_ip4(self): return self._test.vapi.sw_interface_add_del_address( sw_if_index=self.sw_if_index, prefix=self.ip_prefix) def remove_vpp_config(self): self._test.vapi.memif_delete(self.sw_if_index) self.sw_if_index = None def query_vpp_config(self): if not self.sw_if_index: return None dump = self._test.vapi.memif_dump() return get_if_dump(dump, self.sw_if_index) def object_id(self): if self.sw_if_index: return "%d:%d:%d" % (self.role, self.if_id, self.sw_if_index) else: return "%d:%d:None" % (self.role, self.if_id)