[ns] Need help -Running files

pepe Delino pepedelino at gmail.com
Sat Oct 11 09:10:16 PDT 2008


   hi guys ,
I am new to NS . Can you please help me running these files .
I am using NS2.32 allinone package on red hat.
Pepe

the files are as follows:

 Pmin80211.h



/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-

 *

 * Copyright (c) 1997 Regents of the University of California.

 * All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 * 1. Redistributions of source code must retain the above copyright

 *    notice, this list of conditions and the following disclaimer.

 * 2. Redistributions in binary form must reproduce the above copyright

 *    notice, this list of conditions and the following disclaimer in the

 *    documentation and/or other materials provided with the distribution.

 * 3. All advertising materials mentioning features or use of this software

 *    must display the following acknowledgement:

 *     This product includes software developed by the Computer Systems

 *     Engineering Group at Lawrence Berkeley Laboratory.

 * 4. Neither the name of the University nor of the Laboratory may be used

 *    to endorse or promote products derived from this software without

 *    specific prior written permission.

 *

 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND

 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE

 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE

 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL

 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT

 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

 * SUCH DAMAGE.

 *

 * $Header: /cvsroot/nsnam/ns-2/mac/mac-802_11.cc,v 1.51 2006/01/30 21:27:51
mweigle Exp $

 *

 * Ported from CMU/Monarch's code, nov'98 -Padma.

 * Contributions by:

 *   - Mike Holland

 *   - Sushmita

 */



#ifndef Pmin80211_H

#define Pmin80211_H



const int PMIN_MAX_NODE=100;

const int PMIN_NUM_PAR=4;

const int MAX_LINE=100;



class Pmin80211 : public TclObject {

public:

       /*initialize from one pmin file*/

       static int initialize(const char* const& filename);



       /*return the minimum power*/

       static double framePowerMin( int n1, int n2);



       /*return the rx range of a power tx.*/

       static double rangePowerMin( int n1, double pRange);



        /*return the cs range of a power tx.*/

       static double csPowerMin( int n1, double pRange);



       static int initialized_;  /*power table is loaded*/

       static int nodes_;

       static double alfa_;

       static int model_;

        static double RXThresh_;

        static double CSThresh_;

        static double Gt_;

        static double Gr_;

        static double freq_;

        static double L_;

        static double ht_;

        static double hr_;



       static double pmin_[PMIN_MAX_NODE][PMIN_NUM_PAR];



private:

       static void printTables();

       static double Friis(double P, double Gt, double Gr, double lambda,
double L, double d);

       static double TwoRay(double Pr, double Gt, double Gr, double ht,
double hr, double L,

                           double d, double lambda);

       static double distPowerMin(int src, int dst);

       static double RangeFriis(double Pt, double P, double Gt, double Gr,
double lambda,

                            double L);

       static double RangeTwoRay(double P, double Pr, double Gt, double Gr,
double ht,

                               double hr, double L, double lambda);

};



#endif
























































































  Pmin80211.CC



/* -

*-     Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-

 *

 * Copyright (c) 1997 Regents of the University of California.

 * All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 * 1. Redistributions of source code must retain the above copyright

 *    notice, this list of conditions and the following disclaimer.

 * 2. Redistributions in binary form must reproduce the above copyright

 *    notice, this list of conditions and the following disclaimer in the

 *    documentation and/or other materials provided with the distribution.

 * 3. All advertising materials mentioning features or use of this software

 *    must display the following acknowledgement:

 *     This product includes software developed by the Computer Systems

 *     Engineering Group at Lawrence Berkeley Laboratory.

 * 4. Neither the name of the University nor of the Laboratory may be used

 *    to endorse or promote products derived from this software without

 *    specific prior written permission.

 *

 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND

 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE

 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE

 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL

 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT

 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

 * SUCH DAMAGE.

 *

 * $Header: /cvsroot/nsnam/ns-2/mac/mac-802_11.cc,v 1.51 2006/01/30 21:27:51
mweigle Exp $

 *

 * Ported from CMU/Monarch's code, nov'98 -Padma.

 * Contributions by:

 *   - Mike Holland

 *   - Sushmita

 */

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <string.h>



#include "config.h"

#include "Pmin80211.h"



#ifndef M_PI

#define M_PI 3.14159265359

#endif



#define SPEED_LIGHT 300000000    // to calculate lambda_



int    Pmin80211::initialized_=0;

int    Pmin80211::nodes_;

double Pmin80211::alfa_=1;

int    Pmin80211::model_=1;

double Pmin80211::RXThresh_;

double Pmin80211::CSThresh_;

double Pmin80211::Gt_;

double Pmin80211::Gr_;

double Pmin80211::freq_;

double Pmin80211::L_;

double Pmin80211::ht_;

double Pmin80211::hr_;



double Pmin80211::pmin_[PMIN_MAX_NODE][PMIN_NUM_PAR];





//-----------------------------------------

//       *-----------------------*

// node  | x | y | z | max power |

//       *-----------------------*

// model  1- friss    2- tworayground   3 - other



static class Pmin80211Class: public TclClass{

public:

       Pmin80211Class() : TclClass("Pmin80211") {}

       TclObject* create(int argc, const char * const * argv)

       {

              return (new Pmin80211());

       }



       virtual void bind();

       virtual int method(int argc, const char * const * argv);

} class_Pmin80211;



void Pmin80211Class::bind()

{

       TclClass::bind();

        add_method("pmin_Alfa_");

        add_method("pmin_LoadPminFile_");

       add_method("pmin_PropagationModel_");

        add_method("pmin_RXThresh_");

        add_method("pmin_CSThresh_");

        add_method("pmin_Gt_");

        add_method("pmin_Gr_");

        add_method("pmin_freq_");

        add_method("pmin_L_");

        add_method("pmin_ht_");

        add_method("pmin_hr_");

}



int Pmin80211Class::method(int ac, const char* const * av)

{

       Tcl& tcl = Tcl::instance();

       int argc = ac - 2;

       const char* const * argv = av+2;

       if(argc == 2)

       {

              if(strcmp(argv[1],"pmin_Alfa_")==0)

              {

                     tcl.resultf("%d",Pmin80211::alfa_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_PropagationModel_")==0)

              {

                     tcl.resultf("%d",Pmin80211::model_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_RXThresh_")==0)

              {

                     tcl.resultf("%f",Pmin80211::RXThresh_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_CSThresh_")==0)

              {

                     tcl.resultf("%f",Pmin80211::RXThresh_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_Gt_")==0)

              {

                     tcl.resultf("%f",Pmin80211::Gt_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_Gr_")==0)

              {

                     tcl.resultf("%f",Pmin80211::Gr_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_freq_")==0)

              {

                     tcl.resultf("%f",Pmin80211::freq_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_L_")==0)

              {

                     tcl.resultf("%f",Pmin80211::L_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_ht_")==0)

              {

                     tcl.resultf("%f",Pmin80211::ht_);

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_hr_")==0)

              {

                     tcl.resultf("%f",Pmin80211::hr_);

                     return (TCL_OK);

              }

       }else if(argc == 3 )

       {

              if(strcmp(argv[1],"pmin_Alfa_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::alfa_);

                     //printf("Alfa : %lf \n",Pmin80211::alfa_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_LoadPminFile_")==0)

              {

                     int rc;

                     rc = Pmin80211::initialize(argv[2]);

                     if(rc == TCL_OK) Pmin80211::initialized_=1;

                     return rc;

              }else if(strcmp(argv[1],"pmin_PropagationModel_")==0)

              {

                     if (!strcmp(argv[2],"FreeSpace")) {

                           Pmin80211::model_=1;

                     }else if (!strcmp(argv[2],"TwoRayGround")) {

                           Pmin80211::model_=2;

                     }else Pmin80211::model_=3;

                     return (TCL_OK);

              }else if(strcmp(argv[1],"pmin_RXThresh_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::RXThresh_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_CSThresh_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::CSThresh_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_Gt_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::Gt_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_Gr_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::Gr_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_freq_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::freq_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_L_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::L_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_ht_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::ht_);

                     return (TCL_OK);

                }else if(strcmp(argv[1],"pmin_hr_")==0)

              {

                     sscanf(argv[2],"%lf",&Pmin80211::hr_);

                     return (TCL_OK);

                }

       }

       return TclClass::method(ac,av);

}



int Pmin80211::initialize(const char* const& filename)

{

       FILE *fin;

       char line[MAX_LINE];

       int i,j,index,size;

       char num[25],*start;



       for(j=0;j<PMIN_MAX_NODE;j++)

              for(i=0;i<PMIN_NUM_PAR;i++)

                     pmin_[j][i]=-1;



       fin = fopen(filename,"r");

       if(fin==NULL)

       {

              printf("%s can not be opened! Check the file name for pmin
table. \n",

              filename);

              return(-1);

       }



       while(fgets(line,MAX_LINE,fin)!=NULL)

       {

              size = strchr(line,')')-strchr(line,'(')-1;

              start = strchr(line,'(');

              memset(num,'\0',25);

              strncpy(num,++start,size);

              index=atoi(num);           //index



              if(index>PMIN_MAX_NODE){

                     printf("too many nodes! \n");

                     return (-1);

              }



              memset(num,'\0',25);

              if((start=strstr(line,"X_"))!=NULL){

                     strncpy(num,start+3,strlen(line)-(start-line));

                     sscanf(num,"%lf",&pmin_[index][0]);

              }

              else if((start=strstr(line,"Y_"))!=NULL){

                     strncpy(num,start+3,strlen(line)-(start-line));

                     sscanf(num,"%lf",&pmin_[index][1]);

              }

              else if((start=strstr(line,"Z_"))!=NULL){

                     strncpy(num,start+3,strlen(line)-(start-line));

                     sscanf(num,"%lf",&pmin_[index][2]);

              }

              else {

                     printf("error in inputfile! \n");

                     return(-1);

              }

       }

       fclose(fin);

       Pmin80211::nodes_=index+1;

//     printTables();

//     printf("Pmin80211 is initialized successfully with %d
nodes\n",index+1);

       initialized_ = 1;

       return TCL_OK;

}



double Pmin80211::Friis(double P, double Gt, double Gr, double lambda,
double L, double d)

{

       /*

         * Friis free space propagation equation:

         *

         *       Pt * Gt * Gr * (lambda^2)         P * ((4 * pi * d)^2 * L)

         *   P = -------------------------- >> Pt= -------------------------

         *       (4 * pi * d)^2 * L                  Gt * Gr * (lambda^2)

         */

       double M = (4 * M_PI * d) / lambda;

       return (P * (M * M) * L) / Gt * Gr;

}



double Pmin80211::TwoRay(double Pr, double Gt, double Gr, double ht,

                      double hr, double L, double d, double lambda)

{      double P;

        /*

         *  if d < crossover_dist, use Friis free space model

         *  if d >= crossover_dist, use two ray model

         *

         *  Two-ray ground reflection model.

         *

         *         Pt * Gt * Gr * (ht^2 * hr^2)             Pr * (d^4 * L)

         *  Pr = -------------------------------- >> Pt =
-------------------------

         *           d^4 * L                              Gt * Gr * (ht^2 *
hr^2)

         *

         * The original equation in Rappaport's book assumes L = 1.

         * To be consistant with the free space equation, L is added here.

         */



       double crossover_dist = (4 * M_PI * ht * hr) / lambda;



       if (d < crossover_dist)

              P = Friis(Pr, Gt, Gr, lambda, L, d);

       else

              P = Pr * (d * d * d * d * L) / (Gt * Gr * (hr * hr * ht *
ht));



       return P;

}



void Pmin80211::printTables()

{

       int i,j;



       for(j=0;j<Pmin80211::nodes_;j++){

              for(i=0;i<PMIN_NUM_PAR;i++){

                     printf("%lf ",pmin_[j][i]);

              }

              printf("\n");

       }

}



double Pmin80211::distPowerMin(int n1, int n2)

{

       double xt,yt,zt,dt;



       xt=pmin_[n1][0] - pmin_[n2][0];

       yt=pmin_[n1][1] - pmin_[n2][1];

       zt=pmin_[n1][2] - pmin_[n2][2];

       dt=sqrt((xt*xt)+(yt*yt)+(zt*zt));

       return dt;

}



double Pmin80211::RangeFriis(double Pt,double P, double Gt, double Gr,
double lambda, double L)

{

       /*

         * Friis free space propagation equation:

         *

         *       Pt * Gt * Gr * (lambda^2)           Pt * Gt * Gr *
(lambda^2)   1/2

         *   P = -------------------------- >> d =
(---------------------------)

         *       (4 * pi * d)^2 * L                   P * L * (4 * pi)^2

         */

       double N = Pt * Gt * Gr * lambda * lambda;

       double M = P * L * (4 * M_PI) * (4 * M_PI);

       return sqrt(N/M);

}



double Pmin80211::RangeTwoRay(double Pt, double P, double Gt, double Gr,
double ht,

                      double hr, double L, double lambda)

{      double dist;

       /*

         *  if d < crossover_dist, use Friis free space model

         *  if d >= crossover_dist, use two ray model

         *

         *  Two-ray ground reflection model.

         *

         *    Pt * Gt * Gr * (ht^2 * hr^2)         Pt * Gt * Gr * (ht^2 *
hr^2)  1/4

         *  P = ---------------------------- >> d =
[-----------------------------]

         *       d^4 * L                                          P * L

         *

         * The original equation in Rappaport's book assumes L = 1.

         * To be consistant with the free space equation, L is added here.

         */





       double N = Pt * Gt * Gr * (hr * hr * ht * ht);

       double M = P * L;

       dist = sqrt ( N / M );

       dist = sqrt ( dist );



       double crossover_dist = (4 * M_PI * ht * hr) / lambda;



       if (dist < crossover_dist){

              dist = RangeFriis(Pt, P, Gt, Gr, lambda, L);

       }

       return dist;

}



// For Tx and Rx

double Pmin80211::framePowerMin( int n1, int n2)

{

       double Pt, dist;

        double lambda_ = SPEED_LIGHT / Pmin80211::freq_;



       if((n1>=0 && n2>=0) && (n1 != n2)){// 1 on 1 transmission



              dist=distPowerMin(n1,n2);



              Pmin80211::ht_ += pmin_[n1][2];

              Pmin80211::hr_ += pmin_[n2][2];



              if(initialized_ == 0){

                     printf("Error! Pmin table was not inicializated \n");

                     return(-1);

              }



              if (model_==1) {

                     Pt = Friis(Pmin80211::RXThresh_, Pmin80211::Gt_,
Pmin80211::Gr_,

                                   lambda_, Pmin80211::L_, dist);

              } else if (model_==2) {

                     Pt = TwoRay(Pmin80211::RXThresh_, Pmin80211::Gt_,
Pmin80211::Gr_,

                         Pmin80211::ht_, Pmin80211::hr_, Pmin80211::L_,
dist, lambda_);

              } else{

                     printf("Error! propagation model! \n");

                     return(-1);

              }

       }

//     printf("src:%d dst:%d dist:%.2f Pmin: %f rxThresh: %e ",
n1,n2,dist,Pt,rxThresh_);

       return Pmin80211::alfa_*Pt;

}





/* return the range of a power tx. Which depends on RxThresh*/

double Pmin80211::rangePowerMin( int n1, double pRange)

{

       double dist;

        double lambda_ = SPEED_LIGHT / Pmin80211::freq_;



       Pmin80211::ht_ += pmin_[n1][2];



       if(initialized_ == 0){

              printf("Error! Pmin table was not inicializated \n");

              return(-1);

       }



       if (model_==1) {

              dist=RangeFriis(pRange,Pmin80211::RXThresh_,Pmin80211::Gt_,Pmin80211::Gr_,


                                  lambda_, Pmin80211::L_);

       } else if (model_==2) {


dist=RangeTwoRay(pRange,Pmin80211::RXThresh_,Pmin80211::Gt_,Pmin80211::Gr_,

                                   Pmin80211::ht_,Pmin80211::ht_,Pmin80211::L_,
lambda_);

       } else{

              printf("Error! propagation model! \n");

              return(-1);

       }

//     printf("src:%d dst:%d dist:%.2f Pmin: %f rxThresh: %e ",
n1,n2,dist,Pt,rxThresh_);

       return dist;

}



/* return the range of a power tx. Which depends on RxThresh*/

double Pmin80211::csPowerMin( int n1, double pRange)

{

       double dist;

        double lambda_ = SPEED_LIGHT / Pmin80211::freq_;



       Pmin80211::ht_ += pmin_[n1][2];



       if(initialized_ == 0){

              printf("Error! Pmin table was not inicializated \n");

              return(-1);

       }



       if (model_==1) {

              dist=RangeFriis(pRange,Pmin80211::CSThresh_,Pmin80211::Gt_,Pmin80211::Gr_,


                                  lambda_, Pmin80211::L_);

       } else if (model_==2) {


dist=RangeTwoRay(pRange,Pmin80211::CSThresh_,Pmin80211::Gt_,Pmin80211::Gr_,

                                   Pmin80211::ht_,Pmin80211::ht_,Pmin80211::L_,
lambda_);

       } else{

              printf("Error! propagation model! \n");

              return(-1);

       }

       return dist;

}


More information about the Ns-users mailing list