25
25
#include < diagnostic_updater/diagnostic_updater.hpp>
26
26
27
27
#include < climits>
28
+ #include < deque>
28
29
#include < map>
29
30
#include < string>
30
31
#include < vector>
@@ -55,11 +56,6 @@ class NetMonitor : public rclcpp::Node
55
56
*/
56
57
~NetMonitor ();
57
58
58
- /* *
59
- * @brief Update the diagnostic state.
60
- */
61
- void update ();
62
-
63
59
/* *
64
60
* @brief Shutdown nl80211 object
65
61
*/
@@ -86,24 +82,120 @@ class NetMonitor : public rclcpp::Node
86
82
void monitorTraffic (
87
83
diagnostic_updater::DiagnosticStatusWrapper & stat); // NOLINT(runtime/references)
88
84
85
+ /* *
86
+ * @brief check CRC error
87
+ * @param [out] stat diagnostic message passed directly to diagnostic publish calls
88
+ * @note NOLINT syntax is needed since diagnostic_updater asks for a non-const reference
89
+ * to pass diagnostic message updated in this function to diagnostic publish calls.
90
+ */
91
+ void checkCrcError (
92
+ diagnostic_updater::DiagnosticStatusWrapper & stat); // NOLINT(runtime/references)
93
+
89
94
/* *
90
95
* @brief get wireless speed
91
96
* @param [in] ifa_name interface name
92
97
* @return wireless speed
93
98
*/
94
99
float getWirelessSpeed (const char * ifa_name);
95
100
101
+ /* *
102
+ * @brief timer callback
103
+ */
104
+ void onTimer ();
105
+
106
+ /* *
107
+ * @brief update Network information list
108
+ */
109
+ void updateNetworkInfoList ();
110
+
111
+ /* *
112
+ * @brief check NetMonitor General Infomation
113
+ * @param [out] stat diagnostic message passed directly to diagnostic publish calls
114
+ * @return check result
115
+ */
116
+ bool checkGeneralInfo (diagnostic_updater::DiagnosticStatusWrapper & stat);
117
+
118
+ /* *
119
+ * @brief Network information
120
+ */
121
+ struct NetworkInfo
122
+ {
123
+ int mtu_errno; // !< @brief errno set by ioctl() with SIOCGIFMTU
124
+ int ethtool_errno; // !< @brief errno set by ioctl() with SIOCETHTOOL
125
+ bool is_running; // !< @brief resource allocated flag
126
+ std::string interface_name; // !< @brief interface name
127
+ float speed; // !< @brief network capacity
128
+ int mtu; // !< @brief MTU
129
+ float rx_traffic; // !< @brief traffic received
130
+ float tx_traffic; // !< @brief traffic transmitted
131
+ float rx_usage; // !< @brief network capacity usage rate received
132
+ float tx_usage; // !< @brief network capacity usage rate transmitted
133
+ unsigned int rx_bytes; // !< @brief total bytes received
134
+ unsigned int rx_errors; // !< @brief bad packets received
135
+ unsigned int tx_bytes; // !< @brief total bytes transmitted
136
+ unsigned int tx_errors; // !< @brief packet transmit problems
137
+ unsigned int collisions; // !< @brief number of collisions during packet transmissions
138
+
139
+ NetworkInfo ()
140
+ : mtu_errno(0 ),
141
+ ethtool_errno (0 ),
142
+ is_running(false ),
143
+ interface_name(" " ),
144
+ speed(0.0 ),
145
+ mtu(0 ),
146
+ rx_traffic(0.0 ),
147
+ tx_traffic(0.0 ),
148
+ rx_usage(0.0 ),
149
+ tx_usage(0.0 ),
150
+ rx_bytes(0 ),
151
+ rx_errors(0 ),
152
+ tx_bytes(0 ),
153
+ tx_errors(0 ),
154
+ collisions(0 )
155
+ {
156
+ }
157
+ };
158
+
159
+ /* *
160
+ * @brief determine if it is a supported network
161
+ * @param [in] net_info network infomation
162
+ * @param [in] index index of network infomation index
163
+ * @param [out] stat diagnostic message passed directly to diagnostic publish calls
164
+ * @param [out] error_str error string
165
+ * @return result of determining whether it is a supported network
166
+ */
167
+ bool isSupportedNetwork (
168
+ const NetworkInfo & net_info, int index, diagnostic_updater::DiagnosticStatusWrapper & stat,
169
+ std::string & error_str);
170
+
96
171
diagnostic_updater::Updater updater_; // !< @brief Updater class which advertises to /diagnostics
172
+ rclcpp::TimerBase::SharedPtr timer_; // !< @brief timer to get Network information
97
173
98
174
char hostname_[HOST_NAME_MAX + 1 ]; // !< @brief host name
99
175
std::map<std::string, bytes> bytes_; // !< @brief list of bytes
100
176
rclcpp::Time last_update_time_; // !< @brief last update time
101
177
std::vector<std::string> device_params_; // !< @brief list of devices
102
- NL80211 nl80211_; // !< @brief 802.11 netlink-based interface
178
+ NL80211 nl80211_; // !< @brief 802.11 netlink-based interface
179
+ int getifaddrs_errno_; // !< @brief errno set by getifaddrs()
180
+ std::vector<NetworkInfo> net_info_list_; // !< @brief list of Network information
103
181
104
- std::string monitor_program_; // !< @brief nethogs monitor program name
105
- bool nethogs_all_; // !< @brief nethogs result all mode
106
- int traffic_reader_port_; // !< @brief port number to connect to traffic_reader
182
+ /* *
183
+ * @brief CRC errors information
184
+ */
185
+ typedef struct crc_errors
186
+ {
187
+ std::deque<unsigned int > errors_queue; // !< @brief queue that holds count of CRC errors
188
+ unsigned int last_rx_crc_errors; // !< @brief rx_crc_error at the time of the last monitoring
189
+
190
+ crc_errors () : last_rx_crc_errors(0 ) {}
191
+ } crc_errors;
192
+ std::map<std::string, crc_errors> crc_errors_; // !< @brief list of CRC errors
193
+
194
+ std::string monitor_program_; // !< @brief nethogs monitor program name
195
+ bool nethogs_all_; // !< @brief nethogs result all mode
196
+ int traffic_reader_port_; // !< @brief port number to connect to traffic_reader
197
+ unsigned int crc_error_check_duration_; // !< @brief CRC error check duration
198
+ unsigned int crc_error_count_threshold_; // !< @brief CRC error count threshold
107
199
108
200
/* *
109
201
* @brief Network usage status messages
0 commit comments