| 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 | |
| 26 | enum Direction |
| 27 | { |
| 28 | OUT, |
| 29 | IN, |
| 30 | }; |
| 31 | |
| 32 | enum EventType |
| 33 | { |
| 34 | TCP, |
| 35 | UDP, |
| 36 | TYPE_COUNT // This must be the last field |
| 37 | }; |
| 38 | |
| 39 | // Stage 1 to 2: These structures are passed from processing to matching modules |
| 40 | // TCP events |
| 41 | typedef struct |
| 42 | { |
| 43 | uint32_t saddr, daddr; |
| 44 | uint16_t source, dest; |
| 45 | } ConnectionKey; |
| 46 | |
| 47 | typedef struct |
| 48 | { |
| 49 | ConnectionKey connectionKey; |
| 50 | uint8_t ihl; |
| 51 | uint16_t tot_len; |
| 52 | uint32_t seq, ack_seq; |
| 53 | uint8_t doff; |
| 54 | uint8_t ack, rst, syn, fin; |
| 55 | } SegmentKey; |
| 56 | |
| 57 | typedef struct |
| 58 | { |
| 59 | enum Direction direction; |
| 60 | SegmentKey* segmentKey; |
| 61 | } TCPEvent; |
| 62 | |
| 63 | // UDP events |
| 64 | typedef struct |
| 65 | { |
| 66 | uint32_t saddr, daddr; |
| 67 | uint16_t source, dest; |
| 68 | uint16_t ulen; |
| 69 | uint8_t dataKey[8]; |
| 70 | } DatagramKey; |
| 71 | |
| 72 | typedef struct |
| 73 | { |
| 74 | enum Direction direction; |
| 75 | DatagramKey* datagramKey; |
| 76 | bool unicast; |
| 77 | } UDPEvent; |
| 78 | |
| 79 | typedef struct |
| 80 | { |
| 81 | uint32_t seconds; |
| 82 | uint32_t nanosec; |
| 83 | } WallTime; |
| 84 | |
| 85 | typedef struct _Event |
| 86 | { |
| 87 | unsigned long traceNum; |
| 88 | // wallTime is corrected according to factors in trace struct, cpuTime |
| 89 | // is not |
| 90 | uint64_t cpuTime; |
| 91 | WallTime wallTime; |
| 92 | |
| 93 | // specific event structures and functions could be in separate files and |
| 94 | // type could be an int |
| 95 | enum EventType type; |
| 96 | // event could be a void*, this union is to avoid having to cast |
| 97 | union { |
| 98 | TCPEvent* tcpEvent; |
| 99 | UDPEvent* udpEvent; |
| 100 | } event; |
| 101 | |
| 102 | void (*copy)(const struct _Event* const event, struct _Event** const newEvent); |
| 103 | void (*destroy)(struct _Event* const event); |
| 104 | } Event; |
| 105 | |
| 106 | // Stage 2 to 3: These structures are passed from matching to analysis modules |
| 107 | typedef struct _Message |
| 108 | { |
| 109 | Event* inE, * outE; |
| 110 | |
| 111 | void (*print)(const struct _Message* const message); |
| 112 | } Message; |
| 113 | |
| 114 | typedef struct |
| 115 | { |
| 116 | Message* message; |
| 117 | // Event* acks[] |
| 118 | GQueue* acks; |
| 119 | } Exchange; |
| 120 | |
| 121 | typedef struct |
| 122 | { |
| 123 | // Event* events[] |
| 124 | GQueue* events; |
| 125 | } Broadcast; |
| 126 | |
| 127 | // One set of factors for each trace, this is the result of synchronization |
| 128 | typedef struct |
| 129 | { |
| 130 | double drift, offset; |
| 131 | } Factors; |
| 132 | |
| 133 | |
| 134 | // ConnectionKey-related functions |
| 135 | guint ghfConnectionKeyHash(gconstpointer key); |
| 136 | |
| 137 | gboolean gefConnectionKeyEqual(gconstpointer a, gconstpointer b); |
| 138 | bool connectionKeyEqual(const ConnectionKey* const a, const ConnectionKey* |
| 139 | const b); |
| 140 | |
| 141 | void gdnConnectionKeyDestroy(gpointer data); |
| 142 | |
| 143 | // SegmentKey-related functions |
| 144 | guint ghfSegmentKeyHash(gconstpointer key); |
| 145 | gboolean gefSegmentKeyEqual(gconstpointer a, gconstpointer b); |
| 146 | |
| 147 | // DatagramKey-related functions |
| 148 | guint ghfDatagramKeyHash(gconstpointer key); |
| 149 | gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b); |
| 150 | void gdnDestroyDatagramKey(gpointer data); |
| 151 | |
| 152 | // Event-related functions |
| 153 | void gdnDestroyEvent(gpointer data); |
| 154 | void copyEvent(const Event* const event, Event** const newEvent); |
| 155 | void copyTCPEvent(const Event* const event, Event** const newEvent); |
| 156 | void copyUDPEvent(const Event* const event, Event** const newEvent); |
| 157 | void destroyEvent(Event* const event); |
| 158 | void destroyTCPEvent(Event* const event); |
| 159 | void destroyUDPEvent(Event* const event); |
| 160 | void gfDestroyEvent(gpointer data, gpointer user_data); |
| 161 | double wallTimeSub(const WallTime const* tA, const WallTime const* tB); |
| 162 | void gfAddEventToArray(gpointer data, gpointer user_data); |
| 163 | |
| 164 | // Message-related functions |
| 165 | void printTCPSegment(const Message* const segment); |
| 166 | void convertIP(char* const str, const uint32_t addr); |
| 167 | |
| 168 | gint gcfTCPSegmentAckCompare(gconstpointer a, gconstpointer b); |
| 169 | bool isAcking(const Message* const ackSegment, const Message* const ackedSegment); |
| 170 | |
| 171 | void gdnTCPSegmentListDestroy(gpointer data); |
| 172 | void gfTCPSegmentDestroy(gpointer data, gpointer user_data); |
| 173 | void destroyTCPSegment(Message* const segment); |
| 174 | |
| 175 | // Exchange-related functions |
| 176 | void destroyTCPExchange(Exchange* const exchange); |
| 177 | |
| 178 | // Broadcast-related functions |
| 179 | void gdnDestroyBroadcast(gpointer data); |
| 180 | void destroyBroadcast(Broadcast* const broadcast); |
| 181 | |
| 182 | #endif |