BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file fairqueue_test2.c |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #include <string.h> |
||
31 | |||
32 | #include <misc/debug.h> |
||
33 | #include <system/BReactor.h> |
||
34 | #include <base/BLog.h> |
||
35 | #include <system/BTime.h> |
||
36 | #include <flow/PacketPassFairQueue.h> |
||
37 | #include <examples/FastPacketSource.h> |
||
38 | #include <examples/RandomPacketSink.h> |
||
39 | |||
40 | #define SINK_TIMER 0 |
||
41 | |||
42 | int main () |
||
43 | { |
||
44 | // initialize logging |
||
45 | BLog_InitStdout(); |
||
46 | |||
47 | // init time |
||
48 | BTime_Init(); |
||
49 | |||
50 | // initialize reactor |
||
51 | BReactor reactor; |
||
52 | if (!BReactor_Init(&reactor)) { |
||
53 | DEBUG("BReactor_Init failed"); |
||
54 | return 1; |
||
55 | } |
||
56 | |||
57 | // initialize sink |
||
58 | RandomPacketSink sink; |
||
59 | RandomPacketSink_Init(&sink, &reactor, 500, SINK_TIMER); |
||
60 | |||
61 | // initialize queue |
||
62 | PacketPassFairQueue fq; |
||
63 | if (!PacketPassFairQueue_Init(&fq, RandomPacketSink_GetInput(&sink), BReactor_PendingGroup(&reactor), 0, 1)) { |
||
64 | DEBUG("PacketPassFairQueue_Init failed"); |
||
65 | return 1; |
||
66 | } |
||
67 | |||
68 | // initialize source 1 |
||
69 | PacketPassFairQueueFlow flow1; |
||
70 | PacketPassFairQueueFlow_Init(&flow1, &fq); |
||
71 | FastPacketSource source1; |
||
72 | char data1[] = "data1"; |
||
73 | FastPacketSource_Init(&source1, PacketPassFairQueueFlow_GetInput(&flow1), (uint8_t *)data1, strlen(data1), BReactor_PendingGroup(&reactor)); |
||
74 | |||
75 | // initialize source 2 |
||
76 | PacketPassFairQueueFlow flow2; |
||
77 | PacketPassFairQueueFlow_Init(&flow2, &fq); |
||
78 | FastPacketSource source2; |
||
79 | char data2[] = "data2data2"; |
||
80 | FastPacketSource_Init(&source2, PacketPassFairQueueFlow_GetInput(&flow2), (uint8_t *)data2, strlen(data2), BReactor_PendingGroup(&reactor)); |
||
81 | |||
82 | // initialize source 3 |
||
83 | PacketPassFairQueueFlow flow3; |
||
84 | PacketPassFairQueueFlow_Init(&flow3, &fq); |
||
85 | FastPacketSource source3; |
||
86 | char data3[] = "data3data3data3data3data3data3data3data3data3"; |
||
87 | FastPacketSource_Init(&source3, PacketPassFairQueueFlow_GetInput(&flow3), (uint8_t *)data3, strlen(data3), BReactor_PendingGroup(&reactor)); |
||
88 | |||
89 | // run reactor |
||
90 | int ret = BReactor_Exec(&reactor); |
||
91 | BReactor_Free(&reactor); |
||
92 | return ret; |
||
93 | } |