X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=trp%2Ftest%2Fptbl_test.c;h=05c3997faa0d63e98b793f2eb06c918644894bb0;hb=b5117dd88f660ee157de3cf96f8fb6d952ac342a;hp=15d6d150aadea4697ea61c7f7eb84c4f6e6453ac;hpb=e427f7d366115d72ded50c2d8de7e7c4c37a773f;p=trust_router.git diff --git a/trp/test/ptbl_test.c b/trp/test/ptbl_test.c index 15d6d15..05c3997 100644 --- a/trp/test/ptbl_test.c +++ b/trp/test/ptbl_test.c @@ -1,22 +1,63 @@ +/* + * Copyright (c) 2016, JANET(UK) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JANET(UK) nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + #include #include #include +#include +#include #include +#include #include +/* Can't do the updates test because trps_select_updates_for_peer() is now static */ +#define VERIFY_UPDATES 0 + struct peer_entry { char *server; - unsigned int port; + char *gss_name; + int port; unsigned int linkcost; }; static struct peer_entry peer_data[]={ - {"peer0", 10000, 0x0001}, - {"peer1", 15000, 0x0002}, - {"peer2", 20000, 0x0004}, - {"peer3", 25000, 0x0008}, - {"peer4", 30000, 0x0010} + {"peer0", "trustrouter@peer0", 10000, 0x0001}, + {"peer1", "trustrouter@peer1", 15000, 0x0002}, + {"peer2", "trustrouter@peer2", 20000, 0x0004}, + {"peer3", "trustrouter@peer3", 25000, 0x0008}, + {"peer4", "trustrouter@peer4", 30000, 0x0010} }; static size_t n_peers=sizeof(peer_data)/sizeof(peer_data[0]); @@ -30,6 +71,8 @@ static void populate_ptable(TRPS_INSTANCE *trps) assert(new_peer!=NULL); trp_peer_set_server(new_peer, peer_data[i].server); assert(trp_peer_get_server(new_peer)!=NULL); + trp_peer_add_gss_name(new_peer, tr_new_name(peer_data[i].gss_name)); + assert(trp_peer_get_gss_names(new_peer)!=NULL); trp_peer_set_port(new_peer, peer_data[i].port); trp_peer_set_linkcost(new_peer, peer_data[i].linkcost); assert(trps_add_peer(trps, new_peer)==TRP_SUCCESS); @@ -65,7 +108,7 @@ static void verify_ptable(TRPS_INSTANCE *trps) gssname=tr_new_name(s); free(s); assert(gssname!=NULL); - assert(!tr_name_cmp(trp_peer_get_gssname(peer), gssname)); + assert(tr_gss_names_matches(trp_peer_get_gss_names(peer), gssname)); tr_free_name(gssname); peer=peer->next; } @@ -103,6 +146,7 @@ static struct route_data route_table[]={ }; static size_t n_routes=sizeof(route_table)/sizeof(route_table[0]); +#if VERIFY_UPDATES /* These are the correct updates to select from the above route table for each peer. * The rule is: send selected route unless it is through that peer, otherwise send * the best (lowest metric) alternative route. @@ -152,30 +196,32 @@ static struct route_data update_table[][10]={ {NULL} } }; +#endif /* VERIFY_UPDATES */ static void populate_rtable(TRPS_INSTANCE *trps) { int i; - TRP_RENTRY *new; + TRP_ROUTE *new; for (i=0; irtable, new); new=NULL; } } -static void verify_update(TRP_RENTRY **updates, size_t n_updates, struct route_data *expected) +#if VERIFY_UPDATES +static void verify_update(TRP_ROUTE **updates, size_t n_updates, struct route_data *expected) { int ii,jj; int found; @@ -183,7 +229,7 @@ static void verify_update(TRP_RENTRY **updates, size_t n_updates, struct route_d for(jj=0; jjapc->buf)) + if ((0==strcmp(expected[ii].apc, updates[jj]->comm->buf)) &&(0==strcmp(expected[ii].realm, updates[jj]->realm->buf)) &&(0==strcmp(expected[ii].peer, updates[jj]->peer->buf)) &&(expected[ii].metric==updates[jj]->metric) @@ -198,7 +244,7 @@ static void verify_update(TRP_RENTRY **updates, size_t n_updates, struct route_d } } if (!found) { - printf("missing:\n%s\n", trp_rentry_to_str(NULL,updates[jj], " | ")); + printf("missing:\n%s\n", trp_route_to_str(NULL,updates[jj], " | ")); assert(0); } } @@ -209,7 +255,7 @@ static void verify_update(TRP_RENTRY **updates, size_t n_updates, struct route_d static void verify_update_selection(TRPS_INSTANCE *trps) { int ii; - TRP_RENTRY **updates=NULL; + TRP_ROUTE **updates=NULL; size_t n_updates; TR_NAME *gssname=NULL; char *s; @@ -218,12 +264,14 @@ static void verify_update_selection(TRPS_INSTANCE *trps) assert(0rtable, " | ", NULL); printf("Route Table:\n%s---\n", s); +#if VERIFY_UPDATES printf("\nVerifying route update selection...\n"); verify_update_selection(trps); +#endif /* VERIFY_UPDATES */ printf("\nDone\n\n"); talloc_report_full(main_ctx, stderr);