summaryrefslogtreecommitdiffstats
path: root/src/vnet/srv6/sr_pt.h
blob: 7242f90b6b3bbcc78d82ada1fdab14d3e190de11 (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
/* SPDX-License-Identifier: Apache-2.0
 * Copyright(c) 2022 Cisco Systems, Inc.
 */

/**
 * @file
 * @brief SR Path Tracing data structures definitions
 *
 */

#ifndef included_vnet_sr_pt_h
#define included_vnet_sr_pt_h

/*PT error codes*/
#define SR_PT_ERR_NOENT		       -1 /* No such entry*/
#define SR_PT_ERR_EXIST		       -2 /* Entry exists */
#define SR_PT_ERR_IFACE_INVALID	       -3 /* IFACE invalid */
#define SR_PT_ERR_ID_INVALID	       -4 /* ID invalid */
#define SR_PT_ERR_LOAD_INVALID	       -5 /* LOAD invalid*/
#define SR_PT_ERR_TTS_TEMPLATE_INVALID -6 /* TTS Template invalid */

/*PT paramters max values*/
#define SR_PT_ID_MAX	       4095
#define SR_PT_LOAD_MAX	       15
#define SR_PT_TTS_TEMPLATE_MAX 3

/*PT TTS Templates*/
#define SR_PT_TTS_TEMPLATE_0	   0
#define SR_PT_TTS_TEMPLATE_1	   1
#define SR_PT_TTS_TEMPLATE_2	   2
#define SR_PT_TTS_TEMPLATE_3	   3
#define SR_PT_TTS_TEMPLATE_DEFAULT 2

/*PT TTS Template shift value*/
#define SR_PT_TTS_SHIFT_TEMPLATE_0 8
#define SR_PT_TTS_SHIFT_TEMPLATE_1 12
#define SR_PT_TTS_SHIFT_TEMPLATE_2 16
#define SR_PT_TTS_SHIFT_TEMPLATE_3 20

typedef struct
{
  u32 iface;	   /**< Interface */
  u16 id;	   /**< Interface ID */
  u8 ingress_load; /**< Interface Ingress Load */
  u8 egress_load;  /**< Interface Egress Load */
  u8 tts_template; /**< Interface TTS Template */
} sr_pt_iface_t;

/**
 * @brief Path Tracing main datastructure
 */
typedef struct
{
  /* Pool of pt_iface instances */
  sr_pt_iface_t *sr_pt_iface;

  /* Hash table for pt iface parameters */
  mhash_t sr_pt_iface_index_hash;

} sr_pt_main_t;

extern sr_pt_main_t sr_pt_main;
extern int sr_pt_add_iface (u32 iface, u16 id, u8 ingress_load, u8 egress_load,
			    u8 tts_template);
extern int sr_pt_del_iface (u32 iface);
extern void *sr_pt_find_iface (u32 iface);

#endif /* included_vnet_sr_pt_h */
ss="cm"> #2 n elements are added T buf[10]; initialize buf[0] .. buf[9]; fifo_add (f, buf, 10); #3 1 element is added, pointer is returned T * x; fifo_add2 (f, x); x->a = 10; x->b = 20; Elements are removed 1 at a time: T x; fifo_sub1 (f, x); fifo_free (f) frees fifo. */ void * _clib_fifo_resize (void *v_old, uword n_new_elts, uword elt_bytes) { void *v_new, *end, *head; uword n_old_elts, header_bytes; uword n_copy_bytes, n_zero_bytes; clib_fifo_header_t *f_new, *f_old; n_old_elts = clib_fifo_elts (v_old); n_new_elts += n_old_elts; if (n_new_elts < 32) n_new_elts = 32; else n_new_elts = max_pow2 (n_new_elts); header_bytes = vec_header_bytes (sizeof (clib_fifo_header_t)); v_new = clib_mem_alloc_no_fail (n_new_elts * elt_bytes + header_bytes); v_new += header_bytes; f_new = clib_fifo_header (v_new); f_new->head_index = 0; f_new->tail_index = n_old_elts; _vec_len (v_new) = n_new_elts; /* Copy old -> new. */ n_copy_bytes = n_old_elts * elt_bytes; if (n_copy_bytes > 0) { f_old = clib_fifo_header (v_old); end = v_old + _vec_len (v_old) * elt_bytes; head = v_old + f_old->head_index * elt_bytes; if (head + n_copy_bytes >= end) { uword n = end - head; clib_memcpy (v_new, head, n); clib_memcpy (v_new + n, v_old, n_copy_bytes - n); } else clib_memcpy (v_new, head, n_copy_bytes); } /* Zero empty space. */ n_zero_bytes = (n_new_elts - n_old_elts) * elt_bytes; memset (v_new + n_copy_bytes, 0, n_zero_bytes); clib_fifo_free (v_old); return v_new; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */