p802_15_4fail.cc

Go to the documentation of this file.
00001 /********************************************/
00002 /*     NS2 Simulator for IEEE 802.15.4      */
00003 /*           (per P802.15.4/D18)            */
00004 /*------------------------------------------*/
00005 /* by:        Jianliang Zheng               */
00006 /*        (zheng@ee.ccny.cuny.edu)          */
00007 /*              Myung J. Lee                */
00008 /*          (lee@ccny.cuny.edu)             */
00009 /*        ~~~~~~~~~~~~~~~~~~~~~~~~~         */
00010 /*           SAIT-CUNY Joint Lab            */
00011 /********************************************/
00012 
00013 // File:  p802_15_4fail.cc
00014 // Mode:  C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t
00015 
00016 // $Header: /nfs/jade/vint/CVSROOT/ns-2/wpan/p802_15_4fail.cc,v 1.1 2005/01/24 18:34:24 haldar Exp $
00017 
00018 /*
00019  * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and
00020  * The City University of New York. All rights reserved.
00021  *
00022  * Redistribution and use in source and binary forms, with or without
00023  * modification, are permitted provided that the following conditions
00024  * are met:
00025  * 1. Redistributions of source code must retain the above copyright
00026  *    notice, this list of conditions and the following disclaimer.
00027  * 2. Redistributions in binary form must reproduce the above copyright
00028  *    notice, this list of conditions and the following disclaimer in the
00029  *    documentation and/or other materials provided with the distribution.
00030  * 3. All advertising materials mentioning features or use of this software
00031  *    must display the following acknowledgement:
00032  *  This product includes software developed by the Joint Lab of Samsung 
00033  *      Advanced Institute of Technology and The City University of New York.
00034  * 4. Neither the name of Samsung Advanced Institute of Technology nor of 
00035  *    The City University of New York may be used to endorse or promote 
00036  *    products derived from this software without specific prior written 
00037  *    permission.
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE
00040  * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS 
00041  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00042  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
00043  * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK 
00044  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00045  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00046  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00048  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00049  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00050  */
00051 
00052 
00053 #include "p802_15_4fail.h"
00054 
00055 LFAILLINK *lfailLink1 = NULL;
00056 LFAILLINK *lfailLink2 = NULL;
00057 NFAILLINK *nfailLink1 = NULL;
00058 NFAILLINK *nfailLink2 = NULL;
00059 
00060 int addLFailLink(int s,int d)
00061 {
00062     LFAILLINK *tmp;
00063     if(lfailLink2 == NULL)      //not exist yet
00064     {
00065         lfailLink2 = new LFAILLINK(s,d);
00066         if (lfailLink2 == NULL) return 1;
00067         lfailLink1 = lfailLink2;
00068     }
00069     else
00070     {
00071         tmp=new LFAILLINK(s,d);
00072         if (tmp == NULL) return 1;
00073         tmp->last = lfailLink2;
00074         (lfailLink2)->next = tmp;
00075         lfailLink2 = tmp;
00076     }
00077     return 0;
00078 }
00079 
00080 int updateLFailLink(int oper,int s,int d)
00081 {
00082     LFAILLINK *tmp;
00083     int rt;
00084 
00085     rt = 1;
00086 
00087     tmp = lfailLink1;
00088     while(tmp != NULL)
00089     {
00090         if ((tmp->src == s)&&(tmp->dst == d))
00091         {
00092             if (oper == fl_oper_del)    //delete an element
00093             {
00094                 if(tmp->last != NULL)
00095                 {
00096                     tmp->last->next = tmp->next;
00097                     if(tmp->next != NULL)
00098                         tmp->next->last = tmp->last;
00099                     else
00100                         lfailLink2 = tmp->last;
00101                 }
00102                 else if (tmp->next != NULL)
00103                 {
00104                     lfailLink1 = tmp->next;
00105                     tmp->next->last = NULL;
00106                 }
00107                 else
00108                 {
00109                     lfailLink1 = NULL;
00110                     lfailLink2 = NULL;
00111                 }
00112                 delete tmp;
00113             }
00114             rt = 0;
00115             break;
00116         }
00117         tmp = tmp->next;
00118     }
00119     return rt;
00120 }
00121 
00122 int chkAddLFailLink(int s,int d)
00123 {
00124         int i;
00125 
00126         i = updateLFailLink(fl_oper_est,s,d);
00127         if (i == 0) return 1;
00128         i = addLFailLink(s,d);
00129         if (i == 0) return 0;
00130         else return 2;
00131 }
00132 
00133 int addNFailLink(int a)
00134 {
00135     NFAILLINK *tmp;
00136     if(nfailLink2 == NULL)      //not exist yet
00137     {
00138         nfailLink2 = new NFAILLINK(a);
00139         if (nfailLink2 == NULL) return 1;
00140         nfailLink1 = nfailLink2;
00141     }
00142     else
00143     {
00144         tmp=new NFAILLINK(a);
00145         if (tmp == NULL) return 1;
00146         tmp->last = nfailLink2;
00147         (nfailLink2)->next = tmp;
00148         nfailLink2 = tmp;
00149     }
00150     return 0;
00151 }
00152 
00153 int updateNFailLink(int oper,int a)
00154 {
00155     NFAILLINK *tmp;
00156     int rt;
00157 
00158     rt = 1;
00159 
00160     tmp = nfailLink1;
00161     while(tmp != NULL)
00162     {
00163         if (tmp->addr == a)
00164         {
00165             if (oper == fl_oper_del)    //delete an element
00166             {
00167                 if(tmp->last != NULL)
00168                 {
00169                     tmp->last->next = tmp->next;
00170                     if(tmp->next != NULL)
00171                         tmp->next->last = tmp->last;
00172                     else
00173                         nfailLink2 = tmp->last;
00174                 }
00175                 else if (tmp->next != NULL)
00176                 {
00177                     nfailLink1 = tmp->next;
00178                     tmp->next->last = NULL;
00179                 }
00180                 else
00181                 {
00182                     nfailLink1 = NULL;
00183                     nfailLink2 = NULL;
00184                 }
00185                 delete tmp;
00186             }
00187             rt = 0;
00188             break;
00189         }
00190         tmp = tmp->next;
00191     }
00192     return rt;
00193 }
00194 
00195 int chkAddNFailLink(int a)
00196 {
00197         int i;
00198 
00199         i = updateNFailLink(fl_oper_est,a);
00200         if (i == 0) return 1;
00201         i = addNFailLink(a);
00202         if (i == 0) return 0;
00203         else return 2;
00204 }
00205 
00206 // End of file: p802_15_4fail.cc

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