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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/bonding/node.h>
19 #include <lacp/node.h>
22 * LACP State = NO_PERIODIC
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
32 * LACP State = FAST_PERIODIC
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
42 * LACP State = SLOW_PERIODIC
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
52 * LACP State = PERIODIC_TX
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
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},
69 lacp_machine_t lacp_ptx_machine = {
75 lacp_ptx_action_no_periodic (void *p1, void *p2)
80 lacp_stop_timer (&sif->periodic_timer);
81 lacp_ptx_post_short_timeout_event (vm, sif);
86 lacp_ptx_action_slow_periodic (void *p1, void *p2)
91 lacp_main_t *lm = &lacp_main;
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);
99 if (lacp_timer_is_running (sif->periodic_timer) &&
100 lacp_timer_is_expired (lm->vlib_main, sif->periodic_timer))
105 lacp_schedule_periodic_timer (lm->vlib_main, sif);
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);
116 lacp_ptx_action_fast_periodic (void *p1, void *p2)
118 vlib_main_t *vm = p1;
119 slave_if_t *sif = p2;
121 lacp_main_t *lm = &lacp_main;
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);
129 if (lacp_timer_is_running (sif->periodic_timer) &&
130 lacp_timer_is_expired (lm->vlib_main, sif->periodic_timer))
135 lacp_start_periodic_timer (lm->vlib_main, sif,
136 LACP_FAST_PERIODIC_TIMER);
139 lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
140 LACP_PTX_EVENT_TIMER_EXPIRED, &sif->ptx_state);
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);
151 lacp_ptx_action_timer_expired (void *p1, void *p2)
153 vlib_main_t *vm = p1;
154 slave_if_t *sif = p2;
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);
163 lacp_machine_dispatch (&lacp_tx_machine, vm, sif, LACP_TX_EVENT_NTT,
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);
169 lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
170 LACP_PTX_EVENT_LONG_TIMEOUT, &sif->ptx_state);
177 format_ptx_event (u8 * s, va_list * args)
179 static lacp_event_struct lacp_ptx_event_array[] = {
180 #define _(b, s, n) {.bit = b, .str = #s, },
181 foreach_lacp_ptx_event
185 int e = va_arg (*args, int);
186 lacp_event_struct *event_entry = lacp_ptx_event_array;
188 if (e >= (sizeof (lacp_ptx_event_array) / sizeof (*event_entry)))
189 s = format (s, "Bad event %d", e);
191 s = format (s, "%s", event_entry[e].str);
197 lacp_ptx_debug_func (slave_if_t * sif, int event, int state,
198 lacp_fsm_state_t * transition)
200 vlib_worker_thread_t *w = vlib_worker_threads + os_get_thread_index ();
202 ELOG_TYPE_DECLARE (e) =
213 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
215 elog_string (&vlib_global_main.elog_main, "%U-PTX: %U, %U->%U%c",
216 format_vnet_sw_if_index_name, vnet_get_main (),
217 sif->sw_if_index, format_ptx_event, event,
218 format_ptx_sm_state, state, format_ptx_sm_state,
219 transition->next_state, 0);
223 lacp_init_ptx_machine (vlib_main_t * vm, slave_if_t * sif)
225 lacp_machine_dispatch (&lacp_ptx_machine, vm, sif,
226 LACP_PTX_EVENT_NO_PERIODIC, &sif->ptx_state);
230 * fd.io coding-style-patch-verification: ON
233 * eval: (c-set-style "gnu")