root/opal/test/reachable/reachable_weighted.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ipv4_test
  2. ranking_test
  3. loop_test
  4. test_ipv6
  5. main

   1 /*
   2  * Copyright (c) 2017 Amazon.com, Inc. or its affiliates.  All Rights
   3  *                    reserved.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  *
  10  */
  11 
  12 #include "opal_config.h"
  13 
  14 #include "reachable_shared.h"
  15 
  16 /* sigh; needs to match with code in reachable_weighted, but those
  17    headers aren't installed. */
  18 enum connection_quality {
  19     CQ_NO_CONNECTION = 0,
  20     CQ_PRIVATE_DIFFERENT_NETWORK = 50,
  21     CQ_PRIVATE_SAME_NETWORK = 80,
  22     CQ_PUBLIC_DIFFERENT_NETWORK = 90,
  23     CQ_PUBLIC_SAME_NETWORK = 100
  24 };
  25 
  26 
  27 /* SUITE 1:
  28  * Tests IPv4 connections by
  29  * modifying ip addresses and
  30  * subnet masks.  Also tests
  31  * IPv4->IPv6 and the other way
  32  * around, to assure no connection
  33  * is returned in that case.
  34  */
  35 int ipv4_test()
  36 {
  37     opal_if_t *int1;
  38     opal_if_t *int2;
  39     int expected_result;
  40     int result;
  41     int test_no = 0;
  42     int failed_no = 0;
  43 
  44     /* TEST1
  45      * Localhost to localhost.  Since localhost range is not a
  46      * private network (RFC1918), expected result is public
  47      * same network.
  48      */
  49     test_no++;
  50     expected_result = CQ_PUBLIC_SAME_NETWORK;
  51     int1 = create_if(AF_INET, "127.0.0.1", 24, 0);
  52     int2 = create_if(AF_INET, "127.0.0.2", 0, 0);
  53     result = run_single_test(int1, int2);
  54     if (result != expected_result) {
  55         ++failed_no;
  56         opal_output(0, "Failed test #%d", test_no);
  57     }
  58     OBJ_RELEASE(int1);
  59     OBJ_RELEASE(int2);
  60 
  61     /* TEST2
  62      * Testing public same network with subnet mask
  63      * 255.255.255.0
  64      */
  65     test_no++;
  66     expected_result = CQ_PUBLIC_SAME_NETWORK;
  67     int1 = create_if(AF_INET, "31.14.15.92", 24, 0);
  68     int2 = create_if(AF_INET, "31.14.15.27", 0, 0);
  69     result = run_single_test(int1, int2);
  70 
  71     if (result != expected_result) {
  72         ++failed_no;
  73         opal_output(0, "Failed test #%d", test_no);
  74     }
  75     OBJ_RELEASE(int1);
  76     OBJ_RELEASE(int2);
  77 
  78     /* TEST3
  79      * Testing public same network with subnet mask
  80      * 255.255.0.0
  81      */
  82     test_no++;
  83     expected_result = CQ_PUBLIC_SAME_NETWORK;
  84     int1 = create_if(AF_INET, "65.35.89.79", 16, 0);
  85     int2 = create_if(AF_INET, "65.35.27.27", 0, 0);
  86     result = run_single_test(int1, int2);
  87 
  88     if (result != expected_result) {
  89         ++failed_no;
  90         opal_output(0, "Failed test #%d", test_no);
  91     }
  92     OBJ_RELEASE(int1);
  93     OBJ_RELEASE(int2);
  94 
  95     /* TEST4
  96      * Testing public same network with subnet mask
  97      * 255.0.0.0
  98      */
  99     test_no++;
 100     expected_result = CQ_PUBLIC_SAME_NETWORK;
 101     int1 = create_if(AF_INET, "3.23.84.62", 8, 0);
 102     int2 = create_if(AF_INET, "3.27.27.27", 0, 0);
 103     result = run_single_test(int1, int2);
 104 
 105     if (result != expected_result) {
 106         ++failed_no;
 107         opal_output(0, "Failed test #%d", test_no);
 108     }
 109     OBJ_RELEASE(int1);
 110     OBJ_RELEASE(int2);
 111 
 112     /* TEST5
 113      * Testing public same network with subnet mask
 114      * 0.0.0.0
 115      */
 116     test_no++;
 117     expected_result = CQ_PUBLIC_SAME_NETWORK;
 118     int1 = create_if(AF_INET, "64.33.83.27", 0, 0);
 119     int2 = create_if(AF_INET, "27.27.27.27", 0, 0);
 120     result = run_single_test(int1, int2);
 121 
 122     if (result != expected_result) {
 123         ++failed_no;
 124         opal_output(0, "Failed test #%d", test_no);
 125     }
 126     OBJ_RELEASE(int1);
 127     OBJ_RELEASE(int2);
 128 
 129     /* TEST6
 130      * Testing public different network with subnet mask
 131      * 255.255.255.0
 132      */
 133     test_no++;
 134     expected_result = CQ_PUBLIC_DIFFERENT_NETWORK;
 135     int1 = create_if(AF_INET, "95.2.88.41", 24, 0);
 136     int2 = create_if(AF_INET, "95.2.27.27", 0, 0);
 137     result = run_single_test(int1, int2);
 138 
 139     if (result != expected_result) {
 140         ++failed_no;
 141         opal_output(0, "Failed test #%d", test_no);
 142     }
 143     OBJ_RELEASE(int1);
 144     OBJ_RELEASE(int2);
 145 
 146     /* TEST7
 147      * Testing public different network with subnet mask
 148      * 255.255.0.0
 149      */
 150     test_no++;
 151     expected_result = CQ_PUBLIC_DIFFERENT_NETWORK;
 152     int1 = create_if(AF_INET, "97.16.93.99", 16, 0);
 153     int2 = create_if(AF_INET, "97.27.27.27", 0, 0);
 154     result = run_single_test(int1, int2);
 155 
 156     if (result != expected_result) {
 157         ++failed_no;
 158         opal_output(0, "Failed test #%d", test_no);
 159     }
 160     OBJ_RELEASE(int1);
 161     OBJ_RELEASE(int2);
 162 
 163     /* TEST8
 164      * Testing public different network with subnet mask
 165      * 255.0.0.0
 166      */
 167     test_no++;
 168     expected_result = CQ_PUBLIC_DIFFERENT_NETWORK;
 169     int1 = create_if(AF_INET, "37.51.5.82", 8, 0);
 170     int2 = create_if(AF_INET, "27.27.27.27", 0, 0);
 171     result = run_single_test(int1, int2);
 172 
 173     if (result != expected_result) {
 174         ++failed_no;
 175         opal_output(0, "Failed test #%d", test_no);
 176     }
 177     OBJ_RELEASE(int1);
 178     OBJ_RELEASE(int2);
 179 
 180     /* TEST9
 181      * Testing private same network with subnet mask
 182      * 255.255.255.0
 183      */
 184     test_no++;
 185     expected_result = CQ_PRIVATE_SAME_NETWORK;
 186     int1 = create_if(AF_INET, "192.168.0.1", 24, 0);
 187     int2 = create_if(AF_INET, "192.168.0.27", 0, 0);
 188     result = run_single_test(int1, int2);
 189 
 190     if (result != expected_result) {
 191         ++failed_no;
 192         opal_output(0, "Failed test #%d", test_no);
 193     }
 194     OBJ_RELEASE(int1);
 195     OBJ_RELEASE(int2);
 196 
 197     /* TEST10
 198      * Testing private same network with subnet mask
 199      * 255.255.0.0
 200      */
 201     test_no++;
 202     expected_result = CQ_PRIVATE_SAME_NETWORK;
 203     int1 = create_if(AF_INET, "192.168.0.1", 16, 0);
 204     int2 = create_if(AF_INET, "192.168.27.27", 0, 0);
 205     result = run_single_test(int1, int2);
 206 
 207     if (result != expected_result) {
 208         ++failed_no;
 209         opal_output(0, "Failed this test #%d", test_no);
 210     }
 211     OBJ_RELEASE(int1);
 212     OBJ_RELEASE(int2);
 213 
 214     /* TEST11
 215      * Testing private same network with subnet mask
 216      * 255.0.0.0
 217      */
 218     test_no++;
 219     expected_result = CQ_PRIVATE_SAME_NETWORK;
 220     int1 = create_if(AF_INET, "172.16.0.1", 8, 0);
 221     int2 = create_if(AF_INET, "172.27.27.27", 0, 0);
 222     result = run_single_test(int1, int2);
 223 
 224     if (result != expected_result) {
 225         ++failed_no;
 226         opal_output(0, "Failed this test #%d", test_no);
 227     }
 228     OBJ_RELEASE(int1);
 229     OBJ_RELEASE(int2);
 230 
 231     /* TEST12
 232      * Testing private same network with subnet mask
 233      * 0.0.0.0
 234      */
 235     test_no++;
 236     expected_result = CQ_PRIVATE_SAME_NETWORK;
 237     int1 = create_if(AF_INET, "192.168.0.1", 0, 0);
 238     int2 = create_if(AF_INET, "10.27.27.27", 0, 0);
 239     result = run_single_test(int1, int2);
 240 
 241     if (result != expected_result) {
 242         ++failed_no;
 243         opal_output(0, "Failed test #%d", test_no);
 244     }
 245     OBJ_RELEASE(int1);
 246     OBJ_RELEASE(int2);
 247 
 248     /* TEST13
 249      * Testing private different network with subnet mask
 250      * 255.255.255.0
 251      */
 252     test_no++;
 253     expected_result = CQ_PRIVATE_DIFFERENT_NETWORK;
 254     int1 = create_if(AF_INET, "192.168.0.1", 24, 0);
 255     int2 = create_if(AF_INET, "192.168.27.27", 0, 0);
 256     result = run_single_test(int1, int2);
 257 
 258     if (result != expected_result) {
 259         ++failed_no;
 260         opal_output(0, "Failed test #%d", test_no);
 261     }
 262     OBJ_RELEASE(int1);
 263     OBJ_RELEASE(int2);
 264 
 265     /* TEST14
 266      * Testing private different network with subnet mask
 267      * 255.255.0.0
 268      */
 269     test_no++;
 270     expected_result = CQ_PRIVATE_DIFFERENT_NETWORK;
 271     int1 = create_if(AF_INET, "192.168.0.1", 16, 0);
 272     int2 = create_if(AF_INET, "10.1.0.1", 16, 0);
 273     result = run_single_test(int1, int2);
 274 
 275     if (result != expected_result) {
 276         ++failed_no;
 277         opal_output(0, "Failed test #%d", test_no);
 278     }
 279     OBJ_RELEASE(int1);
 280     OBJ_RELEASE(int2);
 281 
 282     /* TEST15
 283      * Testing private different network with subnet mask
 284      * 255.0.0.0
 285      */
 286     test_no++;
 287     expected_result = CQ_PRIVATE_DIFFERENT_NETWORK;
 288     int1 = create_if(AF_INET, "192.168.0.1", 8, 0);
 289     int2 = create_if(AF_INET, "10.27.27.27", 0, 0);
 290     result = run_single_test(int1, int2);
 291 
 292     if (result != expected_result) {
 293         ++failed_no;
 294         opal_output(0, "Failed test #%d", test_no);
 295     }
 296     OBJ_RELEASE(int1);
 297     OBJ_RELEASE(int2);
 298 
 299     /* TEST16
 300      * Testing public to private with subnet mask
 301      * 255.255.255.0
 302      */
 303     test_no++;
 304     expected_result = CQ_NO_CONNECTION;
 305     int1 = create_if(AF_INET, "27.27.27.27", 24 , 0);
 306     int2 = create_if(AF_INET, "192.168.0.1", 16, 0);
 307     result = run_single_test(int1, int2);
 308 
 309     if (result != expected_result) {
 310         ++failed_no;
 311         opal_output(0, "Failed test #%d", test_no);
 312     }
 313     OBJ_RELEASE(int1);
 314     OBJ_RELEASE(int2);
 315 
 316     /* TEST17
 317      * Testing private to public with subnet mask
 318      * 255.255.255.0
 319      */
 320     test_no++;
 321     expected_result = CQ_NO_CONNECTION;
 322     int1 = create_if(AF_INET, "192.168.0.1", 24, 0);
 323     int2 = create_if(AF_INET, "27.27.27.27", 8, 0);
 324     result = run_single_test(int1, int2);
 325 
 326     if (result != expected_result) {
 327         ++failed_no;
 328         opal_output(0, "Failed test #%d", test_no);
 329     }
 330     OBJ_RELEASE(int1);
 331     OBJ_RELEASE(int2);
 332 
 333     /* TEST18
 334      * IPv4->IPv6
 335      */
 336     expected_result = CQ_NO_CONNECTION;
 337     int1 = create_if(AF_INET, "8.8.8.8", 24, 0);
 338     int2 = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8888", 0, 0);
 339     result = run_single_test(int1, int2);
 340     test_no++;
 341     if (result != expected_result) {
 342         ++failed_no;
 343         opal_output(0, "Failed test #%d", test_no);
 344     }
 345     OBJ_RELEASE(int1);
 346     OBJ_RELEASE(int2);
 347 
 348     /* TEST19
 349      * IPv6->IPv4
 350      */
 351     expected_result = CQ_NO_CONNECTION;
 352     int1 = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8888", 64, 0);
 353     int2 = create_if(AF_INET, "8.8.8.8", 0, 0);
 354     result = run_single_test(int1, int2);
 355     test_no++;
 356     if (result != expected_result) {
 357         ++failed_no;
 358         opal_output(0, "Failed test #%d", test_no);
 359     }
 360     OBJ_RELEASE(int1);
 361     OBJ_RELEASE(int2);
 362 
 363     opal_output(0, "Finished Reachable IPv4 Tests.  %d/%d successful", test_no-failed_no, test_no);
 364 
 365     if (0 == failed_no) {
 366         return 0;
 367     } else {
 368         return 1;
 369     }
 370 }
 371 
 372 
 373 /* SUITE 2:
 374  * Compares connections with different
 375  * bandwidths to see ensure the
 376  * relative ranking is as expected
 377  */
 378 int ranking_test()
 379 {
 380     opal_if_t *int1;
 381     opal_if_t *int2;
 382     int result1;
 383     int result2;
 384     int test_no = 0;
 385     int failed_no = 0;
 386 
 387     /* TEST1
 388      * Compares pairs with bandwidths 0->0 and 1->0.
 389      * The former connection should be better, as
 390      * there is a smaller difference in bandwidth
 391      * (This is an edge case, but this behavior makes
 392      * sense.  We want 0->0 to still work, incase
 393      * bandwidth was never set.  Thus, the behavior
 394      * for a->b where a = 0 and a != b should
 395      * act the same as any other case, where
 396      * a greater difference in leads to a greater
 397      * penalty in bandwidth)
 398      */
 399     test_no++;
 400 
 401     int1 = create_if(AF_INET, "31.14.15.92", 24, 0);
 402     int2 = create_if(AF_INET, "31.14.15.27", 0, 0);
 403     result1 = run_single_test(int1, int2);
 404     OBJ_RELEASE(int1);
 405     OBJ_RELEASE(int2);
 406 
 407     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 408     int2 = create_if(AF_INET, "31.14.15.27", 0, 0);
 409     result2 = run_single_test(int1, int2);
 410     OBJ_RELEASE(int1);
 411     OBJ_RELEASE(int2);
 412 
 413     if (!(result1 > result2)) {
 414         ++failed_no;
 415         opal_output(0, "Failed test #%d", test_no);
 416     }
 417 
 418     /* TEST2
 419      * Compares interface pairs with bandwidth 0->0 and 1->2.
 420      * The latter should be better as it has greater bandwidth
 421      */
 422     test_no++;
 423 
 424     int1 = create_if(AF_INET, "31.14.15.92", 24, 0);
 425     int2 = create_if(AF_INET, "31.14.15.27", 0, 0);
 426     result1 = run_single_test(int1, int2);
 427     OBJ_RELEASE(int1);
 428     OBJ_RELEASE(int2);
 429 
 430     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 431     int2 = create_if(AF_INET, "31.14.15.27", 0, 2);
 432     result2 = run_single_test(int1, int2);
 433     OBJ_RELEASE(int1);
 434     OBJ_RELEASE(int2);
 435 
 436     if (!(result1 < result2)) {
 437         ++failed_no;
 438         opal_output(0, "Failed test #%d", test_no);
 439     }
 440 
 441     /* TEST3
 442      * Compares interface pairs with bandwidth 1->2 and 1->1.
 443      * The later should be better as there is a smaller
 444      * difference in bandwidth
 445      */
 446     test_no++;
 447 
 448     int1 = create_if(AF_INET, "31.14.15.92", 24, 0);
 449     int2 = create_if(AF_INET, "31.14.15.27", 0, 0);
 450     result1 = run_single_test(int1, int2);
 451     OBJ_RELEASE(int1);
 452     OBJ_RELEASE(int2);
 453 
 454     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 455     int2 = create_if(AF_INET, "31.14.15.27", 0, 1);
 456     result2 = run_single_test(int1, int2);
 457     OBJ_RELEASE(int1);
 458     OBJ_RELEASE(int2);
 459 
 460     if (!(result1 < result2)) {
 461         ++failed_no;
 462         opal_output(0, "Failed test #%d", test_no);
 463     }
 464 
 465     /* TEST4
 466      * Compares interface pairs with bandwidth 1->3 and 1->2.
 467      * The later should be better as there is a smaller
 468      * difference in bandwidth
 469      */
 470     test_no++;
 471 
 472     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 473     int2 = create_if(AF_INET, "31.14.15.27", 0, 3);
 474     result1 = run_single_test(int1, int2);
 475     OBJ_RELEASE(int1);
 476     OBJ_RELEASE(int2);
 477 
 478     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 479     int2 = create_if(AF_INET, "31.14.15.27", 0, 2);
 480     result2 = run_single_test(int1, int2);
 481     OBJ_RELEASE(int1);
 482     OBJ_RELEASE(int2);
 483 
 484     if (!(result1 < result2)) {
 485         ++failed_no;
 486         opal_output(0, "Failed test #%d", test_no);
 487     }
 488 
 489     /* TEST5
 490      * Compares interface pairs with bandwidth 1->10 and 1->3.
 491      * The later should be better as there is less discrepancy
 492      * in bandwidth
 493      */
 494     test_no++;
 495 
 496     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 497     int2 = create_if(AF_INET, "31.14.15.27", 0, 10);
 498     result1 = run_single_test(int1, int2);
 499     OBJ_RELEASE(int1);
 500     OBJ_RELEASE(int2);
 501 
 502     int1 = create_if(AF_INET, "31.14.15.92", 24, 1);
 503     int2 = create_if(AF_INET, "31.14.15.27", 0, 3);
 504     result2 = run_single_test(int1, int2);
 505     OBJ_RELEASE(int1);
 506     OBJ_RELEASE(int2);
 507 
 508     if (!(result1 < result2)) {
 509         ++failed_no;
 510         opal_output(0, "Failed test #%d", test_no);
 511     }
 512 
 513     /* TEST6
 514      * Compares interface pairs with bandwidth 5->5 and 10->10.
 515      * The later should be better as it has higher bandwidth
 516      */
 517     test_no++;
 518 
 519     int1 = create_if(AF_INET, "31.14.15.92", 24, 5);
 520     int2 = create_if(AF_INET, "31.14.15.27", 0, 5);
 521     result1 = run_single_test(int1, int2);
 522     OBJ_RELEASE(int1);
 523     OBJ_RELEASE(int2);
 524 
 525     int1 = create_if(AF_INET, "31.14.15.92", 24, 10);
 526     int2 = create_if(AF_INET, "31.14.15.27", 0, 10);
 527     result2 = run_single_test(int1, int2);
 528     OBJ_RELEASE(int1);
 529     OBJ_RELEASE(int2);
 530 
 531     if (!(result1 < result2)) {
 532         ++failed_no;
 533         opal_output(0, "Failed test #%d", test_no);
 534     }
 535 
 536     /* TEST7
 537      * Compares interface pairs with bandwidth 10->11 and 10->10.
 538      * The later should be better as there is no discrepancy in
 539      * bandwidth.
 540      */
 541     test_no++;
 542 
 543     int1 = create_if(AF_INET, "31.14.15.92", 24, 10);
 544     int2 = create_if(AF_INET, "31.14.15.27", 0, 11);
 545     result1 = run_single_test(int1, int2);
 546     OBJ_RELEASE(int1);
 547     OBJ_RELEASE(int2);
 548 
 549     int1 = create_if(AF_INET, "31.14.15.92", 24, 10);
 550     int2 = create_if(AF_INET, "31.14.15.27", 0, 10);
 551     result2 = run_single_test(int1, int2);
 552     OBJ_RELEASE(int1);
 553     OBJ_RELEASE(int2);
 554 
 555     if (!(result1 < result2)) {
 556         ++failed_no;
 557         opal_output(0, "Failed test #%d", test_no);
 558     }
 559 
 560     /* TEST8
 561      * Compares interface pairs with bandwidth 10->11 and 11->10.
 562      * These connections should be equivilant, as they have the same
 563      * bandwidth and same discrepancy.
 564      */
 565     test_no++;
 566 
 567     int1 = create_if(AF_INET, "31.14.15.92", 24, 10);
 568     int2 = create_if(AF_INET, "31.14.15.27", 0, 11);
 569     result1 = run_single_test(int1, int2);
 570     OBJ_RELEASE(int1);
 571     OBJ_RELEASE(int2);
 572 
 573     int1 = create_if(AF_INET, "31.14.15.92", 24, 11);
 574     int2 = create_if(AF_INET, "31.14.15.27", 0, 10);
 575     result2 = run_single_test(int1, int2);
 576     OBJ_RELEASE(int1);
 577     OBJ_RELEASE(int2);
 578 
 579     if (!(result1 == result2)) {
 580         ++failed_no;
 581         opal_output(0, "Failed test #%d", test_no);
 582     }
 583 
 584     /* TEST9
 585      * Compares interface pairs with bandwidth 10->14 and 11->15.
 586      * The latter should be better as it has higher bandwidth.
 587      */
 588     test_no++;
 589 
 590     int1 = create_if(AF_INET, "31.14.15.92", 24, 10);
 591     int2 = create_if(AF_INET, "31.14.15.27", 0, 14);
 592     result1 = run_single_test(int1, int2);
 593     OBJ_RELEASE(int1);
 594     OBJ_RELEASE(int2);
 595 
 596     int1 = create_if(AF_INET, "31.14.15.92", 24, 11);
 597     int2 = create_if(AF_INET, "31.14.15.27", 0, 15);
 598     result2 = run_single_test(int1, int2);
 599     OBJ_RELEASE(int1);
 600     OBJ_RELEASE(int2);
 601 
 602     if (!(result1 < result2)) {
 603         ++failed_no;
 604         opal_output(0, "Failed test #%d", test_no);
 605     }
 606 
 607     opal_output(0, "Finished Reachable Weighted Ranking Tests.  %d/%d successful", test_no-failed_no, test_no);
 608     if (0 == failed_no) {
 609         return 0;
 610     } else {
 611         return 1;
 612     }
 613 }
 614 
 615 
 616 /* SUITE 3:
 617  * Tests interfaces lists of various sizes
 618  * to ensure no crashes occur and results
 619  * are outputted in proper order
 620  */
 621 int loop_test()
 622 {
 623     int test_no = 0;
 624     int failed_no = 0;
 625 
 626     opal_list_t *if_list1, *if_list2;
 627     opal_if_t *intf;
 628     opal_reachable_t *results;
 629 
 630     int i;
 631 
 632     /* TEST1:
 633      * Ensure opal_reachable doesn't crash
 634      * when called with empty lists
 635      */
 636     test_no++;
 637 
 638     if_list1 = OBJ_NEW(opal_list_t);
 639     if_list2 = OBJ_NEW(opal_list_t);
 640 
 641     results = opal_reachable.reachable(if_list1, if_list2);
 642 
 643     OBJ_RELEASE(if_list1);
 644     OBJ_RELEASE(if_list2);
 645 
 646     if (!(0 == results->num_local && 0 == results->num_remote)) {
 647         ++failed_no;
 648         opal_output(0, "Failed test #%d", test_no);
 649     }
 650     OBJ_RELEASE(results);
 651 
 652     /* TEST2:
 653      * Ensure opal_reachable doesn't crash
 654      * when called with empty local list
 655      */
 656     test_no++;
 657 
 658     if_list1 = OBJ_NEW(opal_list_t);
 659     if_list2 = OBJ_NEW(opal_list_t);
 660 
 661     intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 662     opal_list_append(if_list2, &(intf->super));
 663     results = opal_reachable.reachable(if_list1, if_list2);
 664 
 665     OBJ_RELEASE(if_list1);
 666     OBJ_RELEASE(if_list2);
 667 
 668     if (!(0 == results->num_local && 1 == results->num_remote)) {
 669         ++failed_no;
 670         opal_output(0, "Failed test #%d", test_no);
 671     }
 672     OBJ_RELEASE(results);
 673 
 674     /* TEST3:
 675      * Ensure opal_reachable doesn't crash
 676      * when called with empty remote list
 677      */
 678     test_no++;
 679 
 680     if_list1 = OBJ_NEW(opal_list_t);
 681     if_list2 = OBJ_NEW(opal_list_t);
 682     intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 683     opal_list_append(if_list1, &(intf->super));
 684     results = opal_reachable.reachable(if_list1, if_list2);
 685 
 686     OBJ_RELEASE(if_list1);
 687     OBJ_RELEASE(if_list2);
 688 
 689     if (!(1 == results->num_local && 0 == results->num_remote)) {
 690         ++failed_no;
 691         opal_output(0, "Failed test #%d", test_no);
 692     }
 693     OBJ_RELEASE(results);
 694 
 695     /* TEST4:
 696      * Ensure opal_reachable doesn't crash
 697      * when the remote list has more elements
 698      * than the local list
 699      */
 700     test_no++;
 701 
 702     if_list1 = OBJ_NEW(opal_list_t);
 703     if_list2 = OBJ_NEW(opal_list_t);
 704     for (i = 0; i < 3; i++) {
 705         intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 706         opal_list_append(if_list1, &(intf->super));
 707     }
 708     for (i = 0; i < 14; i++) {
 709         intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 710         opal_list_append(if_list2, &(intf->super));
 711     }
 712     results = opal_reachable.reachable(if_list1, if_list2);
 713 
 714     OBJ_RELEASE(if_list1);
 715     OBJ_RELEASE(if_list2);
 716 
 717     if (!(3 == results->num_local && 14 == results->num_remote)) {
 718         ++failed_no;
 719         opal_output(0, "Failed test #%d", test_no);
 720     }
 721     OBJ_RELEASE(results);
 722 
 723     /* TEST5:
 724      * Ensure opal_reachable doesn't crash
 725      * when the local list has more elements
 726      * than the remote list
 727      */
 728     test_no++;
 729 
 730     if_list1 = OBJ_NEW(opal_list_t);
 731     if_list2 = OBJ_NEW(opal_list_t);
 732     for (i = 0; i < 14; i++) {
 733         intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 734         opal_list_append(if_list1, &(intf->super));
 735     }
 736     for (i = 0; i < 3; i++) {
 737         intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 738         opal_list_append(if_list2, &(intf->super));
 739     }
 740     results = opal_reachable.reachable(if_list1, if_list2);
 741 
 742     OBJ_RELEASE(if_list1);
 743     OBJ_RELEASE(if_list2);
 744 
 745     if (!(14 == results->num_local && 3 == results->num_remote)) {
 746         ++failed_no;
 747         opal_output(0, "Failed test #%d", test_no);
 748     }
 749     OBJ_RELEASE(results);
 750 
 751     /* TEST6:
 752      * Ensure opal_reachable doesn't crash
 753      * when the local list has the same number
 754      * of elements as the remote list
 755      */
 756     test_no++;
 757 
 758     if_list1 = OBJ_NEW(opal_list_t);
 759     if_list2 = OBJ_NEW(opal_list_t);
 760     for (i = 0; i < 27; i++) {
 761         intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 762         opal_list_append(if_list1, &(intf->super));
 763     }
 764     for (i = 0; i < 27; i++) {
 765         intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 766         opal_list_append(if_list2, &(intf->super));
 767     }
 768     results = opal_reachable.reachable(if_list1, if_list2);
 769 
 770     OBJ_RELEASE(if_list1);
 771     OBJ_RELEASE(if_list2);
 772 
 773     if (!(27 == results->num_local && 27 == results->num_remote)) {
 774         ++failed_no;
 775         opal_output(0, "Failed test #%d", test_no);
 776     }
 777     OBJ_RELEASE(results);
 778 
 779     /* TEST7:
 780      * Tests proper ordering of results
 781      * when same number of local interfaces and
 782      * remote interfaces
 783      */
 784     test_no++;
 785     if_list1 = OBJ_NEW(opal_list_t);
 786     if_list2 = OBJ_NEW(opal_list_t);
 787 
 788     intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 789     opal_list_append(if_list1, &(intf->super));
 790     intf = create_if(AF_INET, "31.14.20.92", 24, 0);
 791     opal_list_append(if_list1, &(intf->super));
 792 
 793     intf = create_if(AF_INET, "31.14.19.93", 24, 0);
 794     opal_list_append(if_list2, &(intf->super));
 795     intf = create_if(AF_INET, "31.14.20.93", 24, 0);
 796     opal_list_append(if_list2, &(intf->super));
 797 
 798     results = opal_reachable.reachable(if_list1, if_list2);
 799 
 800     OBJ_RELEASE(if_list1);
 801     OBJ_RELEASE(if_list2);
 802 
 803     if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] &&
 804           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] &&
 805           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] &&
 806           CQ_PUBLIC_SAME_NETWORK == results->weights[1][1])) {
 807         ++failed_no;
 808         opal_output(0, "Failed test #%d", test_no);
 809     }
 810     OBJ_RELEASE(results);
 811 
 812     /* TEST8:
 813      * Tests proper ordering of results
 814      * when greater number of remote interfaces
 815      * than local interfaces
 816      */
 817     test_no++;
 818     if_list1 = OBJ_NEW(opal_list_t);
 819     if_list2 = OBJ_NEW(opal_list_t);
 820 
 821     intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 822     opal_list_append(if_list1, &(intf->super));
 823     intf = create_if(AF_INET, "31.14.20.92", 24, 0);
 824     opal_list_append(if_list1, &(intf->super));
 825 
 826     intf = create_if(AF_INET, "31.14.19.93", 24, 0);
 827     opal_list_append(if_list2, &(intf->super));
 828     intf = create_if(AF_INET, "31.14.20.93", 24, 0);
 829     opal_list_append(if_list2, &(intf->super));
 830     intf = create_if(AF_INET, "31.14.21.93", 24, 0);
 831     opal_list_append(if_list2, &(intf->super));
 832 
 833     results = opal_reachable.reachable(if_list1, if_list2);
 834 
 835     OBJ_RELEASE(if_list1);
 836     OBJ_RELEASE(if_list2);
 837 
 838     if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] &&
 839           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] &&
 840           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][2] &&
 841           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] &&
 842           CQ_PUBLIC_SAME_NETWORK == results->weights[1][1]) &&
 843         CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][2]) {
 844         ++failed_no;
 845         opal_output(0, "Failed test #%d", test_no);
 846     }
 847     OBJ_RELEASE(results);
 848 
 849     /* TEST9:
 850      * Tests proper ordering of results
 851      * when greater number of local interfaces
 852      * than remote interfaces
 853      */
 854     test_no++;
 855     if_list1 = OBJ_NEW(opal_list_t);
 856     if_list2 = OBJ_NEW(opal_list_t);
 857 
 858     intf = create_if(AF_INET, "31.14.19.92", 24, 0);
 859     opal_list_append(if_list1, &(intf->super));
 860     intf = create_if(AF_INET, "31.14.20.92", 24, 0);
 861     opal_list_append(if_list1, &(intf->super));
 862     intf = create_if(AF_INET, "31.14.21.93", 24, 0);
 863     opal_list_append(if_list1, &(intf->super));
 864 
 865     intf = create_if(AF_INET, "31.14.19.93", 24, 0);
 866     opal_list_append(if_list2, &(intf->super));
 867     intf = create_if(AF_INET, "31.14.20.93", 24, 0);
 868     opal_list_append(if_list2, &(intf->super));
 869 
 870     results = opal_reachable.reachable(if_list1, if_list2);
 871 
 872     OBJ_RELEASE(if_list1);
 873     OBJ_RELEASE(if_list2);
 874 
 875     if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] &&
 876           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] &&
 877           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] &&
 878           CQ_PUBLIC_SAME_NETWORK == results->weights[1][1] &&
 879           CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[2][0]) &&
 880         CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[2][1]) {
 881         ++failed_no;
 882         opal_output(0, "Failed test #%d", test_no);
 883     }
 884     OBJ_RELEASE(results);
 885 
 886     opal_output(0, "Finished Reachable Weighted Loop Tests.  %d/%d successful", test_no-failed_no, test_no);
 887 
 888     if (0 == failed_no) {
 889         return 0;
 890     } else {
 891         return 1;
 892     }
 893 
 894 }
 895 
 896 
 897 /* SUITE 4:
 898  * Test IPv6
 899  */
 900 int test_ipv6()
 901 {
 902     int failed_no = 0;
 903 
 904 #if OPAL_ENABLE_IPV6
 905     opal_if_t *int1;
 906     opal_if_t *int2;
 907     int expected_result;
 908     int result;
 909     int test_no = 0;
 910 
 911     /* TEST1
 912      * Testing ipv6 same network with subnet mask
 913      * \64
 914      */
 915     expected_result = CQ_PUBLIC_SAME_NETWORK;
 916     int1 = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8888", 64, 0);
 917     int2 = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8889", 8, 0);
 918     result = run_single_test(int1, int2);
 919     test_no++;
 920     if (result != expected_result) {
 921         ++failed_no;
 922         opal_output(0, "Failed test #%d", test_no);
 923     }
 924     OBJ_RELEASE(int1);
 925     OBJ_RELEASE(int2);
 926 
 927     /* TEST2
 928      * Testing ipv6 different network with subnet mask
 929      * \64
 930      */
 931     expected_result = CQ_PUBLIC_DIFFERENT_NETWORK;
 932     int1 = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8888", 64, 0);
 933     int2 = create_if(AF_INET6, "2001:4860:4860:1:0:0:0:8888", 0, 0);
 934     result = run_single_test(int1, int2);
 935     test_no++;
 936     if (result != expected_result) {
 937         ++failed_no;
 938         opal_output(0, "Failed test #%d", test_no);
 939     }
 940     OBJ_RELEASE(int1);
 941     OBJ_RELEASE(int2);
 942 
 943     expected_result = CQ_PRIVATE_SAME_NETWORK;
 944     int1 = create_if(AF_INET6, "fe80::8888", 64, 0);
 945     int2 = create_if(AF_INET6, "fe80::8889", 64, 0);
 946     result = run_single_test(int1, int2);
 947     test_no++;
 948     if (result != expected_result) {
 949         ++failed_no;
 950         opal_output(0, "Failed test #%d", test_no);
 951     }
 952     OBJ_RELEASE(int1);
 953     OBJ_RELEASE(int2);
 954 
 955     expected_result = CQ_NO_CONNECTION;
 956     int1 = create_if(AF_INET6, "2001::8888", 64, 0);
 957     int2 = create_if(AF_INET6, "fe80::8889", 64, 0);
 958     result = run_single_test(int1, int2);
 959     test_no++;
 960     if (result != expected_result) {
 961         ++failed_no;
 962         opal_output(0, "Failed test #%d", test_no);
 963     }
 964     OBJ_RELEASE(int1);
 965     OBJ_RELEASE(int2);
 966 
 967     opal_output(0, "Finished Reachable Weighted IPv6 Tests.  %d/%d successful", test_no-failed_no, test_no);
 968 
 969     if (0 == failed_no) {
 970         return 0;
 971     } else {
 972         return 1;
 973     }
 974 #else
 975     opal_output(0, "No IPv6 support; skipped tests");
 976     return 0;
 977 #endif
 978 }
 979 
 980 int main(int argc, char **argv)
 981 {
 982     int failed = 0;
 983     int total = 0;
 984 
 985     opal_init(&argc, &argv);
 986     opal_output(0, "\n\nBeginning Reachable Weighted tests\n\n");
 987 
 988     total++;
 989     if (ipv4_test()) {
 990         failed++;
 991     }
 992 
 993     total++;
 994     if (ranking_test()) {
 995         failed++;
 996     }
 997 
 998     total++;
 999     if (loop_test()) {
1000         failed++;
1001     }
1002 
1003     total++;
1004     if (test_ipv6()) {
1005         failed++;
1006     }
1007 
1008     if (0 != failed) {
1009         opal_output(0, "\n\nFailed %d/%d Reachable Weighted Test Suites :(\n\n", failed, total);        
1010     } else {
1011         opal_output(0, "\n\nPassed %d/%d Reachable Weighted Test Suites :)\n\n", total, total); 
1012     }
1013 
1014     return failed;
1015 }

/* [<][>][^][v][top][bottom][index][help] */