summaryrefslogtreecommitdiff
path: root/staging/llist.h
blob: 49a87c7d8810f09e9354d8eaa20169072b5c7e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Mausezahn - A fast versatile traffic generator
 * Copyright (C) 2010 Herbert Haas
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the 
 * Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with 
 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
 * 
*/



#ifndef MZ_LINKED_LIST
#define MZ_LINKED_LIST

#define MAX_PACKET_SEQUENCE_LEN 20  // how many packets can be defined in a sequence at maximum

// A packet sequence -- this is the list data (each list element corresponds to one sequence)
struct pseq {
	struct mops *packet[MAX_PACKET_SEQUENCE_LEN];  // pointer to the packets
	struct timespec gap[MAX_PACKET_SEQUENCE_LEN];  // optional delay between different packets
	int count; // total number of current members (=packets)
};


// --------------- Mausezahn Multipurpose Linked List: -------------------

#define MZ_LL_NAME_LEN 64

// one list element 
struct mz_ll {
	struct mz_ll *prev;
	struct mz_ll *next;
	struct mz_ll *head; // always points to head element
	int refcount; // head element: total number of list items! (Otherwise can be used as refcount.)
	char name[MZ_LL_NAME_LEN];
	pthread_t  sequence_thread;
	int state; // 0 = inactive, 1 = active
	int index; // monotonically increasing;
	int index_last; //head always stores the last value!
	void *data; // points to your data
};

struct mz_ll *packet_sequences;
struct mz_ll *cli_seq; // currently edited packet sequence used by CLI

// prototypes
struct mz_ll * mz_ll_create_new_element(struct mz_ll *list);
int  mz_ll_delete_element (struct mz_ll *cur);
int mz_ll_delete_list(struct mz_ll *list);
struct mz_ll * mz_ll_search_name (struct mz_ll *list, char *str);
void _mz_ll_set_default (struct mz_ll *cur);
int mz_ll_dump_all(struct mz_ll *list);
int mops_tx_sequence (struct mz_ll *seq);

// convenience functions using the above in a more intelligent way
int mops_delete_sequence(char *name);
struct mz_ll * mops_create_sequence (char *name);
int mops_dump_sequence (char* str);
int mops_add_packet_to_sequence (struct mz_ll *seq, struct mops *mp);
int mops_add_delay_to_sequence (struct mz_ll *seq, struct timespec *t);
int mops_delete_packet_from_pseq (struct mz_ll *seq, int index);
int mops_delete_all_packets_from_pseq (struct mz_ll *seq);
int stop_sequence (char *name);
int stop_all_sequences ();
#endif