/* * Copyright (c) 2015 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* Copyright (c) 2001-2005 Eliot Dresselhaus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include /* for clib_arch_is_big_endian */ always_inline void zero_pair (hash_t * h, hash_pair_t * p) { clib_memset (p, 0, hash_pair_bytes (h)); } always_inline void init_pair (hash_t * h, hash_pair_t * p) { clib_memset (p->value, ~0, hash_value_bytes (h)); } always_inline hash_pair_union_t * get_pair (void *v, uword i) { hash_t *h = hash_header (v); hash_pair_t *p; ASSERT (i < vec_len (v)); p = v; p += i << h->log2_pair_size; return (hash_pair_union_t *) p; } always_inline void set_is_user (void *v, uword i, uword is_user) { hash_t *h = hash_header (v); uword i0 = i / BITS (h->is_user[0]); uword i1 = (uword) 1 << (i % BITS (h->is_user[0])); if (is_user) h->is_user[i0] |= i1; else h->is_user[i0] &= ~i1; } static u8 *hash_format_pair_default (u8 * s, va_list * args); #if uword_bits == 64 static inline u64 zap64 (u64 x, word n) { #define _(n) (((u64) 1 << (u64) (8*(n))) - (u64) 1) static u64 masks_little_endian[] = { 0, _(1), _(2), _(3), _(4), _(5), _(6), _(7), }; static u64 masks_big_endian[] = { 0, ~_(7), ~_(6), ~_(5), ~_(4), ~_(3), ~_(2), ~_(1), }; #undef _ if (clib_arch_is_big_endian) return x & masks_big_endian[n]; else return x & masks_little_endian[n]; } /** * make address-sanitizer skip this: * clib_mem_unaligned + zap64 casts its input as u64, computes a mask * according to the input length, and returns the casted maked value. * Therefore all the 8 Bytes of the u64 are systematically read, which * rightfully causes address-sanitizer to raise an error on smaller inputs. * * However the invalid Bytes are discarded within zap64(), whicj is why * this can be silenced safely. */ static inline u64 __attribute__ ((no_sanitize_address)) hash_memory64 (void *p, word n_bytes, u64 state) { u64 *q = p; u64 a, b, c, n; a = b = 0x9e3779b97f4a7c13LL; c = state; n = n_bytes; while (n >= 3 * sizeof (u64)) { a += clib_mem_unaligned (q + 0, u64); b += clib_mem_unaligned (q + 1, u64); c += clib_mem_unaligned (q + 2, u64); hash_mix64 (a, b, c); n -= 3 * sizeof (u64); q += 3; } c += n_bytes; switch (n / sizeof (u64)) { case 2: a += clib_mem_unaligned (q + 0, u64); b += clib_mem_unaligned (q + 1, u64); if (n % sizeof (u64)) c += zap64 (clib_mem_unaligned (q + 2, u64), n % sizeof (u64)) << 8; break; case 1: a += clib_mem_unaligned (q + 0, u64); if (n % sizeof (u64)) b += zap64 (clib_mem_unaligned (q + 1, u64), n % sizeof (u64)); break; case 0: if (n % sizeof (u64)) a += zap64 (clib_mem_unaligned (q + 0, u64), n % sizeof (u64)); break; } hash_mix64 (a, b, c); return c; } #else /* if uword_bits == 64 */ static inline u32 zap32 (u32 x, word n) { #define _(n) (((u32) 1 << (u32) (8*(n))) - (u32) 1) static u32 masks_little_endian[] = { 0, _(1), _(2), _(3), }; static u32 masks_big_endian[] = { 0, ~_(3), ~_(2), ~_(1), }; #undef _ if (clib_arch_is_big_endian) return x & masks_big_endian[n]; else return x & masks_little_endian[n]; } static inline u32 hash_memory32 (void *p, word n_bytes, u32 state) { u32 *q = p; u32 a, b, c, n; a = b = 0x9e3779b9; c = state; n = n_bytes; while (n >= 3 * sizeof (u32)) { a += clib_mem_unaligned (q + 0, u32); b += clib_mem_unaligned (q + 1, u32); c += clib_mem_unaligned (q + 2, u32); hash_mix32 (a, b, c); n -= 3 * sizeof (u32); q += 3; } c += n_bytes; switch (n / sizeof (u32)) { case 2: a += clib_mem_unaligned (q + 0, u32); b += clib_mem_unaligned (q + 1, u32); if (n % sizeof (u32)) c += zap32 (clib_mem_unaligned (q + 2, u32), n % sizeof (u32)) << 8; break; case 1: a += clib_mem_unaligned (q + 0, u32); if (n % sizeof (u32)) b += zap32 (clib_mem_unaligned (q + 1, u32), n % sizeof (u32)); break; case 0: if (n % sizeof (u32)) a += zap32 (clib_mem_unaligned (q + 0, u32), n % sizeof (u32)); break; } hash_mix32 (a, b, c); return c; } #endif uword hash_memory (void *p, word n_bytes, uword state) { uword *q = p; #if uword_bits == 64 return hash_memory64 (q, n_bytes, state); #else return hash_memory32 (q, n_bytes, state); #endif } #if uword_bits == 64 always_inline uword hash_uword (uword x) { u64 a, b, c; a = b = 0x9e3779b97f4a7c13LL; c = 0; a += x; hash_mix64 (a, b, c); return c; } #else always_inline uword hash_uword (uword x) { u32 a, b, c; a = b = 0x9e3779b9; c = 0; a += x; hash_mix32 (a, b, c); return c; } #endif /* Call sum function. Hash code will be sum function value modulo the prime length of the hash table. */ always_inline uword key_sum (hash_t * h, uword key) { uword sum; switch (pointer_to_uword ((void *) h->key_sum)) { case KEY_FUNC_NONE: sum = hash_uword (key); break; case KEY_FUNC_PO
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2015 Cisco and/or its affiliates.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at:

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>io.fd.honeycomb.common</groupId>
        <artifactId>api-parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../../common/api-parent</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>io.fd.honeycomb.v3po</groupId>
    <artifactId>v3po2vpp</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>vpp-facade-spi</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>vpp-facade-utils</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>v3po-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>io.fd.vpp</groupId>
            <artifactId>vppjapi</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>

        <!-- Testing Dependencies -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>vpp-facade-impl</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>
        <!--Needed due to final vppAPI, TODO remove once vppAPi refactored-->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.5.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.5.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.skinny-framework</groupId>
            <artifactId>skinny-logback</artifactId>
            <version>1.0.8</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>