summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat44-ed/nat44_ed_out2in.c
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-03-31 13:38:09 +0200
committerOle Tr�an <otroan@employees.org>2021-04-21 09:24:50 +0000
commit1fbf034e3ea97d507e41420248c99da7bdc916bf (patch)
tree772293b463e8924d675e3aa5a211c316d8502245 /src/plugins/nat/nat44-ed/nat44_ed_out2in.c
parent00338e09122e803cb31187cd85af69b8d6dbcb9c (diff)
nat: fix multi worker scenarios
Properly select worker from hash table in out2in direction, increase number of worker threads in MW test to 4 to test these cases. Type: fix Change-Id: I76eda5761ff497b85b031dd913a64b7fcb53b33a Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat44-ed/nat44_ed_out2in.c')
-rw-r--r--src/plugins/nat/nat44-ed/nat44_ed_out2in.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/plugins/nat/nat44-ed/nat44_ed_out2in.c b/src/plugins/nat/nat44-ed/nat44_ed_out2in.c
index f46433c9e53..e8cf7c930fa 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed_out2in.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed_out2in.c
@@ -37,6 +37,15 @@ static char *nat_out2in_ed_error_strings[] = {
#undef _
};
+typedef enum
+{
+ NAT_ED_SP_REASON_NO_REASON,
+ NAT_ED_SP_REASON_LOOKUP_FAILED,
+ NAT_ED_SP_REASON_VRF_EXPIRED,
+ NAT_ED_SP_TCP_CLOSED,
+ NAT_ED_SP_SESS_EXPIRED,
+} nat_slow_path_reason_e;
+
typedef struct
{
u32 sw_if_index;
@@ -49,9 +58,30 @@ typedef struct
u8 is_slow_path;
u8 translation_via_i2of;
u8 lookup_skipped;
+ nat_slow_path_reason_e slow_path_reason;
} nat44_ed_out2in_trace_t;
static u8 *
+format_slow_path_reason (u8 *s, va_list *args)
+{
+ nat_slow_path_reason_e reason = va_arg (*args, nat_slow_path_reason_e);
+ switch (reason)
+ {
+ case NAT_ED_SP_REASON_NO_REASON:
+ return format (s, "no reason for slow path");
+ case NAT_ED_SP_REASON_LOOKUP_FAILED:
+ return format (s, "slow path because lookup failed");
+ case NAT_ED_SP_REASON_VRF_EXPIRED:
+ return format (s, "slow path because vrf expired");
+ case NAT_ED_SP_TCP_CLOSED:
+ return format (s, "slow path because tcp closed");
+ case NAT_ED_SP_SESS_EXPIRED:
+ return format (s, "slow path because session expired");
+ }
+ return format (s, "invalid reason value");
+}
+
+static u8 *
format_nat44_ed_out2in_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -85,6 +115,7 @@ format_nat44_ed_out2in_trace (u8 * s, va_list * args)
s = format (s, "\n search key %U", format_ed_session_kvp,
&t->search_key);
}
+ s = format (s, "\n %U", format_slow_path_reason, t->slow_path_reason);
}
return s;
@@ -790,6 +821,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
snat_session_t *s0 = 0;
clib_bihash_kv_16_8_t kv0, value0;
nat_translation_error_e translation_error = NAT_ED_TRNSL_ERR_SUCCESS;
+ nat_slow_path_reason_e slow_path_reason = NAT_ED_SP_REASON_NO_REASON;
nat_6t_flow_t *f = 0;
nat_6t_t lookup;
int lookup_skipped = 0;
@@ -891,6 +923,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
if (clib_bihash_search_16_8 (&sm->flow_hash, &kv0, &value0))
{
// flow does not exist go slow path
+ slow_path_reason = NAT_ED_SP_REASON_LOOKUP_FAILED;
next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
goto trace0;
}
@@ -905,6 +938,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
// session is closed, go slow path
nat_free_session_data (sm, s0, thread_index, 0);
nat_ed_session_delete (sm, s0, thread_index, 1);
+ slow_path_reason = NAT_ED_SP_REASON_VRF_EXPIRED;
next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
goto trace0;
}
@@ -914,6 +948,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
if (now >= s0->tcp_closed_timestamp)
{
// session is closed, go slow path, freed in slow path
+ slow_path_reason = NAT_ED_SP_TCP_CLOSED;
next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
}
else
@@ -934,6 +969,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
// session is closed, go slow path
nat_free_session_data (sm, s0, thread_index, 0);
nat_ed_session_delete (sm, s0, thread_index, 1);
+ slow_path_reason = NAT_ED_SP_SESS_EXPIRED;
next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
goto trace0;
}
@@ -1042,6 +1078,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
t->translation_error = translation_error;
clib_memcpy (&t->search_key, &kv0, sizeof (t->search_key));
t->lookup_skipped = lookup_skipped;
+ t->slow_path_reason = slow_path_reason;
if (s0)
{
.mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file
 * @brief LLDP global declarations
 */
#ifndef __included_lldp_node_h__
#define __included_lldp_node_h__

#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/snap/snap.h>
#include <vppinfra/format.h>
#include <vppinfra/hash.h>

#include <vnet/lldp/lldp_protocol.h>

typedef struct lldp_intf
{
  /* hw interface index */
  u32 hw_if_index;

  /* Timers */
  f64 last_heard;
  f64 last_sent;

  /* Info received from peer */
  u8 *chassis_id;
  u8 *port_id;
  u16 ttl;
  lldp_port_id_subtype_t port_id_subtype;
  lldp_chassis_id_subtype_t chassis_id_subtype;

  /* Local info */
  u8 *port_desc;

  /* management ipv4 address */
  u8 *mgmt_ip4;

  /* management ipv6 address */
  u8 *mgmt_ip6;

  /* management object identifier */
  u8 *mgmt_oid;
} lldp_intf_t;

typedef struct
{
  /* pool of lldp-enabled interface context data */
  lldp_intf_t *intfs;

  /* rapidly find an interface by vlib hw interface index */
  uword *intf_by_hw_if_index;

  /* Background process node index */
  u32 lldp_process_node_index;

  /* interface idxs (into intfs pool) in the order of timing out */
  u32 *intfs_timeouts;

  /* index of the interface which will time out next */
  u32 intfs_timeouts_idx;

  /* packet template for sending out packets */
  vlib_packet_template_t packet_template;

  /* convenience variables */
  vlib_main_t *vlib_main;
  vnet_main_t *vnet_main;

  /* system name advertised over LLDP (default is none) */
  u8 *sys_name;

  /* IEEE Std 802.1AB-2009:
   * 9.2.5.6 msgTxHold
   * This variable is used, as a multiplier of msgTxInterval, to determine the
   * value of txTTL that is carried in LLDP frames transmitted by the LLDP
   * agent. The recommended default value of msgTxHold is 4; this value can
   * be changed by management to any value in the range 1 through 100.
   */
  u8 msg_tx_hold;

  /* IEEE Std 802.1AB-2009:
   * 9.2.5.7 msgTxInterval
   * This variable defines the time interval in timer ticks between
   * transmissions during normal transmission periods (i.e., txFast is zero).
   * The recommended default value for msgTxInterval is 30 s; this value can
   * be changed by management to any value in the range 1 through 3600.
   */
  u16 msg_tx_interval;
} lldp_main_t;

#define LLDP_MIN_TX_HOLD (1)
#define LLDP_MAX_TX_HOLD (100)
#define LLDP_MIN_TX_INTERVAL (1)
#define LLDP_MAX_TX_INTERVAL (3600)

extern lldp_main_t lldp_main;

/* Packet counters */
#define foreach_lldp_error(F)                     \
    F(NONE, "good lldp packets (processed)")      \
    F(CACHE_HIT, "good lldp packets (cache hit)") \
    F(BAD_TLV, "lldp packets with bad TLVs")      \
    F(DISABLED, "lldp packets received on disabled interfaces")

typedef enum
{
#define F(sym, str) LLDP_ERROR_##sym,
  foreach_lldp_error (F)
#undef F
    LLDP_N_ERROR,
} lldp_error_t;

/* lldp packet trace capture */
typedef struct
{
  u32 len;
  u8 data[400];
} lldp_input_trace_t;

enum
{
  LLDP_EVENT_RESCHEDULE = 1,
} lldp_process_event_t;

lldp_intf_t *lldp_get_intf (lldp_main_t * lm, u32 hw_if_index);
lldp_intf_t *lldp_create_intf (lldp_main_t * lm, u32 hw_if_index);
void lldp_delete_intf (lldp_main_t * lm, lldp_intf_t * n);
lldp_error_t lldp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0);
u8 *lldp_input_format_trace (u8 * s, va_list * args);
void lldp_send_ethernet (lldp_main_t * lm, lldp_intf_t * n, int shutdown);
void lldp_schedule_intf (lldp_main_t * lm, lldp_intf_t * n);
void lldp_unschedule_intf (lldp_main_t * lm, lldp_intf_t * n);

#endif /* __included_lldp_node_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */