1 #ifndef __MTCP_UTIL_H__
2 #define __MTCP_UTIL_H__
3 
4 #include <stdint.h>
5 #include <netinet/in.h>
6 #include <arpa/inet.h>
7 #include <unistd.h>
8 
9 
10 /** Calculate the RSS hash result using given addresses and
11  *  port number, and returns the CPU core to be mapped.
12  * @param [in] sip: source IP address
13  * @param [in] dip: destination IP address
14  * @param [in] sp: source port number
15  * @param [in] dp: destination port number
16  * @param [in] num_queues: number of receive-side queues
17  * @return core number which will be mapped to the given addr
18  */
19 int
20 GetRSSCPUCore(in_addr_t sip, in_addr_t dip,
21 	      in_port_t sp, in_port_t dp, int num_queues,
22 	      int endian_check);
23 
24 /** Fill argc and argv by parsing str. Original str might be modified.
25  * @param [in] str: source string
26  * @param [in] argc: number of parsed arguments
27  * @param [in] argv: argument string list
28  * @param [in] max_argc: maximum value of argc
29  * @return 0 for success, -1 for error
30  */
31 int
32 StrToArgs(char *str, int *argc, char **argv, int max_argc);
33 
34 
35 
36 /*
37    xxHash - Extremely Fast Hash algorithm
38    Header File
39    Copyright (C) 2012-2015, Yann Collet.
40 
41    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
42 
43    Redistribution and use in source and binary forms, with or without
44    modification, are permitted provided that the following conditions are
45    met:
46 
47        * Redistributions of source code must retain the above copyright
48    notice, this list of conditions and the following disclaimer.
49        * Redistributions in binary form must reproduce the above
50    copyright notice, this list of conditions and the following disclaimer
51    in the documentation and/or other materials provided with the
52    distribution.
53 
54    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 
66    You can contact the author at :
67    - xxHash source repository : https://github.com/Cyan4973/xxHash
68 */
69 
70 /* Notice extracted from xxHash homepage :
71 
72 xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
73 It also successfully passes all tests from the SMHasher suite.
74 
75 Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
76 
77 Name            Speed       Q.Score   Author
78 xxHash          5.4 GB/s     10
79 CrapWow         3.2 GB/s      2       Andrew
80 MumurHash 3a    2.7 GB/s     10       Austin Appleby
81 SpookyHash      2.0 GB/s     10       Bob Jenkins
82 SBox            1.4 GB/s      9       Bret Mulvey
83 Lookup3         1.2 GB/s      9       Bob Jenkins
84 SuperFastHash   1.2 GB/s      1       Paul Hsieh
85 CityHash64      1.05 GB/s    10       Pike & Alakuijala
86 FNV             0.55 GB/s     5       Fowler, Noll, Vo
87 CRC32           0.43 GB/s     9
88 MD5-32          0.33 GB/s    10       Ronald L. Rivest
89 SHA1-32         0.28 GB/s    10
90 
91 Q.Score is a measure of quality of the hash function.
92 It depends on successfully passing SMHasher test set.
93 10 is a perfect score.
94 
95 A 64-bits version, named XXH64, is available since r35.
96 It offers much better speed, but for 64-bits applications only.
97 Name     Speed on 64 bits    Speed on 32 bits
98 XXH64       13.8 GB/s            1.9 GB/s
99 XXH32        6.8 GB/s            6.0 GB/s
100 */
101 
102 #if defined (__cplusplus)
103 extern "C" {
104 #endif
105 
106 
107 /*****************************
108 *  Simple Hash Functions
109 *****************************/
110 
111 unsigned int       XXH32 (const void* input, size_t length, unsigned seed);
112 unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed);
113 
114 /*
115 XXH32() :
116     Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
117     The memory between input & input+length must be valid (allocated and read-accessible).
118     "seed" can be used to alter the result predictably.
119     This function successfully passes all SMHasher tests.
120     Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
121 XXH64() :
122     Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
123     Faster on 64-bits systems. Slower on 32-bits systems.
124 */
125 
126 
127 #if defined (__cplusplus)
128 }
129 #endif
130 
131 #endif /* !__MTCP_UTIL_H__ */
132