FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
tx_machine.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define _GNU_SOURCE
17 
18 #include <vnet/bonding/node.h>
19 #include <lacp/node.h>
20 
21 /*
22  * LACP State = TRANSMIT
23  */
24 static lacp_fsm_state_t lacp_tx_state_transmit[] = {
25  {LACP_ACTION_TRANSMIT, LACP_TX_STATE_TRANSMIT}, // event 0 BEGIN
26  {LACP_ACTION_TRANSMIT, LACP_TX_STATE_TRANSMIT}, // event 1 NTT
27 };
28 
29 static lacp_fsm_machine_t lacp_tx_fsm_table[] = {
30  {lacp_tx_state_transmit},
31 };
32 
33 lacp_machine_t lacp_tx_machine = {
36 };
37 
38 int
39 lacp_tx_action_transmit (void *p1, void *p2)
40 {
41  vlib_main_t *vm = p1;
42  slave_if_t *sif = p2;
43  lacp_main_t *lm = &lacp_main;
44  f64 now = vlib_time_now (lm->vlib_main);
45 
47  return 0;
48 
49  // No more than 3 LACPDUs per fast interval
50  if (now <= (sif->last_lacpdu_sent_time + 0.333))
51  return 0;
52 
53  if (sif->ntt)
54  {
55  lacp_send_lacp_pdu (vm, sif);
57  }
58  sif->ntt = 0;
59 
60  return 0;
61 }
62 
63 static u8 *
64 format_tx_event (u8 * s, va_list * args)
65 {
66  static lacp_event_struct lacp_tx_event_array[] = {
67 #define _(b, s, n) {.bit = b, .str = #s, },
69 #undef _
70  {.str = NULL}
71  };
72  int e = va_arg (*args, int);
73  lacp_event_struct *event_entry = lacp_tx_event_array;
74 
75  if (e >= (sizeof (lacp_tx_event_array) / sizeof (*event_entry)))
76  s = format (s, "Bad event %d", e);
77  else
78  s = format (s, "%s", event_entry[e].str);
79 
80  return s;
81 }
82 
83 void
84 lacp_tx_debug_func (slave_if_t * sif, int event, int state,
85  lacp_fsm_state_t * transition)
86 {
88  /* *INDENT-OFF* */
89  ELOG_TYPE_DECLARE (e) =
90  {
91  .format = "%s",
92  .format_args = "T4",
93  };
94  /* *INDENT-ON* */
95  struct
96  {
97  u32 event;
98  } *ed = 0;
99 
101  ed->event = elog_string (&vlib_global_main.elog_main, "%U-TX: %U, %U->%U%c",
103  sif->sw_if_index, format_tx_event, event,
105  transition->next_state, 0);
106 }
107 
108 void
110 {
111  lacp_machine_dispatch (&lacp_tx_machine, vm, sif, LACP_TX_EVENT_BEGIN,
112  &sif->tx_state);
113 }
114 
115 /*
116  * fd.io coding-style-patch-verification: ON
117  *
118  * Local Variables:
119  * eval: (c-set-style "gnu")
120  * End:
121  */
void lacp_send_lacp_pdu(vlib_main_t *vm, slave_if_t *sif)
Definition: lacp.c:108
vlib_main_t * vlib_main
Definition: node.h:121
vlib_main_t vlib_global_main
Definition: main.c:1940
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:279
int tx_state
Definition: node.h:305
elog_track_t elog_track
Definition: threads.h:100
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
u8 ntt
Definition: node.h:253
double f64
Definition: types.h:142
f64 periodic_timer
Definition: node.h:295
static lacp_fsm_machine_t lacp_tx_fsm_table[]
Definition: tx_machine.c:29
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:166
vhost_vring_state_t state
Definition: vhost_user.h:146
unsigned int u32
Definition: types.h:88
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:37
int lacp_tx_action_transmit(void *p1, void *p2)
Definition: tx_machine.c:39
u32 sw_if_index
Definition: node.h:212
vlib_main_t * vm
Definition: buffer.c:323
#define LACP_ACTION_TRANSMIT
Definition: tx_machine.h:49
elog_main_t elog_main
Definition: main.h:193
lacp_main_t lacp_main
Definition: lacp.c:25
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
f64 last_lacpdu_sent_time
Definition: node.h:283
#define ELOG_TRACK_DATA(em, f, track)
Definition: elog.h:478
static void lacp_schedule_periodic_timer(vlib_main_t *vm, slave_if_t *sif)
Definition: ptx_machine.h:73
u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
Definition: elog.c:562
void lacp_tx_debug_func(slave_if_t *sif, int event, int state, lacp_fsm_state_t *transition)
Definition: tx_machine.c:84
void lacp_init_tx_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: tx_machine.c:109
static_always_inline uword os_get_thread_index(void)
Definition: os.h:62
static u8 * format_tx_sm_state(u8 *s, va_list *args)
Definition: node.h:200
static u8 * format_tx_event(u8 *s, va_list *args)
Definition: tx_machine.c:64
int lacp_machine_dispatch(lacp_machine_t *machine, vlib_main_t *vm, slave_if_t *sif, int event, int *state)
Definition: lacp.c:300