fairqueue_test2.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. int main ()
  31. {
  32. // initialize logging
  33. BLog_InitStdout();
  34. // init time
  35. BTime_Init();
  36. // initialize reactor
  37. BReactor reactor;
  38. if (!BReactor_Init(&reactor)) {
  39. DEBUG("BReactor_Init failed");
  40. return 1;
  41. }
  42. // initialize sink
  43. RandomPacketSink sink;
  44. RandomPacketSink_Init(&sink, &reactor, 500, 0);
  45. // initialize queue
  46. PacketPassFairQueue fq;
  47. PacketPassFairQueue_Init(&fq, RandomPacketSink_GetInput(&sink), BReactor_PendingGroup(&reactor));
  48. // initialize source 1
  49. PacketPassFairQueueFlow flow1;
  50. PacketPassFairQueueFlow_Init(&flow1, &fq);
  51. FastPacketSource source1;
  52. char data1[] = "data1";
  53. FastPacketSource_Init(&source1, PacketPassFairQueueFlow_GetInput(&flow1), (uint8_t *)data1, strlen(data1), BReactor_PendingGroup(&reactor));
  54. // initialize source 2
  55. PacketPassFairQueueFlow flow2;
  56. PacketPassFairQueueFlow_Init(&flow2, &fq);
  57. FastPacketSource source2;
  58. char data2[] = "data2data2";
  59. FastPacketSource_Init(&source2, PacketPassFairQueueFlow_GetInput(&flow2), (uint8_t *)data2, strlen(data2), BReactor_PendingGroup(&reactor));
  60. // initialize source 3
  61. PacketPassFairQueueFlow flow3;
  62. PacketPassFairQueueFlow_Init(&flow3, &fq);
  63. FastPacketSource source3;
  64. char data3[] = "data3data3data3data3data3data3data3data3data3";
  65. FastPacketSource_Init(&source3, PacketPassFairQueueFlow_GetInput(&flow3), (uint8_t *)data3, strlen(data3), BReactor_PendingGroup(&reactor));
  66. // run reactor
  67. int ret = BReactor_Exec(&reactor);
  68. BReactor_Free(&reactor);
  69. return ret;
  70. }