Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion syncd/ComparisonLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "meta/SaiAttributeList.h"

#include <inttypes.h>
#include <random>

using namespace syncd;
using namespace saimeta;
Expand Down Expand Up @@ -64,7 +65,8 @@ ComparisonLogic::ComparisonLogic(
m_current->m_defaultTrapGroupRid = m_switch->getSwitchDefaultAttrOid(SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP);
m_temp->m_defaultTrapGroupRid = m_switch->getSwitchDefaultAttrOid(SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP);

auto seed = (unsigned int)std::time(0);
std::random_device rd;
auto seed = rd();

SWSS_LOG_NOTICE("srand seed for switch %s: %u", sai_serialize_object_id(m_switch->getVid()).c_str(), seed);

Expand Down
15 changes: 15 additions & 0 deletions vslib/FdbInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "swss/logger.h"

#include <climits>
#include <ctime>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -167,3 +170,15 @@ void FdbInfo::setTimestamp(

m_timestamp = timestamp;
}

uint32_t FdbInfo::currentEpochTimeSec()
{
SWSS_LOG_ENTER();

time_t now = time(nullptr);

if (now > static_cast<time_t>(UINT32_MAX))
return UINT32_MAX;

return static_cast<uint32_t>(now);
}
2 changes: 2 additions & 0 deletions vslib/FdbInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace saivs
void setTimestamp(
_In_ uint32_t timestamp);

static uint32_t currentEpochTimeSec();

public: // serialize

std::string serialize() const;
Expand Down
2 changes: 1 addition & 1 deletion vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2948,7 +2948,7 @@ void SwitchStateBase::processFdbEntriesForAging()

SWSS_LOG_DEBUG("fdb infos to process: %zu", m_fdb_info_set.size());

uint32_t current = (uint32_t)time(NULL);
uint32_t current = FdbInfo::currentEpochTimeSec();

sai_attribute_t attr;

Expand Down
2 changes: 1 addition & 1 deletion vslib/SwitchStateBaseFdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void SwitchStateBase::process_packet_for_fdb_event(
// we would need hostif info here and maybe interface index, then we can
// find host info from index

uint32_t frametime = (uint32_t)time(NULL);
uint32_t frametime = FdbInfo::currentEpochTimeSec();

/*
* We add +2 in case if frame contains 1Q VLAN tag.
Expand Down
Loading