00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_BUNDLE_CORE_H_
00018 #define _PROPHET_BUNDLE_CORE_H_
00019
00020 #include "prophet/Node.h"
00021 #include "prophet/Params.h"
00022 #include "prophet/BundleList.h"
00023 #include "prophet/BundleCore.h"
00024 #include "prophet/Repository.h"
00025 #include "contacts/Link.h"
00026 #include "bundling/Bundle.h"
00027 #include "bundling/BundleActions.h"
00028 #include "bundling/BundleList.h"
00029 #include "ProphetBundleList.h"
00030 #include "ProphetLinkList.h"
00031 #include "ProphetNodeList.h"
00032 #include <oasys/debug/Log.h>
00033 #include <oasys/thread/Lock.h>
00034
00035 #include <string>
00036
00037 namespace dtn
00038 {
00039
00044 class ProphetBundleCore : public prophet::BundleCore,
00045 public prophet::Repository::BundleCoreRep,
00046 public oasys::Logger
00047 {
00048 public:
00049
00053 ProphetBundleCore(const std::string& local_eid,
00054 BundleActions* actions,
00055 oasys::SpinLock* lock);
00056
00060 ProphetBundleCore(oasys::Builder);
00061
00065 virtual ~ProphetBundleCore();
00066
00068 bool is_route(const std::string& dest_id,
00069 const std::string& route) const;
00070 bool should_fwd(const prophet::Bundle* bundle,
00071 const prophet::Link* link) const;
00072 std::string get_route(const std::string& dest_id) const;
00073 std::string get_route_pattern(const std::string& dest_id) const;
00074 u_int64_t max_bundle_quota() const;
00075 bool custody_accepted() const;
00076 void drop_bundle(const prophet::Bundle* bundle);
00077 bool send_bundle(const prophet::Bundle* bundle,
00078 const prophet::Link* link);
00079 bool write_bundle(const prophet::Bundle* bundle,
00080 const u_char* buffer,
00081 size_t len);
00082 bool read_bundle(const prophet::Bundle* bundle,
00083 u_char* buffer,
00084 size_t& len) const
00085 {
00086 return const_cast<ProphetBundleCore*>(this)->read_bundle(
00087 bundle,buffer,len);
00088 }
00089 prophet::Bundle* create_bundle(const std::string& src,
00090 const std::string& dst,
00091 u_int expiration);
00092 const prophet::BundleList& bundles() const
00093 {
00094 return bundles_.get_bundles();
00095 }
00096 const prophet::Bundle* find(const prophet::BundleList& list,
00097 const std::string& eid, u_int32_t creation_ts,
00098 u_int32_t seqno) const;
00099 void update_node(const prophet::Node* node);
00100 void delete_node(const prophet::Node* node);
00101 std::string local_eid() const
00102 {
00103 return local_eid_;
00104 }
00105 std::string prophet_id(const prophet::Link* link) const;
00106 std::string prophet_id() const
00107 {
00108 EndpointID eid(get_route(local_eid()));
00109 eid.append_service_tag("prophet");
00110 return eid.str();
00111 }
00112 prophet::Alarm* create_alarm(prophet::ExpirationHandler* handler,
00113 u_int timeout, bool jitter = false);
00114 void print_log(const char* name, int level, const char* fmt, ...)
00115 PRINTFLIKE(4,5);
00117
00121 bool read_bundle(const prophet::Bundle* bundle,
00122 u_char* buffer,
00123 size_t& len);
00124
00129 void load_prophet_nodes(prophet::Table* nodes,
00130 prophet::ProphetParams* params);
00131
00136 void load_dtn_bundles(const BundleList* list);
00137
00141 void shutdown()
00142 {
00143 bundles_.clear();
00144 links_.clear();
00145 nodes_.clear();
00146 }
00147
00149 const Bundle* get_bundle(const prophet::Bundle* b);
00150 const prophet::Bundle* get_bundle(const Bundle* b);
00151 const prophet::Bundle* get_temp_bundle(const BundleRef& b);
00152 const Link* get_link(const prophet::Link* link);
00153 const prophet::Link* get_link(const Link* link);
00155
00158 void add(const BundleRef& b);
00159 void del(const BundleRef& b);
00160 void add(const LinkRef& link);
00161 void del(const LinkRef& link);
00163
00167 prophet::Repository* bundles() { return bundles_.bundles(); }
00168
00169 protected:
00170 friend class ProphetRouter;
00171
00172 BundleActions* const actions_;
00173 ProphetBundleList bundles_;
00174 ProphetLinkList links_;
00175 ProphetNodeList nodes_;
00176 const std::string local_eid_;
00177 oasys::SpinLock* const lock_;
00178 bool test_mode_;
00179
00180
00181 };
00182
00183 };
00184
00185 #endif // _PROPHET_BUNDLE_CORE_H_