26 double x = 0.0,
double y = 0.0,
double radius = 400.0,
const void*
data =
nullptr,
unsigned int data_size = 0);
33 std::chrono::milliseconds
period()
const;
44 std::chrono::milliseconds _period;
45 std::vector<std::uint8_t> _data;
59 std::atomic<bool> _running;
75inline RSU::RSU(
unsigned int rsu_id,
Unit unit, std::chrono::milliseconds period,
76 double x,
double y,
double radius,
const void*
data,
unsigned int data_size)
77 : _rsu_id(rsu_id), _unit(unit), _period(period), _x(x), _y(y), _radius(radius), _running(
false),
78 _periodic_thread(
this, &
RSU::broadcast) {
80 db<RSU>(
TRC) <<
"RSU::RSU() called with id=" << rsu_id <<
", unit=" <<
unit <<
", period=" <<
period.count() <<
"ms\n";
100 _rsu_key[0] = (rsu_id >> 8) & 0xFF;
101 _rsu_key[1] = rsu_id & 0xFF;
105 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" initialized with address " <<
rsu_addr.to_string() <<
"\n";
114 db<RSU>(
WRN) <<
"[RSU] RSU " << _rsu_id <<
" has an INVALID_LEADER_ID based on its MAC. Clock self_id not set.\n";
120 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" registered key in LeaderKeyStorage for MAC verification.\n";
137 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" destroyed\n";
146 if (!_running.load()) {
147 _running.store(
true);
148 _periodic_thread.
start(
static_cast<std::int64_t
>(_period.count()) * 1000);
149 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" started broadcasting every " << _period.count() <<
"ms\n";
159 if (_running.load(std::memory_order_acquire)) {
161 _running.store(
false, std::memory_order_release);
162 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" stopping broadcasting\n";
166 _periodic_thread.
join();
167 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" periodic thread stopped\n";
174 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" stopped broadcasting\n";
183 return _running.load(std::memory_order_acquire);
222 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" period adjusted to " <<
new_period.count() <<
"ms\n";
239 unsigned int payload_size =
sizeof(_x) +
sizeof(_y) +
sizeof(_radius) +
sizeof(_rsu_key) + _data.size();
247 std::memcpy(
payload.data() +
offset, &_radius,
sizeof(_radius));
248 offset +=
sizeof(_radius);
249 std::memcpy(
payload.data() +
offset, &_rsu_key,
sizeof(_rsu_key));
250 offset +=
sizeof(_rsu_key);
252 if (!_data.empty()) {
253 std::memcpy(
payload.data() +
offset, _data.data(), _data.size());
260 db<RSU>(
TRC) <<
"[RSU] RSU " << _rsu_id <<
" broadcasting STATUS for unit " << _unit
261 <<
" with data size " <<
payload.size() <<
"\n";
267 db<RSU>(
INF) <<
"[RSU] RSU " << _rsu_id <<
" broadcast STATUS for unit " << _unit <<
"\n";
269 db<RSU>(
WRN) <<
"[RSU] RSU " << _rsu_id <<
" failed to broadcast STATUS for unit " << _unit <<
"\n";
282 if (!_network || !_network->
channel()) {
283 db<RSU>(
WRN) <<
"[RSU] Cannot initialize protocol neighbors - no network or protocol\n";
287 db<RSU>(
INF) <<
"[RSU] Initializing neighbor RSUs directly in Protocol for RSU " << _rsu_id <<
"\n";
322 db<RSU>(
INF) <<
"[RSU] Successfully initialized neighbor RSUs directly in Protocol\n";
void setSelfId(LeaderIdType id)
Set the self ID for this clock instance (node's own PTP-relevant ID)
Definition clock.h:156
void activate(const PtpRelevantData *new_msg_data)
Activate the state machine with new PTP data.
Definition clock.h:177
static Clock & getInstance()
Get the singleton instance.
Definition clock.h:145
Definition communicator.h:16
const Address & address() const
Definition communicator.h:134
bool send(const Message_T *message)
Definition communicator.h:78
void release()
Definition communicator.h:123
void setLeaderId(const Ethernet::Address &leader_id)
Set the current leader ID.
Definition leaderKeyStorage.h:65
static LeaderKeyStorage & getInstance()
Get the singleton instance.
Definition leaderKeyStorage.h:54
void setGroupMacKey(const MacKeyType &key)
Set the current group MAC key.
Definition leaderKeyStorage.h:93
Template class for network messages with Clock integration.
Definition message.h:31
static constexpr Microseconds ZERO
Definition message.h:51
std::uint32_t Unit
Definition message.h:48
void stop()
Definition network.h:19
Protocol * channel()
Definition network.h:67
const NIC::Address address()
Definition network.h:75
Definition periodicThread.h:72
void adjust_period(std::int64_t period)
Definition periodicThread.h:155
void start(std::int64_t period)
Definition periodicThread.h:130
void join()
Definition periodicThread.h:116
Definition protocol.h:134
void setRadius(double radius)
Definition protocol.h:730
void clear_neighbor_rsus()
Definition protocol.h:1304
void add_neighbor_rsu(unsigned int rsu_id, const MacKeyType &key, const Address &address)
Definition protocol.h:1282
void broadcast()
Send a single broadcast message (called by periodic thread)
Definition rsu.h:228
std::chrono::milliseconds period() const
Get the broadcasting period.
Definition rsu.h:206
Message::Unit Unit
Definition rsu.h:23
const Address & address() const
Get the RSU's network address.
Definition rsu.h:190
RSU(unsigned int rsu_id, Unit unit, std::chrono::milliseconds period, double x=0.0, double y=0.0, double radius=400.0, const void *data=nullptr, unsigned int data_size=0)
Construct a new RSU object.
Definition rsu.h:75
Protocol::Address Address
Definition rsu.h:21
bool running() const
Check if the RSU is running.
Definition rsu.h:182
~RSU()
Destroy the RSU object.
Definition rsu.h:129
void adjust_period(std::chrono::milliseconds new_period)
Adjust the broadcasting period.
Definition rsu.h:214
void stop()
Stop the RSU broadcasting.
Definition rsu.h:156
Network::Message Message
Definition rsu.h:22
Network::Communicator Communicator
Definition rsu.h:19
void start()
Start the RSU broadcasting.
Definition rsu.h:143
void initialize_neighbor_rsus()
Initialize neighbor RSUs directly in Protocol structure In a real system, this would be loaded from c...
Definition rsu.h:281
Unit unit() const
Get the unit type being broadcast.
Definition rsu.h:198
Network::Protocol Protocol
Definition rsu.h:20
uint32_t LeaderIdType
Definition clock.h:26
const LeaderIdType INVALID_LEADER_ID
Definition clock.h:27
@ INF
Definition debug.h:208
Select_Debug<(Traits< T >::debugged &&Traits< Debug >::error)> db(Debug_Error l)
Definition debug.h:166
@ TRC
Definition debug.h:231
@ WRN
Definition debug.h:185
std::uint8_t payload[MTU]
Definition ethernet.h:3
std::array< uint8_t, 16 > MacKeyType
Definition leaderKeyStorage.h:15
T * data()
Definition protocol.h:24
std::uint8_t bytes[MAC_SIZE]
Definition ethernet.h:17