FD.io VPP  v21.06-3-gbb25fbf28
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  }
72  LACP_MUX_EVENT_SELECTED, &mif->mux_state);
73 }
74 
75 int
77 {
78  member_if_t *mif2;
79  bond_if_t *bif;
81 
84  {
86  if (mif2 && (mif2->actor.state & LACP_STATE_SYNCHRONIZATION) &&
87  (mif2->ready_n == 0))
88  goto out;
89  }
90 
92  {
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  */
vlib.h
lacp_set_port_selected
static int lacp_set_port_selected(vlib_main_t *vm, bond_if_t *bif, member_if_t *mif)
Definition: selection.c:23
bond_get_bond_if_by_dev_instance
static bond_if_t * bond_get_bond_if_by_dev_instance(u32 dev_instance)
Definition: node.h:517
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
bond_if_t
Definition: node.h:168
member_if_t::loopback_port
u8 loopback_port
Definition: node.h:325
member_if_t::mux_state
int mux_state
Definition: node.h:315
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
member_if_t::partner
lacp_port_info_t partner
Definition: node.h:254
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
bond_if_t::members
u32 * members
Definition: node.h:187
uword
u64 uword
Definition: types.h:112
member_if_t::actor
lacp_port_info_t actor
Definition: node.h:255
node.h
lacp_mux_machine
lacp_machine_t lacp_mux_machine
Definition: mux_machine.c:77
member_if_t::selected
int selected
Definition: node.h:280
lacp_machine_dispatch
int lacp_machine_dispatch(lacp_machine_t *machine, vlib_main_t *vm, member_if_t *mif, int event, int *state)
Definition: lacp.c:317
member_if_t
Definition: node.h:213
member_if_t::ready
u8 ready
Definition: node.h:277
u32
unsigned int u32
Definition: types.h:88
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
lacp_selection_logic
int lacp_selection_logic(vlib_main_t *vm, member_if_t *mif)
Definition: selection.c:76
member_if_t::bif_dev_instance
u32 bif_dev_instance
Definition: node.h:323
bond_get_member_by_sw_if_index
static member_if_t * bond_get_member_by_sw_if_index(u32 sw_if_index)
Definition: node.h:525
vlib_main_t
Definition: main.h:102
unix.h
bond_if_t::active_members
u32 * active_members
Definition: node.h:190
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
member_if_t::ready_n
u8 ready_n
Definition: node.h:274
node.h