FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ptx_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 = NO_PERIODIC
23  */
25  {LACP_ACTION_NO_PERIODIC, LACP_PTX_STATE_NO_PERIODIC}, // event 0 NO_PERIODIC
26  {LACP_ACTION_SLOW_PERIODIC, LACP_PTX_STATE_SLOW_PERIODIC}, // event 1 LONG_TIMEOUT
27  {LACP_ACTION_NO_PERIODIC, LACP_PTX_STATE_NO_PERIODIC}, // event 2 TIMER_EXPIRED
28  {LACP_ACTION_FAST_PERIODIC, LACP_PTX_STATE_FAST_PERIODIC}, // event 3 SHORT_TIMEOUT
29 };
30 
31 /*
32  * LACP State = FAST_PERIODIC
33  */
35  {LACP_ACTION_NO_PERIODIC, LACP_PTX_STATE_NO_PERIODIC}, // event 0 NO_PERIODIC
36  {LACP_ACTION_SLOW_PERIODIC, LACP_PTX_STATE_SLOW_PERIODIC}, // event 1 LONG_TIMEOUT
37  {LACP_ACTION_TIMER_EXPIRED, LACP_PTX_STATE_PERIODIC_TX}, // event 2 TIMER_EXPIRED
38  {LACP_ACTION_FAST_PERIODIC, LACP_PTX_STATE_FAST_PERIODIC}, // event 3 SHORT_TIMEOUT
39 };
40 
41 /*
42  * LACP State = SLOW_PERIODIC
43  */
45  {LACP_ACTION_NO_PERIODIC, LACP_PTX_STATE_NO_PERIODIC}, // event 0 NO_PERIODIC
46  {LACP_ACTION_SLOW_PERIODIC, LACP_PTX_STATE_SLOW_PERIODIC}, // event 1 LONG_TIMEOUT
47  {LACP_ACTION_TIMER_EXPIRED, LACP_PTX_STATE_PERIODIC_TX}, // event 2 TIMER_EXPIRED
48  {LACP_ACTION_FAST_PERIODIC, LACP_PTX_STATE_FAST_PERIODIC}, // event 3 SHORT_TIMEOUT
49 };
50 
51 /*
52  * LACP State = PERIODIC_TX
53  */
55  {LACP_ACTION_NO_PERIODIC, LACP_PTX_STATE_NO_PERIODIC}, // event 0 NO_PERIODIC
56  {LACP_NOACTION, LACP_PTX_STATE_PERIODIC_TX}, // event 1 LONG_TIMEOUT
57  {LACP_ACTION_TIMER_EXPIRED, LACP_PTX_STATE_PERIODIC_TX}, // event 2 TIMER_EXPIRED
58  {LACP_NOACTION, LACP_PTX_STATE_PERIODIC_TX}, // event 3 SHORT_TIMEOUT
59 };
60 
61 
67 };
68 
72 };
73 
74 int
75 lacp_ptx_action_no_periodic (void *p1, void *p2)
76 {
77  vlib_main_t *vm = p1;
78  member_if_t *mif = p2;
79 
82  return 0;
83 }
84 
85 int
86 lacp_ptx_action_slow_periodic (void *p1, void *p2)
87 {
88  vlib_main_t *vm = p1;
89  member_if_t *mif = p2;
90  u8 timer_expired;
91 
92  if (!(mif->partner.state & LACP_STATE_LACP_ACTIVITY) &&
93  !(mif->actor.state & LACP_STATE_LACP_ACTIVITY))
95  LACP_PTX_EVENT_NO_PERIODIC, &mif->ptx_state);
96  else
97  {
100  timer_expired = 1;
101  else
102  timer_expired = 0;
103 
105 
106  if (timer_expired || (mif->partner.state & LACP_STATE_LACP_TIMEOUT))
108  LACP_PTX_EVENT_TIMER_EXPIRED, &mif->ptx_state);
109  }
110 
111  return 0;
112 }
113 
114 int
115 lacp_ptx_action_fast_periodic (void *p1, void *p2)
116 {
117  vlib_main_t *vm = p1;
118  member_if_t *mif = p2;
119  u8 timer_expired;
120 
121  if (!(mif->partner.state & LACP_STATE_LACP_ACTIVITY) &&
122  !(mif->actor.state & LACP_STATE_LACP_ACTIVITY))
124  LACP_PTX_EVENT_NO_PERIODIC, &mif->ptx_state);
125  else
126  {
129  timer_expired = 1;
130  else
131  timer_expired = 0;
132 
134 
135  if (timer_expired)
137  LACP_PTX_EVENT_TIMER_EXPIRED, &mif->ptx_state);
138 
139  if (!(mif->partner.state & LACP_STATE_LACP_TIMEOUT))
141  LACP_PTX_EVENT_LONG_TIMEOUT, &mif->ptx_state);
142  }
143 
144  return 0;
145 }
146 
147 int
148 lacp_ptx_action_timer_expired (void *p1, void *p2)
149 {
150  vlib_main_t *vm = p1;
151  member_if_t *mif = p2;
152 
153  if (!(mif->partner.state & LACP_STATE_LACP_ACTIVITY) &&
154  !(mif->actor.state & LACP_STATE_LACP_ACTIVITY))
156  LACP_PTX_EVENT_NO_PERIODIC, &mif->ptx_state);
157  else
158  {
159  mif->ntt = 1;
160  lacp_machine_dispatch (&lacp_tx_machine, vm, mif, LACP_TX_EVENT_NTT,
161  &mif->tx_state);
162  if (mif->partner.state & LACP_STATE_LACP_TIMEOUT)
164  LACP_PTX_EVENT_SHORT_TIMEOUT, &mif->ptx_state);
165  else
167  LACP_PTX_EVENT_LONG_TIMEOUT, &mif->ptx_state);
168  }
169 
170  return 0;
171 }
172 
173 static u8 *
174 format_ptx_event (u8 * s, va_list * args)
175 {
176  static lacp_event_struct lacp_ptx_event_array[] = {
177 #define _(b, s, n) {.bit = b, .str = #s, },
179 #undef _
180  {.str = NULL}
181  };
182  int e = va_arg (*args, int);
183  lacp_event_struct *event_entry = lacp_ptx_event_array;
184 
185  if (e >= (sizeof (lacp_ptx_event_array) / sizeof (*event_entry)))
186  s = format (s, "Bad event %d", e);
187  else
188  s = format (s, "%s", event_entry[e].str);
189 
190  return s;
191 }
192 
193 void
194 lacp_ptx_debug_func (member_if_t * mif, int event, int state,
195  lacp_fsm_state_t * transition)
196 {
198  /* *INDENT-OFF* */
199  ELOG_TYPE_DECLARE (e) =
200  {
201  .format = "%s",
202  .format_args = "T4",
203  };
204  /* *INDENT-ON* */
205  struct
206  {
207  u32 event;
208  } *ed = 0;
209 
211  ed->event =
212  elog_string (&vlib_global_main.elog_main, "%U-PTX: %U, %U->%U%c",
214  mif->sw_if_index, format_ptx_event, event,
216  transition->next_state, 0);
217 }
218 
219 void
221 {
223  LACP_PTX_EVENT_NO_PERIODIC, &mif->ptx_state);
224 }
225 
226 /*
227  * fd.io coding-style-patch-verification: ON
228  *
229  * Local Variables:
230  * eval: (c-set-style "gnu")
231  * End:
232  */
lacp_timer_is_expired
static u8 lacp_timer_is_expired(vlib_main_t *vm, f64 timer)
Definition: node.h:174
lacp_ptx_action_fast_periodic
int lacp_ptx_action_fast_periodic(void *p1, void *p2)
Definition: ptx_machine.c:115
lacp_ptx_state_no_periodic
static lacp_fsm_state_t lacp_ptx_state_no_periodic[]
Definition: ptx_machine.c:24
LACP_ACTION_SLOW_PERIODIC
#define LACP_ACTION_SLOW_PERIODIC
Definition: ptx_machine.h:59
format_ptx_sm_state
static u8 * format_ptx_sm_state(u8 *s, va_list *args)
Definition: node.h:242
lacp_timer_is_running
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:168
foreach_lacp_ptx_event
@ foreach_lacp_ptx_event
Definition: ptx_machine.h:31
member_if_t::ntt
u8 ntt
Definition: node.h:262
lacp_event_struct
Definition: protocol.h:91
lacp_start_periodic_timer
static void lacp_start_periodic_timer(vlib_main_t *vm, member_if_t *mif, u8 expiration)
Definition: ptx_machine.h:67
lacp_ptx_post_short_timeout_event
static void lacp_ptx_post_short_timeout_event(vlib_main_t *vm, member_if_t *mif)
Definition: ptx_machine.h:90
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_ptx_action_slow_periodic
int lacp_ptx_action_slow_periodic(void *p1, void *p2)
Definition: ptx_machine.c:86
lacp_fsm_state_t
Definition: machine.h:26
vlib_worker_threads
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
LACP_FAST_PERIODIC_TIMER
#define LACP_FAST_PERIODIC_TIMER
Definition: node.h:25
lacp_ptx_action_timer_expired
int lacp_ptx_action_timer_expired(void *p1, void *p2)
Definition: ptx_machine.c:148
lacp_ptx_state_slow_periodic
static lacp_fsm_state_t lacp_ptx_state_slow_periodic[]
Definition: ptx_machine.c:44
ELOG_TYPE_DECLARE
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
member_if_t::tx_state
int tx_state
Definition: node.h:314
lacp_ptx_action_no_periodic
int lacp_ptx_action_no_periodic(void *p1, void *p2)
Definition: ptx_machine.c:75
ELOG_TRACK_DATA
#define ELOG_TRACK_DATA(em, f, track)
Definition: elog.h:478
member_if_t::partner
lacp_port_info_t partner
Definition: node.h:254
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vlib_global_main
vlib_global_main_t vlib_global_main
Definition: main.c:1786
member_if_t::periodic_timer
f64 periodic_timer
Definition: node.h:304
member_if_t::actor
lacp_port_info_t actor
Definition: node.h:255
lacp_ptx_fsm_table
static lacp_fsm_machine_t lacp_ptx_fsm_table[]
Definition: ptx_machine.c:62
lacp_init_ptx_machine
void lacp_init_ptx_machine(vlib_main_t *vm, member_if_t *mif)
Definition: ptx_machine.c:220
node.h
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_ptx_machine
lacp_machine_t lacp_ptx_machine
Definition: ptx_machine.c:69
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_ptx_state_periodic_tx
static lacp_fsm_state_t lacp_ptx_state_periodic_tx[]
Definition: ptx_machine.c:54
LACP_ACTION_TIMER_EXPIRED
#define LACP_ACTION_TIMER_EXPIRED
Definition: ptx_machine.h:63
LACP_ACTION_NO_PERIODIC
#define LACP_ACTION_NO_PERIODIC
Definition: ptx_machine.h:57
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
lacp_stop_timer
static void lacp_stop_timer(f64 *timer)
Definition: node.h:162
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
lacp_ptx_state_fast_periodic
static lacp_fsm_state_t lacp_ptx_state_fast_periodic[]
Definition: ptx_machine.c:34
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
LACP_ACTION_FAST_PERIODIC
#define LACP_ACTION_FAST_PERIODIC
Definition: ptx_machine.h:61
lacp_fsm_state_t::next_state
int next_state
Definition: machine.h:29
member_if_t::ptx_state
int ptx_state
Definition: node.h:316
LACP_NOACTION
#define LACP_NOACTION
Definition: machine.h:21
lacp_machine_t
Definition: machine.h:40
format_ptx_event
static u8 * format_ptx_event(u8 *s, va_list *args)
Definition: ptx_machine.c:174
node.h
lacp_ptx_debug_func
void lacp_ptx_debug_func(member_if_t *mif, int event, int state, lacp_fsm_state_t *transition)
Definition: ptx_machine.c:194