root/opal/test/reachable/reachable_netlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. build_if_list
  2. main

   1 /*
   2  * Copyright (c) 2017 Amazon.com, Inc. or its affiliates.  All Rights
   3  *                    reserved.
   4  * Copyright (c) 2018      Cisco Systems, Inc.  All rights reserved
   5  * $COPYRIGHT$
   6  *
   7  * Additional copyrights may follow
   8  *
   9  * $HEADER$
  10  *
  11  */
  12 
  13 #include "opal_config.h"
  14 
  15 #include "reachable_shared.h"
  16 
  17 #include "opal/runtime/opal.h"
  18 #include "opal/mca/reachable/reachable.h"
  19 #include "opal/util/if.h"
  20 #include "opal/class/opal_list.h"
  21 #include "opal/util/if.h"
  22 
  23 /*
  24  * Creates list of remote interfaces for testing reachability.
  25  * Only minimum information is filled out.
  26  */
  27 opal_list_t* build_if_list(void)
  28 {
  29     /* Allocate memory for and create interface list */
  30     opal_list_t *if_list = OBJ_NEW(opal_list_t);
  31     opal_if_t *intf;
  32 
  33     /*
  34      * Add localhost to list
  35      */
  36     intf = create_if(AF_INET, "127.0.0.1", 8, 0);
  37     opal_list_append(if_list, &(intf->super));
  38 
  39     /*
  40      * Add localhost with non-standard address
  41      */
  42     intf = create_if(AF_INET, "127.31.41.59", 8, 0);
  43     opal_list_append(if_list, &(intf->super));
  44 
  45     /*
  46      * Add another localhost with non-standard address
  47      */
  48     intf = create_if(AF_INET, "127.26.53.58", 8, 0);
  49     opal_list_append(if_list, &(intf->super));
  50 
  51     /*
  52      * Google's public DNS
  53      */
  54     intf = create_if(AF_INET, "8.8.8.8", 16, 0);
  55     opal_list_append(if_list, &(intf->super));
  56 
  57     /*
  58      * Google's public DNS (2)
  59      */
  60     intf = create_if(AF_INET, "8.8.4.4", 16, 0);
  61     opal_list_append(if_list, &(intf->super));
  62 
  63     /*
  64      * IPv6: Google's public DNS (IPv6)
  65      */
  66     intf = create_if(AF_INET6, "2001:4860:4860::8888", 64, 0);
  67     opal_list_append(if_list, &(intf->super));
  68 
  69     /*
  70      * IPv6: Google's public DNS 2 (IPv6)
  71      */
  72     intf = create_if(AF_INET6, "2001:4860:4860::8844", 128, 0);
  73     opal_list_append(if_list, &(intf->super));
  74 
  75     /*
  76      * IPv6: Google's public DNS 1 (IPv6) EXPLICIT ADDRESS
  77      */
  78     intf = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8888", 64, 0);
  79     opal_list_append(if_list, &(intf->super));
  80 
  81     /*
  82      * IPv6: Google's public DNS 2 (IPv6) EXPLICIT ADDRESS
  83      */
  84     intf = create_if(AF_INET6, "2001:4860:4860:0:0:0:0:8844", 64, 0);
  85     opal_list_append(if_list, &(intf->super));
  86 
  87     /*
  88      * IPv6: something that should be on the same link local...
  89      */
  90     intf = create_if(AF_INET6, "fe80::0001", 64, 0);
  91     opal_list_append(if_list, &(intf->super));
  92 
  93     return if_list;
  94 }
  95 
  96 
  97 int main(int argc, char **argv)
  98 {
  99     opal_list_t *local_list, *remote_list;
 100     opal_reachable_t *results;
 101     uint32_t i, j;
 102     int successful_connections = 0;
 103     int local_ifs;
 104     int remote_ifs;
 105     opal_if_t *local_if;
 106 
 107     opal_init(&argc, &argv);
 108 
 109     /* List of interfaces generated by opal */
 110     local_list = &opal_if_list;
 111     /* Create test interfaces */
 112     remote_list = build_if_list();
 113 
 114     local_ifs = opal_list_get_size(local_list);
 115     remote_ifs = opal_list_get_size(remote_list);
 116 
 117     /* Tests reachability by looking up entries in routing table.
 118      * Tests routes to localhost and google's nameservers.
 119      */
 120     results = opal_reachable.reachable(local_list, remote_list);
 121 
 122     printf("Local interfaces:\n");
 123     i = 0;
 124     OPAL_LIST_FOREACH(local_if, local_list, opal_if_t) {
 125         char addr[128];
 126         char *family;
 127 
 128         switch (local_if->af_family) {
 129             case AF_INET:
 130                 family = "IPv4";
 131                 inet_ntop(AF_INET, &(((struct sockaddr_in*) &local_if->if_addr))->sin_addr,
 132                           addr, sizeof(addr));
 133                 break;
 134             case AF_INET6:
 135                 family = "IPv6";
 136                 inet_ntop(AF_INET6, &(((struct sockaddr_in6*) &local_if->if_addr))->sin6_addr,
 137                           addr, sizeof(addr));
 138                 break;
 139             default:
 140                 family = "Unknown";
 141                 opal_string_copy(addr, "Unknown", sizeof(addr));
 142                 break;
 143         }
 144 
 145         printf("  %3d: %s\t%s\t%s/%d\n", i, local_if->if_name,
 146                family, addr, local_if->if_mask);
 147         i++;
 148     }
 149 
 150     printf("\nRemote interfaces:\n");
 151     i = 0;
 152     OPAL_LIST_FOREACH(local_if, remote_list, opal_if_t) {
 153         char addr[128];
 154         char *family;
 155 
 156         switch (local_if->af_family) {
 157             case AF_INET:
 158                 family = "IPv4";
 159                 inet_ntop(AF_INET, &(((struct sockaddr_in*) &local_if->if_addr))->sin_addr,
 160                           addr, sizeof(addr));
 161                 break;
 162             case AF_INET6:
 163                 family = "IPv6";
 164                 inet_ntop(AF_INET6, &(((struct sockaddr_in6*) &local_if->if_addr))->sin6_addr,
 165                           addr, sizeof(addr));
 166                 break;
 167             default:
 168                 family = "Unknown";
 169                 opal_string_copy(addr, "Unknown", sizeof(addr));
 170                 break;
 171         }
 172 
 173         printf("  %3d: %s\t%s\t%s/%d\n", i, local_if->if_name,
 174                family, addr, local_if->if_mask);
 175         i++;
 176     }
 177 
 178     printf("\nConnectivity Table:\n       ");
 179     for (j = 0 ; j < remote_ifs ; j++) {
 180         printf("%3d ", j);
 181     }
 182     printf("\n");
 183 
 184     for (i = 0; i < local_ifs ; i++) {
 185         printf("  %3d: ", i);
 186         for (j = 0 ; j < remote_ifs ; j++) {
 187             printf("%3d ", results->weights[i][j]);
 188         }
 189         printf("\n");
 190     }
 191     printf("\n");
 192 
 193     OBJ_RELEASE(remote_list);
 194 
 195     opal_output(0, "Passed all tests!\n");
 196     return 0;
 197 }

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