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