]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - wme_test/common.h
Use thicker lines for plotting individual directions.
[frescor/fwp.git] / wme_test / common.h
1 #ifndef COMMON_H
2 #define COMMON_H
3
4 #include <time.h>
5
6 #define BASE_PORT       5100
7 #define AC_NUM          4
8 #define MTU             800 
9 #define BUFFSIZE        65536
10
11 #define Kbit 1000
12 #define Mbit (Kbit*Kbit)
13
14 #define SEC_TO_USEC        1000000LL
15 #define MSEC_TO_USEC       1000LL
16 #define USEC_TO_NSEC       1000LL
17
18 enum ac {
19         AC_VO = 0,
20         AC_VI = 1,
21         AC_BE = 2,
22         AC_BK = 3
23 };
24
25 struct msg_t {
26 /*      unsigned int tos; */
27         struct timespec send_timestamp;
28         struct timespec sendback_timestamp;
29 /*      unsigned long int seqn; */
30         int stream;
31 };
32
33 union msg_buff {
34         struct msg_t msg;
35         char nonsense[BUFFSIZE];
36 };
37
38
39 extern const int prio_to_ac[8];
40 extern const unsigned int ac_to_tos[4];
41 extern const char *ac_to_text[4];
42
43 void block_signals(void);
44 void set_rt_prio(int priority);
45 char *bandwidth_to_text(char *buf, unsigned bandwidth_bps);
46 char *usec_to_text(char *buf, unsigned usec);
47
48 static inline 
49 void timespec_add (struct timespec *sum, const struct timespec *left,
50               const struct timespec *right)
51 {
52         sum->tv_sec = left->tv_sec + right->tv_sec;
53         sum->tv_nsec = left->tv_nsec + right->tv_nsec;
54
55         if (sum->tv_nsec >= 1000000000){
56                 ++sum->tv_sec;
57                 sum->tv_nsec -= 1000000000;
58         }
59 }
60
61 static inline 
62 void timespec_sub (struct timespec *diff, const struct timespec *left,
63               const struct timespec *right)
64 {
65         diff->tv_sec = left->tv_sec - right->tv_sec;
66         diff->tv_nsec = left->tv_nsec - right->tv_nsec;
67
68         if (diff->tv_nsec < 0){
69                   --diff->tv_sec;
70                   diff->tv_nsec += 1000000000;
71         }
72 }
73
74 static inline long long timespec_sub_usec(const struct timespec *left,
75                                           const struct timespec *right)
76 {
77         struct timespec result;
78         timespec_sub(&result, left, right);
79         return (long long)result.tv_sec * SEC_TO_USEC +
80                 result.tv_nsec / USEC_TO_NSEC;
81 }
82
83 static inline long long timespec2usec(const struct timespec *ts)
84 {
85         return ts->tv_sec * SEC_TO_USEC + ts->tv_nsec / USEC_TO_NSEC;
86 }
87
88 #endif