Commit | Line | Data |
---|---|---|
10341d26 | 1 | /* This file is part of the Linux Trace Toolkit viewer |
277e5b53 | 2 | * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca> |
10341d26 | 3 | * |
277e5b53 BP |
4 | * This program is free software: you can redistribute it and/or modify it |
5 | * under the terms of the GNU Lesser General Public License as published by | |
6 | * the Free Software Foundation, either version 2.1 of the License, or (at | |
7 | * your option) any later version. | |
10341d26 | 8 | * |
277e5b53 BP |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | |
12 | * License for more details. | |
10341d26 | 13 | * |
277e5b53 BP |
14 | * You should have received a copy of the GNU Lesser General Public License |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
10341d26 BP |
16 | */ |
17 | ||
18 | #ifndef DATA_STRUCTURES_H | |
19 | #define DATA_STRUCTURES_H | |
20 | ||
21 | #include <glib.h> | |
22 | #include <stdbool.h> | |
23 | #include <stdint.h> | |
24 | ||
b2da0724 BP |
25 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
26 | ||
f10c27a8 BP |
27 | |
28 | enum Direction | |
29 | { | |
30 | OUT, | |
31 | IN, | |
32 | }; | |
33 | ||
34 | enum EventType | |
35 | { | |
36 | TCP, | |
37 | UDP, | |
2bd4b3e4 | 38 | TYPE_COUNT // This must be the last field |
f10c27a8 BP |
39 | }; |
40 | ||
10341d26 BP |
41 | // Stage 1 to 2: These structures are passed from processing to matching modules |
42 | // TCP events | |
43 | typedef struct | |
44 | { | |
45 | uint32_t saddr, daddr; | |
46 | uint16_t source, dest; | |
47 | } ConnectionKey; | |
48 | ||
49 | typedef struct | |
50 | { | |
51 | ConnectionKey connectionKey; | |
52 | uint8_t ihl; | |
53 | uint16_t tot_len; | |
54 | uint32_t seq, ack_seq; | |
55 | uint8_t doff; | |
56 | uint8_t ack, rst, syn, fin; | |
57 | } SegmentKey; | |
58 | ||
10341d26 BP |
59 | typedef struct |
60 | { | |
61 | enum Direction direction; | |
62 | SegmentKey* segmentKey; | |
63 | } TCPEvent; | |
64 | ||
65 | // UDP events | |
66 | typedef struct | |
67 | { | |
68 | uint32_t saddr, daddr; | |
f6691532 BP |
69 | uint16_t source, dest; |
70 | uint16_t ulen; | |
10341d26 BP |
71 | uint8_t dataKey[8]; |
72 | } DatagramKey; | |
73 | ||
74 | typedef struct | |
75 | { | |
76 | enum Direction direction; | |
77 | DatagramKey* datagramKey; | |
78 | bool unicast; | |
79 | } UDPEvent; | |
80 | ||
76be6fc2 BP |
81 | typedef struct |
82 | { | |
83 | uint32_t seconds; | |
84 | uint32_t nanosec; | |
85 | } WallTime; | |
86 | ||
10341d26 BP |
87 | typedef struct _Event |
88 | { | |
89 | unsigned long traceNum; | |
467066ee BP |
90 | // wallTime is corrected according to factors in trace struct, cpuTime |
91 | // is not | |
76be6fc2 BP |
92 | uint64_t cpuTime; |
93 | WallTime wallTime; | |
10341d26 BP |
94 | |
95 | // specific event structures and functions could be in separate files and | |
96 | // type could be an int | |
f6691532 | 97 | enum EventType type; |
10341d26 BP |
98 | // event could be a void*, this union is to avoid having to cast |
99 | union { | |
100 | TCPEvent* tcpEvent; | |
101 | UDPEvent* udpEvent; | |
102 | } event; | |
103 | ||
d4721e1a | 104 | void (*copy)(const struct _Event* const event, struct _Event** const newEvent); |
10341d26 BP |
105 | void (*destroy)(struct _Event* const event); |
106 | } Event; | |
107 | ||
108 | // Stage 2 to 3: These structures are passed from matching to analysis modules | |
109 | typedef struct _Message | |
110 | { | |
111 | Event* inE, * outE; | |
112 | ||
113 | void (*print)(const struct _Message* const message); | |
114 | } Message; | |
115 | ||
116 | typedef struct | |
117 | { | |
118 | Message* message; | |
ffa21cfd | 119 | // Event* acks[] |
10341d26 BP |
120 | GQueue* acks; |
121 | } Exchange; | |
122 | ||
123 | typedef struct | |
124 | { | |
ffa21cfd | 125 | // Event* events[] |
10341d26 BP |
126 | GQueue* events; |
127 | } Broadcast; | |
128 | ||
0a87ec9a BP |
129 | // Stage 4: These structures contain correction factors |
130 | /* Correction factors for each trace, this is the final result of | |
131 | * synchronization */ | |
10341d26 BP |
132 | typedef struct |
133 | { | |
134 | double drift, offset; | |
135 | } Factors; | |
136 | ||
0a87ec9a BP |
137 | // Correction factors between trace pairs, to be used for reduction |
138 | typedef enum | |
139 | { | |
140 | EXACT, | |
141 | /* Used for identity factors (a0= 0, a1= 1) that map a trace to itself. In | |
142 | * this case, min, max and accuracy are NULL. | |
143 | */ | |
144 | ||
145 | ACCURATE, | |
146 | /* The approximation is the middle of the min and max limits. All fields | |
147 | * are initialized. | |
148 | */ | |
149 | ||
150 | APPROXIMATE, | |
151 | /* min and max are not available. The approximation is a "best effort". | |
152 | * min and max are NULL. | |
153 | */ | |
154 | ||
155 | INCOMPLETE, | |
156 | /* min or max is available but not both. approx and accuracy are not | |
157 | * NULL. | |
158 | */ | |
159 | ||
160 | ABSENT, | |
161 | /* The pair of trace did not have communications in both directions (maybe | |
162 | * even no communication at all). approx and accuracy are NULL. | |
163 | */ | |
164 | ||
165 | SCREWED, | |
166 | /* The algorithms are screwed. All fields may be NULL. | |
167 | */ | |
168 | ||
169 | APPROX_NB, // This must be the last member | |
170 | } ApproxType; | |
171 | ||
172 | extern const char* const approxNames[APPROX_NB]; | |
173 | ||
174 | typedef struct | |
175 | { | |
176 | Factors* min, * max, * approx; | |
177 | ApproxType type; | |
178 | double accuracy; | |
179 | } PairFactors; | |
180 | ||
181 | typedef struct | |
182 | { | |
183 | unsigned int refCount; | |
0a87ec9a BP |
184 | PairFactors** pairFactors; |
185 | } AllFactors; | |
186 | ||
10341d26 BP |
187 | |
188 | // ConnectionKey-related functions | |
189 | guint ghfConnectionKeyHash(gconstpointer key); | |
190 | ||
191 | gboolean gefConnectionKeyEqual(gconstpointer a, gconstpointer b); | |
192 | bool connectionKeyEqual(const ConnectionKey* const a, const ConnectionKey* | |
193 | const b); | |
194 | ||
195 | void gdnConnectionKeyDestroy(gpointer data); | |
196 | ||
197 | // SegmentKey-related functions | |
198 | guint ghfSegmentKeyHash(gconstpointer key); | |
199 | gboolean gefSegmentKeyEqual(gconstpointer a, gconstpointer b); | |
200 | ||
f10c27a8 BP |
201 | // DatagramKey-related functions |
202 | guint ghfDatagramKeyHash(gconstpointer key); | |
203 | gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b); | |
204 | void gdnDestroyDatagramKey(gpointer data); | |
205 | ||
10341d26 BP |
206 | // Event-related functions |
207 | void gdnDestroyEvent(gpointer data); | |
d4721e1a BP |
208 | void copyEvent(const Event* const event, Event** const newEvent); |
209 | void copyTCPEvent(const Event* const event, Event** const newEvent); | |
210 | void copyUDPEvent(const Event* const event, Event** const newEvent); | |
10341d26 BP |
211 | void destroyEvent(Event* const event); |
212 | void destroyTCPEvent(Event* const event); | |
213 | void destroyUDPEvent(Event* const event); | |
f6691532 | 214 | void gfDestroyEvent(gpointer data, gpointer user_data); |
76be6fc2 | 215 | double wallTimeSub(const WallTime const* tA, const WallTime const* tB); |
66eaf2eb | 216 | void gfAddEventToArray(gpointer data, gpointer user_data); |
10341d26 BP |
217 | |
218 | // Message-related functions | |
219 | void printTCPSegment(const Message* const segment); | |
220 | void convertIP(char* const str, const uint32_t addr); | |
221 | ||
222 | gint gcfTCPSegmentAckCompare(gconstpointer a, gconstpointer b); | |
223 | bool isAcking(const Message* const ackSegment, const Message* const ackedSegment); | |
224 | ||
225 | void gdnTCPSegmentListDestroy(gpointer data); | |
226 | void gfTCPSegmentDestroy(gpointer data, gpointer user_data); | |
227 | void destroyTCPSegment(Message* const segment); | |
228 | ||
229 | // Exchange-related functions | |
230 | void destroyTCPExchange(Exchange* const exchange); | |
f6691532 BP |
231 | |
232 | // Broadcast-related functions | |
233 | void gdnDestroyBroadcast(gpointer data); | |
234 | void destroyBroadcast(Broadcast* const broadcast); | |
235 | ||
0a87ec9a BP |
236 | // Factor-related functions |
237 | void destroyPairFactors(PairFactors* factorsCHull); | |
238 | ||
239 | AllFactors* createAllFactors(const unsigned int traceNb); | |
b2da0724 | 240 | void freeAllFactors(AllFactors* const allFactors, const unsigned int traceNb); |
0a87ec9a | 241 | |
10341d26 | 242 | #endif |