AODVApp.cc

00001 // Copyright 2008 Michael Marsh, University of Maryland.
00002 //
00003 // This file is part of pydtn.
00004 //
00005 // pydtn is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // pydtn is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with pydtn.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // The views and conclusions contained in the software and documentation
00019 // are those of the authors and should not be interpreted as representing
00020 // official policies, either expressed or implied, of the University
00021 // of Maryland.
00022 //
00023 // pydtn extends and embeds the Python interpreter, which is
00024 // Copyright 2001-2006 Python Software Foundation, All Rights Reserved,
00025 // and is released under the PSF License Agreement.
00026 //
00027 // RANLUX random number generation uses the Boost library,
00028 // Copyright 1994-2006 by various authors (details in individual files),
00029 // which is released under the Boost Software License, Version 1.0.
00030 
00031 #include "config.h"
00032 
00033 #include "dtnaodv.h"
00034 #include "AODVApp.h"
00035 #include "AODVForwardingPolicy.h"
00036 #include "dtn/Bundle.h"
00037 #include "dtn/Node.h"
00038 #include "dtn/Exception.h"
00039 
00040 #include <iostream>
00041 
00042 static unsigned char initstring[] = {'a','o','d','v','a','p','p'}; 
00043 DTN::ByteString AODVApp::m_appID(initstring);
00044 
00045 AODVApp::AODVApp( AODVForwardingPolicy* pol ) :
00046    Application(),
00047    m_policy( pol )
00048 {
00049    if ( 0 != pol )
00050    {
00051       dtnaodv_appMap[ &(pol->state()) ] = this;
00052    }
00053 }
00054 
00055 AODVApp::~AODVApp()
00056 {
00057 }
00058 
00059 void
00060 AODVApp::send( const aodv_msghdr_t* headers, const aodv_chunk_t* message )
00061 {
00062    if ( 0 == m_owner ) return;
00063    if ( 0 == m_policy ) return;
00064    if ( 0 == headers ) return;
00065    if ( 0 == message ) return;
00066 
00067    struct timeval tv = DTN::dtn_time();
00068    struct timeval e;
00069    e.tv_sec = tv.tv_sec;
00070    e.tv_usec = tv.tv_usec + 1000*m_policy->traversalTime();
00071    e.tv_sec += ( e.tv_usec / 1000000 );
00072    e.tv_usec = ( e.tv_usec % 1000000 );
00073 
00074    DTN::ByteString dest( headers->addr.data, headers->addr.length );
00075    const aodv_chunk_t* c = message;
00076    DTN::ByteString data;
00077    while ( 0 != c )
00078    {
00079       data.append( c->data, c->length );
00080       c = c->next;
00081    }
00082    DTN::Bundle::BundleType bt = DTN::Bundle::kData | DTN::Bundle::kNoACK;
00083    if ( dtnaodv_bcast_addr == dest )
00084    {
00085       bt |= DTN::Bundle::kBcast;
00086    }
00087    DTN::Bundle* b = new DTN::Bundle( m_owner->nextSeq(),
00088                                      m_owner->addr(),
00089                                      dest,
00090                                      data,
00091                                      tv,
00092                                      e,
00093                                      bt,
00094                                      m_appID );
00095    m_owner->forward(b);
00096 }
00097 
00098 void
00099 AODVApp::notify()
00100 {
00101    if ( 0 == m_owner ) return;
00102    if ( 0 == m_policy ) return;
00103    m_policy->notify();
00104 }
00105 
00106 void
00107 AODVApp::process( const DTN::Bundle& b )
00108 {
00109    if ( 0 == m_owner ) return;
00110    if ( 0 == m_policy ) return;
00111    m_policy->handleMessage(b);
00112 }

Generated on Mon Mar 24 11:15:45 2008 for Pydtn Simulator by  doxygen 1.5.4