FD.io VPP  v21.06-1-gbb7418cf9
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 int
24 {
25  uword p;
26  member_if_t *mif2;
27 
28  /* Handle loopback port */
29  if (!memcmp (mif->partner.system, mif->actor.system, 6) &&
30  (mif->partner.key == mif->actor.key))
31  {
32  mif->loopback_port = 1;
33  mif->actor.state &= ~LACP_STATE_AGGREGATION;
34  mif->selected = LACP_PORT_UNSELECTED;
36  LACP_MUX_EVENT_UNSELECTED, &mif->mux_state);
37  return LACP_ERROR_LOOPBACK_PORT;
38  }
39  if (vec_len (bif->active_members))
40  {
41  p = *vec_elt_at_index (bif->active_members, 0);
43  if (mif2 && ((mif2->partner.key != mif->partner.key) ||
44  memcmp (mif2->partner.system, mif->partner.system, 6)))
45  {
46  mif->selected = LACP_PORT_UNSELECTED;
48  LACP_MUX_EVENT_UNSELECTED, &mif->mux_state);
49  return LACP_ERROR_BAD_KEY;
50  }
51  }
52  mif->selected = LACP_PORT_SELECTED;
53 
54  switch (mif->mux_state)
55  {
56  case LACP_MUX_STATE_DETACHED:
57  break;
58  case LACP_MUX_STATE_WAITING:
59  if (!mif->ready)
60  return LACP_ERROR_NONE;
61  break;
62  case LACP_MUX_STATE_ATTACHED:
63  if (!(mif->partner.state & LACP_STATE_SYNCHRONIZATION))
64  return LACP_ERROR_NONE;
65  break;
66  case LACP_MUX_STATE_COLLECTING_DISTRIBUTING:
67  break;
68  default:
69  break;
70  }
71  return lacp_machine_dispatch (&lacp_mux_machine, vm, mif,
72  LACP_MUX_EVENT_SELECTED, &mif->mux_state);
73 }
74 
75 int
77 {
78  member_if_t *mif2;
79  bond_if_t *bif;
81 
83  vec_foreach (sw_if_index, bif->members)
84  {
85  mif2 = bond_get_member_by_sw_if_index (*sw_if_index);
86  if (mif2 && (mif2->actor.state & LACP_STATE_SYNCHRONIZATION) &&
87  (mif2->ready_n == 0))
88  goto out;
89  }
90 
91  vec_foreach (sw_if_index, bif->members)
92  {
93  mif2 = bond_get_member_by_sw_if_index (*sw_if_index);
94  if (mif2)
95  {
96  mif2->ready = 1;
97  if (mif2->selected == LACP_PORT_SELECTED)
99  LACP_MUX_EVENT_READY, &mif2->mux_state);
100  }
101  }
102 out:
103  return lacp_set_port_selected (vm, bif, mif);
104 }
105 
106 /*
107  * fd.io coding-style-patch-verification: ON
108  *
109  * Local Variables:
110  * eval: (c-set-style "gnu")
111  * End:
112  */
static bond_if_t * bond_get_bond_if_by_dev_instance(u32 dev_instance)
Definition: node.h:517
int selected
Definition: node.h:280
unsigned int u32
Definition: types.h:88
u8 ready_n
Definition: node.h:274
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
lacp_port_info_t partner
Definition: node.h:254
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
u32 * members
Definition: node.h:187
int mux_state
Definition: node.h:315
lacp_machine_t lacp_mux_machine
Definition: mux_machine.c:77
u32 * active_members
Definition: node.h:190
static member_if_t * bond_get_member_by_sw_if_index(u32 sw_if_index)
Definition: node.h:525
u8 ready
Definition: node.h:277
static int lacp_set_port_selected(vlib_main_t *vm, bond_if_t *bif, member_if_t *mif)
Definition: selection.c:23
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
u8 loopback_port
Definition: node.h:325
int lacp_selection_logic(vlib_main_t *vm, member_if_t *mif)
Definition: selection.c:76
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
u32 bif_dev_instance
Definition: node.h:323