Free Electron
BeaconServer.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __BeaconServer_h__
8 #define __BeaconServer_h__
9 
10 namespace beacon
11 {
12 
13 // Time without a keep alive message until the node is considered alive
14 #define DEAD_TIME (10000)
15 
16 struct NodeEntry
17 {
18  uint8_t id; // Unique ID per node
19  uint32_t ipAddress; // IP address of the none
20  uint16_t replyPort; // Requested port it will listen to the reponces from the beacon
21  int64_t lastHeardFromTime; // Last time the Beacon heard from the node
22 
23  NodeEntry(const uint8_t _id,
24  const uint32_t _ipdAddress,
25  const uint16_t _replyPort,
26  const int64_t _lastHeardFromTime)
27  {
28  id = _id;
29  ipAddress = _ipdAddress;
30  replyPort = _replyPort;
31  lastHeardFromTime = _lastHeardFromTime;
32  }
33 };
34 
35 /***************************************************************************//**
36  @brief Node registration and simulation time syncronization
37 
38  @ingroup beacon
39 *//****************************************************************************/
40 class FE_DL_EXPORT BeaconServer : virtual public BeaconServerStartupI
41 {
42 public:
43  BeaconServer();
44  virtual ~BeaconServer();
45 
46  virtual bool startup(const char *fileName) { return true; }
47  virtual bool start(uint16_t beaconPort, uint16_t gdPort) override;
48  virtual void stop() override;
49  virtual bool running() override;
50 
51  void getList(std::list<NodeEntry> &registeredNodes);
52 
53 protected:
54  GlobalDictionary m_globalDictionary;
55 
56 private:
57  bool m_initialized;
58  std::atomic<bool> m_done;
59  std::atomic<bool> m_running;
60  uint8_t m_id; // Next ID to be assigned
61  std::thread* m_registeringThread;
62  fe::sp<fe::SingleMaster> m_spSingleMaster;
63  fe::sp<fe::ext::MessageI> m_recMsgSystem;
64  fe::sp<fe::ext::MessageI> m_sendMsgSystem;
65  std::list<NodeEntry> m_registeredNodes;
66  std::mutex m_nodeListMutex;
67  fe::ext::Messagegram m_listMsg;
68  fe::ext::Messagegram m_timeMsg;
69  fe::ext::Messagegram m_respMsg;
70 
71  void registrationThread();
72 
73  void add(const uint32_t ipAddress,
74  const uint16_t replyPort);
75  void remove(const uint32_t ipAddress);
76  void remove(const uint8_t id);
77  void keepAlive(const uint32_t id);
78 
79  void sendTimeResponse(const int64_t time,
80  const int64_t estBeaconTime,
81  const uint16_t port);
82  void sendKeepAliveResponse(const uint16_t port);
83  void sendUpdatedList();
84  void sendListMsgToAll(const fe::ext::Messagegram &msg);
85 
86  void checkForDeadNodes();
87  int64_t getCurrentTime();
88 
89  void displayList();
90  void clearList();
91 };
92 
93 } // namespace beacon
94 
95 #endif // __BeaconServer_h__
Node registration and simulation time syncronization.
Definition: BeaconServer.h:40
Global Dictionary of name/value strings.
Definition: GlobalDictionary.h:18
Definition: BeaconClient.cc:16