summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_reass.c
AgeCommit message (Collapse)AuthorFilesLines
2018-10-05NAT: convert remaining clib_warning to nat_log_*Juraj Sloboda1-2/+2
Change-Id: Ie999ab852cc3775ec90820624d97be746d2590a4 Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
2018-09-20NAT44 virtual fragmentation reassembly for endpoint-dependent mode (VPP-1325)Juraj Sloboda1-4/+45
Change-Id: I36ece2ef2eaef9fa559d69ec7f7f07e7c16a7a9d Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
2018-09-06NAT: fix maximum out of order fragments (VPP-1399)Matus Fabian1-2/+22
All fragments should be dropped when max_frag is 1 and 2 non-initial fragments are received before first fragment. Change-Id: Id0c968f45629698e347e8226c5926f27b48b82d6 Signed-off-by: Matus Fabian <matfabia@cisco.com>
2018-03-09when exceed max reass,ahdj0071-6/+12
frag packet can't get reass. adding bihash,it can rewrite new hash value. so need to delete hash after compare hash value. Change-Id: I83b5c47890110e9a598b78cfbe8fcd27bbe291bb Signed-off-by: ahdj007 <dong.juan1@zte.com.cn>
2018-03-06reass frag_n should to be inited to 0ahdj0071-0/+1
Change-Id: I8a4a7a85e86acbfe411e6dfa22e3976d7d4c903b Signed-off-by: ahdj007 <dong.juan1@zte.com.cn>
2018-01-08NAT64: IPFix (VPP-1106)Matus Fabian1-4/+13
Change-Id: Ib90dc5613c9fdac0344b3bd7f163e2f7163c64d8 Signed-off-by: Matus Fabian <matfabia@cisco.com>
2017-12-13NAT64: multi-thread support (VPP-891)Matus Fabian1-0/+22
Change-Id: Iebf859b6d86482e4465423bad598eecf87e53ec4 Signed-off-by: Matus Fabian <matfabia@cisco.com>
2017-11-07SNAT: IP fragmentation (VPP-890)Matus Fabian1-0/+739
Translation of fragmented packets. Change-Id: I9b1f2e9433ce273638080f32c2d3bff39c49899d Signed-off-by: Matus Fabian <matfabia@cisco.com>
50 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
/*
 * Copyright (c) 2016 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 <vnet/mpls/mpls_types.h>

#include <vnet/mfib/mfib_table.h>
#include <vnet/mfib/mfib_entry.h>
#include <vnet/mfib/mfib_signal.h>
#include <vnet/mfib/ip6_mfib.h>
#include <vnet/fib/fib_path_list.h>
#include <vnet/fib/fib_test.h>
#include <vnet/fib/fib_table.h>
#include <vnet/fib/mpls_fib.h>

#include <vnet/dpo/replicate_dpo.h>
#include <vnet/adj/adj_mcast.h>

#define MFIB_TEST_I(_cond, _comment, _args...)			\
({								\
    int _evald = (_cond);					\
    if (!(_evald)) {						\
        fformat(stderr, "FAIL:%d: " _comment "\n",		\
                __LINE__, ##_args);				\
        res = 1;                                                \
    } else {							\
        fformat(stderr, "PASS:%d: " _comment "\n",		\
                __LINE__, ##_args);				\
    }								\
    res;							\
})
#define MFIB_TEST(_cond, _comment, _args...)			\
{								\
    if (MFIB_TEST_I(_cond, _comment, ##_args)) {		\
        return 1;                                               \
        ASSERT(!("FAIL: " _comment));				\
    }								\
}
#define MFIB_TEST_NS(_cond)                                     \
{								\
    if (MFIB_TEST_I(_cond, "")) {                               \
        return 1;                                               \
        ASSERT(!("FAIL: "));                                    \
    }								\
}

/**
 * A 'i'm not fussed is this is not efficient' store of test data
 */
typedef struct test_main_t_ {
    /**
     * HW if indicies
     */
    u32 hw_if_indicies[4];
    /**
     * HW interfaces
     */
    vnet_hw_interface_t * hw[4];

} test_main_t;
static test_main_t test_main;

/* fake ethernet device class, distinct from "fake-ethX" */
static u8 * format_test_interface_name (u8 * s, va_list * args)
{
  u32 dev_instance = va_arg (*args, u32);
  return format (s, "test-eth%d", dev_instance);
}

static uword dummy_interface_tx (vlib_main_t * vm,
                                 vlib_node_runtime_t * node,
                                 vlib_frame_t * frame)
{
  clib_warning ("you shouldn't be here, leaking buffers...");
  return frame->n_vectors;
}

static clib_error_t *
test_interface_admin_up_down (vnet_main_t * vnm,
                              u32 hw_if_index,
                              u32 flags)
{
  u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
    VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
  vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
  return 0;
}

VNET_DEVICE_CLASS (test_interface_device_class,static) = {
  .name = "Test interface",
  .format_device_name = format_test_interface_name,
  .tx_function = dummy_interface_tx,
  .admin_up_down_function = test_interface_admin_up_down,
};

static u8 *hw_address;

static int
mfib_test_mk_intf (u32 ninterfaces)
{
    clib_error_t * error = NULL;
    test_main_t *tm = &test_main;
    u8 byte;
    int res;
    u32 i;

    res = 0;
    ASSERT(ninterfaces <= ARRAY_LEN(tm->hw_if_indicies));

    for (i=0; i<6; i++)
    {
        byte = 0xd0+i;
        vec_add1(hw_address, byte);
    }

    for (i = 0; i < ninterfaces; i++)
    {
        hw_address[5] = i;

        error = ethernet_register_interface(vnet_get_main(),
                                            test_interface_device_class.index,
                                            i /* instance */,
                                            hw_address,
                                            &tm->hw_if_indicies[i],
                                            /* flag change */ 0);

        MFIB_TEST((NULL == error), "ADD interface %d", i);

        error = vnet_hw_interface_set_flags(vnet_get_main(),
                                            tm->hw_if_indicies[i],
                                            VNET_HW_INTERFACE_FLAG_LINK_UP);
        tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
                                          tm->hw_if_indicies[i]);
        vec_validate (ip4_main.fib_index_by_sw_if_index,
                      tm->hw[i]->sw_if_index);
        vec_validate (ip6_main.fib_index_by_sw_if_index,
                      tm->hw[i]->sw_if_index);
        ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
        ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;

        vec_validate (ip4_main.mfib_index_by_sw_if_index,
                      tm->hw[i]->sw_if_index);
        vec_validate (ip6_main.mfib_index_by_sw_if_index,
                      tm->hw[i]->sw_if_index);
        ip4_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
        ip6_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;

        error = vnet_sw_interface_set_flags(vnet_get_main(),
                                            tm->hw[i]->sw_if_index,
                                            VNET_SW_INTERFACE_FLAG_ADMIN_UP);
        MFIB_TEST((NULL == error), "UP interface %d", i);
    }
    /*
     * re-eval after the inevitable realloc
     */
    for (i = 0; i < ninterfaces; i++)
    {
        tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
                                          tm->hw_if_indicies[i]);
    }

    return (res);
}

#define MFIB_TEST_REP(_cond, _comment, _args...)		\
{								\
    if (MFIB_TEST_I(_cond, _comment, ##_args)) {		\
        return (1);						\
    }								\
}

static int
mfib_test_validate_rep_v (const replicate_t *rep,
                          u16 n_buckets,
                          va_list *ap)
{
    const dpo_id_t *dpo;
    adj_index_t ai;
    dpo_type_t dt;
    int bucket;
    int res;

    res = 0;
    MFIB_TEST_REP((n_buckets == rep->rep_n_buckets),
                  "n_buckets = %d", rep->rep_n_buckets);

    for (bucket = 0; bucket < n_buckets; bucket++)
    {
        dt = va_arg(*ap, int);  // type promotion
        ai = va_arg(*ap, adj_index_t);
        dpo = replicate_get_bucket_i(rep, bucket);

        MFIB_TEST_REP((dt == dpo->dpoi_type),
                      "bucket %d stacks on %U",
                      bucket,
                      format_dpo_type, dpo->dpoi_type);

        if (DPO_RECEIVE != dt)
        {
            MFIB_TEST_REP((ai == dpo->dpoi_index),
                          "bucket %d [exp:%d] stacks on %U",
                          bucket, ai,
                          format_dpo_id, dpo, 0);
        }
    }
    return (res);
}

static int
mfib_test_entry (fib_node_index_t fei,
                 mfib_entry_flags_t eflags,
                 int n_buckets,
                 ...)
{
    const mfib_entry_t *mfe;
    const replicate_t *rep;
    mfib_prefix_t pfx;
    va_list ap;
    int res;


    res = 0;
    mfe = mfib_entry_get(fei);
    mfib_entry_get_prefix(fei, &pfx);

    MFIB_TEST_REP((eflags == mfe->mfe_flags),
                  "%U has %U expect %U",
                  format_mfib_prefix, &pfx,
                  format_mfib_entry_flags, mfe->mfe_flags,
                  format_mfib_entry_flags, eflags);

    if (0 == n_buckets)
    {
        MFIB_TEST_REP((DPO_DROP == mfe->mfe_rep.dpoi_type),
                      "%U links to %U",
                      format_mfib_prefix, &pfx,
                      format_dpo_id, &mfe->mfe_rep, 0);
    }
    else
    {
        dpo_id_t tmp = DPO_INVALID;

        mfib_entry_contribute_forwarding(
            fei,
            fib_forw_chain_type_from_fib_proto(pfx.fp_proto),
            &tmp);
        rep = replicate_get(tmp.dpoi_index);

        MFIB_TEST_REP((DPO_REPLICATE == tmp.dpoi_type),
                      "%U links to %U",
                      format_mfib_prefix, &pfx,
                      format_dpo_type, tmp.dpoi_type);

        va_start(ap, n_buckets);
        res = mfib_test_validate_rep_v(rep, n_buckets, &ap);
        va_end(ap);

        dpo_reset(&tmp);
    }


    return (res);
}

static int
mfib_test_entry_itf (fib_node_index_t fei,
                     u32 sw_if_index,
                     mfib_itf_flags_t flags)
{
    const mfib_entry_t *mfe;
    const mfib_itf_t *mfi;
    mfib_prefix_t pfx;
    int res;

    res = 0;
    mfe = mfib_entry_get(fei);
    mfi = mfib_entry_get_itf(mfe, sw_if_index);
    mfib_entry_get_prefix(fei, &pfx);

    MFIB_TEST_REP((NULL != mfi),
                  "%U has interface %d",
                  format_mfib_prefix, &pfx, sw_if_index);

    MFIB_TEST_REP((flags == mfi->mfi_flags),
                  "%U interface %d has flags %U expect %U",
                  format_mfib_prefix, &pfx, sw_if_index,
                  format_mfib_itf_flags, flags,
                  format_mfib_itf_flags, mfi->mfi_flags);

    return (res);
}

static int
mfib_test_entry_no_itf (fib_node_index_t fei,
                        u32 sw_if_index)
{
    const mfib_entry_t *mfe;
    const mfib_itf_t *mfi;
    mfib_prefix_t pfx;
    int res;

    res = 0;
    mfe = mfib_entry_get(fei);
    mfi = mfib_entry_get_itf(mfe, sw_if_index);
    mfib_entry_get_prefix(fei, &pfx);

    MFIB_TEST_REP((NULL == mfi),
                  "%U has no interface %d",
                  format_mfib_prefix, &pfx, sw_if_index);

    return (res);
}

static int
mfib_test_i (fib_protocol_t PROTO,
             vnet_link_t LINKT,
             const mfib_prefix_t *pfx_no_forward,
             const mfib_prefix_t *pfx_s_g,
             const mfib_prefix_t *pfx_star_g_1,
             const mfib_prefix_t *pfx_star_g_2,
             const mfib_prefix_t *pfx_star_g_3,
             const mfib_prefix_t *pfx_star_g_slash_m,
             const fib_prefix_t *pfx_itf,
             const ip46_address_t *addr_nbr1,
             const ip46_address_t *addr_nbr2)
{
    fib_node_index_t mfei, mfei_dflt, mfei_no_f, mfei_s_g, mfei_g_1, mfei_g_2, mfei_g_3, mfei_g_m;
    u32 fib_index, n_entries, n_itfs, n_reps, n_pls;
    fib_node_index_t ai_1, ai_2, ai_3, ai_nbr1, ai_nbr2;
    test_main_t *tm;
    int res;

    mfib_prefix_t all_1s;
    clib_memset(&all_1s, 0xfd, sizeof(all_1s));

    res = 0;
    n_entries = pool_elts(mfib_entry_pool);
    n_itfs = pool_elts(mfib_itf_pool);
    n_reps = pool_elts(replicate_pool);
    n_pls = fib_path_list_pool_size();
    tm = &test_main;

    ai_1 = adj_mcast_add_or_lock(PROTO,
                                 LINKT,
                                 tm->hw[1]->sw_if_index);
    ai_2 = adj_mcast_add_or_lock(PROTO,
                                 LINKT,
                                 tm->hw[2]->sw_if_index);
    ai_3 = adj_mcast_add_or_lock(PROTO,
                                 LINKT,
                                 tm->hw[3]->sw_if_index);
    ai_nbr1 = adj_nbr_add_or_lock(PROTO,
                                  LINKT,
                                  addr_nbr1,
                                  tm->hw[0]->sw_if_index);
    ai_nbr2 = adj_nbr_add_or_lock(PROTO,
                                  LINKT,
                                  addr_nbr2,
                                  tm->hw[0]->sw_if_index);

    MFIB_TEST(3 == adj_mcast_db_size(), "3 MCAST adjs");

    /* Find or create FIB table 11 */
    fib_index = mfib_table_find_or_create_and_lock(PROTO, 11, MFIB_SOURCE_API);

    fib_table_entry_update_one_path(0,
                                    pfx_itf,
				    FIB_SOURCE_INTERFACE,
				    (FIB_ENTRY_FLAG_CONNECTED |
				     FIB_ENTRY_FLAG_ATTACHED),
				    DPO_PROTO_IP4,
				    NULL,
				    tm->hw[0]->sw_if_index,
				    ~0, // invalid fib index
				    1, // weight
				    NULL,
				    FIB_ROUTE_PATH_FLAG_NONE);

    mfib_prefix_t pfx_dft = {
        .fp_len = 0,
        .fp_proto = PROTO,
    };
    mfei_dflt = mfib_table_lookup_exact_match(fib_index, &pfx_dft);
    MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_dflt, "(*,*) presnet");
    MFIB_TEST(!mfib_test_entry(mfei_dflt,
                               MFIB_ENTRY_FLAG_DROP,
                               0),
              "(*,*) no replcaitions");

    MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_dflt, "(*,*) presnet");
    MFIB_TEST(!mfib_test_entry(mfei_dflt,
                               MFIB_ENTRY_FLAG_DROP,
                               0),
              "(*,*) no replcaitions");


    fib_route_path_t path_via_if0 = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = zero_addr,
        .frp_sw_if_index = tm->hw[0]->sw_if_index,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = 0,
    };

    mfib_table_entry_path_update(fib_index,
                                 pfx_no_forward,
                                 MFIB_SOURCE_API,
                                 &path_via_if0,
                                 MFIB_ITF_FLAG_ACCEPT);

    mfei_no_f = mfib_table_lookup_exact_match(fib_index, pfx_no_forward);
    MFIB_TEST(!mfib_test_entry(mfei_no_f,
                               MFIB_ENTRY_FLAG_NONE,
                               0),
              "%U no replcaitions",
              format_mfib_prefix, pfx_no_forward);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_no_f, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));

    fib_route_path_t path_via_if1 = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = zero_addr,
        .frp_sw_if_index = tm->hw[1]->sw_if_index,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = 0,
    };
    fib_route_path_t path_via_if2 = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = zero_addr,
        .frp_sw_if_index = tm->hw[2]->sw_if_index,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = 0,
    };
    fib_route_path_t path_via_if3 = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = zero_addr,
        .frp_sw_if_index = tm->hw[3]->sw_if_index,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = 0,
    };
    fib_route_path_t path_for_us = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = zero_addr,
        .frp_sw_if_index = 0xffffffff,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = FIB_ROUTE_PATH_LOCAL,
    };

    /*
     * An (S,G) with 1 accepting and 3 forwarding paths
     */
    mfib_table_entry_path_update(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if0,
                                 MFIB_ITF_FLAG_ACCEPT);
    mfib_table_entry_path_update(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if1,
                                 MFIB_ITF_FLAG_FORWARD);
    mfib_table_entry_path_update(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if2,
                                 MFIB_ITF_FLAG_FORWARD);
    mfib_table_entry_path_update(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if3,
                                 (MFIB_ITF_FLAG_FORWARD |
                                  MFIB_ITF_FLAG_NEGATE_SIGNAL));

    mfei_s_g = mfib_table_lookup_exact_match(fib_index, pfx_s_g);

    MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_s_g,
              "%U present",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST(!mfib_test_entry(mfei_s_g,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate ok",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[1]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[2]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[3]->sw_if_index,
                                      (MFIB_ITF_FLAG_FORWARD |
                                       MFIB_ITF_FLAG_NEGATE_SIGNAL)));

    /*
     * A (*,G), which the same G as the (S,G).
     * different paths. test our LPM.
     */
    mfei_g_1 = mfib_table_entry_path_update(fib_index,
                                            pfx_star_g_1,
                                            MFIB_SOURCE_API,
                                            &path_via_if0,
                                            MFIB_ITF_FLAG_ACCEPT);
    mfib_table_entry_path_update(fib_index,
                                 pfx_star_g_1,
                                 MFIB_SOURCE_API,
                                 &path_via_if1,
                                 MFIB_ITF_FLAG_FORWARD);

    /*
     * test we find the *,G and S,G via LPM and exact matches
     */
    mfei = mfib_table_lookup_exact_match(fib_index,
                                         pfx_star_g_1);
    MFIB_TEST(mfei == mfei_g_1,
              "%U found via exact match",
              format_mfib_prefix, pfx_star_g_1);
    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_ADJACENCY_MCAST, ai_1),
              "%U replicate ok",
              format_mfib_prefix, pfx_star_g_1);

    mfei = mfib_table_lookup(fib_index,
                             pfx_star_g_1);
    MFIB_TEST(mfei == mfei_g_1,
              "%U found via LP match",
              format_mfib_prefix, pfx_star_g_1);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_ADJACENCY_MCAST, ai_1),
              "%U replicate ok",
              format_mfib_prefix, pfx_star_g_1);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g);
    MFIB_TEST(mfei == mfei_s_g,
              "%U found via exact match",
              format_mfib_prefix, pfx_s_g);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    mfei = mfib_table_lookup(fib_index, pfx_s_g);
    MFIB_TEST(mfei == mfei_s_g,
              "%U found via LP match",
              format_mfib_prefix, pfx_s_g);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);

    /*
     * A (*,G/m), which the same root G as the (*,G).
     * different paths. test our LPM.
     */
    mfei_g_m = mfib_table_entry_path_update(fib_index,
                                            pfx_star_g_slash_m,
                                            MFIB_SOURCE_API,
                                            &path_via_if2,
                                            MFIB_ITF_FLAG_ACCEPT);
    mfib_table_entry_path_update(fib_index,
                                 pfx_star_g_slash_m,
                                 MFIB_SOURCE_API,
                                 &path_via_if3,
                                 MFIB_ITF_FLAG_FORWARD);

    /*
     * test we find the (*,G/m), (*,G) and (S,G) via LPM and exact matches
     */
    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1);
    MFIB_TEST((mfei_g_1 == mfei),
              "%U found via DP LPM: %d",
              format_mfib_prefix, pfx_star_g_1, mfei);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_ADJACENCY_MCAST, ai_1),
              "%U replicate ok",
              format_mfib_prefix, pfx_star_g_1);

    mfei = mfib_table_lookup(fib_index, pfx_star_g_1);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_ADJACENCY_MCAST, ai_1),
              "%U replicate ok",
              format_mfib_prefix, pfx_star_g_1);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    mfei = mfib_table_lookup(fib_index, pfx_s_g);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_slash_m);
    MFIB_TEST(mfei = mfei_g_m,
              "%U Found via exact match",
              format_mfib_prefix, pfx_star_g_slash_m);
    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_star_g_slash_m);
    MFIB_TEST(mfei_g_m == mfib_table_lookup(fib_index, pfx_star_g_slash_m),
              "%U found via LPM",
              format_mfib_prefix, pfx_star_g_slash_m);

    /*
     * Add a for-us path
     */
    mfei = mfib_table_entry_path_update(fib_index,
                                        pfx_s_g,
                                        MFIB_SOURCE_API,
                                        &path_for_us,
                                        MFIB_ITF_FLAG_FORWARD);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               4,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3,
                               DPO_RECEIVE, 0),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);

    /*
     * remove a for-us path
     */
    mfib_table_entry_path_remove(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_for_us);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);

    /*
     * update an existing forwarding path to be only accepting
     *   - expect it to be removed from the replication set.
     */
    mfib_table_entry_path_update(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if3,
                                 MFIB_ITF_FLAG_ACCEPT);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               2,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[3]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));
    /*
     * Make the path forwarding again
     *  - expect it to be added back to the replication set
     */
    mfib_table_entry_path_update(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if3,
                                 (MFIB_ITF_FLAG_FORWARD |
                                  MFIB_ITF_FLAG_ACCEPT |
                                  MFIB_ITF_FLAG_NEGATE_SIGNAL));

    mfei = mfib_table_lookup_exact_match(fib_index,
                                         pfx_s_g);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[3]->sw_if_index,
                                      (MFIB_ITF_FLAG_FORWARD |
                                       MFIB_ITF_FLAG_ACCEPT |
                                       MFIB_ITF_FLAG_NEGATE_SIGNAL)));

    /*
     * update flags on the entry
     */
    mfib_table_entry_update(fib_index,
                            pfx_s_g,
                            MFIB_SOURCE_API,
                            MFIB_RPF_ID_NONE,
                            MFIB_ENTRY_FLAG_SIGNAL);
    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_SIGNAL,
                               3,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2,
                               DPO_ADJACENCY_MCAST, ai_3),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);

    /*
     * remove paths
     */
    mfib_table_entry_path_remove(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if3);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_SIGNAL,
                               2,
                               DPO_ADJACENCY_MCAST, ai_1,
                               DPO_ADJACENCY_MCAST, ai_2),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index));

    mfib_table_entry_path_remove(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if1);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_SIGNAL,
                               1,
                               DPO_ADJACENCY_MCAST, ai_2),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_ACCEPT));
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index));

    /*
     * remove the accpeting only interface
     */
    mfib_table_entry_path_remove(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if0);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_SIGNAL,
                               1,
                               DPO_ADJACENCY_MCAST, ai_2),
              "%U replicate OK",
              format_mfib_prefix, pfx_s_g);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[0]->sw_if_index));
    MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[1]->sw_if_index));
    MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index));

    /*
     * remove the last path, the entry still has flags so it remains
     */
    mfib_table_entry_path_remove(fib_index,
                                 pfx_s_g,
                                 MFIB_SOURCE_API,
                                 &path_via_if2);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_SIGNAL,
                               0),
              "%U no replications",
              format_mfib_prefix, pfx_s_g);

    /*
     * update flags on the entry
     */
    mfib_table_entry_update(fib_index,
                            pfx_s_g,
                            MFIB_SOURCE_API,
                            MFIB_RPF_ID_NONE,
                            (MFIB_ENTRY_FLAG_SIGNAL |
                             MFIB_ENTRY_FLAG_CONNECTED));
    MFIB_TEST(!mfib_test_entry(mfei,
                               (MFIB_ENTRY_FLAG_SIGNAL |
                                MFIB_ENTRY_FLAG_CONNECTED),
                               0),
              "%U no replications",
              format_mfib_prefix, pfx_s_g);

    /*
     * An entry with a NS interface
     */
    mfei_g_2 = mfib_table_entry_path_update(fib_index,
                                            pfx_star_g_2,
                                            MFIB_SOURCE_API,
                                            &path_via_if0,
                                            (MFIB_ITF_FLAG_ACCEPT |
                                             MFIB_ITF_FLAG_NEGATE_SIGNAL));
    MFIB_TEST(!mfib_test_entry(mfei_g_2,
                               MFIB_ENTRY_FLAG_NONE,
                               0),
              "%U No replications",
              format_mfib_prefix, pfx_star_g_2);

    /*
     * Simulate a signal from the data-plane
     */
    {
        mfib_entry_t *mfe;
        mfib_itf_t *mfi;

        mfe = mfib_entry_get(mfei_g_2);
        mfi = mfib_entry_get_itf(mfe, path_via_if0.frp_sw_if_index);

        mfib_signal_push(mfe, mfi, NULL);
    }

    /*
     * An entry with a NS interface
     */
    mfei_g_3 = mfib_table_entry_path_update(fib_index,
                                            pfx_star_g_3,
                                            MFIB_SOURCE_API,
                                            &path_via_if0,
                                            (MFIB_ITF_FLAG_ACCEPT |
                                             MFIB_ITF_NEGATE_SIGNAL));
    MFIB_TEST(!mfib_test_entry(mfei_g_3,
                               MFIB_ENTRY_FLAG_NONE,
                               0),
              "%U No replications",
              format_mfib_prefix, pfx_star_g_3);

    /*
     * Simulate a signal from the data-plane
     */
    {
        mfib_entry_t *mfe;
        mfib_itf_t *mfi;

        mfe = mfib_entry_get(mfei_g_3);
        mfi = mfib_entry_get_itf(mfe, path_via_if0.frp_sw_if_index);

        mfib_signal_push(mfe, mfi, NULL);
    }

    if (FIB_PROTOCOL_IP6 == PROTO)
    {
        /*
         * All the entries are present. let's ensure we can find them all
         * via exact and longest prefix matches.
         */
        /*
         * A source address we will never match
         */
        ip6_address_t src = {
            .as_u64[0] = clib_host_to_net_u64(0x3001000000000000),
            .as_u64[1] = clib_host_to_net_u64(0xffffffffffffffff),
        };

        /*
         * Find the (*,G/m)
         */
        MFIB_TEST((mfei_g_m == ip6_mfib_table_lookup2(
                       ip6_mfib_get(fib_index),
                       &src,
                       &pfx_star_g_slash_m->fp_grp_addr.ip6)),
                  "%U found via DP LPM grp=%U",
                  format_mfib_prefix, pfx_star_g_slash_m,
                  format_ip6_address, &pfx_star_g_slash_m->fp_grp_addr.ip6);

        ip6_address_t tmp = pfx_star_g_slash_m->fp_grp_addr.ip6;
        tmp.as_u8[15] = 0xff;

        MFIB_TEST((mfei_g_m == ip6_mfib_table_lookup2(
                       ip6_mfib_get(fib_index),
                       &pfx_s_g->fp_src_addr.ip6,
                       &tmp)),
                  "%U found via DP LPM grp=%U",
                  format_mfib_prefix, pfx_star_g_slash_m,
                  format_ip6_address, &tmp);

        /*
         * Find the (S,G).
         */
        mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
                                      &pfx_s_g->fp_src_addr.ip6,
                                      &pfx_s_g->fp_grp_addr.ip6);
        MFIB_TEST((mfei_s_g == mfei),
                  "%U found via DP LPM: %d",
                  format_mfib_prefix, pfx_s_g, mfei);

        /*
         * Find the 3 (*,G) s
         */
        mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
                                      &src,
                                      &pfx_star_g_1->fp_grp_addr.ip6);
        MFIB_TEST((mfei_g_1 == mfei),
                  "%U found via DP LPM: %d",
                  format_mfib_prefix, pfx_star_g_1, mfei);
        mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
                                      &src,
                                      &pfx_star_g_2->fp_grp_addr.ip6);
        MFIB_TEST((mfei_g_2 == mfei),
                  "%U found via DP LPM: %d",
                  format_mfib_prefix, pfx_star_g_2, mfei);
        mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
                                      &src,
                                      &pfx_star_g_3->fp_grp_addr.ip6);
        MFIB_TEST((mfei_g_3 == mfei),
                  "%U found via DP LPM: %d",
                  format_mfib_prefix, pfx_star_g_3, mfei);
    }

    /*
     * remove flags on the entry. This is the last of the
     * state associated with the entry, so now it goes.
     */
    mfib_table_entry_update(fib_index,
                            pfx_s_g,
                            MFIB_SOURCE_API,
                            MFIB_RPF_ID_NONE,
                            MFIB_ENTRY_FLAG_NONE);
    mfei = mfib_table_lookup_exact_match(fib_index,
                                         pfx_s_g);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U gone",
              format_mfib_prefix, pfx_s_g);

    /*
     * remove the last path on the no forward entry - the last entry
     */
    mfib_table_entry_path_remove(fib_index,
                                 pfx_no_forward,
                                 MFIB_SOURCE_API,
                                 &path_via_if0);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_no_forward);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U gone",
              format_mfib_prefix, pfx_no_forward);

    /*
     * hard delete the (*,232.1.1.1)
     */
    mfib_table_entry_delete(fib_index,
                            pfx_star_g_1,
                            MFIB_SOURCE_API);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U gone",
              format_mfib_prefix, pfx_star_g_1);
    /*
     * remove the entry whilst the signal is pending
     */
    mfib_table_entry_delete(fib_index,
                            pfx_star_g_2,
                            MFIB_SOURCE_API);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_2);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U Gone",
              format_mfib_prefix, pfx_star_g_2);
    mfib_table_entry_delete(fib_index,
                            pfx_star_g_3,
                            MFIB_SOURCE_API);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_3);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U Gone",
              format_mfib_prefix, pfx_star_g_3);

    mfib_table_entry_delete(fib_index,
                            pfx_star_g_slash_m,
                            MFIB_SOURCE_API);

    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_slash_m);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U Gone",
              format_mfib_prefix, pfx_star_g_slash_m);

    /*
     * Entries with paths via unicast next-hops
     */
    fib_route_path_t path_via_nbr1 = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = *addr_nbr1,
        .frp_sw_if_index = tm->hw[0]->sw_if_index,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = 0,
    };
    fib_route_path_t path_via_nbr2 = {
        .frp_proto = fib_proto_to_dpo(PROTO),
        .frp_addr = *addr_nbr2,
        .frp_sw_if_index = tm->hw[0]->sw_if_index,
        .frp_fib_index = ~0,
        .frp_weight = 0,
        .frp_flags = 0,
    };

    mfei_g_1 = mfib_table_entry_path_update(fib_index,
                                            pfx_star_g_1,
                                            MFIB_SOURCE_API,
                                            &path_via_nbr1,
                                            (MFIB_ITF_FLAG_FORWARD));
    mfei_g_1 = mfib_table_entry_path_update(fib_index,
                                            pfx_star_g_1,
                                            MFIB_SOURCE_API,
                                            &path_via_nbr2,
                                            (MFIB_ITF_FLAG_FORWARD));
    MFIB_TEST(!mfib_test_entry(mfei_g_1,
                               MFIB_ENTRY_FLAG_NONE,
                               2,
                               DPO_ADJACENCY_INCOMPLETE, ai_nbr1,
                               DPO_ADJACENCY_INCOMPLETE, ai_nbr2),
              "%U replicate OK",
              format_mfib_prefix, pfx_star_g_1);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_g_1, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));

    mfib_table_entry_path_remove(fib_index,
                                 pfx_star_g_1,
                                 MFIB_SOURCE_API,
                                 &path_via_nbr1);

    MFIB_TEST(!mfib_test_entry(mfei_g_1,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_ADJACENCY_INCOMPLETE, ai_nbr2),
              "%U replicate OK",
              format_mfib_prefix, pfx_star_g_1);
    MFIB_TEST_NS(!mfib_test_entry_itf(mfei_g_1, tm->hw[0]->sw_if_index,
                                      MFIB_ITF_FLAG_FORWARD));

    mfib_table_entry_path_remove(fib_index,
                                 pfx_star_g_1,
                                 MFIB_SOURCE_API,
                                 &path_via_nbr2);
    mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1);
    MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
              "%U Gone",
              format_mfib_prefix, pfx_star_g_1);

    /*
     * Add a prefix as a special/exclusive route
     */
    dpo_id_t td = DPO_INVALID;
    index_t repi = replicate_create(1, fib_proto_to_dpo(PROTO));

    dpo_set(&td, DPO_ADJACENCY_MCAST, fib_proto_to_dpo(PROTO), ai_2);
    replicate_set_bucket(repi, 0, &td);

    mfei = mfib_table_entry_special_add(fib_index,
                                        pfx_star_g_3,
                                        MFIB_SOURCE_SRv6,
                                        MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF,
                                        repi);
    MFIB_TEST(!mfib_test_entry(mfei,
                               (MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF |
                                MFIB_ENTRY_FLAG_EXCLUSIVE),
                               1,
                               DPO_ADJACENCY_MCAST, ai_2),
              "%U exclusive replicate OK",
              format_mfib_prefix, pfx_star_g_3);

    /*
     * update a special/exclusive route
     */
    index_t repi2 = replicate_create(1, fib_proto_to_dpo(PROTO));

    dpo_set(&td, DPO_ADJACENCY_MCAST, fib_proto_to_dpo(PROTO), ai_1);
    replicate_set_bucket(repi2, 0, &td);

    mfei = mfib_table_entry_special_add(fib_index,
                                        pfx_star_g_3,
                                        MFIB_SOURCE_SRv6,
                                        MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF,
                                        repi2);
    MFIB_TEST(!mfib_test_entry(mfei,
                               (MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF |
                                MFIB_ENTRY_FLAG_EXCLUSIVE),
                               1,
                               DPO_ADJACENCY_MCAST, ai_1),
              "%U exclusive update replicate OK",
              format_mfib_prefix, pfx_star_g_3);

    mfib_table_entry_delete(fib_index,
                            pfx_star_g_3,
                            MFIB_SOURCE_SRv6);
    dpo_reset(&td);

    /*
     * A Multicast LSP. This a mLDP head-end
     */
    fib_node_index_t ai_mpls_10_10_10_1, lfei;
    ip46_address_t nh_10_10_10_1 = {
	.ip4 = {
	    .as_u32 = clib_host_to_net_u32(0x0a0a0a01),
	},
    };
    ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4,
                                             VNET_LINK_MPLS,
                                             &nh_10_10_10_1,
                                             tm->hw[0]->sw_if_index);

    fib_prefix_t pfx_3500 = {
	.fp_len = 21,
	.fp_proto = FIB_PROTOCOL_MPLS,
	.fp_label = 3500,
	.fp_eos = MPLS_EOS,
	.fp_payload_proto = DPO_PROTO_IP4,
    };
    fib_test_rep_bucket_t mc_0 = {
        .type = FT_REP_LABEL_O_ADJ,
	.label_o_adj = {
	    .adj = ai_mpls_10_10_10_1,
	    .label = 3300,
	    .eos = MPLS_EOS,
	},
    };
    fib_mpls_label_t *l3300 = NULL, fml3300 = {
        .fml_value = 3300,
    };
    vec_add1(l3300, fml3300);

    /*
     * MPLS enable an interface so we get the MPLS table created
     */
    mpls_table_create(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API, NULL);
    mpls_sw_interface_enable_disable(&mpls_main,
                                     tm->hw[0]->sw_if_index,
                                     1, 0);

    lfei = fib_table_entry_update_one_path(0, // default MPLS Table
                                           &pfx_3500,
                                           FIB_SOURCE_API,
                                           FIB_ENTRY_FLAG_MULTICAST,
                                           DPO_PROTO_IP4,
                                           &nh_10_10_10_1,
                                           tm->hw[0]->sw_if_index,
                                           ~0, // invalid fib index
                                           1,
                                           l3300,
                                           FIB_ROUTE_PATH_FLAG_NONE);
    MFIB_TEST(!fib_test_validate_entry(lfei,
                                       FIB_FORW_CHAIN_TYPE_MPLS_EOS,
                                       1,
                                       &mc_0),
              "3500 via replicate over 10.10.10.1");

    /*
     * An (S,G) that resolves via the mLDP head-end
     */
    fib_route_path_t path_via_mldp = {
        .frp_proto = DPO_PROTO_MPLS,
        .frp_local_label = pfx_3500.fp_label,
        .frp_eos = MPLS_EOS,
        .frp_sw_if_index = 0xffffffff,
        .frp_fib_index = 0,
        .frp_weight = 1,
        .frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
    };
    dpo_id_t mldp_dpo = DPO_INVALID;

    fib_entry_contribute_forwarding(lfei,
                                    FIB_FORW_CHAIN_TYPE_MPLS_EOS,
                                    &mldp_dpo);

    mfei = mfib_table_entry_path_update(fib_index,
                                        pfx_s_g,
                                        MFIB_SOURCE_API,
                                        &path_via_mldp,
                                        MFIB_ITF_FLAG_FORWARD);

    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               1,
                               DPO_REPLICATE, mldp_dpo.dpoi_index),
              "%U over-mLDP replicate OK",
              format_mfib_prefix, pfx_s_g);

    /*
     * add a for-us path. this tests two types of non-attached paths on one entry
     */
    mfei = mfib_table_entry_path_update(fib_index,
                                        pfx_s_g,
                                        MFIB_SOURCE_API,
                                        &path_for_us,
                                        MFIB_ITF_FLAG_FORWARD);
    MFIB_TEST(!mfib_test_entry(mfei,
                               MFIB_ENTRY_FLAG_NONE,
                               2,
                               DPO_REPLICATE, mldp_dpo.dpoi_index,
                               DPO_RECEIVE, 0),
              "%U mLDP+for-us replicate OK",
              format_mfib_prefix, pfx_s_g);

    mfib_table_entry_delete(fib_index,
                            pfx_s_g,
                            MFIB_SOURCE_API);
    fib_table_entry_delete(0,
                           &pfx_3500,
                           FIB_SOURCE_API);
    dpo_reset(&mldp_dpo);

    /*
     * Unlock the table - it's the last lock so should be gone thereafter
     */
    mfib_table_unlock(fib_index, PROTO, MFIB_SOURCE_API);

    MFIB_TEST((FIB_NODE_INDEX_INVALID ==
               mfib_table_find(PROTO, fib_index)),
              "MFIB table %d gone", fib_index);

    adj_unlock(ai_1);
    adj_unlock(ai_2);
    adj_unlock(ai_3);
    adj_unlock(ai_nbr1);
    adj_unlock(ai_nbr2);

    /*
     * MPLS disable the interface
     */
    mpls_sw_interface_enable_disable(&mpls_main,
                                     tm->hw[0]->sw_if_index,
                                     0, 0);
    mpls_table_delete(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API);

    /*
     * remove the connected
     */
    fib_table_entry_delete(0, pfx_itf, FIB_SOURCE_INTERFACE);

    /*
     * test we've leaked no resources
     */
    MFIB_TEST(0 == adj_mcast_db_size(), "%d MCAST adjs", adj_mcast_db_size());
    MFIB_TEST(n_pls == fib_path_list_pool_size(), "%d=%d path-lists",
              n_pls, fib_path_list_pool_size());
    MFIB_TEST(n_reps == pool_elts(replicate_pool), "%d=%d replicates",
              n_reps, pool_elts(replicate_pool));
    MFIB_TEST(n_entries == pool_elts(mfib_entry_pool),
              " No more entries %d!=%d",
              n_entries, pool_elts(mfib_entry_pool));
    MFIB_TEST(n_itfs == pool_elts(mfib_itf_pool),
              " No more Interfaces %d!=%d",
              n_itfs, pool_elts(mfib_itf_pool));

    return (res);
}

static int
mfib_test_v4 (void)
{
    const mfib_prefix_t pfx_224_s_8 = {
        .fp_len = 8,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_grp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0xe0000000),
        }
    };
    const mfib_prefix_t pfx_1_1_1_1_c_239_1_1_1 = {
        .fp_len = 64,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_grp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0xef010101),
        },
        .fp_src_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0x01010101),
        },
    };
    const mfib_prefix_t pfx_239_1_1_1 = {
        .fp_len = 32,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_grp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0xef010101),
        },
        .fp_src_addr = {
            .ip4.as_u32 = 0,
        },
    };
    const mfib_prefix_t pfx_239_1_1_2 = {
        .fp_len = 32,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_grp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0xef010102),
        },
        .fp_src_addr = {
            .ip4.as_u32 = 0,
        },
    };
    const mfib_prefix_t pfx_239_1_1_3 = {
        .fp_len = 32,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_grp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0xef010103),
        },
        .fp_src_addr = {
            .ip4.as_u32 = 0,
        },
    };
    const mfib_prefix_t pfx_239 = {
        .fp_len = 8,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_grp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0xef000000),
        },
        .fp_src_addr = {
            .ip4.as_u32 = 0,
        },
    };
    const fib_prefix_t pfx_itf = {
        .fp_len = 24,
        .fp_proto = FIB_PROTOCOL_IP4,
        .fp_addr = {
            .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0a),
        },
    };
    const ip46_address_t nbr1 = {
        .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0b),
    };
    const ip46_address_t nbr2 = {
        .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0c),
    };
    return (mfib_test_i(FIB_PROTOCOL_IP4,
                        VNET_LINK_IP4,
                        &pfx_224_s_8,
                        &pfx_1_1_1_1_c_239_1_1_1,
                        &pfx_239_1_1_1,
                        &pfx_239_1_1_2,
                        &pfx_239_1_1_3,
                        &pfx_239,
                        &pfx_itf,
                        &nbr1,
                        &nbr2));
}

static int
mfib_test_v6 (void)
{
    const mfib_prefix_t pfx_ffd_s_12 = {
        .fp_len = 12,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_grp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0xffd0000000000000),
        }
    };
    const mfib_prefix_t pfx_2001_1_c_ff_1 = {
        .fp_len = 256,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_grp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
        },
        .fp_src_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
        },
    };
    const mfib_prefix_t pfx_ff_1 = {
        .fp_len = 128,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_grp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
        },
    };
    const mfib_prefix_t pfx_ff_2 = {
        .fp_len = 128,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_grp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002),
        },
    };
    const mfib_prefix_t pfx_ff_3 = {
        /*
         * this is the ALL DHCP routers address
         */
        .fp_len = 128,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_grp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0xff02000100000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002),
        },
    };
    const mfib_prefix_t pfx_ff = {
        .fp_len = 16,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_grp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000000),
        },
    };
    const fib_prefix_t pfx_itf = {
        .fp_len = 64,
        .fp_proto = FIB_PROTOCOL_IP6,
        .fp_addr = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
        },
    };
    const ip46_address_t nbr1 = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002),
    };
    const ip46_address_t nbr2 = {
            .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000),
            .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000003),
    };

    return (mfib_test_i(FIB_PROTOCOL_IP6,
                        VNET_LINK_IP6,
                        &pfx_ffd_s_12,
                        &pfx_2001_1_c_ff_1,
                        &pfx_ff_1,
                        &pfx_ff_2,
                        &pfx_ff_3,
                        &pfx_ff,
                        &pfx_itf,
                        &nbr1,
                        &nbr2));
}

static clib_error_t *
mfib_test (vlib_main_t * vm,
           unformat_input_t * input,
           vlib_cli_command_t * cmd_arg)
{
    int res = 0;

    res += mfib_test_mk_intf(4);
    res += mfib_test_v4();

    if (res)
    {
        return clib_error_return(0, "MFIB Unit Test Failed");
    }

    res += mfib_test_v6();

    if (res)
    {
        return clib_error_return(0, "MFIB Unit Test Failed");
    }
    else
    {
        return (NULL);
    }
}

VLIB_CLI_COMMAND (test_fib_command, static) = {
    .path = "test mfib",
    .short_help = "mfib unit tests - DO NOT RUN ON A LIVE SYSTEM",
    .function = mfib_test,
};

clib_error_t *
mfib_test_init (vlib_main_t *vm)
{
    return 0;
}

VLIB_INIT_FUNCTION (mfib_test_init);