fairqueue_test2.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @file fairqueue_test2.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <string.h>
  23. #include <misc/debug.h>
  24. #include <system/BReactor.h>
  25. #include <system/BLog.h>
  26. #include <system/BTime.h>
  27. #include <flow/PacketPassFairQueue.h>
  28. #include <examples/FastPacketSource.h>
  29. #include <examples/RandomPacketSink.h>
  30. #define SINK_TIMER 0
  31. int main ()
  32. {
  33. // initialize logging
  34. BLog_InitStdout();
  35. // init time
  36. BTime_Init();
  37. // initialize reactor
  38. BReactor reactor;
  39. if (!BReactor_Init(&reactor)) {
  40. DEBUG("BReactor_Init failed");
  41. return 1;
  42. }
  43. // initialize sink
  44. RandomPacketSink sink;
  45. RandomPacketSink_Init(&sink, &reactor, 500, SINK_TIMER);
  46. // initialize queue
  47. PacketPassFairQueue fq;
  48. PacketPassFairQueue_Init(&fq, RandomPacketSink_GetInput(&sink), BReactor_PendingGroup(&reactor), 0);
  49. // initialize source 1
  50. PacketPassFairQueueFlow flow1;
  51. PacketPassFairQueueFlow_Init(&flow1, &fq);
  52. FastPacketSource source1;
  53. char data1[] = "data1";
  54. FastPacketSource_Init(&source1, PacketPassFairQueueFlow_GetInput(&flow1), (uint8_t *)data1, strlen(data1), BReactor_PendingGroup(&reactor));
  55. // initialize source 2
  56. PacketPassFairQueueFlow flow2;
  57. PacketPassFairQueueFlow_Init(&flow2, &fq);
  58. FastPacketSource source2;
  59. char data2[] = "data2data2";
  60. FastPacketSource_Init(&source2, PacketPassFairQueueFlow_GetInput(&flow2), (uint8_t *)data2, strlen(data2), BReactor_PendingGroup(&reactor));
  61. // initialize source 3
  62. PacketPassFairQueueFlow flow3;
  63. PacketPassFairQueueFlow_Init(&flow3, &fq);
  64. FastPacketSource source3;
  65. char data3[] = "data3data3data3data3data3data3data3data3data3";
  66. FastPacketSource_Init(&source3, PacketPassFairQueueFlow_GetInput(&flow3), (uint8_t *)data3, strlen(data3), BReactor_PendingGroup(&reactor));
  67. // run reactor
  68. int ret = BReactor_Exec(&reactor);
  69. BReactor_Free(&reactor);
  70. return ret;
  71. }