Compare commits

..

No commits in common. "eccff7691f242dfea976a2da4f7f78e3fa4c87cc" and "9e91d8f82629df8b0f25edf0d159d88215b9f0c7" have entirely different histories.

2 changed files with 13 additions and 31 deletions

View File

@ -5,14 +5,15 @@ from ipaddress import IPv6Network
def parse_rule(rule):
parts = rule.split()
prefix, next_hop = parts
return IPv6Network(prefix), int(next_hop)
return prefix, int(next_hop)
def generate_random_test_cases(rules, n):
with open('../data/test-data', 'w') as f:
for rule in rules:
rule_network = rule[0]
rule_prefix = rule[0]
rule_next_hop = rule[1]
rule_network = IPv6Network(rule_prefix)
for _ in range(n):
next_hop = rule_next_hop
@ -21,16 +22,15 @@ def generate_random_test_cases(rules, n):
for oth_rule in rules:
if oth_rule == rule:
continue
oth_network = oth_rule[0]
oth_prefix = oth_rule[0]
oth_next_hop = oth_rule[1]
if address in oth_network and oth_network.subnet_of( rule_network ):
print(f"address {address} is closer to {oth_network} {rule_next_hop} than {rule_network} {oth_next_hop}")
if address in IPv6Network(oth_prefix) and rule_prefix < oth_prefix:
next_hop = oth_next_hop
f.write(f"{address} {next_hop}\n")
print(f"Generated test case: {address} {next_hop}")
print("tests for rule ", rule_network, " with next hop ", rule_next_hop, " generated")
# print(f"Generated test case: {address} {next_hop}")
print("tests for rule ", rule_prefix, " with next hop ", rule_next_hop, " generated")
def main():
def main(): #1111:2222:3333:4444:5555:6666:7777:88 120
rules = []
with open('../data/routing-data', 'r') as f:
@ -39,7 +39,7 @@ def main():
parsed_rules = [parse_rule(rule) for rule in rules]
num_tests = 10
num_tests = 10 # Change this to desired number of tests
generate_random_test_cases(parsed_rules, num_tests)

View File

@ -2,10 +2,10 @@
#define RULES_FILE "../data/routing-data"
#define TEST_FILE "../data/test-data"
#define TEST_ROWS 11 /*17217*/
#define TEST_ROWS 70 /*17217*/
#define READ_MODE "r"
#define RULE_NOT_FOUND -1
#define GET_BIT(key, bit) ( ( key.s[ bit / 16 ] & (1u << (15 - bit % 16)) ) != 0 )
#define GET_BIT(key, bit) ( ( key.s[ bit / 16 ] & (1ul << (15 - bit % 16)) ) != 0 )
trie_node_t create_node() {
@ -20,20 +20,6 @@ trie_holder_t create_holder() {
return ret;
}
int destory_holder(struct trie_holder* t) {
destory_node(t->_root);
free(t);
return 1;
}
int destory_node(struct trie_node* n) {
int ret = 0;
if (!n) return ret;
ret = destory_node(n->_l) + destory_node(n->_r);
free(n);
return ret;
}
int trie_insert(trie_holder_t t, ipv6_t key, int val, int mask) {
trie_node_t iter = t->_root;
trie_node_t* next = &t->_root;
@ -117,7 +103,6 @@ int load_input(trie_holder_t t) {
trie_insert(t, key, val, mask);
++cnt;
}
fclose(f);
return cnt;
}
@ -144,8 +129,7 @@ int load_tests(ipv6_t** rips, int** rref) {
while (fgetc(f) != ' ');
fscanf(f, "%d", &(ref[row]));
}
fclose(f);
*rips = ips;
*rref = ref;
return TEST_ROWS;
@ -162,8 +146,6 @@ int fire_tests(trie_holder_t t, ipv6_t* ips, int* ref, int num_tests ) {
}
}
free(ips);
free(ref);
return wrong;
}
@ -176,6 +158,6 @@ int main() {
printf("Loaded %d tests\n", load_tests(&ips, &ref) );
printf("%d tests wrong\n", fire_tests(t, ips, ref, TEST_ROWS) );
destory_holder(t);
return 0;
}