Skip to content

Commit 015d5c7

Browse files
committed
Add parametr neighbor_resolve_removed
1 parent 5434b6f commit 015d5c7

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

common/config.release.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ static constexpr std::uint32_t YANET_BALANCER_WRR_SERVICE_SIZE = YANET_CONFIG_BA
7474
#define YANET_CONFIG_BALANCER_STATE_TIMEOUT_DEFAULT (60)
7575
#define YANET_CONFIG_NEIGHBOR_CHECK_INTERVAL (5)
7676
#define YANET_CONFIG_NEIGHBOR_REMOVE_TIMEOUT (60)
77+
#define YANET_CONFIG_RESOLVE_REMOVED (2)

dataplane/config_values.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct ConfigValues
4848
uint64_t neighbor_rcvbuf_size = 0;
4949
uint64_t neighbor_checks_interval = YANET_CONFIG_NEIGHBOR_CHECK_INTERVAL;
5050
uint64_t neighbor_remove_timeout = YANET_CONFIG_NEIGHBOR_REMOVE_TIMEOUT;
51+
uint64_t neighbor_resolve_removed = YANET_CONFIG_RESOLVE_REMOVED;
5152
};
5253

5354
inline uint64_t ReadNeighStaleTime()
@@ -131,4 +132,5 @@ inline void from_json(const nlohmann::json& j, ConfigValues& cfg)
131132
}
132133
cfg.neighbor_checks_interval = j.value("neighbor_checks_interval", cfg.neighbor_checks_interval);
133134
cfg.neighbor_remove_timeout = j.value("neighbor_remove_timeout", cfg.neighbor_remove_timeout);
135+
cfg.neighbor_resolve_removed = j.value("neighbor_resolve_removed", cfg.neighbor_resolve_removed);
134136
}

dataplane/dataplane.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ eResult cDataPlane::init(const std::string& binaryPath,
292292
getConfigValues().neighbor_rcvbuf_size,
293293
getConfigValues().neighbor_checks_interval,
294294
getConfigValues().neighbor_remove_timeout,
295+
getConfigValues().neighbor_resolve_removed,
295296
[this](tSocketId socket_id) {
296297
return memory_manager.create<dataplane::neighbor::hashtable>(
297298
"neighbor.ht",

dataplane/neighbor.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ eResult module::init(
2626
uint64_t rcvbuf_size,
2727
uint64_t checks_interval,
2828
uint64_t remove_timeout,
29+
uint64_t resolve_removed,
2930
std::function<dataplane::neighbor::hashtable*(tSocketId)> ht_allocator,
3031
std::function<std::uint32_t()> current_time,
3132
std::function<void()> on_neighbor_flush,
@@ -38,6 +39,7 @@ eResult module::init(
3839
rcvbuf_size_ = rcvbuf_size;
3940
checks_interval_ = checks_interval;
4041
remove_timeout_ = remove_timeout;
42+
resolve_removed_ = resolve_removed;
4143

4244
generation_hashtable.fill([&](neighbor::generation_hashtable& hashtable) {
4345
for (const auto socket_id : socket_ids)
@@ -345,7 +347,7 @@ eResult module::DumpOSNeighbors()
345347
hashtable_updater.get_pointer()
346348
->insert_or_update(
347349
dataplane::neighbor::key{iface, is_v6 ? flag_is_ipv6 : uint16_t{}, dst},
348-
dataplane::neighbor::value{mac.value(), 0, now, 0, 0});
350+
dataplane::neighbor::value{mac.value(), 0, now, 0, 0, 0});
349351
stats.netlink_neighbor_update++;
350352
}
351353
}
@@ -420,7 +422,7 @@ void module::StartResolveJob()
420422
void module::Upsert(tInterfaceId iface, const ipv6_address_t& dst, bool is_v6, const rte_ether_addr& mac)
421423
{
422424
TransformHashtables([k = key{iface, is_v6 ? flag_is_ipv6 : uint16_t{}, dst},
423-
v = value{mac, 0, current_time_provider_(), 0, 0},
425+
v = value{mac, 0, current_time_provider_(), 0, 0, 0},
424426
this](dataplane::neighbor::hashtable& hashtable) {
425427
if (!hashtable.insert_or_update(k, v))
426428
{
@@ -444,6 +446,7 @@ void module::UpdateTimestamp(tInterfaceId iface, const ipv6_address_t& dst, bool
444446
value->last_update_timestamp = current_time_provider_();
445447
value->last_remove_timestamp = 0;
446448
value->last_resolve_timestamp = 0;
449+
value->number_resolve_after_remove = 0;
447450
stats.hashtable_insert_success++;
448451
}
449452
else
@@ -462,6 +465,7 @@ void module::Remove(tInterfaceId iface, const ipv6_address_t& dst, bool is_v6)
462465
if (value)
463466
{
464467
value->last_remove_timestamp = current_time_provider_();
468+
value->number_resolve_after_remove = 0;
465469
stats.hashtable_remove_success++;
466470
}
467471
else
@@ -471,7 +475,7 @@ void module::Remove(tInterfaceId iface, const ipv6_address_t& dst, bool is_v6)
471475
});
472476
}
473477

474-
void module::resolve(const dataplane::neighbor::key& key)
478+
bool module::resolve(const dataplane::neighbor::key& key)
475479
{
476480
stats.resolve++;
477481

@@ -486,7 +490,7 @@ void module::resolve(const dataplane::neighbor::key& key)
486490
YANET_LOG_ERROR("unknown interface_id: %u [ipv4_address: %s]\n",
487491
key.interface_id,
488492
ip_address.toString().data());
489-
return;
493+
return false;
490494
}
491495

492496
const auto& [it_route_name, it_interface_name] = it->second;
@@ -548,7 +552,7 @@ void module::resolve(const dataplane::neighbor::key& key)
548552
{
549553
YANET_LOG_WARNING("neighbor_resolve: socket(): %s\n",
550554
strerror(errno));
551-
return;
555+
return false;
552556
}
553557

554558
int rc = setsockopt(icmp_socket,
@@ -562,7 +566,7 @@ void module::resolve(const dataplane::neighbor::key& key)
562566
interface_name.data(),
563567
strerror(errno));
564568
close(icmp_socket);
565-
return;
569+
return false;
566570
}
567571

568572
union
@@ -591,6 +595,7 @@ void module::resolve(const dataplane::neighbor::key& key)
591595

592596
icmphdr header;
593597
memset(&header, 0, sizeof(header));
598+
bool result = true;
594599
if (sendto(icmp_socket,
595600
&header,
596601
sizeof(header),
@@ -600,10 +605,12 @@ void module::resolve(const dataplane::neighbor::key& key)
600605
{
601606
YANET_LOG_WARNING("neighbor_resolve: sendto(): %s\n",
602607
strerror(errno));
608+
result = false;
603609
}
604610

605611
close(icmp_socket);
606612
#endif // CONFIG_YADECAP_AUTOTEST
613+
return result;
607614
}
608615

609616
void module::NeighborThreadAction(uint32_t current_time)
@@ -638,7 +645,7 @@ void module::NeighborThreadAction(uint32_t current_time)
638645
{
639646
keys_to_remove.push_back(key);
640647
}
641-
else if (value.last_resolve_timestamp + checks_interval_ <= current_time)
648+
else if (value.last_resolve_timestamp + checks_interval_ <= current_time && value.number_resolve_after_remove < resolve_removed_)
642649
{
643650
keys_to_resolve.push_back(key);
644651
}
@@ -662,21 +669,24 @@ void module::NeighborThreadAction(uint32_t current_time)
662669
// resolve
663670
for (const key& cur_key : keys_to_resolve)
664671
{
672+
if (!resolve(cur_key))
673+
{
674+
continue;
675+
}
665676
TransformHashtables([cur_key, current_time, this](dataplane::neighbor::hashtable& hashtable) {
666-
YANET_LOG_INFO("resolve\n");
667677
dataplane::neighbor::value* value;
668678
hashtable.lookup(cur_key, value);
669679
if (value)
670680
{
671681
value->last_resolve_timestamp = current_time;
682+
value->number_resolve_after_remove++;
672683
stats.resolve_removed++;
673684
}
674685
else
675686
{
676687
stats.hashtable_insert_error++;
677688
}
678689
});
679-
resolve(cur_key);
680690
}
681691
}
682692

dataplane/neighbor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct value
5757
uint32_t last_update_timestamp;
5858
uint32_t last_remove_timestamp;
5959
uint32_t last_resolve_timestamp;
60+
uint32_t number_resolve_after_remove;
6061
};
6162

6263
//
@@ -89,6 +90,7 @@ class module
8990
uint64_t rcvbuf_size_ = 0;
9091
uint64_t checks_interval_ = YANET_CONFIG_NEIGHBOR_CHECK_INTERVAL;
9192
uint64_t remove_timeout_ = YANET_CONFIG_NEIGHBOR_REMOVE_TIMEOUT;
93+
uint64_t resolve_removed_ = YANET_CONFIG_RESOLVE_REMOVED;
9294
std::mutex mutex_restart_monitor_;
9395

9496
public:
@@ -100,6 +102,7 @@ class module
100102
uint64_t rcvbuf_size,
101103
uint64_t checks_interval,
102104
uint64_t remove_timeout,
105+
uint64_t resolve_removed,
103106
std::function<dataplane::neighbor::hashtable*(tSocketId)> ht_allocator,
104107
std::function<std::uint32_t()> current_time,
105108
std::function<void()> on_update,
@@ -128,7 +131,7 @@ class module
128131
void StopNetlinkMonitor();
129132
eResult DumpOSNeighbors();
130133

131-
void resolve(const dataplane::neighbor::key& key);
134+
bool resolve(const dataplane::neighbor::key& key);
132135

133136
protected:
134137
generation_manager<dataplane::neighbor::generation_interface> generation_interface;

dataplane/unittest/neighbor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ TEST(NeighborTest, Basic)
142142
0,
143143
YANET_CONFIG_NEIGHBOR_CHECK_INTERVAL,
144144
2, // remove_timeout
145+
YANET_CONFIG_RESOLVE_REMOVED,
145146
[](tSocketId) {
146147
auto size = dataplane::neighbor::hashtable::calculate_sizeof(64 * 1024);
147148
void* ptr = new char[size];
@@ -224,6 +225,7 @@ TEST(NeighborTest, Provider)
224225
0,
225226
YANET_CONFIG_NEIGHBOR_CHECK_INTERVAL,
226227
YANET_CONFIG_NEIGHBOR_REMOVE_TIMEOUT,
228+
YANET_CONFIG_RESOLVE_REMOVED,
227229
[](tSocketId) {
228230
auto size = dataplane::neighbor::hashtable::calculate_sizeof(64 * 1024);
229231
void* ptr = new char[size];

0 commit comments

Comments
 (0)