FD.io VPP  v21.10.1-2-g0a485f517
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  */
25  {LACP_ACTION_TRANSMIT, LACP_TX_STATE_TRANSMIT}, // event 0 BEGIN
26  {LACP_ACTION_TRANSMIT, LACP_TX_STATE_TRANSMIT}, // event 1 NTT
27 };
28 
31 };
32 
36 };
37 
38 int
39 lacp_tx_action_transmit (void *p1, void *p2)
40 {
41  vlib_main_t *vm = p1;
42  member_if_t *mif = p2;
43  f64 now = vlib_time_now (vm);
44 
46  return 0;
47 
48  // No more than 3 LACPDUs per fast interval
49  if (now <= (mif->last_lacpdu_sent_time + 0.333))
50  return 0;
51 
52  if (mif->ntt)
53  {
54  lacp_send_lacp_pdu (vm, mif);
56  }
57  mif->ntt = 0;
58 
59  return 0;
60 }
61 
62 static u8 *
63 format_tx_event (u8 * s, va_list * args)
64 {
65  static lacp_event_struct lacp_tx_event_array[] = {
66 #define _(b, s, n) {.bit = b, .str = #s, },
68 #undef _
69  {.str = NULL}
70  };
71  int e = va_arg (*args, int);
72  lacp_event_struct *event_entry = lacp_tx_event_array;
73 
74  if (e >= (sizeof (lacp_tx_event_array) / sizeof (*event_entry)))
75  s = format (s, "Bad event %d", e);
76  else
77  s = format (s, "%s", event_entry[e].str);
78 
79  return s;
80 }
81 
82 void
83 lacp_tx_debug_func (member_if_t * mif, int event, int state,
84  lacp_fsm_state_t * transition)
85 {
87  /* *INDENT-OFF* */
88  ELOG_TYPE_DECLARE (e) =
89  {
90  .format = "%s",
91  .format_args = "T4",
92  };
93  /* *INDENT-ON* */
94  struct
95  {
96  u32 event;
97  } *ed = 0;
98 
100  ed->event = elog_string (&vlib_global_main.elog_main, "%U-TX: %U, %U->%U%c",
102  mif->sw_if_index, format_tx_event, event,
104  transition->next_state, 0);
105 }
106 
107 void
109 {
110  lacp_machine_dispatch (&lacp_tx_machine, vm, mif, LACP_TX_EVENT_BEGIN,
111  &mif->tx_state);
112 }
113 
114 /*
115  * fd.io coding-style-patch-verification: ON
116  *
117  * Local Variables:
118  * eval: (c-set-style "gnu")
119  * End:
120  */
format_tx_sm_state
static u8 * format_tx_sm_state(u8 *s, va_list *args)
Definition: node.h:202
member_if_t::last_lacpdu_sent_time
f64 last_lacpdu_sent_time
Definition: node.h:292
lacp_timer_is_running
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:168
member_if_t::ntt
u8 ntt
Definition: node.h:262
lacp_event_struct
Definition: protocol.h:91
lacp_tx_fsm_table
static lacp_fsm_machine_t lacp_tx_fsm_table[]
Definition: tx_machine.c:29
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
elog_string
__clib_export u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
Definition: elog.c:582
lacp_fsm_state_t
Definition: machine.h:26
vlib_worker_threads
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
format_tx_event
static u8 * format_tx_event(u8 *s, va_list *args)
Definition: tx_machine.c:63
ELOG_TYPE_DECLARE
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
member_if_t::tx_state
int tx_state
Definition: node.h:314
ELOG_TRACK_DATA
#define ELOG_TRACK_DATA(em, f, track)
Definition: elog.h:478
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
lacp_init_tx_machine
void lacp_init_tx_machine(vlib_main_t *vm, member_if_t *mif)
Definition: tx_machine.c:108
vlib_global_main
vlib_global_main_t vlib_global_main
Definition: main.c:1786
foreach_lacp_tx_event
@ foreach_lacp_tx_event
Definition: tx_machine.h:29
member_if_t::periodic_timer
f64 periodic_timer
Definition: node.h:304
node.h
f64
double f64
Definition: types.h:142
lacp_fsm_machine_t
Definition: machine.h:35
member_if_t::sw_if_index
u32 sw_if_index
Definition: node.h:218
vlib_global_main_t::elog_main
elog_main_t elog_main
Definition: main.h:302
os_get_thread_index
static_always_inline uword os_get_thread_index(void)
Definition: os.h:63
lacp_tx_machine
lacp_machine_t lacp_tx_machine
Definition: tx_machine.c:33
lacp_machine_dispatch
int lacp_machine_dispatch(lacp_machine_t *machine, vlib_main_t *vm, member_if_t *mif, int event, int *state)
Definition: lacp.c:317
lacp_tx_action_transmit
int lacp_tx_action_transmit(void *p1, void *p2)
Definition: tx_machine.c:39
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
member_if_t
Definition: node.h:213
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
vlib_worker_thread_t
Definition: threads.h:81
lacp_schedule_periodic_timer
static void lacp_schedule_periodic_timer(vlib_main_t *vm, member_if_t *mif)
Definition: ptx_machine.h:73
vlib_worker_thread_t::elog_track
elog_track_t elog_track
Definition: threads.h:95
now
f64 now
Definition: nat44_ei_out2in.c:710
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
lacp_send_lacp_pdu
void lacp_send_lacp_pdu(vlib_main_t *vm, member_if_t *mif)
Definition: lacp.c:108
LACP_ACTION_TRANSMIT
#define LACP_ACTION_TRANSMIT
Definition: tx_machine.h:49
lacp_tx_state_transmit
static lacp_fsm_state_t lacp_tx_state_transmit[]
Definition: tx_machine.c:24
lacp_fsm_state_t::next_state
int next_state
Definition: machine.h:29
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
lacp_machine_t
Definition: machine.h:40
lacp_tx_debug_func
void lacp_tx_debug_func(member_if_t *mif, int event, int state, lacp_fsm_state_t *transition)
Definition: tx_machine.c:83
node.h