|
1 #ifdef HAVE_CONFIG_H |
|
2 # include <dtn-config.h> |
|
3 #endif |
|
4 #include <oasys/util/UnitTest.h> |
|
5 #include <oasys/thread/SpinLock.h> |
|
6 #include "conv_layers/NullConvergenceLayer.h" |
|
7 #include "contacts/Link.h" |
|
8 #include "routing/ProphetBundle.h" |
|
9 #include "routing/ProphetBundleList.h" |
|
10 #include "routing/ProphetBundleCore.h" |
|
11 #include "bundling/Bundle.h" |
|
12 #include "bundling/BundleActions.h" |
|
13 |
|
14 using namespace oasys; |
|
15 |
|
16 dtn::Bundle *b; |
|
17 dtn::BundleRef br("temp test ref"); |
|
18 dtn::LinkRef l; |
|
19 dtn::NullConvergenceLayer *cl = NULL; |
|
20 dtn::BundleActions actions; |
|
21 oasys::SpinLock lock; |
|
22 dtn::ProphetBundleCore core(oasys::Builder::builder()); |
|
23 |
|
24 DECLARE_TEST(ProphetBundleCore) |
|
25 { |
|
26 prophet::LinkImpl link("dtn://remotehost"); |
|
27 dtn::ProphetBundleCore core("dtn://localhost",&actions,&lock); |
|
28 CHECK( core.is_route("dtn://localhost/prophet","dtn://localhost")); |
|
29 CHECK(!core.is_route("dtn://remotehost","dtn://localhost")); |
|
30 CHECK_EQUALSTR(core.prophet_id().c_str(), "dtn://localhost/prophet"); |
|
31 CHECK_EQUALSTR(core.prophet_id(&link).c_str(), "dtn://remotehost/prophet"); |
|
32 |
|
33 return UNIT_TEST_PASSED; |
|
34 } |
|
35 |
|
36 DECLARE_TEST(ProphetBundleWrapper) |
|
37 { |
|
38 b = new dtn::Bundle(oasys::Builder::builder()); |
|
39 b->test_set_bundleid(0); |
|
40 b->mutable_payload()->init(0, dtn::BundlePayload::NODATA); |
|
41 b->add_ref("test"); |
|
42 b->mutable_dest()->assign("dtn://dtn.howdy.dtn"); |
|
43 b->mutable_source()->assign("dtn://dtn.mysrc.dtn"); |
|
44 b->set_creation_ts(dtn::BundleTimestamp(98765, 4321)); |
|
45 b->set_expiration(123); |
|
46 b->set_custody_requested(true); |
|
47 |
|
48 br = b; |
|
49 CHECK(br.object() != NULL); |
|
50 dtn::ProphetBundle p(br); |
|
51 CHECK_EQUALSTR(b->dest().c_str(), p.destination_id().c_str()); |
|
52 CHECK_EQUALSTR(b->source().c_str(), p.source_id().c_str()); |
|
53 CHECK_EQUAL(b->creation_ts().seconds_, p.creation_ts()); |
|
54 CHECK_EQUAL(b->creation_ts().seqno_, p.sequence_num()); |
|
55 CHECK_EQUAL(b->payload().length(), p.size()); |
|
56 CHECK_EQUAL(p.num_forward(), 0); |
|
57 CHECK(p.custody_requested()); |
|
58 |
|
59 return UNIT_TEST_PASSED; |
|
60 } |
|
61 |
|
62 DECLARE_TEST(ProphetBundleList) |
|
63 { |
|
64 dtn::ProphetBundleList bl(&core); |
|
65 CHECK(br.object() != NULL); |
|
66 bl.add(br); |
|
67 const prophet::Bundle* res = bl.find("dtn://dtn.howdy.dtn", |
|
68 98765, 4321); |
|
69 CHECK( res != NULL ); |
|
70 |
|
71 dtn::BundleRef bres("test finder temp"); |
|
72 bres = bl.find_ref(res); |
|
73 CHECK( bres.object() != NULL ); |
|
74 |
|
75 bl.clear(); |
|
76 CHECK(bl.find("dtn://dtn.howdy.dtn",98765,4321) == NULL); |
|
77 |
|
78 return UNIT_TEST_PASSED; |
|
79 } |
|
80 |
|
81 DECLARE_TEST(ProphetLinkWrapper) |
|
82 { |
|
83 cl = new dtn::NullConvergenceLayer();; |
|
84 l = dtn::Link::create_link("l", dtn::Link::OPPORTUNISTIC, cl, |
|
85 "ever-so-where-i-go", 0, NULL); |
|
86 l->set_remote_eid(std::string("dtn://whodat.over.der.dtn")); |
|
87 dtn::ProphetLink pl(l); |
|
88 CHECK_EQUALSTR(l->nexthop(),pl.nexthop()); |
|
89 CHECK_EQUALSTR(l->remote_eid().c_str(),pl.remote_eid()); |
|
90 |
|
91 return UNIT_TEST_PASSED; |
|
92 } |
|
93 |
|
94 DECLARE_TEST(ProphetLinkList) |
|
95 { |
|
96 dtn::ProphetLinkList pll; |
|
97 pll.add(l); |
|
98 CHECK( pll.find("dtn://whodat.over.der.dtn") != NULL ); |
|
99 dtn::LinkRef tmp("ProphetLinkList"); |
|
100 tmp = pll.find_ref("dtn://whodat.over.der.dtn"); |
|
101 CHECK( tmp.object() != NULL ); |
|
102 return UNIT_TEST_PASSED; |
|
103 } |
|
104 |
|
105 DECLARE_TEST(CleanErUpper) |
|
106 { |
|
107 br = NULL; |
|
108 cl->delete_link(l); |
|
109 l = NULL; |
|
110 return UNIT_TEST_PASSED; |
|
111 } |
|
112 |
|
113 DECLARE_TESTER(ProphetBundleCore) |
|
114 { |
|
115 ADD_TEST(ProphetBundleCore); |
|
116 ADD_TEST(ProphetBundleWrapper); |
|
117 ADD_TEST(ProphetBundleList); |
|
118 ADD_TEST(ProphetLinkWrapper); |
|
119 ADD_TEST(ProphetLinkList); |
|
120 ADD_TEST(CleanErUpper); |
|
121 } |
|
122 |
|
123 DECLARE_TEST_FILE(ProphetBundleCore, "prophet bundle core test"); |