00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <oasys/util/OptParser.h>
00040 #include <oasys/util/StringBuffer.h>
00041
00042 #include "SimConvergenceLayer.h"
00043 #include "Node.h"
00044 #include "Simulator.h"
00045 #include "Topology.h"
00046 #include "bundling/Bundle.h"
00047 #include "bundling/BundleEvent.h"
00048 #include "bundling/BundleList.h"
00049
00050 namespace dtnsim {
00051
00052 class SimCLInfo : public CLInfo {
00053 public:
00054 SimCLInfo()
00055 {
00056 params_.deliver_partial_ = true;
00057 params_.reliable_ = true;
00058 }
00059
00060 ~SimCLInfo() {};
00061
00062 struct Params {
00065 bool deliver_partial_;
00066
00070 bool reliable_;
00071
00072 } params_;
00073
00074 Node* peer_node_;
00075 };
00076
00077 SimConvergenceLayer* SimConvergenceLayer::instance_;
00078
00079 SimConvergenceLayer::SimConvergenceLayer()
00080 : ConvergenceLayer("SimConvergenceLayer", "sim")
00081 {
00082 }
00083
00084 bool
00085 SimConvergenceLayer::init_link(Link* link, int argc, const char* argv[])
00086 {
00087 oasys::OptParser p;
00088
00089 SimCLInfo* info = new SimCLInfo();
00090 info->peer_node_ = Topology::find_node(link->nexthop());
00091 ASSERT(info->peer_node_);
00092
00093 p.addopt(new oasys::BoolOpt("deliver_partial",
00094 &info->params_.deliver_partial_));
00095 p.addopt(new oasys::BoolOpt("reliable", &info->params_.reliable_));
00096
00097 const char* invalid;
00098 if (! p.parse(argc, argv, &invalid)) {
00099 log_err("error parsing link options: invalid option %s", invalid);
00100 return false;
00101 }
00102
00103 link->set_cl_info(info);
00104
00105 return true;
00106 }
00107
00108 bool
00109 SimConvergenceLayer::open_contact(const ContactRef& contact)
00110 {
00111 log_debug("opening contact for link *%p", link);
00112
00113 BundleDaemon::post(new ContactUpEvent(contact));
00114 return true;
00115 }
00116
00117 void
00118 SimConvergenceLayer::send_bundle(const ContactRef& contact, Bundle* bundle)
00119 {
00120 log_debug("send_bundles on contact %s", contact->link()->nexthop());
00121
00122 SimCLInfo* info = (SimCLInfo*)contact->link()->cl_info();
00123 ASSERT(info);
00124
00125
00126
00127
00128
00129 Node* src_node = Node::active_node();
00130 Node* dst_node = info->peer_node_;
00131
00132 ASSERT(src_node != dst_node);
00133
00134 size_t len;
00135 bool reliable = info->params_.reliable_;
00136
00137 len = bundle->payload_.length();
00138
00139 BundleTransmittedEvent* tx_event =
00140 new BundleTransmittedEvent(bundle, contact, len, reliable ? len : 0);
00141
00142 Simulator::post(new SimRouterEvent(Simulator::time(),
00143 src_node, tx_event));
00144
00145 BundleReceivedEvent* rcv_event =
00146 new BundleReceivedEvent(bundle, EVENTSRC_PEER, len);
00147
00148 Simulator::post(new SimRouterEvent(Simulator::time(),
00149 dst_node, rcv_event));
00150 }
00151
00152
00153 }