summaryrefslogtreecommitdiffstats
path: root/test/vpp_qos.py
blob: a7fa9e748aae32d07efe933acecd66dd78c1cead (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
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
  QoS

  object abstractions for representing QoS config VPP
"""

from vpp_object import VppObject


class VppQosRecord(VppObject):
    """ QoS Record(ing) configuration """

    def __init__(self, test, intf, source):
        self._test = test
        self.intf = intf
        self.source = source

    def add_vpp_config(self):
        self._test.vapi.qos_record_enable_disable(
            enable=1,
            record={'sw_if_index': self.intf.sw_if_index,
                    'input_source': self.source})
        self._test.registry.register(self, self._test.logger)
        return self

    def remove_vpp_config(self):
        self._test.vapi.qos_record_enable_disable(
            enable=0,
            record={'sw_if_index': self.intf.sw_if_index,
                    'input_source': self.source})

    def query_vpp_config(self):
        rs = self._test.vapi.qos_record_dump()

        for r in rs:
            if self.intf.sw_if_index == r.record.sw_if_index and \
               self.source == r.record.input_source:
                return True
        return False

    def object_id(self):
        return ("qos-record-%s-%d" % (self.intf, self.source))


class VppQosStore(VppObject):
    """ QoS Store(ing) configuration """

    def __init__(self, test, intf, source, value):
        self._test = test
        self.intf = intf
        self.source = source
        self.value = value

    def add_vpp_config(self):
        self._test.vapi.qos_store_enable_disable(
            enable=1,
            store={'sw_if_index': self.intf.sw_if_index,
                   'input_source': self.source,
                   'value': self.value})
        self._test.registry.register(self, self._test.logger)
        return self

    def remove_vpp_config(self):
        self._test.vapi.qos_store_enable_disable(
            enable=0,
            store={'sw_if_index': self.intf.sw_if_index,
                   'input_source': self.source})

    def query_vpp_config(self):
        rs = self._test.vapi.qos_store_dump()

        for r in rs:
            if self.intf.sw_if_index == r.store.sw_if_index and \
               self.source == r.store.input_source and \
               self.value == r.store.value:
                return True
        return False

    def object_id(self):
        return ("qos-store-%s-%d" % (self.intf, self.source))


class VppQosEgressMap(VppObject):
    """ QoS Egress Map(ping) configuration """

    def __init__(self, test, id, rows):
        self._test = test
        self.id = id
        self.rows = rows

    def add_vpp_config(self):
        self._test.vapi.qos_egress_map_update(
            map={'id': self.id,
                 'rows': self.rows})
        self._test.registry.register(self, self._test.logger)
        return self

    def remove_vpp_config(self):
        self._test.vapi.qos_egress_map_delete(id=self.id)

    def query_vpp_config(self):
        rs = self._test.vapi.qos_egress_map_dump()

        for r in rs:
            if self.id == r.map.id:
                return True
        return False

    def object_id(self):
        return ("qos-map-%d" % (self.id))


class VppQosMark(VppObject):
    """ QoS Mark(ing) configuration """

    def __init__(self, test, intf, map, source):
        self._test = test
        self.intf = intf
        self.source = source
        self.map = map

    def add_vpp_config(self):
        self._test.vapi.qos_mark_enable_disable(
            enable=1,
            mark={'sw_if_index': self.intf.sw_if_index,
                  'map_id': self.map.id,
                  'output_source': self.source})
        self._test.registry.register(self, self._test.logger)
        return self

    def remove_vpp_config(self):
        self._test.vapi.qos_mark_enable_disable(
            enable=0,
            mark={'sw_if_index': self.intf.sw_if_index,
                  'output_source': self.source})

    def query_vpp_config(self):
        ms = self._test.vapi.qos_mark_dump()

        for m in ms:
            if self.intf.sw_if_index == m.mark.sw_if_index and \
               self.source == m.mark.output_source and \
               self.map.id == m.mark.map_id:
                return True
        return False

    def object_id(self):
        return ("qos-mark-%s-%d" % (self.intf, self.source))
an class="o">* node, vlib_frame_t * frame); /* Stream index to use for distribution when MC is enabled. */ u32 mc_stream_index; vlib_one_time_waiting_process_t *procs_waiting_for_mc_stream_join; /* Event logger. */ elog_main_t elog_main; /* Event logger trace flags */ int elog_trace_api_messages; int elog_trace_cli_commands; int elog_trace_graph_dispatch; int elog_trace_graph_circuit; u32 elog_trace_graph_circuit_node_index; /* Node call and return event types. */ elog_event_type_t *node_call_elog_event_types; elog_event_type_t *node_return_elog_event_types; elog_event_type_t *error_elog_event_types; /* Seed for random number generator. */ uword random_seed; /* Buffer of random data for various uses. */ clib_random_buffer_t random_buffer; /* Hash table to record which init functions have been called. */ uword *init_functions_called; /* thread, cpu and numa_node indices */ u32 thread_index; u32 cpu_id; u32 numa_node; /* List of init functions to call, setup by constructors */ _vlib_init_function_list_elt_t *init_function_registrations; _vlib_init_function_list_elt_t *worker_init_function_registrations; _vlib_init_function_list_elt_t *main_loop_enter_function_registrations; _vlib_init_function_list_elt_t *main_loop_exit_function_registrations; _vlib_init_function_list_elt_t *api_init_function_registrations; vlib_config_function_runtime_t *config_function_registrations; /* control-plane API queue signal pending, length indication */ volatile u32 queue_signal_pending; volatile u32 api_queue_nonempty; void (*queue_signal_callback) (struct vlib_main_t *); u8 **argv; /* Top of (worker) dispatch loop callback */ void (**volatile worker_thread_main_loop_callbacks) (struct vlib_main_t *); void (**volatile worker_thread_main_loop_callback_tmp) (struct vlib_main_t *); clib_spinlock_t worker_thread_main_loop_callback_lock; /* debugging */ volatile int parked_at_barrier; /* Attempt to do a post-mortem elog dump */ int elog_post_mortem_dump; /* * Need to call vlib_worker_thread_node_runtime_update before * releasing worker thread barrier. Only valid in vlib_global_main. */ int need_vlib_worker_thread_node_runtime_update; /* Dispatch loop time accounting */ u64 loops_this_reporting_interval; f64 loop_interval_end; f64 loop_interval_start; f64 loops_per_second; f64 seconds_per_loop; f64 damping_constant; /* * Barrier epoch - Set to current time, each time barrier_sync or * barrier_release is called with zero recursion. */ f64 barrier_epoch; /* Earliest barrier can be closed again */ f64 barrier_no_close_before; /* Need to check the frame queues */ volatile uword check_frame_queues; /* RPC requests, main thread only */ uword *pending_rpc_requests; uword *processing_rpc_requests; clib_spinlock_t pending_rpc_lock; /* buffer fault injector */ u32 buffer_alloc_success_seed; f64 buffer_alloc_success_rate; #ifdef CLIB_SANITIZE_ADDR /* address sanitizer stack save */ void *asan_stack_save; #endif } vlib_main_t; /* Global main structure. */ extern vlib_main_t vlib_global_main; void vlib_worker_loop (vlib_main_t * vm); always_inline f64 vlib_time_now (vlib_main_t * vm) { #if CLIB_DEBUG > 0 extern __thread uword __os_thread_index; #endif /* * Make sure folks don't pass &vlib_global_main from a worker thread. */ ASSERT (vm->thread_index == __os_thread_index); return clib_time_now (&vm->clib_time) + vm->time_offset; } always_inline f64 vlib_time_now_ticks (vlib_main_t * vm, u64 n) { return clib_time_now_internal (&vm->clib_time, n); } /* Busy wait for specified time. */ always_inline void vlib_time_wait (vlib_main_t * vm, f64 wait) { f64 t = vlib_time_now (vm); f64 limit = t + wait; while (t < limit) t = vlib_time_now (vm); } /* Time a piece of code. */ #define vlib_time_code(vm,body) \ do { \ f64 _t[2]; \ _t[0] = vlib_time_now (vm); \ do { body; } while (0); \ _t[1] = vlib_time_now (vm); \ clib_warning ("%.7e", _t[1] - _t[0]); \ } while (0) #define vlib_wait_with_timeout(vm,suspend_time,timeout_time,test) \ ({ \ uword __vlib_wait_with_timeout = 0; \ f64 __vlib_wait_time = 0; \ while (! (__vlib_wait_with_timeout = (test)) \ && __vlib_wait_time < (timeout_time)) \ { \ vlib_process_suspend (vm, suspend_time); \ __vlib_wait_time += suspend_time; \ } \ __vlib_wait_with_timeout; \ }) always_inline void vlib_panic_with_error (vlib_main_t * vm, clib_error_t * error) { vm->main_loop_error = error; clib_longjmp (&vm->main_loop_exit, VLIB_MAIN_LOOP_EXIT_PANIC); } #define vlib_panic_with_msg(vm,args...) \ vlib_panic_with_error (vm, clib_error_return (0, args)) always_inline void vlib_panic (vlib_main_t * vm) { vlib_panic_with_error (vm, 0); } always_inline f64 vlib_internal_node_vector_rate (vlib_main_t * vm) { u64 vectors; u64 calls; calls = vm->internal_node_calls - vm->internal_node_calls_last_clear; if (PREDICT_FALSE (calls == 0)) return 0.0; vectors = vm->internal_node_vectors - vm->internal_node_vectors_last_clear; return (f64) vectors / (f64) calls; } always_inline void vlib_clear_internal_node_vector_rate (vlib_main_t * vm) { vm->internal_node_calls_last_clear = vm->internal_node_calls; vm->internal_node_vectors_last_clear = vm->internal_node_vectors; } always_inline void vlib_increment_main_loop_counter (vlib_main_t * vm) { vm->main_loop_count++; vm->internal_node_last_vectors_per_main_loop = 0; if (PREDICT_FALSE (vm->main_loop_exit_now)) clib_longjmp (&vm->main_loop_exit, VLIB_MAIN_LOOP_EXIT_CLI); } always_inline u32 vlib_last_vectors_per_main_loop (vlib_main_t * vm) { return vm->internal_node_last_vectors_per_main_loop; } always_inline void vlib_set_queue_signal_callback (vlib_main_t * vm, void (*fp) (vlib_main_t *)) { vm->queue_signal_callback = fp; } /* Main routine. */ int vlib_main (vlib_main_t * vm, unformat_input_t * input); /* Thread stacks, for os_get_thread_index */ extern u8 **vlib_thread_stacks; /* Number of thread stacks that the application needs */ u32 vlib_app_num_thread_stacks_needed (void) __attribute__ ((weak)); extern void vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n); #define VLIB_PCAP_MAJOR_VERSION 1 #define VLIB_PCAP_MINOR_VERSION 0 typedef struct { u8 *filename; int enable; int status; u32 packets_to_capture; u32 buffer_trace_node_index; u32 buffer_traces_to_capture; } vlib_pcap_dispatch_trace_args_t; int vlib_pcap_dispatch_trace_configure (vlib_pcap_dispatch_trace_args_t *); #endif /* included_vlib_main_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */