The native userspace tunnel neighbor cache extends a complete entry's lifetime whenever it is used. An idle entry is instead removed when its aging timer expires. The first packet after removal is dropped while OVS resolves the neighbor again.
Refresh complete entries before they expire while keeping the cached MAC usable. Start up to three retransmission intervals before expiration, capped at half the aging interval, and retry at the retransmission interval while the entry remains valid. The cap prevents immediate repeated probes when aging and retransmission intervals are equal. Unanswered entries still expire at their original deadline. Check the cache deadline in the ofproto run loop and scan the table when an event is due. Send ARP or Neighbor Discovery requests through the bridge pipeline outside the neighbor mutex. Refresh learned entries on their original interface to preserve policy-routing context. For manually inserted entries, select a suitable IP interface on their bridge. Show entries being refreshed in tnl/neigh/show. Process each snooped neighbor reply in userspace so identical replies renew the entry even when they match a cached datapath flow. Renew the aging deadline on neighbor learning, rather than cache lookup. Remove the now-unused XC_TNL_NEIGH statistics bookkeeping. Cold entries, flushed entries, and entries lost on restart still require resolution and can drop their triggering packet. Add IPv4 and IPv6 tests covering proactive refresh, retries, actual tunnel forwarding while refresh is pending and after renewal, and expiration without a reply. Also cover equal timers, source-based routing with two VTEPs, and learned and manual entries on a non-local tunnel endpoint. Verify that a changed neighbor MAC invalidates existing datapath actions and that unanswered expiration invalidates them even with ongoing traffic. Assisted-by: GPT-6, OpenAI Codex Signed-off-by: Tim Rozet <[email protected]> --- v4: - Move cache maintenance and refresh to the ofproto run and wait loops. Share ARP/ND packet injection with cold resolution while preserving translation limits (Eelco). - Tidy entry initialization and refresh queue locking, relax timer atomics, widen the retry calculation, and skip empty-table wakeups (Eelco). Keep release/acquire on publication of a newly learned MAC. - Show REFRESHING in tnl/neigh/show and use grep -q in the tunnel tests (Mike). - Process repeated ARP replies and Neighbor Advertisements even when a datapath flow matches. Test that they renew the cached entry. - Cover loss of the learned port when another port can reach the same subnet. Keep the cached MAC until expiry and retry on the learned interface to preserve the original VLAN. v3 review: https://mail.openvswitch.org/pipermail/ovs-dev/2026-October/437534.html https://mail.openvswitch.org/pipermail/ovs-dev/2026-November/438134.html v3: - Replace stale-entry retention with proactive ARP/ND refresh. - Schedule up to three probes before expiration, retaining the cached MAC while awaiting a reply. - Preserve the learned interface for policy-routed tunnels. - Remove obsolete neighbor lookup statistics bookkeeping. - Test cached datapath forwarding after MAC changes and invalidate cached actions on unanswered expiration, addressing Eelco's concern. - Freeze test clocks and avoid immediate wakeups for queued probes. Previous discussion: https://mail.openvswitch.org/pipermail/ovs-dev/2026-September/436265.html lib/dpif-netdev.c | 2 - lib/tnl-neigh-cache.c | 262 +++++++++++++++++++++-------- lib/tnl-neigh-cache.h | 8 +- ofproto/ofproto-dpif-xlate-cache.c | 11 -- ofproto/ofproto-dpif-xlate-cache.h | 5 - ofproto/ofproto-dpif-xlate.c | 127 +++++++++----- ofproto/ofproto-dpif-xlate.h | 1 + ofproto/ofproto-dpif.c | 10 +- ofproto/ofproto-tnl-unixctl.man | 7 +- tests/tunnel-push-pop-ipv6.at | 115 ++++++++++++- tests/tunnel-push-pop.at | 184 +++++++++++++++++++- 11 files changed, 594 insertions(+), 138 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4151ea056..edf6df48f 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -82,7 +82,6 @@ #include "smap.h" #include "sset.h" #include "timeval.h" -#include "tnl-neigh-cache.h" #include "tnl-ports.h" #include "unixctl.h" #include "util.h" @@ -5915,7 +5914,6 @@ dpif_netdev_run(struct dpif *dpif) } ovs_rwlock_unlock(&dp->port_rwlock); - tnl_neigh_cache_run(); tnl_port_map_run(); new_tnl_seq = seq_read(tnl_conf_seq); diff --git a/lib/tnl-neigh-cache.c b/lib/tnl-neigh-cache.c index fbefc3d51..a2dac7116 100644 --- a/lib/tnl-neigh-cache.c +++ b/lib/tnl-neigh-cache.c @@ -33,6 +33,7 @@ #include "flow.h" #include "netdev.h" #include "ovs-atomic.h" +#include "openvswitch/list.h" #include "ovs-thread.h" #include "packets.h" #include "openvswitch/poll-loop.h" @@ -51,17 +52,24 @@ struct tnl_neigh_entry { struct cmap_node cmap_node; + struct ovs_list refresh_node; struct in6_addr ip; struct eth_addr mac; atomic_llong expires; /* Expiration time in ms. */ + long long refresh_at; /* Next probe, protected by mutex. */ char br_name[IFNAMSIZ]; + char dev_name[IFNAMSIZ]; /* IP interface used to learn the neighbor. */ atomic_bool complete; + bool refreshing; /* Refresh started since last learning. */ }; static struct cmap table = CMAP_INITIALIZER; static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; +static struct ovs_list refresh_list OVS_GUARDED_BY(mutex) + = OVS_LIST_INITIALIZER(&refresh_list); static atomic_uint32_t neigh_aging; static atomic_uint32_t neigh_retrans_time; +static atomic_llong next_event; static uint32_t tnl_neigh_hash(const struct in6_addr *ip) @@ -74,7 +82,7 @@ tnl_neigh_expired(struct tnl_neigh_entry *neigh) { long long expires; - atomic_read_explicit(&neigh->expires, &expires, memory_order_acquire); + atomic_read_relaxed(&neigh->expires, &expires); return expires <= time_msec(); } @@ -84,7 +92,7 @@ tnl_neigh_get_aging(void) { unsigned int aging; - atomic_read_explicit(&neigh_aging, &aging, memory_order_acquire); + atomic_read_relaxed(&neigh_aging, &aging); return aging; } @@ -93,11 +101,33 @@ tnl_neigh_get_retrans_time(void) { unsigned int retrans_time; - atomic_read_explicit(&neigh_retrans_time, &retrans_time, - memory_order_acquire); + atomic_read_relaxed(&neigh_retrans_time, &retrans_time); return retrans_time; } +static void +tnl_neigh_schedule(long long deadline) + OVS_REQUIRES(mutex) +{ + long long next; + + atomic_read_relaxed(&next_event, &next); + if (deadline < next) { + atomic_store_relaxed(&next_event, deadline); + } +} + +static long long +tnl_neigh_refresh_deadline(long long expires) +{ + uint32_t refresh_time = tnl_neigh_get_retrans_time(); + + /* Leave time for two retries when the intervals permit, but always give + * a learned entry at least half its lifetime before probing again, + * including when aging == retrans. */ + return expires - MIN(3LL * refresh_time, tnl_neigh_get_aging() / 2); +} + static bool tnl_neigh_is_complete(struct tnl_neigh_entry *neigh) { @@ -120,12 +150,6 @@ tnl_neigh_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst) return NULL; } - if (tnl_neigh_is_complete(neigh)) { - atomic_store_explicit(&neigh->expires, - time_msec() + tnl_neigh_get_aging(), - memory_order_release); - } - return neigh; } } @@ -136,6 +160,7 @@ static void tnl_neigh_set_partial(const char name[IFNAMSIZ], const struct in6_addr *dst) { ovs_mutex_lock(&mutex); + long long expires = time_msec() + tnl_neigh_get_retrans_time(); struct tnl_neigh_entry *neigh = tnl_neigh_lookup__(name, dst); if (neigh) { /* Entry inserted before lock taken. */ @@ -147,10 +172,14 @@ tnl_neigh_set_partial(const char name[IFNAMSIZ], const struct in6_addr *dst) neigh->ip = *dst; atomic_store_relaxed(&neigh->complete, false); - atomic_store_relaxed(&neigh->expires, - time_msec() + tnl_neigh_get_retrans_time()); + atomic_store_relaxed(&neigh->expires, expires); + neigh->refresh_at = LLONG_MAX; + neigh->refreshing = false; ovs_strlcpy(neigh->br_name, name, sizeof neigh->br_name); + neigh->dev_name[0] = '\0'; + ovs_list_init(&neigh->refresh_node); cmap_insert(&table, &neigh->cmap_node, tnl_neigh_hash(&neigh->ip)); + tnl_neigh_schedule(expires); ovs_mutex_unlock(&mutex); seq_change(tnl_conf_seq); @@ -185,67 +214,80 @@ neigh_entry_free(struct tnl_neigh_entry *neigh) free(neigh); } +static void +tnl_neigh_cancel_refresh(struct tnl_neigh_entry *neigh) + OVS_REQUIRES(mutex) +{ + if (!ovs_list_is_empty(&neigh->refresh_node)) { + ovs_list_remove(&neigh->refresh_node); + ovs_list_init(&neigh->refresh_node); + } +} + static void tnl_neigh_delete(struct tnl_neigh_entry *neigh) + OVS_REQUIRES(mutex) { uint32_t hash = tnl_neigh_hash(&neigh->ip); + + tnl_neigh_cancel_refresh(neigh); cmap_remove(&table, &neigh->cmap_node, hash); ovsrcu_postpone(neigh_entry_free, neigh); } void -tnl_neigh_set(const char name[IFNAMSIZ], const struct in6_addr *dst, - const struct eth_addr mac) +tnl_neigh_set(const char name[IFNAMSIZ], const char dev_name[IFNAMSIZ], + const struct in6_addr *dst, const struct eth_addr mac) { ovs_mutex_lock(&mutex); + long long expires = time_msec() + tnl_neigh_get_aging(); struct tnl_neigh_entry *neigh = tnl_neigh_lookup__(name, dst); - bool insert = true; + bool complete = neigh && tnl_neigh_is_complete(neigh); - if (neigh) { - if (!tnl_neigh_is_complete(neigh)) { - insert = false; - } else if (eth_addr_equals(neigh->mac, mac)) { - atomic_store_relaxed(&neigh->expires, - time_msec() + tnl_neigh_get_aging()); - ovs_mutex_unlock(&mutex); - return; - } else { - tnl_neigh_delete(neigh); - } + if (complete && !eth_addr_equals(neigh->mac, mac)) { + tnl_neigh_delete(neigh); + neigh = NULL; + complete = false; } + bool insert = !neigh; if (insert) { neigh = xmalloc(sizeof *neigh); - neigh->ip = *dst; ovs_strlcpy(neigh->br_name, name, sizeof neigh->br_name); + neigh->dev_name[0] = '\0'; + ovs_list_init(&neigh->refresh_node); + } else { + tnl_neigh_cancel_refresh(neigh); } - neigh->mac = mac; - atomic_store_explicit(&neigh->expires, - time_msec() + tnl_neigh_get_aging(), - memory_order_release); - atomic_store_explicit(&neigh->complete, true, memory_order_release); - - if (insert) { - cmap_insert(&table, &neigh->cmap_node, tnl_neigh_hash(&neigh->ip)); + if (dev_name && dev_name[0]) { + ovs_strlcpy(neigh->dev_name, dev_name, sizeof neigh->dev_name); + } + atomic_store_relaxed(&neigh->expires, expires); + neigh->refreshing = false; + neigh->refresh_at = tnl_neigh_refresh_deadline(expires); + tnl_neigh_schedule(neigh->refresh_at); + + if (!complete) { + neigh->mac = mac; + /* Lockless readers can use the MAC once they see a complete entry. */ + atomic_store_explicit(&neigh->complete, true, memory_order_release); + if (insert) { + cmap_insert(&table, &neigh->cmap_node, tnl_neigh_hash(dst)); + } } - ovs_mutex_unlock(&mutex); - seq_change(tnl_conf_seq); -} -static void -tnl_arp_set(const char name[IFNAMSIZ], ovs_be32 dst, - const struct eth_addr mac) -{ - struct in6_addr dst6 = in6_addr_mapped_ipv4(dst); - tnl_neigh_set(name, &dst6, mac); + if (!complete) { + seq_change(tnl_conf_seq); + } } static int tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, - const char name[IFNAMSIZ], bool allow_update) + const char name[IFNAMSIZ], const char dev_name[IFNAMSIZ], + bool allow_update) { /* Snoop normal ARP replies and gratuitous ARP requests/replies only */ if (!is_arp(flow) @@ -258,14 +300,17 @@ tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src); if (allow_update) { - tnl_arp_set(name, flow->nw_src, flow->arp_sha); + struct in6_addr dst = in6_addr_mapped_ipv4(flow->nw_src); + + tnl_neigh_set(name, dev_name, &dst, flow->arp_sha); } return 0; } static int tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc, - const char name[IFNAMSIZ], bool allow_update) + const char name[IFNAMSIZ], const char dev_name[IFNAMSIZ], + bool allow_update) { if (!is_nd(flow, wc) || flow->tp_src != htons(ND_NEIGHBOR_ADVERT)) { return EINVAL; @@ -285,36 +330,63 @@ tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc, memset(&wc->masks.nd_target, 0xff, sizeof wc->masks.nd_target); if (allow_update) { - tnl_neigh_set(name, &flow->nd_target, flow->arp_tha); + tnl_neigh_set(name, dev_name, &flow->nd_target, flow->arp_tha); } return 0; } int tnl_neigh_snoop(const struct flow *flow, struct flow_wildcards *wc, - const char name[IFNAMSIZ], bool allow_update) + const char name[IFNAMSIZ], const char dev_name[IFNAMSIZ], + bool allow_update) { int res; - res = tnl_arp_snoop(flow, wc, name, allow_update); + res = tnl_arp_snoop(flow, wc, name, dev_name, allow_update); if (res != EINVAL) { return res; } - return tnl_nd_snoop(flow, wc, name, allow_update); + return tnl_nd_snoop(flow, wc, name, dev_name, allow_update); } void tnl_neigh_cache_run(void) { struct tnl_neigh_entry *neigh; + long long wakeup = LLONG_MAX; + long long now = time_msec(); + long long scheduled; + uint32_t refresh_time; bool changed = false; + atomic_read_relaxed(&next_event, &scheduled); + if (scheduled > now) { + return; + } + + refresh_time = tnl_neigh_get_retrans_time(); ovs_mutex_lock(&mutex); CMAP_FOR_EACH(neigh, cmap_node, &table) { - if (tnl_neigh_expired(neigh)) { + long long expires; + + atomic_read_relaxed(&neigh->expires, &expires); + if (expires <= now) { tnl_neigh_delete(neigh); changed = true; + continue; + } + + if (tnl_neigh_is_complete(neigh) && refresh_time + && ovs_list_is_empty(&neigh->refresh_node)) { + if (neigh->refresh_at <= now) { + neigh->refreshing = true; + ovs_list_push_back(&refresh_list, &neigh->refresh_node); + } else { + expires = MIN(expires, neigh->refresh_at); + } } + wakeup = MIN(wakeup, expires); } + atomic_store_relaxed(&next_event, wakeup); ovs_mutex_unlock(&mutex); if (changed) { @@ -322,6 +394,47 @@ tnl_neigh_cache_run(void) } } +/* Removes one pending refresh and copies its bridge, IP interface and + * destination. Returns false if no refresh is pending. */ +bool +tnl_neigh_get_refresh(char br_name[IFNAMSIZ], char dev_name[IFNAMSIZ], + struct in6_addr *dst) + OVS_EXCLUDED(mutex) +{ + struct tnl_neigh_entry *neigh; + bool found = false; + + ovs_mutex_lock(&mutex); + if (!ovs_list_is_empty(&refresh_list)) { + neigh = CONTAINER_OF(ovs_list_pop_front(&refresh_list), + struct tnl_neigh_entry, refresh_node); + ovs_list_init(&neigh->refresh_node); + + /* Space retries from the attempt, even if the probe waited in the + * queue or the learned interface is temporarily unavailable. */ + neigh->refresh_at = time_msec() + tnl_neigh_get_retrans_time(); + tnl_neigh_schedule(neigh->refresh_at); + ovs_strlcpy(br_name, neigh->br_name, IFNAMSIZ); + ovs_strlcpy(dev_name, neigh->dev_name, IFNAMSIZ); + *dst = neigh->ip; + found = true; + } + ovs_mutex_unlock(&mutex); + + return found; +} + +void +tnl_neigh_cache_wait(void) +{ + long long wakeup; + + atomic_read_relaxed(&next_event, &wakeup); + if (wakeup != LLONG_MAX) { + poll_timer_wait_until(wakeup); + } +} + void tnl_neigh_flush(const char br_name[IFNAMSIZ]) { @@ -392,17 +505,22 @@ tnl_neigh_cache_aging(struct unixctl_conn *conn, int argc, return; } - atomic_store_explicit(&neigh_aging, aging, memory_order_release); + atomic_store_relaxed(&neigh_aging, aging); new_exp = time_msec() + aging; + ovs_mutex_lock(&mutex); CMAP_FOR_EACH (neigh, cmap_node, &table) { - atomic_read_explicit(&neigh->expires, &curr_exp, - memory_order_acquire); + atomic_read_relaxed(&neigh->expires, &curr_exp); if (new_exp < curr_exp) { - atomic_store_explicit(&neigh->expires, new_exp, - memory_order_release); + atomic_store_relaxed(&neigh->expires, new_exp); + curr_exp = new_exp; } + neigh->refresh_at = tnl_neigh_refresh_deadline(curr_exp); } + if (!cmap_is_empty(&table)) { + tnl_neigh_schedule(time_msec()); + } + ovs_mutex_unlock(&mutex); unixctl_command_reply(conn, "OK"); } @@ -434,21 +552,26 @@ tnl_neigh_cache_retrans_time(struct unixctl_conn *conn, int argc, return; } - atomic_store_explicit(&neigh_retrans_time, retrans_time, - memory_order_release); + atomic_store_relaxed(&neigh_retrans_time, retrans_time); new_exp = time_msec() + retrans_time; + ovs_mutex_lock(&mutex); CMAP_FOR_EACH (neigh, cmap_node, &table) { - if (tnl_neigh_is_complete(neigh)) { - continue; + atomic_read_relaxed(&neigh->expires, &curr_exp); + if (!tnl_neigh_is_complete(neigh) && new_exp < curr_exp) { + atomic_store_relaxed(&neigh->expires, new_exp); + curr_exp = new_exp; } - atomic_read_explicit(&neigh->expires, &curr_exp, - memory_order_acquire); - if (new_exp < curr_exp) { - atomic_store_explicit(&neigh->expires, new_exp, - memory_order_release); + if (!retrans_time) { + tnl_neigh_cancel_refresh(neigh); + neigh->refreshing = false; } + neigh->refresh_at = tnl_neigh_refresh_deadline(curr_exp); } + if (!cmap_is_empty(&table)) { + tnl_neigh_schedule(time_msec()); + } + ovs_mutex_unlock(&mutex); unixctl_command_reply(conn, "OK"); } @@ -488,7 +611,7 @@ tnl_neigh_cache_add(struct unixctl_conn *conn, int argc OVS_UNUSED, return; } - tnl_neigh_set(br_name, &ip6, mac); + tnl_neigh_set(br_name, NULL, &ip6, mac); unixctl_command_reply(conn, "OK"); } @@ -519,7 +642,9 @@ tnl_neigh_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED, neigh->br_name); } if (tnl_neigh_expired(neigh)) { - ds_put_format(&ds, " STALE"); + ds_put_cstr(&ds, " STALE"); + } else if (neigh->refreshing) { + ds_put_cstr(&ds, " REFRESHING"); } ds_put_char(&ds, '\n'); @@ -534,6 +659,7 @@ tnl_neigh_cache_init(void) { atomic_init(&neigh_aging, NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS); atomic_init(&neigh_retrans_time, NEIGH_ENTRY_LOOKUP_RETRANS_TIME); + atomic_init(&next_event, LLONG_MAX); unixctl_command_register("tnl/arp/show", "", 0, 0, tnl_neigh_cache_show, NULL); unixctl_command_register("tnl/arp/set", "BRIDGE IP MAC", 3, 3, diff --git a/lib/tnl-neigh-cache.h b/lib/tnl-neigh-cache.h index e16155b4d..7e40ebed2 100644 --- a/lib/tnl-neigh-cache.h +++ b/lib/tnl-neigh-cache.h @@ -32,13 +32,17 @@ #include "util.h" int tnl_neigh_snoop(const struct flow *flow, struct flow_wildcards *wc, + const char br_name[IFNAMSIZ], const char dev_name[IFNAMSIZ], bool allow_update); -void tnl_neigh_set(const char name[IFNAMSIZ], const struct in6_addr *dst, - const struct eth_addr mac); +void tnl_neigh_set(const char name[IFNAMSIZ], const char dev_name[IFNAMSIZ], + const struct in6_addr *dst, const struct eth_addr mac); int tnl_neigh_lookup(const char dev_name[IFNAMSIZ], const struct in6_addr *dst, struct eth_addr *mac, bool insert_partial); void tnl_neigh_cache_init(void); void tnl_neigh_cache_run(void); +bool tnl_neigh_get_refresh(char br_name[IFNAMSIZ], char dev_name[IFNAMSIZ], + struct in6_addr *dst); +void tnl_neigh_cache_wait(void); void tnl_neigh_flush(const char dev_name[IFNAMSIZ]); #endif diff --git a/ofproto/ofproto-dpif-xlate-cache.c b/ofproto/ofproto-dpif-xlate-cache.c index cb37e2462..ac170fba4 100644 --- a/ofproto/ofproto-dpif-xlate-cache.c +++ b/ofproto/ofproto-dpif-xlate-cache.c @@ -43,7 +43,6 @@ #include "openvswitch/vlog.h" #include "ovs-router.h" #include "packets.h" -#include "tnl-neigh-cache.h" #include "util.h" VLOG_DEFINE_THIS_MODULE(ofproto_xlate_cache); @@ -92,8 +91,6 @@ void xlate_push_stats_entry(struct xc_entry *entry, struct dpif_flow_stats *stats, bool offloaded) { - struct eth_addr dmac; - switch (entry->type) { case XC_TABLE: ofproto_dpif_credit_table_stats(entry->table.ofproto, @@ -149,11 +146,6 @@ xlate_push_stats_entry(struct xc_entry *entry, group_dpif_credit_stats(entry->group.group, entry->group.bucket, stats); break; - case XC_TNL_NEIGH: - /* Lookup neighbor to avoid timeout. */ - tnl_neigh_lookup(entry->tnl_neigh_cache.br_name, - &entry->tnl_neigh_cache.d_ipv6, &dmac, false); - break; case XC_TUNNEL_HEADER: if (entry->tunnel_hdr.operation == ADD) { stats->n_bytes += stats->n_packets * entry->tunnel_hdr.hdr_size; @@ -241,8 +233,6 @@ xlate_cache_clear_entry(struct xc_entry *entry) case XC_GROUP: ofproto_group_unref(&entry->group.group->up); break; - case XC_TNL_NEIGH: - break; case XC_TUNNEL_HEADER: break; default: @@ -348,7 +338,6 @@ xlate_xcache_format(struct ds *s, const struct xlate_cache *xcache) case XC_LEARN: case XC_NORMAL: case XC_FIN_TIMEOUT: - case XC_TNL_NEIGH: case XC_TUNNEL_HEADER: break; } diff --git a/ofproto/ofproto-dpif-xlate-cache.h b/ofproto/ofproto-dpif-xlate-cache.h index e701734d7..adcd6856f 100644 --- a/ofproto/ofproto-dpif-xlate-cache.h +++ b/ofproto/ofproto-dpif-xlate-cache.h @@ -51,7 +51,6 @@ enum xc_type { XC_NORMAL, XC_FIN_TIMEOUT, /* Calls back to ofproto. */ XC_GROUP, - XC_TNL_NEIGH, XC_TUNNEL_HEADER, }; @@ -111,10 +110,6 @@ struct xc_entry { struct group_dpif *group; struct ofputil_bucket *bucket; } group; - struct { - char br_name[IFNAMSIZ]; - struct in6_addr d_ipv6; - } tnl_neigh_cache; struct { struct ofproto_dpif *ofproto; struct ofproto_async_msg *am; diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 4e7d6fb40..77e935d99 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -3758,57 +3758,101 @@ tnl_route_lookup_flow(const struct xlate_ctx *ctx, return -ENOENT; } -static int -compose_table_xlate(struct xlate_ctx *ctx, const struct xport *out_dev, - struct dp_packet *packet) +static void +xlate_send_packet_pipeline(const struct xport *out_dev, + struct dp_packet *packet, int depth, int resubmits) { struct xbridge *xbridge = out_dev->xbridge; ovs_version_t version = ofproto_dpif_get_tables_version(xbridge->ofproto); struct ofpact_output output; struct flow flow; - if (!xlate_resubmit_resource_check(ctx)) { - return 0; - } - ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output); flow_extract(packet, &flow); flow.in_port.ofp_port = out_dev->ofp_port; output.port = OFPP_TABLE; output.max_len = 0; - return ofproto_dpif_execute_actions__(xbridge->ofproto, version, &flow, - NULL, &output.ofpact, sizeof output, - ctx->depth + 1, ctx->resubmits, - packet); + ofproto_dpif_execute_actions__(xbridge->ofproto, version, &flow, NULL, + &output.ofpact, sizeof output, + depth, resubmits, packet); } static void -tnl_send_nd_request(struct xlate_ctx *ctx, const struct xport *out_dev, - const struct eth_addr eth_src, - struct in6_addr * ipv6_src, struct in6_addr * ipv6_dst) +tnl_send_neigh_request(const struct xport *out_dev, struct eth_addr smac, + const struct in6_addr *src, const struct in6_addr *dst, + int depth, int resubmits) { struct dp_packet packet; dp_packet_init(&packet, 0); - compose_nd_ns(&packet, true, eth_src, eth_addr_zero, ipv6_src, ipv6_dst); - compose_table_xlate(ctx, out_dev, &packet); + if (IN6_IS_ADDR_V4MAPPED(dst)) { + compose_arp(&packet, ARP_OP_REQUEST, smac, eth_addr_zero, true, + in6_addr_get_mapped_ipv4(src), + in6_addr_get_mapped_ipv4(dst)); + } else { + compose_nd_ns(&packet, true, smac, eth_addr_zero, src, dst); + } + xlate_send_packet_pipeline(out_dev, &packet, depth, resubmits); dp_packet_uninit(&packet); } -static void -tnl_send_arp_request(struct xlate_ctx *ctx, const struct xport *out_dev, - const struct eth_addr eth_src, - ovs_be32 ip_src, ovs_be32 ip_dst) +/* Sends all tunnel neighbor refresh requests queued by the cache. */ +void +xlate_tnl_neigh_refresh(void) { - struct dp_packet packet; + struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp); + char br_name[IFNAMSIZ], out_dev_name[IFNAMSIZ]; + struct in6_addr dst; - dp_packet_init(&packet, 0); - compose_arp(&packet, ARP_OP_REQUEST, - eth_src, eth_addr_zero, true, ip_src, ip_dst); + if (!xcfg) { + return; + } - compose_table_xlate(ctx, out_dev, &packet); - dp_packet_uninit(&packet); + while (tnl_neigh_get_refresh(br_name, out_dev_name, &dst)) { + struct xbridge *xbridge = NULL; + struct xport *out_dev = NULL; + char dst_s[INET6_ADDRSTRLEN]; + struct xbridge *iter; + struct eth_addr smac; + struct in6_addr src; + struct xport *port; + + HMAP_FOR_EACH (iter, hmap_node, &xcfg->xbridges) { + if (!strcmp(iter->name, br_name)) { + xbridge = iter; + break; + } + } + + if (!xbridge) { + continue; + } + + ipv6_string_mapped(dst_s, &dst); + VLOG_DBG("refreshing tunnel neighbor %s on bridge %s", + dst_s, xbridge->name); + + /* A different port on the same bridge may use another VLAN. Only + * manual entries without a learned interface can use any port. */ + HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) { + const char *name = netdev_get_name(port->netdev); + + if ((!out_dev_name[0] || !strncmp(name, out_dev_name, IFNAMSIZ)) + && !ovs_router_get_netdev_source_address(&dst, name, &src)) { + out_dev = port; + break; + } + } + + if (!out_dev || netdev_get_etheraddr(out_dev->netdev, &smac)) { + VLOG_DBG("no output port for tunnel neighbor %s", dst_s); + continue; + } + + COVERAGE_INC(xlate_actions_neigh_sent); + tnl_send_neigh_request(out_dev, smac, &src, &dst, 0, 0); + } } static void @@ -3990,26 +4034,13 @@ native_tunnel_output(struct xlate_ctx *ctx, const struct xport *xport, nh_s_ip6 = s_ip6; } - if (d_ip) { - ovs_be32 nh_s_ip; - - nh_s_ip = in6_addr_get_mapped_ipv4(&nh_s_ip6); - tnl_send_arp_request(ctx, out_dev, smac, nh_s_ip, d_ip); - } else { - tnl_send_nd_request(ctx, out_dev, smac, &nh_s_ip6, &d_ip6); + if (xlate_resubmit_resource_check(ctx)) { + tnl_send_neigh_request(out_dev, smac, &nh_s_ip6, &d_ip6, + ctx->depth + 1, ctx->resubmits); } return err; } - if (ctx->xin->xcache) { - struct xc_entry *entry; - - entry = xlate_cache_add_entry(ctx->xin->xcache, XC_TNL_NEIGH); - ovs_strlcpy(entry->tnl_neigh_cache.br_name, out_dev->xbridge->name, - sizeof entry->tnl_neigh_cache.br_name); - entry->tnl_neigh_cache.d_ipv6 = d_ip6; - } - xlate_report(ctx, OFT_DETAIL, "tunneling from "ETH_ADDR_FMT" %s" " to "ETH_ADDR_FMT" %s", ETH_ADDR_ARGS(smac), ipv6_string_mapped(buf_sip6, &s_ip6), @@ -4475,8 +4506,13 @@ terminate_native_tunnel(struct xlate_ctx *ctx, const struct xport *xport, * do tunnel neighbor snooping. */ if (*tnl_port == ODPP_NONE && (check_neighbor_reply(ctx, flow) || is_garp(flow, wc))) { - tnl_neigh_snoop(flow, wc, ctx->xbridge->name, - ctx->xin->allow_side_effects); + if (!tnl_neigh_snoop(flow, wc, ctx->xbridge->name, + netdev_get_name(xport->netdev), + ctx->xin->allow_side_effects)) { + /* Each reply must renew the entry, including replies that + * match an already installed datapath flow. */ + ctx->xout->slow |= SLOW_ACTION; + } } else if (*tnl_port != ODPP_NONE && ctx->xin->allow_side_effects && dl_type_is_ip_any(flow->dl_type)) { @@ -4489,7 +4525,8 @@ terminate_native_tunnel(struct xlate_ctx *ctx, const struct xport *xport, s_ip6 = flow->ipv6_src; } - tnl_neigh_set(ctx->xbridge->name, &s_ip6, mac); + tnl_neigh_set(ctx->xbridge->name, netdev_get_name(xport->netdev), + &s_ip6, mac); } } diff --git a/ofproto/ofproto-dpif-xlate.h b/ofproto/ofproto-dpif-xlate.h index d973a634a..7b87ed73c 100644 --- a/ofproto/ofproto-dpif-xlate.h +++ b/ofproto/ofproto-dpif-xlate.h @@ -231,6 +231,7 @@ enum ofperr xlate_resume(struct ofproto_dpif *, struct ofpbuf *odp_actions, enum slow_path_reason *, struct flow *, struct xlate_cache *); int xlate_send_packet(const struct ofport_dpif *, bool oam, struct dp_packet *); +void xlate_tnl_neigh_refresh(void); void xlate_mac_learning_update(const struct ofproto_dpif *ofproto, ofp_port_t in_port, struct eth_addr dl_src, diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 0f0f71d14..6c60f295b 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -69,6 +69,7 @@ #include "simap.h" #include "smap.h" #include "timer.h" +#include "tnl-neigh-cache.h" #include "tunnel.h" #include "unaligned.h" #include "unixctl.h" @@ -369,6 +370,11 @@ type_run(const char *type) return 0; } + if (dpif_supports_tnl_push_pop(backer->dpif)) { + tnl_neigh_cache_run(); + xlate_tnl_neigh_refresh(); + } + if (dpif_run(backer->dpif)) { backer->need_revalidate = REV_RECONFIGURE; } @@ -674,6 +680,9 @@ type_wait(const char *type) return; } + if (dpif_supports_tnl_push_pop(backer->dpif)) { + tnl_neigh_cache_wait(); + } dpif_wait(backer->dpif); } @@ -5172,7 +5181,6 @@ ofproto_dpif_xcache_execute(struct ofproto_dpif *ofproto, case XC_MIRROR: case XC_NORMAL: case XC_GROUP: - case XC_TNL_NEIGH: case XC_TUNNEL_HEADER: xlate_push_stats_entry(entry, stats, false); break; diff --git a/ofproto/ofproto-tnl-unixctl.man b/ofproto/ofproto-tnl-unixctl.man index b2a401564..895a2f5b4 100644 --- a/ofproto/ofproto-tnl-unixctl.man +++ b/ofproto/ofproto-tnl-unixctl.man @@ -52,8 +52,11 @@ the first matching rule will be selected for deletion. . .IP "\fBtnl/neigh/show\fR" .IP "\fBtnl/arp/show\fR" -OVS builds ARP cache by snooping are messages. This command shows -ARP cache table. +Shows the tunnel neighbor cache learned from ARP and IPv6 Neighbor Discovery +or configured with \fBtnl/neigh/set\fR. An entry marked \fBREFRESHING\fR +can still forward packets using its cached MAC while OVS tries to renew it. +If the neighbor is not learned again, the entry expires at its original +deadline. . .IP "\fBtnl/neigh/set\fR \fIbridge\fR \fIip\fR \fImac\fR" .IP "\fBtnl/arp/set\fR \fIbridge\fR \fIip\fR \fImac\fR" diff --git a/tests/tunnel-push-pop-ipv6.at b/tests/tunnel-push-pop-ipv6.at index ec757f7d7..640ad7a62 100644 --- a/tests/tunnel-push-pop-ipv6.at +++ b/tests/tunnel-push-pop-ipv6.at @@ -373,7 +373,7 @@ AT_CHECK([cat p0.pcap.txt | grep 93aa55aa55000086dd6000000000203aff2001cafe | un ]) dnl Set the aging time to 5 seconds -AT_CHECK([ovs-appctl tnl/neigh/retrans_time 5000], [0], [OK +AT_CHECK([ovs-appctl tnl/neigh/retrans_time 1000], [0], [OK ]) AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK ]) @@ -382,6 +382,9 @@ dnl Read the current aging time AT_CHECK([ovs-appctl tnl/neigh/aging], [0], [5 ]) +dnl Freeze time so deadlines depend only on explicit time/warp calls. +AT_CHECK([ovs-appctl time/stop]) + dnl Add an entry AT_CHECK([ovs-appctl tnl/neigh/set br0 2001:cafe::92 aa:bb:cc:00:00:01], [0], [OK ]) @@ -391,6 +394,55 @@ AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl 2001:cafe::93 br0 INCOMPLETE ]) +dnl Refresh early enough to retry twice before expiration. +AT_CHECK([ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l > nd_count]) +ovs-appctl time/warp 2500 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l` \ + -gt `cat nd_count`]) + +dnl The cached MAC remains usable while the refresh is outstanding. +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +2001:cafe::92 aa:bb:cc:00:00:01 br0 REFRESHING +]) + +dnl Forward a packet through the tunnel while the refresh is unanswered. +AT_CHECK([ovs-ofctl -O OpenFlow13 packet-out int-br CONTROLLER "output:2" '50540000000a5054000000091235']) +OVS_WAIT_UNTIL([ovs-pcap p0.pcap | grep -q '^aabbcc000001.*50540000000a5054000000091235']) + +dnl A lost first probe is retried before the original expiration. +AT_CHECK([ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l > nd_count]) +ovs-appctl time/warp 1000 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l` \ + -gt `cat nd_count`]) + +dnl A second lost probe gets one more attempt before expiration. +AT_CHECK([ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l > nd_count]) +ovs-appctl time/warp 1000 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l` \ + -gt `cat nd_count`]) + +dnl A reply renews the entry and allows another refresh cycle. +reply='in_port(1),eth(src=aa:bb:cc:00:00:01,dst=aa:55:aa:55:00:00),eth_type(0x86dd),ipv6(src=2001:cafe::92,dst=2001:cafe::88,label=0,proto=58,tclass=0,hlimit=255,frag=no),icmpv6(type=136,code=0),nd(target=2001:cafe::92,sll=00:00:00:00:00:00,tll=aa:bb:cc:00:00:01)' +AT_CHECK([ovs-appctl netdev-dummy/receive p0 "$reply"]) +OVS_WAIT_UNTIL([ovs-appctl tnl/neigh/show | grep -q 'aa:bb:cc:00:00:01 br0$']) +AT_CHECK([ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l > nd_count]) +ovs-appctl time/warp 4000 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 92aa55aa55000086dd | wc -l` \ + -gt `cat nd_count`]) + +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +2001:cafe::92 aa:bb:cc:00:00:01 br0 REFRESHING +]) + +dnl Forward beyond the original deadline after the reply renewed the entry. +AT_CHECK([ovs-ofctl -O OpenFlow13 packet-out int-br CONTROLLER "output:2" '50540000000a5054000000091236']) +OVS_WAIT_UNTIL([ovs-pcap p0.pcap | grep -q '^aabbcc000001.*50540000000a5054000000091236']) + +dnl The same reply must renew the entry even after its flow is installed. +AT_CHECK([ovs-appctl netdev-dummy/receive p0 "$reply"]) +OVS_WAIT_UNTIL([ovs-appctl tnl/neigh/show | grep -q 'aa:bb:cc:00:00:01 br0$']) + +dnl An unanswered refresh does not keep the entry past its expiration. ovs-appctl time/warp 5000 dnl Check the entry has been removed @@ -957,3 +1009,64 @@ AT_CHECK([grep -q "GENEVE_ACT" stdout]) OVS_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([tunnel_push_pop_ipv6 - neighbor changes revalidate cached flows]) + +OVS_VSWITCHD_START([add-port br0 p0 \ + -- set Interface p0 type=dummy ofport_request=1]) +AT_CHECK([ovs-vsctl add-br int-br -- set bridge int-br datapath_type=dummy \ + -- add-port int-br t1 -- set Interface t1 type=vxlan \ + options:remote_ip=2001:cafe::92 ofport_request=2]) +AT_CHECK([ovs-appctl netdev-dummy/ip6addr br0 2001:cafe::88/64], [0], [OK +]) +dnl Avoid NORMAL learning so it cannot independently trigger revalidation. +AT_CHECK([ovs-ofctl add-flow br0 'in_port=LOCAL,actions=1']) +AT_CHECK([ovs-ofctl add-flow br0 'in_port=1,actions=LOCAL']) +AT_CHECK([ovs-ofctl add-flow int-br 'in_port=LOCAL,actions=2']) +AT_CHECK([ovs-vsctl set Interface p0 options:tx_pcap=p0.pcap]) +AT_CHECK([ovs-appctl time/stop]) +AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK +]) +AT_CHECK([ovs-appctl tnl/neigh/set br0 2001:cafe::92 aa:bb:cc:00:00:01], [0], [OK +]) + +packet=50540000000a5054000000091235 +dnl Install a datapath flow and exercise its cached action. +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:01']) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000001.*$packet"` -eq 2]) +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'packets:1,.*tnl_push.*dst=aa:bb:cc:00:00:01']) + +AT_CHECK([ovs-appctl time/warp 2500], [0], [ignore]) +dnl The existing flow still forwards while the proactive probe is unanswered. +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000001.*$packet"` -eq 3]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:01']) + +dnl A reply with a changed MAC must invalidate the already-cached action. +AT_CHECK([ovs-appctl netdev-dummy/receive p0 'eth(src=aa:bb:cc:00:00:02,dst=aa:55:aa:55:00:00),eth_type(0x86dd),ipv6(src=2001:cafe::92,dst=2001:cafe::88,label=0,proto=58,tclass=0,hlimit=255,frag=no),icmpv6(type=136,code=0),nd(target=2001:cafe::92,sll=00:00:00:00:00:00,tll=aa:bb:cc:00:00:02)']) +OVS_WAIT_UNTIL([test `ovs-appctl dpctl/dump-flows | grep -c 'tnl_push.*dst=aa:bb:cc:00:00:01'` -eq 0]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:02']) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000002.*$packet"` -eq 2]) + +dnl Keep hitting the flow throughout the next three unanswered probes. +dnl Transmitting packets must not extend the neighbor's learned lifetime. +AT_CHECK([ovs-appctl time/warp 2500], [0], [ignore]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000002.*$packet"` -eq 5]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:02']) +AT_CHECK([ovs-appctl time/warp 500], [0], [ignore]) +OVS_WAIT_UNTIL([test `ovs-appctl dpctl/dump-flows | grep -c 'tnl_push.*dst=aa:bb:cc:00:00:02'` -eq 0]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +AT_CHECK([ovs-pcap p0.pcap | grep -c "^aabbcc000002.*$packet"], [0], [5 +]) + +OVS_VSWITCHD_STOP +AT_CLEANUP diff --git a/tests/tunnel-push-pop.at b/tests/tunnel-push-pop.at index ab393cfc7..cafd2d3a8 100644 --- a/tests/tunnel-push-pop.at +++ b/tests/tunnel-push-pop.at @@ -325,6 +325,9 @@ aging value cannot be less than retrans_time ovs-appctl: ovs-vswitchd: server returned an error ]) +AT_CHECK([ovs-appctl tnl/neigh/retrans_time 1000], [0], [OK +]) + dnl Set the aging time to 5 seconds AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK ]) @@ -333,9 +336,12 @@ dnl Read the current aging time AT_CHECK([ovs-appctl tnl/neigh/aging], [0], [5 ]) -AT_CHECK([ovs-appctl tnl/neigh/retrans_time], [0], [5000 +AT_CHECK([ovs-appctl tnl/neigh/retrans_time], [0], [1000 ]) +dnl Freeze time so deadlines depend only on explicit time/warp calls. +AT_CHECK([ovs-appctl time/stop]) + dnl Add an entry AT_CHECK([ovs-appctl tnl/neigh/set br0 1.1.2.92 aa:bb:cc:00:00:01], [0], [OK ]) @@ -344,6 +350,55 @@ AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl 1.1.2.92 aa:bb:cc:00:00:01 br0 ]) +dnl Refresh early enough to retry twice before expiration. +AT_CHECK([ovs-pcap p0.pcap | grep 101025c | wc -l > arp_count]) +ovs-appctl time/warp 2500 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 101025c | wc -l` \ + -gt `cat arp_count`]) + +dnl The cached MAC remains usable while the refresh is outstanding. +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +1.1.2.92 aa:bb:cc:00:00:01 br0 REFRESHING +]) + +dnl Forward a packet through the tunnel while the refresh is unanswered. +AT_CHECK([ovs-ofctl -O OpenFlow13 packet-out int-br CONTROLLER "output:2" '50540000000a5054000000091235']) +OVS_WAIT_UNTIL([ovs-pcap p0.pcap | grep -q '^aabbcc000001.*50540000000a5054000000091235']) + +dnl A lost first probe is retried before the original expiration. +AT_CHECK([ovs-pcap p0.pcap | grep 101025c | wc -l > arp_count]) +ovs-appctl time/warp 1000 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 101025c | wc -l` \ + -gt `cat arp_count`]) + +dnl A second lost probe gets one more attempt before expiration. +AT_CHECK([ovs-pcap p0.pcap | grep 101025c | wc -l > arp_count]) +ovs-appctl time/warp 1000 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 101025c | wc -l` \ + -gt `cat arp_count`]) + +dnl A reply renews the entry and allows another refresh cycle. +reply='recirc_id(0),in_port(1),eth(src=aa:bb:cc:00:00:01,dst=aa:55:aa:55:00:00),eth_type(0x0806),arp(sip=1.1.2.92,tip=1.1.2.88,op=2,sha=aa:bb:cc:00:00:01,tha=aa:55:aa:55:00:00)' +AT_CHECK([ovs-appctl netdev-dummy/receive p0 "$reply"]) +OVS_WAIT_UNTIL([ovs-appctl tnl/neigh/show | grep -q 'aa:bb:cc:00:00:01 br0$']) +AT_CHECK([ovs-pcap p0.pcap | grep 101025c | wc -l > arp_count]) +ovs-appctl time/warp 4000 +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep 101025c | wc -l` \ + -gt `cat arp_count`]) + +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +1.1.2.92 aa:bb:cc:00:00:01 br0 REFRESHING +]) + +dnl Forward beyond the original deadline after the reply renewed the entry. +AT_CHECK([ovs-ofctl -O OpenFlow13 packet-out int-br CONTROLLER "output:2" '50540000000a5054000000091236']) +OVS_WAIT_UNTIL([ovs-pcap p0.pcap | grep -q '^aabbcc000001.*50540000000a5054000000091236']) + +dnl The same reply must renew the entry even after its flow is installed. +AT_CHECK([ovs-appctl netdev-dummy/receive p0 "$reply"]) +OVS_WAIT_UNTIL([ovs-appctl tnl/neigh/show | grep -q 'aa:bb:cc:00:00:01 br0$']) + +dnl An unanswered refresh does not keep the entry past its expiration. ovs-appctl time/warp 5000 dnl Check the entry has been removed @@ -1304,6 +1359,42 @@ ipv4(src=1.1.2.88,dst=1.1.2.92,proto=47,tos=0,ttl=64,frag=0x4000),dnl gre((flags=0x0,proto=0x6558))),out_port(2)),1 ]) +dnl Refresh uses the non-local IP interface, including for manual entries. +AT_CHECK([ovs-appctl time/stop]) +AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK +]) +AT_CHECK([ovs-vsctl set Interface p0 options:tx_pcap=refresh.pcap]) +AT_CHECK([ovs-appctl time/warp 3000], [0], [ignore]) +OVS_WAIT_UNTIL([test `ovs-pcap refresh.pcap | wc -l` -eq 1]) +AT_CHECK([ovs-pcap refresh.pcap], [0], [dnl +ffffffffffffaa55aa55000308060001080006040001aa55aa550003010102580000000000000101025c +]) +AT_CHECK([ovs-appctl tnl/neigh/flush], [0], [OK +]) +AT_CHECK([ovs-appctl tnl/neigh/set br0 1.1.2.92 f8:bc:12:44:34:b6], [0], [OK +]) +AT_CHECK([ovs-appctl time/warp 3000], [0], [ignore]) +OVS_WAIT_UNTIL([test `ovs-pcap refresh.pcap | wc -l` -eq 2]) +AT_CHECK([ovs-pcap refresh.pcap | sort -u], [0], [dnl +ffffffffffffaa55aa55000308060001080006040001aa55aa550003010102580000000000000101025c +]) + +dnl Relearn on vtep0, then remove it. Even though br0 can address the +dnl neighbor, refresh must preserve the learned interface and aging deadline. +AT_CHECK([ovs-appctl netdev-dummy/receive p0 'in_port(1),dnl + eth(src=f8:bc:12:44:34:b6,dst=aa:55:aa:55:00:03),eth_type(0x0806),dnl + arp(sip=1.1.2.92,tip=1.1.2.88,op=2,sha=f8:bc:12:44:34:b6,tha=aa:55:aa:55:00:03)']) +OVS_WAIT_UNTIL([ovs-appctl tnl/neigh/show | grep -q 'f8:bc:12:44:34:b6 br0$']) +AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 1.1.2.89/24], [0], [OK +]) +AT_CHECK([ovs-vsctl del-port br0 vtep0]) +AT_CHECK([ovs-appctl time/warp 2500], [0], [ignore]) +OVS_WAIT_UNTIL([ovs-appctl tnl/neigh/show | grep -q 'f8:bc:12:44:34:b6 br0 REFRESHING$']) +AT_CHECK([ovs-appctl time/warp 2500], [0], [ignore]) +OVS_WAIT_WHILE([ovs-appctl tnl/neigh/show | grep -qF 1.1.2.92]) +AT_CHECK([ovs-pcap refresh.pcap | grep -c '0101025c$'], [0], [2 +]) + OVS_VSWITCHD_STOP AT_CLEANUP @@ -1614,5 +1705,96 @@ AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(int-br),dnl -> tunneling to 1.1.2.91 via br1 ]) +dnl Refresh must retain each learned interface despite the source-based routes. +dnl Equal aging/retrans timers must leave a quiet period after learning. +AT_CHECK([ovs-appctl time/stop]) +AT_CHECK([ovs-appctl tnl/neigh/aging 2], [0], [OK +]) +AT_CHECK([ovs-appctl tnl/neigh/retrans_time 2000], [0], [OK +]) +AT_CHECK([ovs-vsctl set Interface p0 options:tx_pcap=refresh0.pcap \ + -- set Interface p1 options:tx_pcap=refresh1.pcap]) +AT_CHECK([ovs-appctl time/warp 1], [0], [ignore]) +AT_CHECK([ovs-pcap refresh0.pcap | wc -l], [0], [0 +]) +AT_CHECK([ovs-pcap refresh1.pcap | wc -l], [0], [0 +]) +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) +OVS_WAIT_UNTIL([test `ovs-pcap refresh0.pcap | wc -l` -eq 1]) +OVS_WAIT_UNTIL([test `ovs-pcap refresh1.pcap | wc -l` -eq 1]) +AT_CHECK([ovs-pcap refresh0.pcap], [0], [dnl +ffffffffffffaa55aa55000008060001080006040001aa55aa550000010102500000000000000101025a +]) +AT_CHECK([ovs-pcap refresh1.pcap | grep -q '010102510000000000000101025b$']) +dnl Renew the same MAC without causing an immediate new probe. +AT_CHECK([ovs-appctl tnl/neigh/set br0 1.1.2.90 f8:bc:12:44:34:b0], [0], [OK +]) +AT_CHECK([ovs-appctl time/warp 1], [0], [ignore]) +AT_CHECK([ovs-pcap refresh0.pcap | wc -l], [0], [1 +]) +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) +OVS_WAIT_UNTIL([test `ovs-pcap refresh0.pcap | wc -l` -eq 2]) + +OVS_VSWITCHD_STOP +AT_CLEANUP + +AT_SETUP([tunnel_push_pop - neighbor changes revalidate cached flows]) + +OVS_VSWITCHD_START([add-port br0 p0 \ + -- set Interface p0 type=dummy ofport_request=1]) +AT_CHECK([ovs-vsctl add-br int-br -- set bridge int-br datapath_type=dummy \ + -- add-port int-br t1 -- set Interface t1 type=vxlan \ + options:remote_ip=1.1.2.92 ofport_request=2]) +AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 1.1.2.88/24], [0], [OK +]) +dnl Avoid NORMAL learning so it cannot independently trigger revalidation. +AT_CHECK([ovs-ofctl add-flow br0 'in_port=LOCAL,actions=1']) +AT_CHECK([ovs-ofctl add-flow br0 'in_port=1,actions=LOCAL']) +AT_CHECK([ovs-ofctl add-flow int-br 'in_port=LOCAL,actions=2']) +AT_CHECK([ovs-vsctl set Interface p0 options:tx_pcap=p0.pcap]) +AT_CHECK([ovs-appctl time/stop]) +AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK +]) +AT_CHECK([ovs-appctl tnl/neigh/set br0 1.1.2.92 aa:bb:cc:00:00:01], [0], [OK +]) + +packet=50540000000a5054000000091235 +dnl Install a datapath flow and exercise its cached action. +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:01']) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000001.*$packet"` -eq 2]) +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'packets:1,.*tnl_push.*dst=aa:bb:cc:00:00:01']) + +AT_CHECK([ovs-appctl time/warp 2500], [0], [ignore]) +dnl The existing flow still forwards while the proactive probe is unanswered. +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000001.*$packet"` -eq 3]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:01']) + +dnl A reply with a changed MAC must invalidate the already-cached action. +AT_CHECK([ovs-appctl netdev-dummy/receive p0 'eth(src=aa:bb:cc:00:00:02,dst=aa:55:aa:55:00:00),eth_type(0x0806),arp(sip=1.1.2.92,tip=1.1.2.88,op=2,sha=aa:bb:cc:00:00:02,tha=aa:55:aa:55:00:00)']) +OVS_WAIT_UNTIL([test `ovs-appctl dpctl/dump-flows | grep -c 'tnl_push.*dst=aa:bb:cc:00:00:01'` -eq 0]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:02']) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000002.*$packet"` -eq 2]) + +dnl Keep hitting the flow throughout the next three unanswered probes. +dnl Transmitting packets must not extend the neighbor's learned lifetime. +AT_CHECK([ovs-appctl time/warp 2500], [0], [ignore]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +OVS_WAIT_UNTIL([test `ovs-pcap p0.pcap | grep -c "^aabbcc000002.*$packet"` -eq 5]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep -q 'tnl_push.*dst=aa:bb:cc:00:00:02']) +AT_CHECK([ovs-appctl time/warp 500], [0], [ignore]) +OVS_WAIT_UNTIL([test `ovs-appctl dpctl/dump-flows | grep -c 'tnl_push.*dst=aa:bb:cc:00:00:02'` -eq 0]) +AT_CHECK([ovs-appctl netdev-dummy/receive int-br "$packet"]) +AT_CHECK([ovs-pcap p0.pcap | grep -c "^aabbcc000002.*$packet"], [0], [5 +]) + OVS_VSWITCHD_STOP AT_CLEANUP -- 2.56.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
