176404edcSAsim Jamshed #ifndef __MTCP_UTIL_H__
276404edcSAsim Jamshed #define __MTCP_UTIL_H__
376404edcSAsim Jamshed 
476404edcSAsim Jamshed #include <stdint.h>
576404edcSAsim Jamshed #include <netinet/in.h>
676404edcSAsim Jamshed #include <arpa/inet.h>
776404edcSAsim Jamshed #include <unistd.h>
876404edcSAsim Jamshed 
976404edcSAsim Jamshed 
1076404edcSAsim Jamshed /** Calculate the RSS hash result using given addresses and
1176404edcSAsim Jamshed  *  port number, and returns the CPU core to be mapped.
1276404edcSAsim Jamshed  * @param [in] sip: source IP address
1376404edcSAsim Jamshed  * @param [in] dip: destination IP address
1476404edcSAsim Jamshed  * @param [in] sp: source port number
1576404edcSAsim Jamshed  * @param [in] dp: destination port number
1676404edcSAsim Jamshed  * @param [in] num_queues: number of receive-side queues
1776404edcSAsim Jamshed  * @return core number which will be mapped to the given addr
1876404edcSAsim Jamshed  */
1976404edcSAsim Jamshed int
2076404edcSAsim Jamshed GetRSSCPUCore(in_addr_t sip, in_addr_t dip,
21*8c9e1184SAsim Jamshed 	      in_port_t sp, in_port_t dp, int num_queues);
2276404edcSAsim Jamshed 
2376404edcSAsim Jamshed /** Fill argc and argv by parsing str. Original str might be modified.
2476404edcSAsim Jamshed  * @param [in] str: source string
2576404edcSAsim Jamshed  * @param [in] argc: number of parsed arguments
2676404edcSAsim Jamshed  * @param [in] argv: argument string list
2776404edcSAsim Jamshed  * @param [in] max_argc: maximum value of argc
2876404edcSAsim Jamshed  * @return 0 for success, -1 for error
2976404edcSAsim Jamshed  */
3076404edcSAsim Jamshed int
3176404edcSAsim Jamshed StrToArgs(char *str, int *argc, char **argv, int max_argc);
3276404edcSAsim Jamshed 
3376404edcSAsim Jamshed 
3476404edcSAsim Jamshed 
3576404edcSAsim Jamshed /*
3676404edcSAsim Jamshed    xxHash - Extremely Fast Hash algorithm
3776404edcSAsim Jamshed    Header File
3876404edcSAsim Jamshed    Copyright (C) 2012-2015, Yann Collet.
3976404edcSAsim Jamshed 
4076404edcSAsim Jamshed    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4176404edcSAsim Jamshed 
4276404edcSAsim Jamshed    Redistribution and use in source and binary forms, with or without
4376404edcSAsim Jamshed    modification, are permitted provided that the following conditions are
4476404edcSAsim Jamshed    met:
4576404edcSAsim Jamshed 
4676404edcSAsim Jamshed        * Redistributions of source code must retain the above copyright
4776404edcSAsim Jamshed    notice, this list of conditions and the following disclaimer.
4876404edcSAsim Jamshed        * Redistributions in binary form must reproduce the above
4976404edcSAsim Jamshed    copyright notice, this list of conditions and the following disclaimer
5076404edcSAsim Jamshed    in the documentation and/or other materials provided with the
5176404edcSAsim Jamshed    distribution.
5276404edcSAsim Jamshed 
5376404edcSAsim Jamshed    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5476404edcSAsim Jamshed    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5576404edcSAsim Jamshed    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
5676404edcSAsim Jamshed    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
5776404edcSAsim Jamshed    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5876404edcSAsim Jamshed    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5976404edcSAsim Jamshed    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6076404edcSAsim Jamshed    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6176404edcSAsim Jamshed    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6276404edcSAsim Jamshed    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6376404edcSAsim Jamshed    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6476404edcSAsim Jamshed 
6576404edcSAsim Jamshed    You can contact the author at :
6676404edcSAsim Jamshed    - xxHash source repository : https://github.com/Cyan4973/xxHash
6776404edcSAsim Jamshed */
6876404edcSAsim Jamshed 
6976404edcSAsim Jamshed /* Notice extracted from xxHash homepage :
7076404edcSAsim Jamshed 
7176404edcSAsim Jamshed xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
7276404edcSAsim Jamshed It also successfully passes all tests from the SMHasher suite.
7376404edcSAsim Jamshed 
7476404edcSAsim Jamshed Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
7576404edcSAsim Jamshed 
7676404edcSAsim Jamshed Name            Speed       Q.Score   Author
7776404edcSAsim Jamshed xxHash          5.4 GB/s     10
7876404edcSAsim Jamshed CrapWow         3.2 GB/s      2       Andrew
7976404edcSAsim Jamshed MumurHash 3a    2.7 GB/s     10       Austin Appleby
8076404edcSAsim Jamshed SpookyHash      2.0 GB/s     10       Bob Jenkins
8176404edcSAsim Jamshed SBox            1.4 GB/s      9       Bret Mulvey
8276404edcSAsim Jamshed Lookup3         1.2 GB/s      9       Bob Jenkins
8376404edcSAsim Jamshed SuperFastHash   1.2 GB/s      1       Paul Hsieh
8476404edcSAsim Jamshed CityHash64      1.05 GB/s    10       Pike & Alakuijala
8576404edcSAsim Jamshed FNV             0.55 GB/s     5       Fowler, Noll, Vo
8676404edcSAsim Jamshed CRC32           0.43 GB/s     9
8776404edcSAsim Jamshed MD5-32          0.33 GB/s    10       Ronald L. Rivest
8876404edcSAsim Jamshed SHA1-32         0.28 GB/s    10
8976404edcSAsim Jamshed 
9076404edcSAsim Jamshed Q.Score is a measure of quality of the hash function.
9176404edcSAsim Jamshed It depends on successfully passing SMHasher test set.
9276404edcSAsim Jamshed 10 is a perfect score.
9376404edcSAsim Jamshed 
9476404edcSAsim Jamshed A 64-bits version, named XXH64, is available since r35.
9576404edcSAsim Jamshed It offers much better speed, but for 64-bits applications only.
9676404edcSAsim Jamshed Name     Speed on 64 bits    Speed on 32 bits
9776404edcSAsim Jamshed XXH64       13.8 GB/s            1.9 GB/s
9876404edcSAsim Jamshed XXH32        6.8 GB/s            6.0 GB/s
9976404edcSAsim Jamshed */
10076404edcSAsim Jamshed 
10176404edcSAsim Jamshed #if defined (__cplusplus)
10276404edcSAsim Jamshed extern "C" {
10376404edcSAsim Jamshed #endif
10476404edcSAsim Jamshed 
10576404edcSAsim Jamshed 
10676404edcSAsim Jamshed /*****************************
10776404edcSAsim Jamshed *  Simple Hash Functions
10876404edcSAsim Jamshed *****************************/
10976404edcSAsim Jamshed 
11076404edcSAsim Jamshed unsigned int       XXH32 (const void* input, size_t length, unsigned seed);
11176404edcSAsim Jamshed unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed);
11276404edcSAsim Jamshed 
11376404edcSAsim Jamshed /*
11476404edcSAsim Jamshed XXH32() :
11576404edcSAsim Jamshed     Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
11676404edcSAsim Jamshed     The memory between input & input+length must be valid (allocated and read-accessible).
11776404edcSAsim Jamshed     "seed" can be used to alter the result predictably.
11876404edcSAsim Jamshed     This function successfully passes all SMHasher tests.
11976404edcSAsim Jamshed     Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
12076404edcSAsim Jamshed XXH64() :
12176404edcSAsim Jamshed     Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
12276404edcSAsim Jamshed     Faster on 64-bits systems. Slower on 32-bits systems.
12376404edcSAsim Jamshed */
12476404edcSAsim Jamshed 
12576404edcSAsim Jamshed 
12676404edcSAsim Jamshed #if defined (__cplusplus)
12776404edcSAsim Jamshed }
12876404edcSAsim Jamshed #endif
12976404edcSAsim Jamshed 
13076404edcSAsim Jamshed #endif /* !__MTCP_UTIL_H__ */
131