LinkStatistics.c.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. LinkStatistics.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='keys.c.html' title=' keys.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='LinkStatus.c.html' title=' LinkStatus.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * signed LinkStatistics (struct plc * plc);
  64. *
  65. * plc.h
  66. *
  67. * this plugin for plcstat reads device link statistics using a
  68. * VS_LNK_STATS message and displays information on stdout; since
  69. * the output may not suite all requirements, users are encouraged
  70. * to modify as needed; there is way too much data displayed here;
  71. *
  72. * some code is duplicated for the sake of modularity;
  73. *
  74. *
  75. * Contributor(s):
  76. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  77. *
  78. *--------------------------------------------------------------------*/
  79. #ifndef LINKSTATISTICS_SOURCE
  80. #define LINKSTATISTICS_SOURCE
  81. #include &lt;stdint.h&gt;
  82. #include &lt;memory.h&gt;
  83. #include &lt;inttypes.h&gt;
  84. #include &quot;../plc/plc.h&quot;
  85. #include &quot;../tools/memory.h&quot;
  86. #include &quot;../tools/number.h&quot;
  87. #include &quot;../tools/error.h&quot;
  88. /*====================================================================*
  89. * constants;
  90. *--------------------------------------------------------------------*/
  91. #define PAD ' '
  92. #define DIGITS 16
  93. /*====================================================================*
  94. * variables;
  95. *--------------------------------------------------------------------*/
  96. #ifndef __GNUC__
  97. #pragma pack (push,1)
  98. #endif
  99. typedef struct __packed transmit
  100. {
  101. uint64_t NUMTXMPDU_ACKD;
  102. uint64_t NUMTXMPDU_COLL;
  103. uint64_t NUMTXMPDU_FAIL;
  104. uint64_t NUMTXPBS_PASS;
  105. uint64_t NUMTXPBS_FAIL;
  106. }
  107. transmit;
  108. typedef struct __packed receive
  109. {
  110. uint64_t NUMRXMPDU_ACKD;
  111. uint64_t NUMRXMPDU_FAIL;
  112. uint64_t NUMRXPBS_PASS;
  113. uint64_t NUMRXPBS_FAIL;
  114. uint64_t SUMTURBOBER_PASS;
  115. uint64_t SUMTURBOBER_FAIL;
  116. uint8_t NUMRXINTERVALS;
  117. uint8_t RXINTERVALSTATS [1];
  118. }
  119. receive;
  120. typedef struct __packed interval
  121. {
  122. uint8_t RXPHYRATE_MBPS_0;
  123. uint64_t NUMRXPBS_PASS;
  124. uint64_t NUMRXPBS_FAIL;
  125. uint64_t SUMTURBOBER_PASS;
  126. uint64_t SUMTURBOBER_FAIL;
  127. }
  128. interval;
  129. #ifndef __GNUC__
  130. #pragma pack (pop)
  131. #endif
  132. /*====================================================================*
  133. *
  134. * unsigned error_rate (uint64_t passed, uint64_t failed);
  135. *
  136. * compute error rate for a given quantity; the error rate is the
  137. * ratio of failures to attempts;
  138. *
  139. *--------------------------------------------------------------------*/
  140. static float error_rate (uint64_t passed, uint64_t failed)
  141. {
  142. if ((passed) || (failed))
  143. {
  144. return ((float)(failed * 100) / (float)(passed + failed));
  145. }
  146. return (0);
  147. }
  148. /*====================================================================*
  149. *
  150. * float fec_bit_error_rate (struct receive * receive);
  151. *
  152. * compute the FEC-BER from the VS_LNK_STATS when DIRECTION=1 and
  153. * LID=0xF8;
  154. *
  155. *--------------------------------------------------------------------*/
  156. static float fec_bit_error_rate (struct receive * receive)
  157. {
  158. float FECBitErrorRate = 0;
  159. if (receive-&gt;SUMTURBOBER_PASS || receive-&gt;SUMTURBOBER_FAIL)
  160. {
  161. float TotalSumOfBitError = 100 * (float)(receive-&gt;SUMTURBOBER_PASS + receive-&gt;SUMTURBOBER_FAIL);
  162. float TotalSumOfBits = 8 * 520 * (float)(receive-&gt;NUMRXPBS_PASS + receive-&gt;NUMRXPBS_FAIL);
  163. FECBitErrorRate = TotalSumOfBitError / TotalSumOfBits;
  164. }
  165. return (FECBitErrorRate);
  166. }
  167. /*====================================================================*
  168. *
  169. * void transmit (struct transmit * transmit);
  170. *
  171. * display transmit statistics in fixed field format;
  172. *
  173. *--------------------------------------------------------------------*/
  174. static void TransmitStatistics (struct transmit * transmit)
  175. {
  176. printf (&quot; TX&quot;);
  177. printf (&quot; %20&quot; PRId64, transmit-&gt;NUMTXPBS_PASS);
  178. printf (&quot; %20&quot; PRId64, transmit-&gt;NUMTXPBS_FAIL);
  179. printf (&quot; %6.2f%%&quot;, error_rate (transmit-&gt;NUMTXPBS_PASS, transmit-&gt;NUMTXPBS_FAIL));
  180. printf (&quot; %20&quot; PRId64, transmit-&gt;NUMTXMPDU_ACKD);
  181. printf (&quot; %20&quot; PRId64, transmit-&gt;NUMTXMPDU_FAIL);
  182. printf (&quot; %20&quot; PRId64, transmit-&gt;NUMTXMPDU_COLL);
  183. printf (&quot; %6.2f%%&quot;, error_rate (transmit-&gt;NUMTXMPDU_ACKD, transmit-&gt;NUMTXMPDU_FAIL));
  184. printf (&quot;\n&quot;);
  185. return;
  186. }
  187. /*====================================================================*
  188. *
  189. * void Receive (struct receive * receive);
  190. *
  191. * display receive statistics in fixed field format;
  192. *
  193. *--------------------------------------------------------------------*/
  194. static void ReceiveStatistics (struct receive * receive)
  195. {
  196. printf (&quot; RX&quot;);
  197. printf (&quot; %20&quot; PRId64, receive-&gt;NUMRXPBS_PASS);
  198. printf (&quot; %20&quot; PRId64, receive-&gt;NUMRXPBS_FAIL);
  199. printf (&quot; %6.2f%%&quot;, error_rate (receive-&gt;NUMRXPBS_PASS, receive-&gt;NUMRXPBS_FAIL));
  200. printf (&quot; %20&quot; PRId64, receive-&gt;NUMRXMPDU_ACKD);
  201. printf (&quot; %20&quot; PRId64, receive-&gt;NUMRXMPDU_FAIL);
  202. printf (&quot; %6.2f%%&quot;, error_rate (receive-&gt;NUMRXMPDU_ACKD, receive-&gt;NUMRXMPDU_FAIL));
  203. printf (&quot;\n&quot;);
  204. return;
  205. }
  206. /*====================================================================*
  207. *
  208. * void Receive (struct receive * receive);
  209. *
  210. * display receive statistics in fixed field format for each slot;
  211. * the last line sumarizes results for all slots;
  212. *
  213. *--------------------------------------------------------------------*/
  214. static void Receive2 (struct receive * receive)
  215. {
  216. struct interval * interval = (struct interval *)(receive-&gt;RXINTERVALSTATS);
  217. uint8_t slot = 0;
  218. while (slot &lt; receive-&gt;NUMRXINTERVALS)
  219. {
  220. printf (&quot; %1d&quot;, slot);
  221. printf (&quot; %3d&quot;, interval-&gt;RXPHYRATE_MBPS_0);
  222. printf (&quot; %20&quot; PRId64, interval-&gt;NUMRXPBS_PASS);
  223. printf (&quot; %20&quot; PRId64, interval-&gt;NUMRXPBS_FAIL);
  224. printf (&quot; %6.2f%%&quot;, error_rate (interval-&gt;NUMRXPBS_PASS, interval-&gt;NUMRXPBS_FAIL));
  225. printf (&quot; %20&quot; PRId64, interval-&gt;SUMTURBOBER_PASS);
  226. printf (&quot; %20&quot; PRId64, interval-&gt;SUMTURBOBER_FAIL);
  227. printf (&quot; %6.2f%%&quot;, error_rate (interval-&gt;SUMTURBOBER_PASS, interval-&gt;SUMTURBOBER_FAIL));
  228. printf (&quot;\n&quot;);
  229. interval++;
  230. slot++;
  231. }
  232. printf (&quot; ALL&quot;);
  233. printf (&quot; %20&quot; PRId64, receive-&gt;NUMRXPBS_PASS);
  234. printf (&quot; %20&quot; PRId64, receive-&gt;NUMRXPBS_FAIL);
  235. printf (&quot; %6.2f%%&quot;, error_rate (receive-&gt;NUMRXPBS_PASS, receive-&gt;NUMRXPBS_FAIL));
  236. printf (&quot; %20&quot; PRId64, receive-&gt;SUMTURBOBER_PASS);
  237. printf (&quot; %20&quot; PRId64, receive-&gt;SUMTURBOBER_FAIL);
  238. printf (&quot; %6.2f%%&quot;, error_rate (receive-&gt;SUMTURBOBER_PASS, receive-&gt;SUMTURBOBER_FAIL));
  239. printf (&quot; %6.2f%%&quot;, fec_bit_error_rate (receive));
  240. printf (&quot;\n&quot;);
  241. return;
  242. }
  243. /*====================================================================*
  244. *
  245. * signed LinkStatistics (struct plc * plc);
  246. *
  247. *
  248. *--------------------------------------------------------------------*/
  249. signed LinkStatistics (struct plc * plc)
  250. {
  251. struct channel * channel = (struct channel *)(plc-&gt;channel);
  252. struct message * message = (struct message *)(plc-&gt;message);
  253. #ifndef __GNUC__
  254. #pragma pack (push,1)
  255. #endif
  256. struct __packed vs_lnk_stats_request
  257. {
  258. struct ethernet_hdr ethernet;
  259. struct qualcomm_hdr qualcomm;
  260. uint8_t MCONTROL;
  261. uint8_t DIRECTION;
  262. uint8_t LID;
  263. uint8_t MACADDRESS [ETHER_ADDR_LEN];
  264. }
  265. * request = (struct vs_lnk_stats_request *) (message);
  266. struct __packed vs_lnk_stats_confirm
  267. {
  268. struct ethernet_hdr ethernet;
  269. struct qualcomm_hdr qualcomm;
  270. uint8_t MSTATUS;
  271. uint8_t DIRECTION;
  272. uint8_t LID;
  273. uint8_t TEI;
  274. uint8_t LSTATS [1];
  275. }
  276. * confirm = (struct vs_lnk_stats_confirm *) (message);
  277. #ifndef __GNUC__
  278. #pragma pack (pop)
  279. #endif
  280. memset (message, 0, sizeof (* message));
  281. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  282. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_LNK_STATS | MMTYPE_REQ));
  283. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  284. request-&gt;MCONTROL = plc-&gt;pushbutton;
  285. request-&gt;DIRECTION = plc-&gt;module;
  286. request-&gt;LID = plc-&gt;action;
  287. memcpy (request-&gt;MACADDRESS, plc-&gt;RDA, sizeof (request-&gt;MACADDRESS));
  288. if (SendMME (plc) &lt;= 0)
  289. {
  290. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  291. return (-1);
  292. }
  293. if (ReadMME (plc, 0, (VS_LNK_STATS | MMTYPE_CNF)) &lt;= 0)
  294. {
  295. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  296. return (-1);
  297. }
  298. if (confirm-&gt;MSTATUS)
  299. {
  300. Failure (plc, PLC_WONTDOIT);
  301. return (-1);
  302. }
  303. if (confirm-&gt;DIRECTION == 0)
  304. {
  305. printf (&quot; DIR&quot;);
  306. printf (&quot; ----------- PBs PASS&quot;);
  307. printf (&quot; ----------- PBs FAIL&quot;);
  308. printf (&quot; PBs ERR&quot;);
  309. printf (&quot; ---------- MPDU ACKD&quot;);
  310. printf (&quot; ---------- MPDU FAIL&quot;);
  311. printf (&quot;\n&quot;);
  312. TransmitStatistics ((struct transmit *)(confirm-&gt;LSTATS));
  313. printf (&quot;\n&quot;);
  314. }
  315. if (confirm-&gt;DIRECTION == 1)
  316. {
  317. printf (&quot; DIR&quot;);
  318. printf (&quot; ----------- PBs PASS&quot;);
  319. printf (&quot; ----------- PBs FAIL&quot;);
  320. printf (&quot; PBs ERR&quot;);
  321. printf (&quot; ---------- MPDU ACKD&quot;);
  322. printf (&quot; ---------- MPDU FAIL&quot;);
  323. printf (&quot;\n&quot;);
  324. ReceiveStatistics ((struct receive *)(confirm-&gt;LSTATS));
  325. printf (&quot;\n&quot;);
  326. printf (&quot; PHY&quot;);
  327. printf (&quot; ----------- PBs PASS&quot;);
  328. printf (&quot; ----------- PBs FAIL&quot;);
  329. printf (&quot; PBs ERR&quot;);
  330. printf (&quot; ----------- BER PASS&quot;);
  331. printf (&quot; ----------- BER FAIL&quot;);
  332. printf (&quot; BER ERR&quot;);
  333. printf (&quot;\n&quot;);
  334. Receive2 ((struct receive *)(confirm-&gt;LSTATS));
  335. printf (&quot;\n&quot;);
  336. }
  337. if (confirm-&gt;DIRECTION == 2)
  338. {
  339. printf (&quot; DIR&quot;);
  340. printf (&quot; ----------- PBs PASS&quot;);
  341. printf (&quot; ----------- PBs FAIL&quot;);
  342. printf (&quot; PBs ERR&quot;);
  343. printf (&quot; ---------- MPDU ACKD&quot;);
  344. printf (&quot; ---------- MPDU FAIL&quot;);
  345. printf (&quot;\n&quot;);
  346. TransmitStatistics ((struct transmit *)(confirm-&gt;LSTATS));
  347. ReceiveStatistics ((struct receive *)(confirm-&gt;LSTATS + sizeof (struct transmit)));
  348. printf (&quot;\n&quot;);
  349. printf (&quot; PHY&quot;);
  350. printf (&quot; ----------- PBs PASS&quot;);
  351. printf (&quot; ----------- PBs FAIL&quot;);
  352. printf (&quot; PBs ERR&quot;);
  353. printf (&quot; ----------- BER PASS&quot;);
  354. printf (&quot; ----------- BER FAIL&quot;);
  355. printf (&quot; BER ERR&quot;);
  356. printf (&quot;\n&quot;);
  357. Receive2 ((struct receive *)(confirm-&gt;LSTATS + sizeof (struct transmit)));
  358. printf (&quot;\n&quot;);
  359. }
  360. return (0);
  361. }
  362. #endif
  363. </pre>
  364. <div class='footerlink'>
  365. [<a href='keys.c.html' title=' keys.c '>PREV</a>]
  366. [<a href='toolkit.html' title=' Index '>HOME</a>]
  367. [<a href='LinkStatus.c.html' title=' LinkStatus.c '>NEXT</a>]
  368. </div>
  369. </body>
  370. </html>