WirelessChannel Class Reference

#include <channel.h>

Inheritance diagram for WirelessChannel:

Channel TclObject Collaboration diagram for WirelessChannel:

Collaboration graph
[legend]

Detailed Description

Definition at line 105 of file channel.h.

Public Member Functions

virtual int command (int argc, const char *const *argv)
double gethighestAntennaZ ()
int index ()
double maxdelay ()
virtual void recv (Packet *p, Handler *)
 WirelessChannel (void)

Data Fields

TclObjectgridkeeper_
if_head ifhead_

Protected Member Functions

void calcHighestAntennaZ (Phy *tifp)

Protected Attributes

double delay_
int index_
Tracetrace_

Static Protected Attributes

static double distCST_ = -1
static double highestAntennaZ_ = -1

Private Member Functions

void addNodeToList (MobileNode *mn)
double get_pdelay (Node *tnode, Node *rnode)
MobileNode ** getAffectedNodes (MobileNode *mn, double radius, int *numAffectedNodes)
void removeNodeFromList (MobileNode *mn)
void sendUp (Packet *p, Phy *txif)
void sortLists (void)
void updateNodesList (class MobileNode *mn, double oldX)

Private Attributes

int numNodes_
bool sorted_
MobileNodexListHead_

Friends

class Topography


Constructor & Destructor Documentation

WirelessChannel::WirelessChannel void   ) 
 

Definition at line 289 of file channel.cc.

00289                                      : Channel(), numNodes_(0), 
00290                      xListHead_(NULL), sorted_(0) {}


Member Function Documentation

void WirelessChannel::addNodeToList MobileNode mn  )  [private]
 

Definition at line 394 of file channel.cc.

References MobileNode::nextX_, numNodes_, MobileNode::prevX_, and xListHead_.

Referenced by command().

00395 {
00396     MobileNode *tmp;
00397 
00398     // create list of mobilenodes for this channel
00399     if (xListHead_ == NULL) {
00400         fprintf(stderr, "INITIALIZE THE LIST xListHead\n");
00401         xListHead_ = mn;
00402         xListHead_->nextX_ = NULL;
00403         xListHead_->prevX_ = NULL;
00404     } else {
00405         for (tmp = xListHead_; tmp->nextX_ != NULL; tmp=tmp->nextX_);
00406         tmp->nextX_ = mn;
00407         mn->prevX_ = tmp;
00408         mn->nextX_ = NULL;
00409     }
00410     numNodes_++;
00411 }

void WirelessChannel::calcHighestAntennaZ Phy tifp  )  [protected]
 

Definition at line 619 of file channel.cc.

References Channel::ifhead_, and Phy::nextchnl().

Referenced by sendUp().

00620 {
00621        double highestZ = 0;
00622        Phy *n;
00623  
00624        for(n = ifhead_.lh_first; n; n = n->nextchnl()) {
00625                    if(((WirelessPhy *)n)->getAntennaZ() > highestZ)
00626                                highestZ = ((WirelessPhy *)n)->getAntennaZ();
00627        }
00628  
00629        highestAntennaZ_ = highestZ;
00630 
00631        WirelessPhy *wifp = (WirelessPhy *)tifp;
00632        distCST_ = wifp->getDist(wifp->getCSThresh(), wifp->getPt(), 1.0, 1.0,
00633                 highestZ , highestZ, wifp->getL(),
00634                 wifp->getLambda());       
00635 }

Here is the call graph for this function:

int WirelessChannel::command int  argc,
const char *const *  argv
[virtual]
 

Reimplemented from Channel.

Definition at line 292 of file channel.cc.

References addNodeToList(), Channel::command(), and removeNodeFromList().

00293 {
00294     
00295     if (argc == 3) {
00296         TclObject *obj;
00297 
00298         if( (obj = TclObject::lookup(argv[2])) == 0) {
00299             fprintf(stderr, "%s lookup failed\n", argv[1]);
00300             return TCL_ERROR;
00301         }
00302         if (strcmp(argv[1], "add-node") == 0) {
00303             addNodeToList((MobileNode*) obj);
00304             return TCL_OK;
00305         }
00306         else if (strcmp(argv[1], "remove-node") == 0) {
00307             removeNodeFromList((MobileNode*) obj);
00308             return TCL_OK;
00309         }
00310     }
00311     return Channel::command(argc, argv);
00312 }

Here is the call graph for this function:

double WirelessChannel::get_pdelay Node tnode,
Node rnode
[private, virtual]
 

Reimplemented from Channel.

Definition at line 639 of file channel.cc.

References MobileNode::propdelay().

Referenced by sendUp().

00640 {
00641     // Scheduler    &s = Scheduler::instance();
00642     MobileNode* tmnode = (MobileNode*)tnode;
00643     MobileNode* rmnode = (MobileNode*)rnode;
00644     double propdelay = 0;
00645     
00646     propdelay = tmnode->propdelay(rmnode);
00647 
00648     assert(propdelay >= 0.0);
00649     if (propdelay == 0.0) {
00650         /* if the propdelay is 0 b/c two nodes are on top of 
00651            each other, move them slightly apart -dam 7/28/98 */
00652         propdelay = 2 * DBL_EPSILON;
00653         //printf ("propdelay 0: %d->%d at %f\n",
00654         //  tmnode->address(), rmnode->address(), s.clock());
00655     }
00656     return propdelay;
00657 }

Here is the call graph for this function:

MobileNode ** WirelessChannel::getAffectedNodes MobileNode mn,
double  radius,
int *  numAffectedNodes
[private]
 

Definition at line 562 of file channel.cc.

References Scheduler::instance(), MobileNode::nextX_, numNodes_, MobileNode::prevX_, MobileNode::X(), XLIST_POSITION_UPDATE_INTERVAL, xListHead_, and MobileNode::Y().

00564 {
00565     double xmin, xmax, ymin, ymax;
00566     int n = 0;
00567     MobileNode *tmp, **list, **tmpList;
00568 
00569     if (xListHead_ == NULL) {
00570         *numAffectedNodes=-1;
00571         fprintf(stderr, "xListHead_ is NULL when trying to send!!!\n");
00572         return NULL;
00573     }
00574     
00575     xmin = mn->X() - radius;
00576     xmax = mn->X() + radius;
00577     ymin = mn->Y() - radius;
00578     ymax = mn->Y() + radius;
00579     
00580     // First allocate as much as possibly needed
00581     tmpList = new MobileNode*[numNodes_];
00582     
00583     for(tmp = xListHead_; tmp != NULL; tmp = tmp->nextX_) tmpList[n++] = tmp;
00584     for(int i = 0; i < n; ++i)
00585         if(tmpList[i]->speed()!=0.0 && (Scheduler::instance().clock() -
00586                         tmpList[i]->getUpdateTime()) > XLIST_POSITION_UPDATE_INTERVAL )
00587             tmpList[i]->update_position();
00588     n=0;
00589     
00590     for(tmp = mn; tmp != NULL && tmp->X() >= xmin; tmp=tmp->prevX_)
00591         if(tmp->Y() >= ymin && tmp->Y() <= ymax){
00592             tmpList[n++] = tmp;
00593         }
00594     for(tmp = mn->nextX_; tmp != NULL && tmp->X() <= xmax; tmp=tmp->nextX_){
00595         if(tmp->Y() >= ymin && tmp->Y() <= ymax){
00596             tmpList[n++] = tmp;
00597         }
00598     }
00599     
00600     list = new MobileNode*[n];
00601     memcpy(list, tmpList, n * sizeof(MobileNode *));
00602     delete [] tmpList;
00603          
00604     *numAffectedNodes = n;
00605     return list;
00606 }

Here is the call graph for this function:

double WirelessChannel::gethighestAntennaZ  )  [inline]
 

Definition at line 110 of file channel.h.

References highestAntennaZ_.

00110 { return highestAntennaZ_; }

int Channel::index  )  [inline, inherited]
 

Definition at line 67 of file channel.h.

References Channel::index_.

00067 {return index_;}

double Channel::maxdelay  )  [inline, inherited]
 

Definition at line 66 of file channel.h.

References Channel::delay_.

Referenced by Mac802_3::sendDown().

00066 { return delay_; };

void Channel::recv Packet p,
Handler
[virtual, inherited]
 

Reimplemented in NoDupChannel.

Definition at line 144 of file channel.cc.

References Channel::sendUp().

Referenced by WirelessPhy::sendDown(), WiredPhy::sendDown(), RepeaterPhy::sendDown(), and SatPhy::sendDown().

00145 {
00146     sendUp(p, (Phy*)h);
00147 }

Here is the call graph for this function:

void WirelessChannel::removeNodeFromList MobileNode mn  )  [private]
 

Definition at line 414 of file channel.cc.

References MobileNode::nextX_, MobileNode::prevX_, and xListHead_.

Referenced by command().

00414                                                   {
00415     
00416     MobileNode *tmp;
00417     // Find node in list
00418     for (tmp = xListHead_; tmp->nextX_ != NULL; tmp=tmp->nextX_) {
00419         if (tmp == mn) {
00420             if (tmp == xListHead_) {
00421                 xListHead_ = tmp->nextX_;
00422                 if (tmp->nextX_ != NULL)
00423                     tmp->nextX_->prevX_ = NULL;
00424             } else if (tmp->nextX_ == NULL) 
00425                 tmp->prevX_->nextX_ = NULL;
00426             else {
00427                 tmp->prevX_->nextX_ = tmp->nextX_;
00428                 tmp->nextX_->prevX_ = tmp->prevX_;
00429             }
00430             numNodes_--;
00431             return;
00432         }
00433     }
00434     fprintf(stderr, "Channel: node not found in list\n");
00435 }

void WirelessChannel::sendUp Packet p,
Phy txif
[private, virtual]
 

Reimplemented from Channel.

Definition at line 316 of file channel.cc.

References calcHighestAntennaZ(), Phy::channel(), Packet::copy(), hdr_cmn::direction(), distCST_, GridKeeper::get_neighbors(), get_pdelay(), HDR_CMN, highestAntennaZ_, Node::ifhead(), Channel::ifhead_, GridKeeper::instance(), Scheduler::instance(), Phy::nextnode(), Phy::node(), MobileNode::propdelay(), Scheduler::schedule(), hdr_cmn::size(), GridKeeper::size_, and hdr_cmn::UP.

00317 {
00318     Scheduler &s = Scheduler::instance();
00319     Phy *rifp = ifhead_.lh_first;
00320     Node *tnode = tifp->node();
00321     Node *rnode = 0;
00322     Packet *newp;
00323     double propdelay = 0.0;
00324     struct hdr_cmn *hdr = HDR_CMN(p);
00325 
00326          /* list-based improvement */
00327          if(highestAntennaZ_ == -1) {
00328                  fprintf(stdout, "channel.cc:sendUp - Calc highestAntennaZ_ and distCST_\n");
00329                  calcHighestAntennaZ(tifp);
00330                  fprintf(stdout, "highestAntennaZ_ = %0.1f,  distCST_ = %0.1f\n", highestAntennaZ_, distCST_);
00331          }
00332     
00333      hdr->direction() = hdr_cmn::UP;
00334 
00335      // still keep grid-keeper around ??
00336      if (GridKeeper::instance()) {
00337         int i;
00338         GridKeeper* gk = GridKeeper::instance();
00339         int size = gk->size_; 
00340         
00341         MobileNode **outlist = new MobileNode *[size];
00342      
00343             int out_index = gk->get_neighbors((MobileNode*)tnode,
00344                                  outlist);
00345         for (i=0; i < out_index; i ++) {
00346         
00347           newp = p->copy();
00348           rnode = outlist[i];
00349           propdelay = get_pdelay(tnode, rnode);
00350 
00351           rifp = (rnode->ifhead()).lh_first; 
00352           for(; rifp; rifp = rifp->nextnode()){
00353               if (rifp->channel() == this){
00354                  s.schedule(rifp, newp, propdelay); 
00355                  break;
00356               }
00357           }
00358         }
00359         delete [] outlist; 
00360      
00361      } else { // use list-based improvement
00362      
00363          MobileNode *mtnode = (MobileNode *) tnode;
00364          MobileNode **affectedNodes;// **aN;
00365          int numAffectedNodes = -1, i;
00366          
00367          if(!sorted_){
00368              sortLists();
00369          }
00370          
00371          affectedNodes = getAffectedNodes(mtnode, distCST_ + /* safety */ 5, &numAffectedNodes);
00372          for (i=0; i < numAffectedNodes; i++) {
00373              rnode = affectedNodes[i];
00374              
00375              if(rnode == tnode)
00376                  continue;
00377              
00378              newp = p->copy();
00379              
00380              propdelay = get_pdelay(tnode, rnode);
00381              
00382              rifp = (rnode->ifhead()).lh_first;
00383              for(; rifp; rifp = rifp->nextnode()){
00384                  s.schedule(rifp, newp, propdelay);
00385              }
00386          }
00387          delete [] affectedNodes;
00388      }
00389      Packet::free(p);
00390 }

Here is the call graph for this function:

void WirelessChannel::sortLists void   )  [private]
 

Definition at line 438 of file channel.cc.

References MobileNode::nextX_, MobileNode::prevX_, sorted_, MobileNode::X(), and xListHead_.

Referenced by updateNodesList().

00438                                {
00439     bool flag = true;
00440     MobileNode *m, *q;
00441 
00442     sorted_ = true;
00443     
00444     fprintf(stderr, "SORTING LISTS ...");
00445     /* Buble sort algorithm */
00446     // SORT x-list
00447     while(flag) {
00448         flag = false;
00449         m = xListHead_;
00450         while (m != NULL){
00451             if(m->nextX_ != NULL)
00452                 if ( m->X() > m->nextX_->X() ){
00453                     flag = true;
00454                     //delete_after m;
00455                     q = m->nextX_;
00456                     m->nextX_ = q->nextX_;
00457                     if (q->nextX_ != NULL)
00458                         q->nextX_->prevX_ = m;
00459                 
00460                     //insert_before m;
00461                     q->nextX_ = m;
00462                     q->prevX_ = m->prevX_;
00463                     m->prevX_ = q;
00464                     if (q->prevX_ != NULL)
00465                         q->prevX_->nextX_ = q;
00466 
00467                     // adjust Head of List
00468                     if(m == xListHead_) 
00469                         xListHead_ = m->prevX_;
00470                 }
00471             m = m -> nextX_;
00472         }
00473     }
00474     
00475     fprintf(stderr, "DONE!\n");
00476 }

Here is the call graph for this function:

void WirelessChannel::updateNodesList class MobileNode mn,
double  oldX
[private]
 

Definition at line 479 of file channel.cc.

References MobileNode::nextX_, MobileNode::prevX_, sorted_, sortLists(), MobileNode::X(), and xListHead_.

Referenced by Topography::updateNodesList().

00479                                                                   {
00480     
00481     MobileNode* tmp;
00482     double X = mn->X();
00483     bool skipX=false;
00484     
00485     if(!sorted_) {
00486         sortLists();
00487         return;
00488     }
00489     
00490     /* xListHead cannot be NULL here (they are created during creation of mobilenode) */
00491     
00492     /***  DELETE ***/
00493     // deleting mn from x-list
00494     if(mn->nextX_ != NULL) {
00495         if(mn->prevX_ != NULL){
00496             if((mn->nextX_->X() >= X) && (mn->prevX_->X() <= X)) skipX = true; // the node doesn't change its position in the list
00497             else{
00498                 mn->nextX_->prevX_ = mn->prevX_;
00499                 mn->prevX_->nextX_ = mn->nextX_;
00500             }
00501         }
00502         
00503         else{
00504             if(mn->nextX_->X() >= X) skipX = true; // skip updating the first element
00505             else{
00506                 mn->nextX_->prevX_ = NULL;
00507                 xListHead_ = mn->nextX_;
00508             }
00509         }
00510     }
00511     
00512     else if(mn->prevX_ !=NULL){
00513         if(mn->prevX_->X() <= X) skipX = true; // skip updating the last element
00514         else mn->prevX_->nextX_ = NULL;
00515     }
00516     
00517     if ((mn->prevX_ == NULL) && (mn->nextX_ == NULL)) skipX = true; //skip updating if only one element in list
00518     
00519     /*** INSERT ***/
00520     //inserting mn in x-list
00521     if(!skipX){
00522         if(X > oldX){           
00523             for(tmp = mn; tmp->nextX_ != NULL && tmp->nextX_->X() < X; tmp = tmp->nextX_);
00524             //fprintf(stdout,"Scanning the element addr %d X=%0.f, next addr %d X=%0.f\n", tmp, tmp->X(), tmp->nextX_, tmp->nextX_->X());
00525             if(tmp->nextX_ == NULL) { 
00526                 //fprintf(stdout, "tmp->nextX_ is NULL\n");
00527                 tmp->nextX_ = mn;
00528                 mn->prevX_ = tmp;
00529                 mn->nextX_ = NULL;
00530             } 
00531             else{ 
00532                 //fprintf(stdout, "tmp->nextX_ is not NULL, tmp->nextX_->X()=%0.f\n", tmp->nextX_->X());
00533                 mn->prevX_ = tmp->nextX_->prevX_;
00534                 mn->nextX_ = tmp->nextX_;
00535                 tmp->nextX_->prevX_ = mn;   
00536                 tmp->nextX_ = mn;
00537             } 
00538         }
00539         else{
00540             for(tmp = mn; tmp->prevX_ != NULL && tmp->prevX_->X() > X; tmp = tmp->prevX_);
00541                 //fprintf(stdout,"Scanning the element addr %d X=%0.f, prev addr %d X=%0.f\n", tmp, tmp->X(), tmp->prevX_, tmp->prevX_->X());
00542             if(tmp->prevX_ == NULL) {
00543                 //fprintf(stdout, "tmp->prevX_ is NULL\n");
00544                 tmp->prevX_ = mn;
00545                 mn->nextX_ = tmp;
00546                 mn->prevX_ = NULL;
00547                 xListHead_ = mn;
00548             } 
00549             else{
00550                 //fprintf(stdout, "tmp->prevX_ is not NULL, tmp->prevX_->X()=%0.f\n", tmp->prevX_->X());
00551                 mn->nextX_ = tmp->prevX_->nextX_;
00552                 mn->prevX_ = tmp->prevX_;
00553                 tmp->prevX_->nextX_ = mn;   
00554                 tmp->prevX_ = mn;       
00555             }
00556         }
00557     }
00558 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Topography [friend]
 

Definition at line 106 of file channel.h.


Field Documentation

double Channel::delay_ [protected, inherited]
 

Definition at line 81 of file channel.h.

Referenced by Channel::Channel(), Channel::get_pdelay(), Channel::maxdelay(), and NoDupChannel::recv().

double WirelessChannel::distCST_ = -1 [static, protected]
 

Definition at line 128 of file channel.h.

Referenced by sendUp().

TclObject* Channel::gridkeeper_ [inherited]
 

Definition at line 65 of file channel.h.

double WirelessChannel::highestAntennaZ_ = -1 [static, protected]
 

Definition at line 129 of file channel.h.

Referenced by gethighestAntennaZ(), and sendUp().

struct if_head Channel::ifhead_ [inherited]
 

Definition at line 64 of file channel.h.

Referenced by SatChannel::add_interface(), calcHighestAntennaZ(), Channel::Channel(), Channel::command(), SatRouteObject::compute_topology(), Channel::dump(), SatChannel::find_peer_mac_addr(), LinkHandoffMgr::get_peer(), LinkHandoffMgr::get_peer_linkhead(), sendUp(), NoDupChannel::sendUp(), and Channel::sendUp().

int Channel::index_ [protected, inherited]
 

Definition at line 80 of file channel.h.

Referenced by Channel::Channel(), Channel::command(), SatChannel::getId(), and Channel::index().

int WirelessChannel::numNodes_ [private]
 

Definition at line 118 of file channel.h.

Referenced by addNodeToList(), and getAffectedNodes().

bool WirelessChannel::sorted_ [private]
 

Definition at line 120 of file channel.h.

Referenced by sortLists(), and updateNodesList().

Trace* Channel::trace_ [protected, inherited]
 

Definition at line 86 of file channel.h.

Referenced by Channel::command().

MobileNode* WirelessChannel::xListHead_ [private]
 

Definition at line 119 of file channel.h.

Referenced by addNodeToList(), getAffectedNodes(), removeNodeFromList(), sortLists(), and updateNodesList().


The documentation for this class was generated from the following files:
Generated on Tue Mar 6 17:35:45 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6