FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
selection.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 #include <stdint.h>
17 #include <vlib/vlib.h>
18 #include <vlib/unix/unix.h>
19 #include <vnet/bonding/node.h>
20 #include <lacp/node.h>
21 
22 static void
24 {
25  /* Handle loopback port */
26  if (!memcmp (mif->partner.system, mif->actor.system, 6) &&
27  (mif->partner.key == mif->actor.key))
28  {
29  mif->loopback_port = 1;
30  mif->actor.state &= ~LACP_STATE_AGGREGATION;
31  }
32  mif->selected = LACP_PORT_SELECTED;
33 
34  switch (mif->mux_state)
35  {
36  case LACP_MUX_STATE_DETACHED:
37  break;
38  case LACP_MUX_STATE_WAITING:
39  if (!mif->ready)
40  return;
41  break;
42  case LACP_MUX_STATE_ATTACHED:
43  if (!(mif->partner.state & LACP_STATE_SYNCHRONIZATION))
44  return;
45  break;
46  case LACP_MUX_STATE_COLLECTING_DISTRIBUTING:
47  break;
48  default:
49  break;
50  }
51  lacp_machine_dispatch (&lacp_mux_machine, vm, mif, LACP_MUX_EVENT_SELECTED,
52  &mif->mux_state);
53 }
54 
55 void
57 {
58  member_if_t *mif2;
59  bond_if_t *bif;
61 
63  vec_foreach (sw_if_index, bif->members)
64  {
65  mif2 = bond_get_member_by_sw_if_index (*sw_if_index);
66  if (mif2 && (mif2->actor.state & LACP_STATE_SYNCHRONIZATION) &&
67  (mif2->ready_n == 0))
68  goto out;
69  }
70 
71  vec_foreach (sw_if_index, bif->members)
72  {
73  mif2 = bond_get_member_by_sw_if_index (*sw_if_index);
74  if (mif2)
75  {
76  mif2->ready = 1;
77  if (mif2->selected == LACP_PORT_SELECTED)
79  LACP_MUX_EVENT_READY, &mif2->mux_state);
80  }
81  }
82 out:
83  lacp_set_port_selected (vm, mif);
84 }
85 
86 /*
87  * fd.io coding-style-patch-verification: ON
88  *
89  * Local Variables:
90  * eval: (c-set-style "gnu")
91  * End:
92  */
void lacp_selection_logic(vlib_main_t *vm, member_if_t *mif)
Definition: selection.c:56
static bond_if_t * bond_get_bond_if_by_dev_instance(u32 dev_instance)
Definition: node.h:517
vlib_main_t * vm
Definition: in2out_ed.c:1582
int selected
Definition: node.h:280
u8 ready_n
Definition: node.h:274
unsigned int u32
Definition: types.h:88
lacp_port_info_t partner
Definition: node.h:254
u32 * members
Definition: node.h:187
int mux_state
Definition: node.h:315
lacp_machine_t lacp_mux_machine
Definition: mux_machine.c:77
static member_if_t * bond_get_member_by_sw_if_index(u32 sw_if_index)
Definition: node.h:525
static void lacp_set_port_selected(vlib_main_t *vm, member_if_t *mif)
Definition: selection.c:23
u8 ready
Definition: node.h:277
u8 loopback_port
Definition: node.h:325
int lacp_machine_dispatch(lacp_machine_t *machine, vlib_main_t *vm, member_if_t *mif, int event, int *state)
Definition: lacp.c:317
#define vec_foreach(var, vec)
Vector iterator.
lacp_port_info_t actor
Definition: node.h:255
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
u32 bif_dev_instance
Definition: node.h:323