annotate extensions/test_netemul/tne_process.c @ 1534:c83e60f28632

dict_dcca_3gpp: simplify rule creation Refactor local_rules_definition to simplify rule creation (to avoid c99 struct initialisers that result in long lines). No change to generated rules.
author Luke Mewburn <luke@mewburn.net>
date Mon, 20 Apr 2020 12:12:42 +1000
parents 6a1042d8075b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1127
1af09cc156d6 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1120
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 #include "test_netemul.h"
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 #include <math.h>
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 /* This file implements the real processing of the message.
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 The entry point is tne_process_message().
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 First, the duplicate filter is applied: with the configured
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 probability, a copy of the message is created. Then, with
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 the tenth probability, a second copy is created, and so on,
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 until the random value tells not to create a copy.
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47 The original message + all copies are stored in a list, for next step.
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 Second step is the latency filter. For each message in the list, a
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 latency value is randomly generated (with a lognormal shape of the
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 random distribution) and stored in the list.
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 Finally, when the latency time is over, the message is sent.
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 static pthread_cond_t cnd = PTHREAD_COND_INITIALIZER;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 static pthread_t thr = (pthread_t)NULL;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59
972
ce3cacbbccc9 Fix some typos.
Thomas Klausner <tk@giga.or.at>
parents: 740
diff changeset
60 /* The lists below are all protected by the same mutex mtx */
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 static struct fd_list input = FD_LIST_INITIALIZER(input); /* messages received from network */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 static struct fd_list forlat = FD_LIST_INITIALIZER(forlat); /* messages after duplicate filter */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 static struct fd_list waitlist = FD_LIST_INITIALIZER(waitlist); /* messages waiting for sending */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 struct process_item {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 struct fd_list chain; /* link into one of the lists. "o" points to the message. */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 struct timespec ts; /* when the message must be sent */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 };
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 /******************************************************************/
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 /* helper functions */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 /* Process all pi in input list and queue in forlat, duplicating when needed */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 static int do_duplicates()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 TRACE_ENTRY("");
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 while (!FD_IS_LIST_EMPTY(&input)) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 struct msg * m;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 struct process_item * pi = (struct process_item *)(input.next);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 /* Take out this pi from input */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 fd_list_unlink(&pi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 /* store it in forlat */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 fd_list_insert_before(&forlat, &pi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 /* Duplicate eventually, unless deactivated */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 if (tne_conf.dupl_proba != 0.0) {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
90 DiamId_t src;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
91 size_t srclen;
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 /* Pick a random value in [0, 1] */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 double my_rand = drand48();
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 m = pi->chain.o;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
95 CHECK_FCT( fd_msg_source_get(m, &src, &srclen) );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 while (my_rand < (double) tne_conf.dupl_proba) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 /* create the duplicate */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 struct process_item * npi;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 struct msg * nm;
655
98a322c319db Added T flag and some debug information for test_netemul
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 651
diff changeset
101 struct msg_hdr * nh;
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 unsigned char * buf;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 size_t len;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 /* Duplicate the message */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 CHECK_FCT( fd_msg_bufferize(m, &buf, &len) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 CHECK_FCT( fd_msg_parse_buffer(&buf, len, &nm) );
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 972
diff changeset
108 CHECK_FCT( fd_msg_source_set(nm, src, srclen) );
655
98a322c319db Added T flag and some debug information for test_netemul
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 651
diff changeset
109 CHECK_FCT( fd_msg_hdr(nm, &nh) );
98a322c319db Added T flag and some debug information for test_netemul
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 651
diff changeset
110 nh->msg_flags |= CMD_FLAG_RETRANSMIT; /* Add the 'T' flag */
98a322c319db Added T flag and some debug information for test_netemul
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 651
diff changeset
111 TRACE_DEBUG(FULL, "[tne] Duplicated message %p as %p", m, nm);
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113 /* Duplicate the pi */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 CHECK_MALLOC( npi = malloc(sizeof(struct process_item)) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 memset(npi, 0, sizeof(struct process_item));
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 fd_list_init(&npi->chain, nm);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 memcpy(&npi->ts, &pi->ts, sizeof(struct timespec));
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 /* Enqueue the candidate in forlat */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 fd_list_insert_before(&forlat, &npi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122 /* loop for another duplicate */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 if (!my_rand)
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124 break; /* otherwise, infinite loop */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 my_rand *= 10.0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
130 /* Done */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131 return 0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
134 /* Generate a random value with a normal distribution, mean 0, variance 1 */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
135 /* Using Box-Muller algo from Numerical Recipes in C++, 2nd Ed. */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
136 static double get_rand_norm()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
137 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138 double ru1, ru2; /* two random uniform values in -1..1 */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 double rsq; /* ru1^2 + ru2^2, to ensure we are in the circle */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 /* Get our appropriate 2 random uniform values */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 do {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 ru1 = 2.0 * drand48() - 1.0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 ru2 = 2.0 * drand48() - 1.0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 rsq = ru1 * ru1 + ru2 * ru2;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 } while ((rsq >= 1.0) || (rsq == 0.0));
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 /* Do the Box-Muller transform -- we don't use the 2nd value generated */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 return ru1 * sqrt( -2.0 * log(rsq) / rsq );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152 /* Return the latency to add, in ms. */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153 static __inline__ unsigned long get_latency()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 unsigned long lat = tne_conf.lat_avg;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 if (tne_conf.lat_dev) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 /* We randomize the value to add */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 double rn;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 rn = get_rand_norm(); /* this is normal random value with mean = 0 and variance = 1 */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 rn = rn * ((double)tne_conf.lat_dev) / 100.0; /* now the variance is lat_dev */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 rn = exp(rn); /* and now, we have a lognormal random value, with geometric mean = 1 */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 lat = (unsigned long)(rn * (double)lat); /* Apply to our mean latency */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 return lat;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 /* Process all pi in forlat and add a random latency, then requeue in order into waitlist */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 static int do_latency()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174 TRACE_ENTRY("");
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 while (!FD_IS_LIST_EMPTY(&forlat)) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 struct process_item * pi = (struct process_item *)(forlat.next);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 struct fd_list * li;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 /* Take out this pi from forlat */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 fd_list_unlink(&pi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 /* If there is a latency to add */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 if (tne_conf.lat_avg) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 unsigned long l = get_latency();
655
98a322c319db Added T flag and some debug information for test_netemul
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 651
diff changeset
186 TRACE_DEBUG(FULL, "[tne] Set %lu ms latency for %p", l, pi->chain.o);
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 pi->ts.tv_sec += l / 1000;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 l %= 1000;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 pi->ts.tv_nsec += l * 1000000;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 if (pi->ts.tv_nsec >= 1000000000) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 pi->ts.tv_sec += 1;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192 pi->ts.tv_nsec -= 1000000000;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 for (li = waitlist.prev; li != &waitlist; li=li->prev) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 struct process_item * p = (struct process_item *)li;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 if (TS_IS_INFERIOR( &p->ts, &pi->ts ))
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 break; /* we must insert after this one */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 /* store it */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
203 fd_list_insert_after(li, &pi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
204 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
205
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 /* Done */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 return 0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 /* Send all messages in waitlist that have passed their latency period */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211 static int send_all_ready()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 struct timespec now;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 TRACE_ENTRY("");
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 while (!FD_IS_LIST_EMPTY(&waitlist)) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220 struct msg * m;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 struct process_item * pi = (struct process_item *)(waitlist.next);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223 if (!TS_IS_INFERIOR( &pi->ts, &now))
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 break; /* We sent already all we could */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 /* Take out this pi and send the message */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 fd_list_unlink(&pi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 m = pi->chain.o;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229 free(pi);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230
655
98a322c319db Added T flag and some debug information for test_netemul
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 651
diff changeset
231 TRACE_DEBUG(FULL, "[tne] Sending now %p", m);
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232 CHECK_FCT( fd_msg_send(&m, NULL, NULL) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235 return 0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
238
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
239
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
240 /******************************************************************/
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241 /* the processing thread */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
242 static void * tne_process_th(void * arg)
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
243 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
244 TRACE_ENTRY("%p", arg);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
245
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
246 /* Name the thread */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
247 fd_log_threadname ( "test_netemul/process" );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
248
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
249 CHECK_POSIX_DO( pthread_mutex_lock(&mtx), goto error );
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
250 pthread_cleanup_push( fd_cleanup_mutex, &mtx );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
251
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
252 /* The loop */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
253 while (1) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
254 /* First, test if we are canceled */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
255 pthread_testcancel();
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
256
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
257 /* Send all messages that are ready (free resources before using new ones) */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
258 CHECK_FCT_DO( send_all_ready(), break );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
259
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
260 /* Now process the new messages in input list for duplicate filter */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
261 CHECK_FCT_DO( do_duplicates(), break );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
262
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
263 /* Now compute the latency for each new item */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
264 CHECK_FCT_DO( do_latency(), break );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
265
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
266 /* Now, wait then loop */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
267 if (FD_IS_LIST_EMPTY(&waitlist)) {
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
268 CHECK_POSIX_DO( pthread_cond_wait(&cnd, &mtx), break );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
269 } else {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
270 CHECK_POSIX_DO2( pthread_cond_timedwait(&cnd, &mtx, &((struct process_item *)(waitlist.next))->ts),
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
271 ETIMEDOUT, /* ETIMEDOUT is a normal return value, continue */,
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
272 /* on other error, */ break );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
273 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
274
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
275 /* loop */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
276 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
277
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
278 pthread_cleanup_pop( 0 );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
279 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
280 error:
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
281 TRACE_DEBUG(INFO, "A fatal error occurred in test_netemul/process thread!");
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
282 ASSERT(0);
1190
6a1042d8075b Replace FDEV_TERMINATE events with calls to fd_core_shutdown to handle the core state properly
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
283 CHECK_FCT_DO(fd_core_shutdown(), );
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
284 return NULL;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
285 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
286
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
287 /******************************************************************/
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
288 /* functions visible from outside this file */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
289 int tne_process_init()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
290 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
291 CHECK_POSIX( pthread_create(&thr, NULL, tne_process_th, NULL) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
292
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
293 #if 0 /* debug */
656
5b05d85682f1 Small fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 655
diff changeset
294 int i;
651
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
295 for (i=0; i< 20; i++) {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
296 printf("LAT: %lu\n", get_latency());
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
297 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
298 #endif /* 0 */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
299
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
300 return 0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
301 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
302
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
303
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
304 int tne_process_fini()
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
305 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
306 CHECK_FCT( fd_thr_term(&thr) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
307 return 0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
308 }
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
309
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
310
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311 int tne_process_message(struct msg * msg)
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312 {
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
313 struct process_item * pi;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
314
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
315 TRACE_ENTRY("%p", msg);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
316
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
317 /* Create a new pi for this message */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
318 CHECK_MALLOC( pi = malloc(sizeof(struct process_item)) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
319 memset(pi, 0, sizeof(struct process_item));
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
320 fd_list_init(&pi->chain, msg);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
321 CHECK_SYS(clock_gettime(CLOCK_REALTIME, &pi->ts));
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
322
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
323 /* Store it in the input list */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
324 CHECK_POSIX( pthread_mutex_lock(&mtx) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
325 fd_list_insert_before(&input, &pi->chain);
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
326 CHECK_POSIX( pthread_mutex_unlock(&mtx) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
327
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
328 /* Wake up the process thread so that it processes the message */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
329 CHECK_POSIX( pthread_cond_signal(&cnd) );
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
330
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
331 /* done */
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
332 return 0;
083317a4e947 Added new test_netemul extension (need testing)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
333 }
"Welcome to our mercurial repository"