| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca> |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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/>. |
| 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 | |
| 25 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 26 | |
| 27 | |
| 28 | enum Direction |
| 29 | { |
| 30 | OUT, |
| 31 | IN, |
| 32 | }; |
| 33 | |
| 34 | enum EventType |
| 35 | { |
| 36 | TCP, |
| 37 | UDP, |
| 38 | TYPE_COUNT // This must be the last field |
| 39 | }; |
| 40 | |
| 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 | |
| 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; |
| 69 | uint16_t source, dest; |
| 70 | uint16_t ulen; |
| 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 | |
| 81 | typedef struct |
| 82 | { |
| 83 | uint32_t seconds; |
| 84 | uint32_t nanosec; |
| 85 | } WallTime; |
| 86 | |
| 87 | typedef struct _Event |
| 88 | { |
| 89 | unsigned long traceNum; |
| 90 | // wallTime is corrected according to factors in trace struct, cpuTime |
| 91 | // is not |
| 92 | uint64_t cpuTime; |
| 93 | WallTime wallTime; |
| 94 | |
| 95 | // specific event structures and functions could be in separate files and |
| 96 | // type could be an int |
| 97 | enum EventType type; |
| 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 | |
| 104 | void (*copy)(const struct _Event* const event, struct _Event** const newEvent); |
| 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; |
| 119 | // Event* acks[] |
| 120 | GQueue* acks; |
| 121 | } Exchange; |
| 122 | |
| 123 | typedef struct |
| 124 | { |
| 125 | // Event* events[] |
| 126 | GQueue* events; |
| 127 | } Broadcast; |
| 128 | |
| 129 | // Stage 4: These structures contain correction factors |
| 130 | /* Correction factors for each trace, this is the final result of |
| 131 | * synchronization */ |
| 132 | typedef struct |
| 133 | { |
| 134 | double drift, offset; |
| 135 | } Factors; |
| 136 | |
| 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 | FAIL, |
| 166 | /* The algorithms are defective. 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; |
| 184 | PairFactors** pairFactors; |
| 185 | } AllFactors; |
| 186 | |
| 187 | |
| 188 | // This structure is used to return a corrected time value with accuracy |
| 189 | // bounds |
| 190 | typedef struct |
| 191 | { |
| 192 | uint64_t time, min, max; |
| 193 | } CorrectedTime; |
| 194 | |
| 195 | |
| 196 | // ConnectionKey-related functions |
| 197 | guint ghfConnectionKeyHash(gconstpointer key); |
| 198 | |
| 199 | gboolean gefConnectionKeyEqual(gconstpointer a, gconstpointer b); |
| 200 | bool connectionKeyEqual(const ConnectionKey* const a, const ConnectionKey* |
| 201 | const b); |
| 202 | |
| 203 | void gdnConnectionKeyDestroy(gpointer data); |
| 204 | |
| 205 | // SegmentKey-related functions |
| 206 | guint ghfSegmentKeyHash(gconstpointer key); |
| 207 | gboolean gefSegmentKeyEqual(gconstpointer a, gconstpointer b); |
| 208 | |
| 209 | // DatagramKey-related functions |
| 210 | guint ghfDatagramKeyHash(gconstpointer key); |
| 211 | gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b); |
| 212 | void gdnDestroyDatagramKey(gpointer data); |
| 213 | |
| 214 | // Event-related functions |
| 215 | void gdnDestroyEvent(gpointer data); |
| 216 | void copyEvent(const Event* const event, Event** const newEvent); |
| 217 | void copyTCPEvent(const Event* const event, Event** const newEvent); |
| 218 | void copyUDPEvent(const Event* const event, Event** const newEvent); |
| 219 | void destroyEvent(Event* const event); |
| 220 | void destroyTCPEvent(Event* const event); |
| 221 | void destroyUDPEvent(Event* const event); |
| 222 | void gfDestroyEvent(gpointer data, gpointer user_data); |
| 223 | double wallTimeSub(const WallTime const* tA, const WallTime const* tB); |
| 224 | void gfAddEventToArray(gpointer data, gpointer user_data); |
| 225 | |
| 226 | // Message-related functions |
| 227 | void printTCPSegment(const Message* const segment); |
| 228 | void convertIP(char* const str, const uint32_t addr); |
| 229 | |
| 230 | gint gcfTCPSegmentAckCompare(gconstpointer a, gconstpointer b); |
| 231 | bool isAcking(const Message* const ackSegment, const Message* const ackedSegment); |
| 232 | |
| 233 | void gdnTCPSegmentListDestroy(gpointer data); |
| 234 | void gfTCPSegmentDestroy(gpointer data, gpointer user_data); |
| 235 | void destroyTCPSegment(Message* const segment); |
| 236 | |
| 237 | // Exchange-related functions |
| 238 | void destroyTCPExchange(Exchange* const exchange); |
| 239 | |
| 240 | // Broadcast-related functions |
| 241 | void gdnDestroyBroadcast(gpointer data); |
| 242 | void destroyBroadcast(Broadcast* const broadcast); |
| 243 | |
| 244 | // Factor-related functions |
| 245 | void destroyPairFactors(PairFactors* factorsCHull); |
| 246 | |
| 247 | AllFactors* createAllFactors(const unsigned int traceNb); |
| 248 | void freeAllFactors(AllFactors* const allFactors, const unsigned int traceNb); |
| 249 | |
| 250 | #endif |