Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

Address Class Reference

#include <address.h>

Inheritance diagram for Address:

Inheritance graph
[legend]
Collaboration diagram for Address:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Address ()
 ~Address ()
char * print_nodeaddr (int address)
char * print_portaddr (int address)
char * get_subnetaddr (int address)
int get_lastaddr (int address)
int get_nodeaddr (int address)
int str2addr (const char *str) const
int create_ipaddr (int nodeid, int portid)
int hier_addr (int address, int level)
int nodeshift ()
int nodemask ()
int set_word_field (int word, int field, int shift, int mask) const

Static Public Member Functions

Addressinstance ()

Public Attributes

int * bpl_
int * NodeShift_
int * NodeMask_
int McastShift_
int McastMask_
int levels_

Protected Member Functions

int command (int argc, const char *const *argv)

Static Protected Attributes

Addressinstance_

Constructor & Destructor Documentation

Address::Address  ) 
 

Definition at line 53 of file address.cc.

00053                  : 
00054         NodeShift_(NULL), NodeMask_(NULL), McastShift_(0), McastMask_(0), 
00055         levels_(0)
00056 {
00057 }

Address::~Address  ) 
 

Definition at line 60 of file address.cc.

References NodeMask_, and NodeShift_.

00061 { 
00062         delete [] NodeShift_;
00063         delete [] NodeMask_;
00064 }


Member Function Documentation

int Address::command int  argc,
const char *const *  argv
[protected]
 

Definition at line 66 of file address.cc.

References bpl_, instance_, levels_, McastMask_, McastShift_, NodeMask_, NodeShift_, and str2addr().

00067 {
00068         int i, c, temp=0;
00069 
00070         Tcl& tcl = Tcl::instance();
00071         if ((instance_ == 0) || (instance_ != this))
00072                 instance_ = this;
00073         if (argc == 3) {
00074                 if (strcmp(argv[1], "str2addr") == 0) {
00075                         tcl.resultf("%d", str2addr(argv[2]));
00076                         return (TCL_OK);
00077                 }
00078         }
00079         if (argc >= 3) {
00080                 if (strcmp(argv[1], "bpl-are") == 0) {
00081                         if (levels_ != (argc-2)) {
00082                                 tcl.resultf("#bpl don't match with #hier levels\n");
00083                                 return (TCL_ERROR);
00084                         }
00085                         bpl_ = new int[levels_ + 1];
00086                         for (c=1; c<=levels_; c++)
00087                                 bpl_[c] = atoi(argv[c+1]);
00088                         return TCL_OK;
00089                 }
00090         }
00091         if (argc == 4) {
00092                 if (strcmp(argv[1], "mcastbits-are") == 0) {
00093                         McastShift_ = atoi(argv[2]);
00094                         McastMask_ = atoi(argv[3]);
00095                         return (TCL_OK);
00096                 }
00097         }
00098         if (argc >= 4) {
00099                 if (strcmp(argv[1], "add-hier") == 0) {
00100                         /*
00101                          * <address> add-hier <level> <mask> <shift>
00102                          */
00103                         int level = atoi(argv[2]);
00104                         int mask = atoi(argv[3]);
00105                         int shift = atoi(argv[4]);
00106                         if (levels_ < level)
00107                                 levels_ = level;
00108                         NodeShift_[level] = shift;
00109                         NodeMask_[level] = mask;
00110                         return (TCL_OK);
00111                 }
00112 
00113                 if (strcmp(argv[1], "idsbits-are") == 0) {
00114                         temp = (argc - 2)/2;
00115                         if (levels_) { 
00116                                 if (temp != levels_) {
00117                                         tcl.resultf("#idshiftbits don't match with #hier levels\n");
00118                                         return (TCL_ERROR);
00119                                 }
00120                         }
00121                         else 
00122                                 levels_ = temp;
00123                         NodeShift_ = new int[levels_ + 1];
00124                         for (i = 3, c = 1; c <= levels_; c++, i+=2)
00125                                 NodeShift_[c] = atoi(argv[i]);
00126                         return (TCL_OK); 
00127                 }
00128         
00129                 if (strcmp(argv[1], "idmbits-are") == 0) {
00130                         temp = (argc - 2)/2;
00131                         if (levels_) { 
00132                                 if (temp != levels_) {
00133                                         tcl.resultf("#idmaskbits don't match with #hier levels\n");
00134                                         return (TCL_ERROR);
00135                                 }
00136                         }
00137                         else 
00138                                 levels_ = temp;
00139                         NodeMask_ = new int[levels_ + 1];
00140                         for (i = 3, c = 1; c <= levels_; c++, i+=2) 
00141                                 NodeMask_[c] = atoi(argv[i]);
00142                         return (TCL_OK);
00143                 }
00144         }
00145         return TclObject::command(argc, argv);
00146 }

Here is the call graph for this function:

int Address::create_ipaddr int  nodeid,
int  portid
 

Definition at line 224 of file address.cc.

References levels_, NodeMask_, and NodeShift_.

Referenced by DSRAgent::getRouteForPacket(), DSRAgent::processBrokenRouteError(), DSRAgent::processUnknownFlowError(), DSRAgent::replyFromRouteCache(), DSRAgent::returnSrcRouteToRequestor(), DSRAgent::sendRouteShortening(), DSRAgent::sendUnknownFlow(), and DSRAgent::xmitFailed().

00225 {
00226         return nodeid;
00227         // The following code is obsolete
00228 #if 0
00229         int address;
00230         if (levels_ < 2) 
00231                 address = (nodeid & NodeMask_[1]) << NodeShift_[1];
00232         else 
00233                 address = nodeid;
00234         address = ((portid & PortMask_) << PortShift_) | \
00235                 ((~(PortMask_) << PortShift_) & address);
00236         return address;
00237 #endif
00238 }

int Address::get_lastaddr int  address  ) 
 

Definition at line 240 of file address.cc.

References levels_, NodeMask_, and NodeShift_.

00241 {
00242         int a;
00243         a = address >> NodeShift_[levels_];
00244         a = a & NodeMask_[levels_];
00245         return a;
00246  }

int Address::get_nodeaddr int  address  ) 
 

Definition at line 211 of file address.cc.

References print_nodeaddr(), and str2addr().

Referenced by ARPTable::arpinput(), CMUTrace::format_ip(), CMUTrace::format_mac(), CMUTrace::format_rtp(), SatRouteAgent::forwardPacket(), DSDV_Agent::forwardPacket(), DSDV_Agent::makeUpdate(), CMUTrace::nam_format(), DSDV_Agent::processUpdate(), MIPEncapsulator::recv(), MIPBSAgent::recv(), DSDV_Agent::recv(), MIPMHAgent::reg(), MIPBSAgent::send_ads(), MIPMHAgent::send_sols(), and LL::sendDown().

00212 {
00213         int a;
00214         char *temp;
00215         
00216         temp = print_nodeaddr(address);
00217         a = str2addr(temp);
00218         delete [] temp;
00219         return a;
00220 }

Here is the call graph for this function:

char * Address::get_subnetaddr int  address  ) 
 

Definition at line 184 of file address.cc.

References levels_, NodeMask_, NodeShift_, and SMALL_LEN.

Referenced by DSRAgent::diff_subnet(), DSDV_Agent::diff_subnet(), and DSDV_Agent::startUp().

00185 {
00186         int a;
00187         char temp[SMALL_LEN];
00188         char str[SMALL_LEN];
00189         char *addrstr;
00190 
00191         if (levels_ > 1) {
00192                 str[0] = '\0';
00193                 for (int i=1; i < levels_; i++) {
00194                         a = address >> NodeShift_[i];
00195                         a = a & NodeMask_[i];
00196                         if (i < (levels_-1))
00197                                 sprintf(temp, "%d.", a);
00198                         else
00199                                 sprintf(temp, "%d", a);
00200                         strcat(str, temp);
00201                 }
00202                 addrstr = new char[strlen(str)+1];
00203                 strcpy(addrstr, str);
00204                 //printf("Subnet_addr - %s\n",addrstr);
00205                 return(addrstr);
00206         }
00207         return NULL;
00208 }

int Address::hier_addr int  address,
int  level
 

Definition at line 176 of file address.cc.

References levels_, NodeMask_, and NodeShift_.

Referenced by Simulator::populate_hier_classifiers().

00176                                              {
00177         if (level <= levels_) {
00178                 return ( (address >> NodeShift_[level]) & NodeMask_[level]);
00179         }
00180         perror("Address::hier_addr: levels greater than total h_levels_\n");
00181         return -1;
00182 }

Address& Address::instance  )  [inline, static]
 

Definition at line 43 of file address.h.

Referenced by ARPTable::arpinput(), SensorQueryAgent::command(), BroadcastNode::command(), AbsLanNode::command(), LanNode::command(), Node::command(), LandmarkAgent::command(), FloodAgent::command(), DSRAgent::command(), DSDV_Agent::command(), AODVclass::create(), QA::debug(), DSRAgent::diff_subnet(), DSDV_Agent::diff_subnet(), Trace::format(), SatTrace::format(), CMUTrace::format_ip(), CMUTrace::format_mac(), CMUTrace::format_rtp(), SatRouteAgent::forwardPacket(), DSDV_Agent::forwardPacket(), DSRAgent::getRouteForPacket(), DSRAgent::handlePacketReceipt(), RapAgent::listen(), MediaApp::log(), RouteLogic::lookup_hier(), DSDV_Agent::makeUpdate(), GAFAgent::makeUpDiscoveryMsg(), CMUTrace::nam_format(), LanRouter::next_hop(), QA::panic(), Simulator::populate_hier_classifiers(), DSRAgent::processBrokenRouteError(), DSRAgent::processUnknownFlowError(), DSDV_Agent::processUpdate(), UdpAgent::recv(), DequeTrace::recv(), SatDequeTrace::recv(), PingAgent::recv(), MIPEncapsulator::recv(), MIPBSAgent::recv(), DSRAgent::recv(), DSDV_Agent::recv(), VirtualClassifier::recv(), MIPMHAgent::reg(), DSRAgent::replyFromRouteCache(), DSRAgent::returnSrcRouteToRequestor(), MIPBSAgent::send_ads(), MIPMHAgent::send_sols(), SatLL::sendDown(), LL::sendDown(), DSRAgent::sendRouteShortening(), DSRAgent::sendUnknownFlow(), RapAgent::start(), DSDV_Agent::startUp(), DSRAgent::tap(), DSRAgent::undeliverablePkt(), DSRAgent::xmitFailed(), and DSRAgent::xmitFlowFailed().

00043 { return (*instance_); }

int Address::nodemask  )  [inline]
 

Definition at line 56 of file address.h.

References levels_, and NodeMask_.

00056 {return NodeMask_[levels_];}

int Address::nodeshift  )  [inline]
 

Definition at line 55 of file address.h.

References levels_, and NodeShift_.

Referenced by DSDV_Agent::makeUpdate(), and GAFAgent::makeUpDiscoveryMsg().

00055 {return NodeShift_[levels_];}

char * Address::print_nodeaddr int  address  ) 
 

Definition at line 148 of file address.cc.

References len, levels_, NodeMask_, NodeShift_, and SMALL_LEN.

Referenced by QA::debug(), Trace::format(), SatTrace::format(), get_nodeaddr(), MediaApp::log(), LanRouter::next_hop(), QA::panic(), DequeTrace::recv(), SatDequeTrace::recv(), VirtualClassifier::recv(), SatLL::sendDown(), and DSDV_Agent::startUp().

00149 {
00150         int a;
00151         char temp[SMALL_LEN];
00152         char str[SMALL_LEN];
00153         char *addrstr;
00154 
00155         str[0] = '\0';
00156         for (int i=1; i <= levels_; i++) {
00157                 a = address >> NodeShift_[i];
00158                 if (levels_ > 1)
00159                         a = a & NodeMask_[i];
00160                 //if (i < levels_)
00161                 sprintf(temp, "%d.", a);
00162                 //else
00163                 //sprintf(temp, "%d", a);
00164                 
00165                 strcat(str, temp);
00166         }
00167         int len;
00168         len = strlen(str);
00169         addrstr = new char[len+1];
00170         str[len-1]= 0; //kill the last dot
00171         strcpy(addrstr, str);
00172         // printf("Nodeaddr - %s\n",addrstr);
00173         return(addrstr);
00174 }

char * Address::print_portaddr int  address  ) 
 

Definition at line 249 of file address.cc.

References SMALL_LEN.

Referenced by QA::debug(), Trace::format(), SatTrace::format(), QA::panic(), DequeTrace::recv(), and SatDequeTrace::recv().

00250 {
00251         char str[SMALL_LEN];
00252         char *addrstr;
00253 
00254         str[0] = '\0';
00255 #if 0
00256         int a;
00257         a = address >> PortShift_;
00258         a = a & PortMask_;
00259 #endif
00260         sprintf(str, "%d", address);
00261         addrstr = new char[strlen(str)+1];
00262         strcpy(addrstr, str);
00263         // printf("Portaddr - %s\n",addrstr);
00264 
00265         return(addrstr);
00266 }

int Address::set_word_field int  word,
int  field,
int  shift,
int  mask
const [inline]
 

Definition at line 57 of file address.h.

Referenced by str2addr().

00057                                                                                   {
00058                 return (((field & mask)<<shift) | ((~(mask << shift)) & word));
00059         }

int Address::str2addr const char *  str  )  const
 

Definition at line 269 of file address.cc.

References bpl_, levels_, NodeMask_, NodeShift_, RouteLogic::ns_strtok(), and set_word_field().

Referenced by SensorQueryAgent::command(), BroadcastNode::command(), AbsLanNode::command(), LanNode::command(), Node::command(), LandmarkAgent::command(), FloodAgent::command(), DSRAgent::command(), DSDV_Agent::command(), command(), get_nodeaddr(), and RouteLogic::lookup_hier().

00270 {
00271         
00272         if (levels_ < 2) {
00273                 int tmp = atoi(str);            
00274                 if (tmp < 0)     
00275                         return (tmp);
00276                 if (tmp > ((unsigned long)(1 << bpl_[1])) ) {
00277                         fprintf(stderr, "Error!!\nstr2addr:Address %d outside range of address field length %d\n", tmp, ((unsigned long)(1<< bpl_[1])));
00278                         exit(1);
00279                 }
00280                 return tmp;
00281         }
00282         /*
00283           int istr[levels_], addr= 0;
00284         */
00285         /*
00286          * for VC++
00287          */
00288 
00289         int *istr= new int[levels_];
00290         int addr= 0;
00291         
00292         RouteLogic::ns_strtok((char*)str, istr);
00293         for (int i = 0; i < levels_; i++) {
00294                 if (--istr[i] > ((unsigned long)(1 << bpl_[i+1])) ) {
00295                         fprintf(stderr, "Error!!\nstr2addr:Address %d outside range of address field length %d\n", istr[i], ((unsigned long)(1<< bpl_[i+1])));
00296                         exit(1);
00297                 }
00298                 addr = set_word_field(addr, istr[i],
00299                                       NodeShift_[i+1], NodeMask_[i+1]);
00300         }
00301         
00302         delete [] istr;
00303         
00304         return addr;
00305 }

Here is the call graph for this function:


Member Data Documentation

int* Address::bpl_
 

Definition at line 63 of file address.h.

Referenced by command(), and str2addr().

Address * Address::instance_ [static, protected]
 

Definition at line 51 of file address.cc.

Referenced by command().

int Address::levels_
 

Definition at line 68 of file address.h.

Referenced by command(), create_ipaddr(), get_lastaddr(), get_subnetaddr(), hier_addr(), nodemask(), nodeshift(), Simulator::populate_hier_classifiers(), print_nodeaddr(), and str2addr().

int Address::McastMask_
 

Definition at line 67 of file address.h.

Referenced by command().

int Address::McastShift_
 

Definition at line 66 of file address.h.

Referenced by command().

int* Address::NodeMask_
 

Definition at line 65 of file address.h.

Referenced by command(), create_ipaddr(), get_lastaddr(), get_subnetaddr(), hier_addr(), nodemask(), print_nodeaddr(), str2addr(), and ~Address().

int* Address::NodeShift_
 

Definition at line 64 of file address.h.

Referenced by command(), create_ipaddr(), get_lastaddr(), get_subnetaddr(), hier_addr(), RapAgent::listen(), nodeshift(), print_nodeaddr(), UdpAgent::recv(), PingAgent::recv(), RapAgent::start(), str2addr(), and ~Address().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:32:08 2004 for NS2.26SourcesOriginal by doxygen 1.3.3