SimConvergenceLayer.cc

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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     // XXX/demmer add Connectivity check to see if it's open and add
00126     // bw/latency restrictions. then move the following events to
00127     // there
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 } // namespace dtnsim

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1