FD.io VPP  v18.11-rc0-18-g2a3fb1a
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_FAST_PERIODIC}, // event 0 BEGIN
26  {LACP_NOACTION, LACP_PTX_STATE_NO_PERIODIC}, // event 1 LONG_TIMEOUT
27  {LACP_NOACTION, LACP_PTX_STATE_NO_PERIODIC}, // event 2 TIMER_EXPIRED
28  {LACP_NOACTION, LACP_PTX_STATE_NO_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_FAST_PERIODIC, LACP_PTX_STATE_FAST_PERIODIC}, // event 0 BEGIN
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 BEGIN
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 BEGIN
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 = (vlib_main_t *) p1;
78  slave_if_t *sif = (slave_if_t *) p2;
79 
81 
82  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
83  LACP_PTX_EVENT_BEGIN, &sif->ptx_state);
84 
85  return 0;
86 }
87 
88 int
89 lacp_ptx_action_slow_periodic (void *p1, void *p2)
90 {
91  vlib_main_t *vm = (vlib_main_t *) p1;
92  slave_if_t *sif = (slave_if_t *) p2;
93  u8 timer_expired;
94  lacp_main_t *lm = &lacp_main;
95 
98  timer_expired = 1;
99  else
100  timer_expired = 0;
101 
103 
104  if (timer_expired || (sif->partner.state & LACP_STATE_LACP_TIMEOUT))
105  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
106  LACP_PTX_EVENT_TIMER_EXPIRED, &sif->ptx_state);
107 
108  return 0;
109 }
110 
111 int
112 lacp_ptx_action_fast_periodic (void *p1, void *p2)
113 {
114  vlib_main_t *vm = (vlib_main_t *) p1;
115  slave_if_t *sif = (slave_if_t *) p2;
116  u8 timer_expired;
117  lacp_main_t *lm = &lacp_main;
118 
121  timer_expired = 1;
122  else
123  timer_expired = 0;
124 
126 
127  if (timer_expired)
128  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
129  LACP_PTX_EVENT_TIMER_EXPIRED, &sif->ptx_state);
130 
131  if (!(sif->partner.state & LACP_STATE_LACP_TIMEOUT))
132  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
133  LACP_PTX_EVENT_LONG_TIMEOUT, &sif->ptx_state);
134 
135  return 0;
136 }
137 
138 int
139 lacp_ptx_action_timer_expired (void *p1, void *p2)
140 {
141  vlib_main_t *vm = (vlib_main_t *) p1;
142  slave_if_t *sif = (slave_if_t *) p2;
143 
144  sif->ntt = 1;
145  lacp_machine_dispatch (&lacp_tx_machine, vm, sif, LACP_TX_EVENT_NTT,
146  &sif->tx_state);
147  if (sif->partner.state & LACP_STATE_LACP_TIMEOUT)
148  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
149  LACP_PTX_EVENT_SHORT_TIMEOUT, &sif->ptx_state);
150  else
151  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
152  LACP_PTX_EVENT_LONG_TIMEOUT, &sif->ptx_state);
153 
154  return 0;
155 }
156 
157 static u8 *
158 format_ptx_event (u8 * s, va_list * args)
159 {
160  static lacp_event_struct lacp_ptx_event_array[] = {
161 #define _(b, s, n) {.bit = b, .str = #s, },
163 #undef _
164  {.str = NULL}
165  };
166  int e = va_arg (*args, int);
167  lacp_event_struct *event_entry =
168  (lacp_event_struct *) & lacp_ptx_event_array;
169 
170  if (e >= (sizeof (lacp_ptx_event_array) / sizeof (*event_entry)))
171  s = format (s, "Bad event %d", e);
172  else
173  s = format (s, "%s", event_entry[e].str);
174 
175  return s;
176 }
177 
178 void
179 lacp_ptx_debug_func (slave_if_t * sif, int event, int state,
180  lacp_fsm_state_t * transition)
181 {
182  clib_warning ("%U-PTX: event %U, old state %U, new state %U",
186  transition->next_state);
187 }
188 
189 void
191 {
192  lacp_machine_dispatch (&lacp_ptx_machine, vm, sif, LACP_PTX_EVENT_BEGIN,
193  &sif->ptx_state);
194 }
195 
196 /*
197  * fd.io coding-style-patch-verification: ON
198  *
199  * Local Variables:
200  * eval: (c-set-style "gnu")
201  * End:
202  */
static u8 * format_ptx_event(u8 *s, va_list *args)
Definition: ptx_machine.c:158
vlib_main_t * vlib_main
Definition: node.h:119
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
#define NULL
Definition: clib.h:55
int tx_state
Definition: node.h:270
int lacp_ptx_action_no_periodic(void *p1, void *p2)
Definition: ptx_machine.c:75
int lacp_ptx_action_fast_periodic(void *p1, void *p2)
Definition: ptx_machine.c:112
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#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:227
f64 periodic_timer
Definition: node.h:260
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:163
#define LACP_ACTION_SLOW_PERIODIC
Definition: ptx_machine.h:59
static u8 lacp_timer_is_expired(vlib_main_t *vm, f64 timer)
Definition: node.h:169
vhost_vring_state_t state
Definition: vhost_user.h:115
#define LACP_NOACTION
Definition: machine.h:21
void lacp_init_ptx_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: ptx_machine.c:190
#define LACP_ACTION_TIMER_EXPIRED
Definition: ptx_machine.h:63
static void lacp_stop_timer(f64 *timer)
Definition: node.h:157
int ptx_state
Definition: node.h:272
static lacp_fsm_machine_t lacp_ptx_fsm_table[]
Definition: ptx_machine.c:62
u32 sw_if_index
Definition: node.h:186
vlib_main_t * vm
Definition: buffer.c:294
lacp_port_info_t partner
Definition: node.h:219
#define clib_warning(format, args...)
Definition: error.h:59
lacp_main_t lacp_main
Definition: lacp.c:25
int lacp_ptx_action_slow_periodic(void *p1, void *p2)
Definition: ptx_machine.c:89
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:179
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:139
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
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:286