const net_addr_flow6 *expect = NET_ADDR_FLOW6_NLRI(
0,
- FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
+ FLOW_TYPE_DST_PREFIX, 103, 61, 0x22, 0x46, 0x8a, 0xcf, 0x13, 0x00,
FLOW_TYPE_SRC_PREFIX, 8, 0, 0xc0,
FLOW_TYPE_NEXT_HEADER, 0x80, 0x06,
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
expect[0] = "flow6 { dst ::1:1234:5678:9800:0/103 offset 61; src c000::/8; next header 6; port 20..40,273; label < 500000; }";
input[0] = NET_ADDR_FLOW6_NLRI(
0,
- FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
+ FLOW_TYPE_DST_PREFIX, 103, 61, 0x22, 0x46, 0x8a, 0xcf, 0x13, 0x00,
FLOW_TYPE_SRC_PREFIX, 8, 0, 0xc0,
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
FLOW_TYPE_PORT, 0x03, 20, 0x45, 40, 0x91, 0x01, 0x11,
return 1;
}
+static int
+t_ip6_shift_left(void)
+{
+ ip6_addr a = ip6_build(0x8D0D8BDC, 0x1F04DB92, 0xE5117673, 0x70E54449);
+
+ struct { int n; ip6_addr val; } test_vectors[] = {
+ 0, ip6_build(0x8D0D8BDC, 0x1F04DB92, 0xE5117673, 0x70E54449),
+ 9, ip6_build(0x1B17B83E, 0x09B725CA, 0x22ECE6E1, 0xCA889200),
+ 18, ip6_build(0x2F707C13, 0x6E4B9445, 0xD9CDC395, 0x11240000),
+ 27, ip6_build(0xE0F826DC, 0x97288BB3, 0x9B872A22, 0x48000000),
+ 36, ip6_build(0xF04DB92E, 0x51176737, 0x0E544490, 0x00000000),
+ 45, ip6_build(0x9B725CA2, 0x2ECE6E1C, 0xA8892000, 0x00000000),
+ 54, ip6_build(0xE4B9445D, 0x9CDC3951, 0x12400000, 0x00000000),
+ 63, ip6_build(0x7288BB39, 0xB872A224, 0x80000000, 0x00000000),
+ 72, ip6_build(0x11767370, 0xE5444900, 0x00000000, 0x00000000),
+ 81, ip6_build(0xECE6E1CA, 0x88920000, 0x00000000, 0x00000000),
+ 90, ip6_build(0xCDC39511, 0x24000000, 0x00000000, 0x00000000),
+ 99, ip6_build(0x872A2248, 0x00000000, 0x00000000, 0x00000000),
+ 108, ip6_build(0x54449000, 0x00000000, 0x00000000, 0x00000000),
+ 117, ip6_build(0x89200000, 0x00000000, 0x00000000, 0x00000000),
+ 126, ip6_build(0x40000000, 0x00000000, 0x00000000, 0x00000000),
+ 128, ip6_build(0x00000000, 0x00000000, 0x00000000, 0x00000000),
+ };
+
+ for (uint i = 0; i < ARRAY_SIZE(test_vectors); i++)
+ bt_assert(ip6_equal(ip6_shift_left(a, test_vectors[i].n), test_vectors[i].val));
+
+ return 1;
+}
+
+static int
+t_ip6_shift_right(void)
+{
+ ip6_addr a = ip6_build(0x8D0D8BDC, 0x1F04DB92, 0xE5117673, 0x70E54449);
+
+ struct { int n; ip6_addr val; } test_vectors[] = {
+ 0, ip6_build(0x8D0D8BDC, 0x1F04DB92, 0xE5117673, 0x70E54449),
+ 9, ip6_build(0x004686C5, 0xEE0F826D, 0xC97288BB, 0x39B872A2),
+ 18, ip6_build(0x00002343, 0x62F707C1, 0x36E4B944, 0x5D9CDC39),
+ 27, ip6_build(0x00000011, 0xA1B17B83, 0xE09B725C, 0xA22ECE6E),
+ 36, ip6_build(0x00000000, 0x08D0D8BD, 0xC1F04DB9, 0x2E511767),
+ 45, ip6_build(0x00000000, 0x0004686C, 0x5EE0F826, 0xDC97288B),
+ 54, ip6_build(0x00000000, 0x00000234, 0x362F707C, 0x136E4B94),
+ 63, ip6_build(0x00000000, 0x00000001, 0x1A1B17B8, 0x3E09B725),
+ 72, ip6_build(0x00000000, 0x00000000, 0x008D0D8B, 0xDC1F04DB),
+ 81, ip6_build(0x00000000, 0x00000000, 0x00004686, 0xC5EE0F82),
+ 90, ip6_build(0x00000000, 0x00000000, 0x00000023, 0x4362F707),
+ 99, ip6_build(0x00000000, 0x00000000, 0x00000000, 0x11A1B17B),
+ 108, ip6_build(0x00000000, 0x00000000, 0x00000000, 0x0008D0D8),
+ 117, ip6_build(0x00000000, 0x00000000, 0x00000000, 0x00000468),
+ 126, ip6_build(0x00000000, 0x00000000, 0x00000000, 0x00000002),
+ 128, ip6_build(0x00000000, 0x00000000, 0x00000000, 0x00000000),
+ };
+
+ for (uint i = 0; i < ARRAY_SIZE(test_vectors); i++)
+ bt_assert(ip6_equal(ip6_shift_right(a, test_vectors[i].n), test_vectors[i].val));
+
+ return 1;
+}
+
int
main(int argc, char *argv[])
{
bt_test_suite(t_ip6_ntop, "Converting ip6_addr struct to IPv6 string");
bt_test_suite(t_ip4_prefix_equal, "Testing ip4_prefix_equal()");
bt_test_suite(t_ip6_prefix_equal, "Testing ip6_prefix_equal()");
+ bt_test_suite(t_ip6_shift_left, "Testing ip6_shift_left()");
+ bt_test_suite(t_ip6_shift_right, "Testing ip6_shift_right()");
return bt_exit_value();
}