test/unit_tests/prophet-decider-test.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 #include <dtn-config.h>
       
     2 #include <oasys/util/UnitTest.h>
       
     3 
       
     4 #include "prophet/Node.h"
       
     5 #include "prophet/Link.h"
       
     6 #include "prophet/Table.h"
       
     7 #include "prophet/Bundle.h"
       
     8 #include "prophet/Stats.h"
       
     9 #include "prophet/Decider.h"
       
    10 
       
    11 using namespace oasys;
       
    12 
       
    13 //                       dest_id, cts, seq, ets, size, num_fwd
       
    14 prophet::BundleImpl m("dtn://test-a",0xfe,   1,  60, 1024,      1);
       
    15 prophet::BundleImpl n("dtn://test-b",0xff,   2,  60,  512,      1);
       
    16 prophet::BundleCoreTestImpl core;
       
    17 prophet::LinkImpl nexthop("dtn://nexthop");
       
    18 
       
    19 DECLARE_TEST(GRTR) {
       
    20     prophet::Table local(&core,"local"), remote(&core,"remote");
       
    21     prophet::Stats stats;
       
    22     prophet::Decider* d =
       
    23         prophet::Decider::decider(prophet::FwdStrategy::GRTR,
       
    24                                   &nexthop, &core, &local, &remote,
       
    25                                   &stats, 0, true);
       
    26 
       
    27     CHECK( d != NULL );
       
    28     CHECK_EQUAL(d->fwd_strategy(), prophet::FwdStrategy::GRTR);
       
    29     CHECK( ! d->operator()(&m) );
       
    30     CHECK( ! d->operator()(&n) );
       
    31 
       
    32     // install a route to m's destination in nexthop's table
       
    33     DO( remote.update_route("dtn://test-a") );
       
    34 
       
    35     CHECK(   d->operator()(&m) );
       
    36     CHECK( ! d->operator()(&n) );
       
    37 
       
    38     delete d;
       
    39 
       
    40     // try again with new decider, not relay
       
    41     d = prophet::Decider::decider(prophet::FwdStrategy::GRTR,
       
    42                                   &nexthop, &core, &local, &remote,
       
    43                                   &stats, 0, false);
       
    44 
       
    45     CHECK( ! d->operator()(&m) );
       
    46     CHECK( ! d->operator()(&n) );
       
    47 
       
    48     delete d;
       
    49 
       
    50     return UNIT_TEST_PASSED;
       
    51 }
       
    52 
       
    53 DECLARE_TEST(GTMX) {
       
    54     prophet::Table local(&core,"local"), remote(&core,"remote");
       
    55     prophet::Stats stats;
       
    56     prophet::Decider* d =
       
    57         prophet::Decider::decider(prophet::FwdStrategy::GTMX,
       
    58                                   &nexthop, &core, &local, &remote,
       
    59                                   &stats, 1, true);
       
    60 
       
    61     CHECK( d != NULL );
       
    62     CHECK_EQUAL(d->fwd_strategy(), prophet::FwdStrategy::GTMX);
       
    63     CHECK( ! d->operator()(&m) );
       
    64     CHECK( ! d->operator()(&n) );
       
    65 
       
    66     // install a route to m's destination in nexthop's table
       
    67     DO( remote.update_route("dtn://test-a") );
       
    68 
       
    69     CHECK( ! d->operator()(&m) );
       
    70     CHECK( ! d->operator()(&n) );
       
    71 
       
    72     // try again with MAX_FWD > 1
       
    73     delete d;
       
    74 
       
    75     d = prophet::Decider::decider(prophet::FwdStrategy::GTMX,
       
    76                                   &nexthop, &core, &local, &remote,
       
    77                                   &stats, 3, true);
       
    78 
       
    79     CHECK(   d->operator()(&m) );
       
    80     CHECK( ! d->operator()(&n) );
       
    81 
       
    82     delete d;
       
    83 
       
    84     return UNIT_TEST_PASSED;
       
    85 }
       
    86 
       
    87 DECLARE_TEST(GRTR_PLUS) {
       
    88     prophet::Table local(&core,"local"), remote(&core,"remote");
       
    89     prophet::Stats stats;
       
    90     prophet::Decider* d =
       
    91         prophet::Decider::decider(prophet::FwdStrategy::GRTR_PLUS,
       
    92                                   &nexthop, &core, &local, &remote,
       
    93                                   &stats, 0, true);
       
    94 
       
    95     CHECK( d != NULL );
       
    96     CHECK_EQUAL(d->fwd_strategy(), prophet::FwdStrategy::GRTR_PLUS);
       
    97     CHECK( ! d->operator()(&m) );
       
    98     CHECK( ! d->operator()(&n) );
       
    99 
       
   100     // install a route to m's destination in nexthop's table
       
   101     DO( remote.update_route("dtn://test-a") );
       
   102 
       
   103     CHECK(   d->operator()(&m) );
       
   104     CHECK( ! d->operator()(&n) );
       
   105 
       
   106     // try again with new stats
       
   107     DO( stats.update_stats(&m,0.9) );
       
   108 
       
   109     CHECK( ! d->operator()(&m) );
       
   110     CHECK( ! d->operator()(&n) );
       
   111 
       
   112     delete d;
       
   113 
       
   114     return UNIT_TEST_PASSED;
       
   115 }
       
   116 
       
   117 DECLARE_TEST(GTMX_PLUS) {
       
   118     prophet::Table local(&core,"local"), remote(&core,"remote");
       
   119     prophet::Stats stats;
       
   120     prophet::Decider* d =
       
   121         prophet::Decider::decider(prophet::FwdStrategy::GTMX_PLUS,
       
   122                                   &nexthop, &core, &local, &remote,
       
   123                                   &stats, 1, true);
       
   124 
       
   125     CHECK( d != NULL );
       
   126     CHECK_EQUAL(d->fwd_strategy(), prophet::FwdStrategy::GTMX_PLUS);
       
   127     CHECK( ! d->operator()(&m) );
       
   128     CHECK( ! d->operator()(&n) );
       
   129 
       
   130     // install a route to m's destination in nexthop's table
       
   131     DO( remote.update_route("dtn://test-a") );
       
   132 
       
   133     CHECK( ! d->operator()(&m) );
       
   134     CHECK( ! d->operator()(&n) );
       
   135 
       
   136     // try again with MAX_FWD > 1
       
   137     delete d;
       
   138     DO( d = prophet::Decider::decider(prophet::FwdStrategy::GTMX_PLUS,
       
   139                                   &nexthop, &core, &local, &remote,
       
   140                                   &stats, 3, true) );
       
   141 
       
   142     CHECK(   d->operator()(&m) );
       
   143     CHECK( ! d->operator()(&n) );
       
   144 
       
   145     // try again with new stats
       
   146     DO( stats.update_stats(&m,0.9) );
       
   147 
       
   148     CHECK( ! d->operator()(&m) );
       
   149     CHECK( ! d->operator()(&n) );
       
   150 
       
   151     delete d;
       
   152 
       
   153     return UNIT_TEST_PASSED;
       
   154 }
       
   155 
       
   156 DECLARE_TEST(GRTR_SORT) {
       
   157     prophet::Table local(&core,"local"), remote(&core,"remote");
       
   158     prophet::Stats stats;
       
   159     prophet::Decider* d =
       
   160         prophet::Decider::decider(prophet::FwdStrategy::GRTR_SORT,
       
   161                                   &nexthop, &core, &local, &remote,
       
   162                                   &stats, 0, true);
       
   163 
       
   164     CHECK( d != NULL );
       
   165     CHECK_EQUAL(d->fwd_strategy(), prophet::FwdStrategy::GRTR_SORT);
       
   166     CHECK( ! d->operator()(&m) );
       
   167     CHECK( ! d->operator()(&n) );
       
   168 
       
   169     // install a route to m's destination in nexthop's table
       
   170     DO( remote.update_route("dtn://test-a") );
       
   171 
       
   172     CHECK(   d->operator()(&m) );
       
   173     CHECK( ! d->operator()(&n) );
       
   174 
       
   175     delete d;
       
   176 
       
   177     // try again with new decider, not relay
       
   178     d = prophet::Decider::decider(prophet::FwdStrategy::GRTR,
       
   179                                   &nexthop, &core, &local, &remote,
       
   180                                   &stats, 0, false);
       
   181 
       
   182     CHECK( ! d->operator()(&m) );
       
   183     CHECK( ! d->operator()(&n) );
       
   184 
       
   185     delete d;
       
   186 
       
   187     return UNIT_TEST_PASSED;
       
   188 }
       
   189 
       
   190 DECLARE_TEST(GRTR_MAX) {
       
   191     prophet::Table local(&core,"local"), remote(&core,"remote");
       
   192     prophet::Stats stats;
       
   193     prophet::Decider* d =
       
   194         prophet::Decider::decider(prophet::FwdStrategy::GRTR_MAX,
       
   195                                   &nexthop, &core, &local, &remote,
       
   196                                   &stats, 0, true);
       
   197 
       
   198     CHECK( d != NULL );
       
   199     CHECK_EQUAL(d->fwd_strategy(), prophet::FwdStrategy::GRTR_MAX);
       
   200     CHECK( ! d->operator()(&m) );
       
   201     CHECK( ! d->operator()(&n) );
       
   202 
       
   203     // install a route to m's destination in nexthop's table
       
   204     DO( remote.update_route("dtn://test-a") );
       
   205 
       
   206     CHECK(   d->operator()(&m) );
       
   207     CHECK( ! d->operator()(&n) );
       
   208 
       
   209     delete d;
       
   210 
       
   211     // try again with new decider, not relay
       
   212     d = prophet::Decider::decider(prophet::FwdStrategy::GRTR,
       
   213                                   &nexthop, &core, &local, &remote,
       
   214                                   &stats, 0, false);
       
   215 
       
   216     CHECK( ! d->operator()(&m) );
       
   217     CHECK( ! d->operator()(&n) );
       
   218 
       
   219     delete d;
       
   220 
       
   221     return UNIT_TEST_PASSED;
       
   222 }
       
   223 
       
   224 DECLARE_TESTER(ProphetStrategyTest) {
       
   225     ADD_TEST(GRTR);
       
   226     ADD_TEST(GTMX);
       
   227     ADD_TEST(GRTR_PLUS);
       
   228     ADD_TEST(GTMX_PLUS);
       
   229     ADD_TEST(GRTR_SORT);
       
   230     ADD_TEST(GRTR_MAX);
       
   231 }
       
   232 
       
   233 DECLARE_TEST_FILE(ProphetStrategyTest, "prophet fwd strategy test");