aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/test/test-fib.cc
blob: 125515e415605cf8231870c72a69ab742663d588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (c) 2021-2022 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.
 */

#include <gtest/gtest.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <netinet/in.h>

extern "C" {
#define WITH_TESTS
#include <hicn/util/ip_address.h>
#include <hicn/config/configuration.h>
#include <hicn/core/forwarder.h>
#include <hicn/core/fib.h>
}

/*
 * TODO
 * - test max_size
 */

#define DEFAULT_SIZE 10
#define ARRAY_SIZE(a) ((sizeof(a) / sizeof(*(a))))

class FibTest : public ::testing::Test {
 protected:
  FibTest() { fib = fib_create(NULL); }
  virtual ~FibTest() { fib_free(fib); }

  configuration_t *configuration;
  forwarder_t *forwarder;
  fib_t *fib;
};

void _fib_add_prefix(fib_t *fib, const hicn_prefix_t *prefix) {
  fib_entry_t *entry =
      fib_entry_create(prefix, STRATEGY_TYPE_UNDEFINED, NULL, NULL);
  fib_add(fib, entry);
}

static const hicn_prefix_t p0010 = (hicn_prefix_t){
    .name = {.v6 = {.as_u64 = {0x1122334455667788, 0x9900aabbccddeeff}}},
    .len = 4};

/* TEST: Fib allocation and initialization */
TEST_F(FibTest, FibAddOne) {
  /* Empty fib should be valid */

  const hicn_prefix_t *empty_prefix_array[] = {};
  bool empty_used_array[] = {};
  EXPECT_TRUE(fib_is_valid(fib));
  EXPECT_TRUE(fib_check_preorder(fib, empty_prefix_array, empty_used_array));

  const hicn_prefix_t *prefix_array[] = {&p0010};
  bool used_array[] = {true};

  for (unsigned i = 0; i < ARRAY_SIZE(prefix_array); i++) {
    if (!used_array[i]) continue;
    _fib_add_prefix(fib, prefix_array[i]);
  }

  fib_dump(fib);

  EXPECT_TRUE(fib_is_valid(fib));
  EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array));

  /* Check that free indices and bitmaps are correctly updated */
}

#if 0
22-09-2022 13:07:57 fib_entry_on_event: b002::/64
22-09-2022 13:08:01 fib_entry_on_event: b002::abcd:0:0:0/128
22-09-2022 13:08:01 fib_entry_on_event: b002::2/128
22-09-2022 13:08:01 fib_entry_on_event: b002::abcd:0:0:1/128
22-09-2022 13:08:01 fib_entry_on_event: b002::3/128
#endif