tora_api.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  */
00034 /* Ported from CMU/Monarch's code*/
00035 /* 
00036    tora_api.cc
00037    $Id: tora_api.cc,v 1.3 1999/09/09 04:02:52 salehi Exp $
00038    
00039    Implement the API used by IMEP
00040    */
00041 
00042 
00043 #include <tora/tora.h>
00044 
00045 #define CURRENT_TIME    Scheduler::instance().clock()
00046 
00047 void
00048 toraAgent::rtNotifyLinkUP(nsaddr_t index)
00049 {
00050     TORADest *td = dstlist.lh_first;
00051 
00052         /*
00053          * Update the destination lists...
00054          */
00055     for( ; td; td = td->link.le_next) {
00056         if(td->nb_find(index) == 0) {
00057                         (void) td->nb_add(index);
00058         }
00059         if (td->rt_req) 
00060           { // must send a new query for this dest so the new
00061             // neighbor can hear it
00062             // IMEP will take care of aggregating all these into
00063             // one physical pkt
00064 
00065             trace("T %.9f _%d_ QRY %d for %d (rtreq set)",
00066               Scheduler::instance().clock(), ipaddr(), 
00067               td->index, index);
00068 
00069             sendQRY(td->index);
00070             td->time_tx_qry = CURRENT_TIME;
00071         }
00072     }
00073 }
00074 
00075 void
00076 toraAgent::rtNotifyLinkDN(nsaddr_t index)
00077 {
00078     TORADest *td = dstlist.lh_first;
00079 
00080         /*
00081          *  Purge each Destination's Neighbor List
00082          */
00083         for( ; td; td = td->link.le_next) {
00084                 if(td->nb_del(index)) {
00085                         /*
00086                          * Send an UPD packet if you've lost the last
00087                          * downstream link.
00088                          */
00089                         sendUPD(td->index);
00090                 }
00091         }
00092 
00093     /*
00094      *  Now purge the Network Interface queues that
00095      *  may have packets destined for this broken
00096      *  neighbor.
00097      */
00098         {
00099                 Packet *head = 0;
00100                 Packet *p;
00101                 Packet *np = 0;
00102 
00103                 while((p = ifqueue->filter(index))) {
00104                         p->next_ = head;
00105                         head = p;
00106                 }
00107 
00108                 for(p = head; p; p = np) {
00109                         np = p->next_;
00110                         /*
00111                          * This make a lot of sense for TORA since we
00112                          * will almost always have multiple routes to
00113                          * a destination.
00114                          */
00115                         log_link_layer_recycle(p);
00116                         rt_resolve(p);
00117                 }
00118         }
00119 }
00120 
00121 
00122 void
00123 toraAgent::rtNotifyLinkStatus(nsaddr_t /* index */, u_int32_t /* status */)
00124 {
00125     abort();
00126 }
00127 
00128 void
00129 toraAgent::rtRoutePacket(Packet *p)
00130 {
00131     struct hdr_cmn *ch = HDR_CMN(p);
00132     struct hdr_ip *ip = HDR_IP(p);
00133 
00134     // Non-data packets and BROADCAST packets can be dropped.
00135     if(DATA_PACKET(ch->ptype()) == 0 || 
00136        ip->daddr() == (nsaddr_t) IP_BROADCAST) {
00137         drop(p, DROP_RTR_MAC_CALLBACK);
00138         return;
00139     }
00140 
00141     rt_resolve(p);
00142 }

Generated on Tue Mar 6 16:47:52 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6