FD.io VPP  v20.01-48-g3e0dafb74
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  */
24 static lacp_fsm_state_t lacp_ptx_state_no_periodic[] = {
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  */
34 static lacp_fsm_state_t lacp_ptx_state_fast_periodic[] = {
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  */
44 static lacp_fsm_state_t lacp_ptx_state_slow_periodic[] = {
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  */
54 static lacp_fsm_state_t lacp_ptx_state_periodic_tx[] = {
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 
62 static lacp_fsm_machine_t lacp_ptx_fsm_table[] = {
63  {lacp_ptx_state_no_periodic},
64  {lacp_ptx_state_fast_periodic},
65  {lacp_ptx_state_slow_periodic},
66  {lacp_ptx_state_periodic_tx},
67 };
68 
69 lacp_machine_t lacp_ptx_machine = {
72 };
73 
74 int
75 lacp_ptx_action_no_periodic (void *p1, void *p2)
76 {
77  vlib_main_t *vm = p1;
78  slave_if_t *sif = 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  slave_if_t *sif = p2;
90  u8 timer_expired;
91  lacp_main_t *lm = &lacp_main;
92 
93  if (!(sif->partner.state & LACP_STATE_LACP_ACTIVITY) &&
94  !(sif->actor.state & LACP_STATE_LACP_ACTIVITY))
95  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
96  LACP_PTX_EVENT_NO_PERIODIC, &sif->ptx_state);
97  else
98  {
101  timer_expired = 1;
102  else
103  timer_expired = 0;
104 
106 
107  if (timer_expired || (sif->partner.state & LACP_STATE_LACP_TIMEOUT))
108  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
109  LACP_PTX_EVENT_TIMER_EXPIRED, &sif->ptx_state);
110  }
111 
112  return 0;
113 }
114 
115 int
116 lacp_ptx_action_fast_periodic (void *p1, void *p2)
117 {
118  vlib_main_t *vm = p1;
119  slave_if_t *sif = p2;
120  u8 timer_expired;
121  lacp_main_t *lm = &lacp_main;
122 
123  if (!(sif->partner.state & LACP_STATE_LACP_ACTIVITY) &&
124  !(sif->actor.state & LACP_STATE_LACP_ACTIVITY))
125  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
126  LACP_PTX_EVENT_NO_PERIODIC, &sif->ptx_state);
127  else
128  {
131  timer_expired = 1;
132  else
133  timer_expired = 0;
134 
137 
138  if (timer_expired)
139  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
140  LACP_PTX_EVENT_TIMER_EXPIRED, &sif->ptx_state);
141 
142  if (!(sif->partner.state & LACP_STATE_LACP_TIMEOUT))
143  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
144  LACP_PTX_EVENT_LONG_TIMEOUT, &sif->ptx_state);
145  }
146 
147  return 0;
148 }
149 
150 int
151 lacp_ptx_action_timer_expired (void *p1, void *p2)
152 {
153  vlib_main_t *vm = p1;
154  slave_if_t *sif = p2;
155 
156  if (!(sif->partner.state & LACP_STATE_LACP_ACTIVITY) &&
157  !(sif->actor.state & LACP_STATE_LACP_ACTIVITY))
158  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
159  LACP_PTX_EVENT_NO_PERIODIC, &sif->ptx_state);
160  else
161  {
162  sif->ntt = 1;
163  lacp_machine_dispatch (&lacp_tx_machine, vm, sif, LACP_TX_EVENT_NTT,
164  &sif->tx_state);
165  if (sif->partner.state & LACP_STATE_LACP_TIMEOUT)
166  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
167  LACP_PTX_EVENT_SHORT_TIMEOUT, &sif->ptx_state);
168  else
169  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
170  LACP_PTX_EVENT_LONG_TIMEOUT, &sif->ptx_state);
171  }
172 
173  return 0;
174 }
175 
176 static u8 *
177 format_ptx_event (u8 * s, va_list * args)
178 {
179  static lacp_event_struct lacp_ptx_event_array[] = {
180 #define _(b, s, n) {.bit = b, .str = #s, },
182 #undef _
183  {.str = NULL}
184  };
185  int e = va_arg (*args, int);
186  lacp_event_struct *event_entry = lacp_ptx_event_array;
187 
188  if (e >= (sizeof (lacp_ptx_event_array) / sizeof (*event_entry)))
189  s = format (s, "Bad event %d", e);
190  else
191  s = format (s, "%s", event_entry[e].str);
192 
193  return s;
194 }
195 
196 void
197 lacp_ptx_debug_func (slave_if_t * sif, int event, int state,
198  lacp_fsm_state_t * transition)
199 {
201  /* *INDENT-OFF* */
202  ELOG_TYPE_DECLARE (e) =
203  {
204  .format = "%s",
205  .format_args = "T4",
206  };
207  /* *INDENT-ON* */
208  struct
209  {
210  u32 event;
211  } *ed = 0;
212 
214  ed->event =
215  elog_string (&vlib_global_main.elog_main, "%U-PTX: %U, %U->%U%c",
217  sif->sw_if_index, format_ptx_event, event,
219  transition->next_state, 0);
220 }
221 
222 void
224 {
225  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
226  LACP_PTX_EVENT_NO_PERIODIC, &sif->ptx_state);
227 }
228 
229 /*
230  * fd.io coding-style-patch-verification: ON
231  *
232  * Local Variables:
233  * eval: (c-set-style "gnu")
234  * End:
235  */
static u8 * format_ptx_event(u8 *s, va_list *args)
Definition: ptx_machine.c:177
vlib_main_t * vlib_main
Definition: node.h:121
vlib_main_t vlib_global_main
Definition: main.c:1943
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define NULL
Definition: clib.h:58
int tx_state
Definition: node.h:314
int lacp_ptx_action_no_periodic(void *p1, void *p2)
Definition: ptx_machine.c:75
elog_track_t elog_track
Definition: threads.h:100
int lacp_ptx_action_fast_periodic(void *p1, void *p2)
Definition: ptx_machine.c:116
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define LACP_FAST_PERIODIC_TIMER
Definition: node.h:25
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
u8 ntt
Definition: node.h:262
f64 periodic_timer
Definition: node.h:304
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:166
#define LACP_ACTION_SLOW_PERIODIC
Definition: ptx_machine.h:59
lacp_port_info_t actor
Definition: node.h:255
static u8 lacp_timer_is_expired(vlib_main_t *vm, f64 timer)
Definition: node.h:172
unsigned int u32
Definition: types.h:88
#define LACP_NOACTION
Definition: machine.h:21
void lacp_init_ptx_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: ptx_machine.c:223
#define LACP_ACTION_TIMER_EXPIRED
Definition: ptx_machine.h:63
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:37
static void lacp_stop_timer(f64 *timer)
Definition: node.h:160
vlib_main_t * vm
Definition: in2out_ed.c:1810
int ptx_state
Definition: node.h:316
static lacp_fsm_machine_t lacp_ptx_fsm_table[]
Definition: ptx_machine.c:62
u32 sw_if_index
Definition: node.h:218
lacp_port_info_t partner
Definition: node.h:254
elog_main_t elog_main
Definition: main.h:193
lacp_main_t lacp_main
Definition: lacp.c:26
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
#define ELOG_TRACK_DATA(em, f, track)
Definition: elog.h:478
int lacp_ptx_action_slow_periodic(void *p1, void *p2)
Definition: ptx_machine.c:86
static u8 * format_ptx_sm_state(u8 *s, va_list *args)
Definition: node.h:240
void lacp_ptx_debug_func(slave_if_t *sif, int event, int state, lacp_fsm_state_t *transition)
Definition: ptx_machine.c:197
static void lacp_schedule_periodic_timer(vlib_main_t *vm, slave_if_t *sif)
Definition: ptx_machine.h:73
int lacp_ptx_action_timer_expired(void *p1, void *p2)
Definition: ptx_machine.c:151
u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
Definition: elog.c:562
static_always_inline uword os_get_thread_index(void)
Definition: os.h:62
static void lacp_start_periodic_timer(vlib_main_t *vm, slave_if_t *sif, u8 expiration)
Definition: ptx_machine.h:67
#define LACP_ACTION_NO_PERIODIC
Definition: ptx_machine.h:57
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
static void lacp_ptx_post_short_timeout_event(vlib_main_t *vm, slave_if_t *sif)
Definition: ptx_machine.h:90
lacp_machine_t lacp_tx_machine
Definition: tx_machine.c:33
#define LACP_ACTION_FAST_PERIODIC
Definition: ptx_machine.h:61
int lacp_machine_dispatch(lacp_machine_t *machine, vlib_main_t *vm, slave_if_t *sif, int event, int *state)
Definition: lacp.c:319