| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef DATA_STRUCTURES_H |
| 20 | #define DATA_STRUCTURES_H |
| 21 | |
| 22 | #include <glib.h> |
| 23 | #include <stdbool.h> |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | #include <ltt/ltt.h> |
| 27 | |
| 28 | |
| 29 | enum Direction |
| 30 | { |
| 31 | OUT, |
| 32 | IN, |
| 33 | }; |
| 34 | |
| 35 | enum EventType |
| 36 | { |
| 37 | TCP, |
| 38 | UDP, |
| 39 | TYPE_COUNT // This must be the last field |
| 40 | }; |
| 41 | |
| 42 | // Stage 1 to 2: These structures are passed from processing to matching modules |
| 43 | // TCP events |
| 44 | typedef struct |
| 45 | { |
| 46 | uint32_t saddr, daddr; |
| 47 | uint16_t source, dest; |
| 48 | } ConnectionKey; |
| 49 | |
| 50 | typedef struct |
| 51 | { |
| 52 | ConnectionKey connectionKey; |
| 53 | uint8_t ihl; |
| 54 | uint16_t tot_len; |
| 55 | uint32_t seq, ack_seq; |
| 56 | uint8_t doff; |
| 57 | uint8_t ack, rst, syn, fin; |
| 58 | } SegmentKey; |
| 59 | |
| 60 | typedef struct |
| 61 | { |
| 62 | enum Direction direction; |
| 63 | SegmentKey* segmentKey; |
| 64 | } TCPEvent; |
| 65 | |
| 66 | // UDP events |
| 67 | typedef struct |
| 68 | { |
| 69 | uint32_t saddr, daddr; |
| 70 | uint16_t source, dest; |
| 71 | uint16_t ulen; |
| 72 | uint8_t dataKey[8]; |
| 73 | } DatagramKey; |
| 74 | |
| 75 | typedef struct |
| 76 | { |
| 77 | enum Direction direction; |
| 78 | DatagramKey* datagramKey; |
| 79 | bool unicast; |
| 80 | } UDPEvent; |
| 81 | |
| 82 | typedef struct |
| 83 | { |
| 84 | uint32_t seconds; |
| 85 | uint32_t nanosec; |
| 86 | } WallTime; |
| 87 | |
| 88 | typedef struct _Event |
| 89 | { |
| 90 | unsigned long traceNum; |
| 91 | uint64_t cpuTime; |
| 92 | WallTime wallTime; |
| 93 | |
| 94 | // specific event structures and functions could be in separate files and |
| 95 | // type could be an int |
| 96 | enum EventType type; |
| 97 | // event could be a void*, this union is to avoid having to cast |
| 98 | union { |
| 99 | TCPEvent* tcpEvent; |
| 100 | UDPEvent* udpEvent; |
| 101 | } event; |
| 102 | |
| 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 | GQueue* acks; |
| 118 | } Exchange; |
| 119 | |
| 120 | typedef struct |
| 121 | { |
| 122 | GQueue* events; |
| 123 | } Broadcast; |
| 124 | |
| 125 | // One set of factors for each trace, this is the result of synchronization |
| 126 | typedef struct |
| 127 | { |
| 128 | double drift, offset; |
| 129 | } Factors; |
| 130 | |
| 131 | |
| 132 | // ConnectionKey-related functions |
| 133 | guint ghfConnectionKeyHash(gconstpointer key); |
| 134 | |
| 135 | gboolean gefConnectionKeyEqual(gconstpointer a, gconstpointer b); |
| 136 | bool connectionKeyEqual(const ConnectionKey* const a, const ConnectionKey* |
| 137 | const b); |
| 138 | |
| 139 | void gdnConnectionKeyDestroy(gpointer data); |
| 140 | |
| 141 | // SegmentKey-related functions |
| 142 | guint ghfSegmentKeyHash(gconstpointer key); |
| 143 | gboolean gefSegmentKeyEqual(gconstpointer a, gconstpointer b); |
| 144 | |
| 145 | // DatagramKey-related functions |
| 146 | guint ghfDatagramKeyHash(gconstpointer key); |
| 147 | gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b); |
| 148 | void gdnDestroyDatagramKey(gpointer data); |
| 149 | |
| 150 | // Event-related functions |
| 151 | void gdnDestroyEvent(gpointer data); |
| 152 | void destroyEvent(Event* const event); |
| 153 | void destroyTCPEvent(Event* const event); |
| 154 | void destroyUDPEvent(Event* const event); |
| 155 | void gfDestroyEvent(gpointer data, gpointer user_data); |
| 156 | double wallTimeSub(const WallTime const* tA, const WallTime const* tB); |
| 157 | |
| 158 | // Message-related functions |
| 159 | void printTCPSegment(const Message* const segment); |
| 160 | void convertIP(char* const str, const uint32_t addr); |
| 161 | |
| 162 | gint gcfTCPSegmentAckCompare(gconstpointer a, gconstpointer b); |
| 163 | bool isAcking(const Message* const ackSegment, const Message* const ackedSegment); |
| 164 | |
| 165 | void gdnTCPSegmentListDestroy(gpointer data); |
| 166 | void gfTCPSegmentDestroy(gpointer data, gpointer user_data); |
| 167 | void destroyTCPSegment(Message* const segment); |
| 168 | |
| 169 | // Exchange-related functions |
| 170 | void destroyTCPExchange(Exchange* const exchange); |
| 171 | |
| 172 | // Broadcast-related functions |
| 173 | void gdnDestroyBroadcast(gpointer data); |
| 174 | void destroyBroadcast(Broadcast* const broadcast); |
| 175 | |
| 176 | #endif |