

Public Member Functions | |
| ArpAgent () | |
| ~ArpAgent () | |
| virtual void | recv (Packet *p, const char *s) |
| virtual void | recvOnly (Packet *) |
| virtual void | delay_bind_init_all () |
| virtual int | delay_bind_dispatch (const char *varName, const char *localName, TclObject *tracer) |
| int | isdebug () const |
| virtual void | debug (const char *fmt,...) |
Protected Member Functions | |
| char | icode (const char *) |
| acache_entry * | find (in_addr &) |
| void | insert (in_addr &, ether_addr &, char code) |
| void | dispatch (int) |
| int | sendreq (in_addr &) |
| int | sendresp (ether_addr &, in_addr &, ether_addr &) |
| int | resolve (const char *host, char *&result, int sendreq) |
| void | doreq (ether_arp *) |
| void | doreply (ether_arp *) |
| void | recv (Packet *, Handler *) |
| int | command (int, const char *const *) |
| virtual void | reset () |
| void | handle (Event *) |
Protected Attributes | |
| Network * | net_ |
| ether_header | eh_template_ |
| ether_arp | ea_template_ |
| ether_addr | my_ether_ |
| in_addr | my_ip_ |
| int | base_size_ |
| u_char * | rcv_buf_ |
| acache_entry * | acache_ |
| int | nacache_ |
| int | cur_ |
| int | pending_ |
| int | debug_ |
|
|
Definition at line 123 of file emulate/arp.cc. References acache_, ARPHRD_ETHER, ARPOP_REQUEST, base_size_, cur_, ea_template_, eh_template_, ETHER_ADDR_LEN, ether_header::ether_dhost, ether_header::ether_shost, ether_header::ether_type, ETHERTYPE_ARP, ETHERTYPE_IP, my_ether_, nacache_, and rcv_buf_.
00123 : net_(NULL), pending_(0) 00124 { 00125 /* dest addr is broadcast */ 00126 eh_template_.ether_dhost[0] = 0xff; 00127 eh_template_.ether_dhost[1] = 0xff; 00128 eh_template_.ether_dhost[2] = 0xff; 00129 eh_template_.ether_dhost[3] = 0xff; 00130 eh_template_.ether_dhost[4] = 0xff; 00131 eh_template_.ether_dhost[5] = 0xff; 00132 /* src addr is mine */ 00133 memcpy(&eh_template_.ether_shost, &my_ether_, ETHER_ADDR_LEN); 00134 /* type is ARP */ 00135 eh_template_.ether_type = htons(ETHERTYPE_ARP); 00136 00137 ea_template_.ea_hdr.ar_hrd = htons(ARPHRD_ETHER); 00138 ea_template_.ea_hdr.ar_pro = htons(ETHERTYPE_IP); 00139 ea_template_.ea_hdr.ar_hln = ETHER_ADDR_LEN; 00140 ea_template_.ea_hdr.ar_pln = 4; /* ip addr len */ 00141 ea_template_.ea_hdr.ar_op = htons(ARPOP_REQUEST); 00142 memcpy(&ea_template_.arp_sha, &my_ether_, ETHER_ADDR_LEN); /* sender hw */ 00143 memset(&ea_template_.arp_spa, 0, 4); /* sender IP */ 00144 memset(&ea_template_.arp_tha, 0, ETHER_ADDR_LEN); /* target hw */ 00145 memset(&ea_template_.arp_tpa, 0, 4); /* target hw */ 00146 base_size_ = sizeof(eh_template_) + sizeof(ea_template_); 00147 rcv_buf_ = new u_char[base_size_]; 00148 00149 bind("cachesize_", &nacache_); 00150 acache_ = new acache_entry[nacache_]; 00151 memset(acache_, 0, nacache_*sizeof(acache_entry)); 00152 cur_ = nacache_; 00153 } |
|
|
Definition at line 155 of file emulate/arp.cc. References acache_, and rcv_buf_.
|
|
||||||||||||
|
Reimplemented from NsObject. Definition at line 355 of file emulate/arp.cc. References NsObject::command(), ea_template_, eh_template_, ETHER_ADDR_LEN, ether_header::ether_shost, icode(), insert(), my_ether_, my_ip_, net_, Network::rchannel(), and resolve().
00356 {
00357 Tcl& tcl = Tcl::instance();
00358 if (argc == 2) {
00359 if (strcmp(argv[1], "network") == 0) {
00360 if (net_ == NULL)
00361 tcl.result("");
00362 else
00363 tcl.result(net_->name());
00364 return (TCL_OK);
00365 }
00366 } else if (argc == 3) {
00367 if (strcmp(argv[1], "network") == 0) {
00368 net_ = (Network *)TclObject::lookup(argv[2]);
00369 if (net_ != 0) {
00370 link(net_->rchannel(), TCL_READABLE);
00371 return (TCL_OK);
00372 } else {
00373 fprintf(stderr,
00374 "ArpAgent(%s): unknown network %s\n",
00375 name(), argv[2]);
00376 return (TCL_ERROR);
00377 }
00378 return(TCL_OK);
00379 }
00380 if (strcmp(argv[1], "myether") == 0) {
00381 my_ether_ = *(::ether_aton((char*)argv[2]));
00382 memcpy(&eh_template_.ether_shost, &my_ether_,
00383 ETHER_ADDR_LEN);
00384 memcpy(&ea_template_.arp_sha,
00385 &my_ether_, ETHER_ADDR_LEN);
00386 return (TCL_OK);
00387 }
00388 if (strcmp(argv[1], "myip") == 0) {
00389 u_long a = inet_addr(argv[2]);
00390 if (a == 0)
00391 return (TCL_ERROR);
00392 in_addr ia;
00393 ia.s_addr = a;
00394 my_ip_ = ia;
00395 memcpy(&ea_template_.arp_spa,
00396 &my_ip_, 4);
00397 return (TCL_OK);
00398 }
00399 if (strcmp(argv[1], "lookup") == 0) {
00400 char *p = NULL;
00401 if (resolve(argv[2], p, 0) < 0)
00402 return (TCL_ERROR);
00403 if (p)
00404 tcl.result(p);
00405 return (TCL_OK);
00406 }
00407 if (strcmp(argv[1], "resolve") == 0) {
00408 char *p = NULL;
00409 if (resolve(argv[2], p, 1) < 0)
00410 return (TCL_ERROR);
00411 if (p)
00412 tcl.resultf("%s", p);
00413 return (TCL_OK);
00414 }
00415 } else if (argc == 5) {
00416 // $obj insert iaddr eaddr how
00417 if (strcmp(argv[1], "insert") == 0) {
00418 u_long a = inet_addr(argv[2]);
00419 if (a == 0)
00420 return (TCL_ERROR);
00421 in_addr ia;
00422 ia.s_addr = a;
00423 ether_addr ea = *(::ether_aton((char*)argv[3]));
00424 insert(ia, ea, icode(argv[4]));
00425 return (TCL_OK);
00426 }
00427 }
00428
00429 return (NsObject::command(argc, argv));
00430 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 102 of file object.cc. References NsObject::debug_.
00103 {
00104 if (!debug_)
00105 return;
00106 va_list ap;
00107 va_start(ap, fmt);
00108 vprintf(fmt, ap);
00109 }
|
|
||||||||||||||||
|
Reimplemented in BayFullTcpAgent, Agent, MPLSAddressClassifier, LDPAgent, FullTcpAgent, SackFullTcpAgent, RFC793eduTcpAgent, TcpSink, TcpAgent, and VegasTcpAgent. Definition at line 63 of file object.cc. References NsObject::debug_. Referenced by MPLSAddressClassifier::delay_bind_dispatch(), and Agent::delay_bind_dispatch().
00064 {
00065 if (delay_bind_bool(varName, localName, "debug_", &debug_, tracer))
00066 return TCL_OK;
00067 return TclObject::delay_bind_dispatch(varName, localName, tracer);
00068 }
|
|
|
Reimplemented in BayFullTcpAgent, Agent, MPLSAddressClassifier, LDPAgent, FullTcpAgent, SackFullTcpAgent, RFC793eduTcpAgent, TcpSink, TcpAgent, and VegasTcpAgent. Definition at line 57 of file object.cc. Referenced by MPLSAddressClassifier::delay_bind_init_all(), and Agent::delay_bind_init_all().
00058 {
00059 delay_bind_init_one("debug_");
00060 }
|
|
|
Definition at line 275 of file emulate/arp.cc. References ARPOP_REPLY, ARPOP_REQUEST, base_size_, doreply(), doreq(), net_, rcv_buf_, Network::recv(), and ts.
00276 {
00277 double ts;
00278 sockaddr sa;
00279 int cc = net_->recv(rcv_buf_, base_size_, sa, ts);
00280 if (cc < int(base_size_ - sizeof(ether_header))) {
00281 if (cc == 0)
00282 return;
00283 fprintf(stderr,
00284 "ArpAgent(%s): recv small pkt (%d) [base sz:%d]: %s\n",
00285 name(), cc, base_size_, strerror(errno));
00286 return;
00287 }
00288 ether_arp* ea = (ether_arp*) rcv_buf_;
00289 int op = ntohs(ea->ea_hdr.ar_op);
00290
00291
00292 switch (op) {
00293 case ARPOP_REPLY:
00294 doreply(ea);
00295 break;
00296 case ARPOP_REQUEST:
00297 doreq(ea);
00298 break;
00299 default:
00300 fprintf(stderr,
00301 "ArpAgent(%s): cannot interpret ARP op %d\n",
00302 name(), op);
00303 return;
00304 }
00305 return;
00306 }
|
Here is the call graph for this function:

|
|
Definition at line 312 of file emulate/arp.cc. References ETHER_ADDR_LEN, and insert(). Referenced by dispatch().
00313 {
00314 /*
00315 * reply will be from the replier's point of view,
00316 * so, look in the sender ha/pa fields for the info
00317 * we want
00318 */
00319 in_addr t;
00320 ether_addr e;
00321 memcpy(&t, ea->arp_spa, 4); // copy IP address
00322 memcpy(&e, ea->arp_sha, ETHER_ADDR_LEN);
00323 insert(t, e, 'D');
00324 return;
00325 }
|
Here is the call graph for this function:

|
|
Definition at line 332 of file emulate/arp.cc. References ArpAgent::acache_entry::code, ArpAgent::acache_entry::ether, ETHER_ADDR_LEN, find(), and sendresp(). Referenced by dispatch().
00333 {
00334 in_addr t;
00335 memcpy(&t, ea->arp_tpa, 4); // requested IP addr
00336
00337 acache_entry *ae;
00338 if ((ae = find(t)) == NULL) {
00339 //printf("doreq: didn't find mapping for IP addr %s\n",
00340 //inet_ntoa(t));
00341 return;
00342 }
00343
00344 if (ae->code == 'P') {
00345 // return answer to the sender's hardware addr
00346 ether_addr dst;
00347 memcpy(&dst, ea->arp_sha, ETHER_ADDR_LEN);
00348 sendresp(dst, t, ae->ether);
00349 }
00350 return;
00351 }
|
Here is the call graph for this function:

|
|
Definition at line 162 of file emulate/arp.cc. References acache_, ArpAgent::acache_entry::ip, and nacache_. Referenced by doreq(), and resolve().
|
|
|
Implements Handler. Reimplemented in LinkDelay, LL, AckRecons, and Snoop. Definition at line 91 of file object.cc. References NsObject::recv().
|
Here is the call graph for this function:

|
|
Definition at line 176 of file emulate/arp.cc. Referenced by command().
00177 {
00178 if (strcmp(how, "publish") == 0)
00179 return 'P';
00180
00181 return 'D';
00182 }
|
|
||||||||||||||||
|
Definition at line 185 of file emulate/arp.cc. References acache_, ArpAgent::acache_entry::code, cur_, ArpAgent::acache_entry::ether, ArpAgent::acache_entry::ip, and nacache_. Referenced by command(), and doreply().
00186 {
00187 acache_entry* ae;
00188 if (--cur_ < 0)
00189 cur_ = nacache_ - 1;
00190
00191 ae = &acache_[cur_];
00192 ae->ip = target;
00193 ae->ether = eaddr;
00194 ae->code = code;
00195 //printf("INSERTED inet %s, ether %s\n",
00196 //inet_ntoa(target), Ethernet::etheraddr_string((u_char*)&eaddr));
00197 return;
00198 }
|
|
|
Definition at line 61 of file object.h. References NsObject::debug_.
00061 { return debug_; }
|
|
||||||||||||
|
Reimplemented in CMUTrace. Definition at line 96 of file object.cc. References Packet::free().
00097 {
00098 Packet::free(p);
00099 }
|
Here is the call graph for this function:

|
||||||||||||
|
Implements NsObject. Definition at line 98 of file emulate/arp.cc. References abort().
00098 { abort(); }
|
Here is the call graph for this function:

|
|
Reimplemented in Agent, and Trace. Definition at line 56 of file object.h. Referenced by Trace::recvOnly().
00056 {};
|
|
|
Reimplemented in BayFullTcpAgent, HashClassifier, IvsSource, dsREDQueue, DiffusionRate, SinkAgent, DiffusionAgent, FloodingAgent, OmniMcastAgent, LinkDelay, CBQueue, DropTail, ErrorModel, PIQueue, Queue< T >, RedPDQueue, REDQueue, REMQueue, RIOQueue, Snoop, FackTcpAgent, FullTcpAgent, SackFullTcpAgent, RFC793eduTcpAgent, Sack1TcpAgent, TcpSink, DelAckSink, TcpAgent, VegasTcpAgent, toraAgent, and Queue< T >. Definition at line 70 of file object.cc. Referenced by NsObject::command().
00071 {
00072 }
|
|
||||||||||||||||
|
Definition at line 433 of file emulate/arp.cc. References ArpAgent::acache_entry::ether, Ethernet::etheraddr_string(), find(), and sendreq(). Referenced by command().
00434 {
00435 u_long a = inet_addr(host);
00436 in_addr ia;
00437 ia.s_addr = a;
00438 acache_entry* ae;
00439 if ((ae = find(ia)) == NULL) {
00440 result = NULL;
00441 if (doreq)
00442 return(sendreq(ia));
00443 return (0);
00444 }
00445 result = Ethernet::etheraddr_string((u_char*) &ae->ether);
00446 return (1);
00447 }
|
Here is the call graph for this function:

|
|
Definition at line 201 of file emulate/arp.cc. References ea_template_, eh_template_, net_, and Network::send(). Referenced by resolve().
00202 {
00203 int pktsz = sizeof(eh_template_) + sizeof(ea_template_);
00204 if (pktsz < 64)
00205 pktsz = 64;
00206 u_char* buf = new u_char[pktsz];
00207 memset(buf, 0, pktsz);
00208
00209 ether_header* eh = (ether_header*) buf;
00210 ether_arp* ea = (ether_arp*) (buf + sizeof(eh_template_));
00211 *eh = eh_template_; /* set ether header */
00212 *ea = ea_template_; /* set ether/IP arp pkt */
00213 memcpy(ea->arp_tpa, &target, sizeof(target));
00214
00215 if (net_->send(buf, pktsz) < 0) {
00216 fprintf(stderr,
00217 "ArpAgent(%s): sendpkt (%p, %d): %s\n",
00218 name(), buf, pktsz, strerror(errno));
00219 return (-1);
00220 }
00221 delete[] buf;
00222 return (0);
00223 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 232 of file emulate/arp.cc. References ARPOP_REPLY, ea_template_, eh_template_, ETHER_ADDR_LEN, ether_header::ether_dhost, net_, and Network::send(). Referenced by doreq().
00233 {
00234 int pktsz = sizeof(eh_template_) + sizeof(ea_template_);
00235 if (pktsz < 64)
00236 pktsz = 64;
00237 u_char* buf = new u_char[pktsz];
00238 memset(buf, 0, pktsz);
00239
00240 ether_header* eh = (ether_header*) buf;
00241 ether_arp* ea = (ether_arp*) (buf + sizeof(eh_template_));
00242
00243 // destination link layer address is back to sender
00244 // (called dest here)
00245 *eh = eh_template_; /* set ether header */
00246 memcpy(eh->ether_dhost, &dest, ETHER_ADDR_LEN);
00247
00248 // set code as ARP reply
00249 *ea = ea_template_; /* set ether/IP arp pkt */
00250 ea->ea_hdr.ar_op = htons(ARPOP_REPLY);
00251
00252 // make it look like a regular arp reply
00253 memcpy(ea->arp_tpa, ea->arp_spa, sizeof(in_addr));
00254 memcpy(ea->arp_tha, ea->arp_sha, sizeof(in_addr));
00255
00256 memcpy(ea->arp_sha, &tea, ETHER_ADDR_LEN);
00257 memcpy(ea->arp_spa, &tip, ETHER_ADDR_LEN);
00258
00259 if (net_->send(buf, pktsz) < 0) {
00260 fprintf(stderr,
00261 "ArpAgent(%s): sendpkt (%p, %d): %s\n",
00262 name(), buf, pktsz, strerror(errno));
00263 return (-1);
00264 }
00265 delete[] buf;
00266 return (0);
00267 }
|
Here is the call graph for this function:

|
|
Definition at line 109 of file emulate/arp.cc. Referenced by ArpAgent(), find(), insert(), and ~ArpAgent(). |
|
|
Definition at line 107 of file emulate/arp.cc. Referenced by ArpAgent(), and dispatch(). |
|
|
Definition at line 111 of file emulate/arp.cc. Referenced by ArpAgent(), and insert(). |
|
|
Reimplemented in FECModel, FloodAgent, and LandmarkAgent. Definition at line 66 of file object.h. Referenced by REDQueue::command(), RedPDQueue::command(), PushbackQueue::command(), NsObject::debug(), NsObject::delay_bind_dispatch(), RedPDQueue::enque(), PushbackQueue::enque(), NsObject::isdebug(), NsObject::NsObject(), TfrcAgent::recv(), PushbackQueue::reportDrop(), and REDQueue::reset(). |
|
|
Definition at line 104 of file emulate/arp.cc. Referenced by ArpAgent(), command(), sendreq(), and sendresp(). |
|
|
Definition at line 103 of file emulate/arp.cc. Referenced by ArpAgent(), command(), sendreq(), and sendresp(). |
|
|
Definition at line 105 of file emulate/arp.cc. Referenced by ArpAgent(), and command(). |
|
|
Definition at line 106 of file emulate/arp.cc. Referenced by command(). |
|
|
Definition at line 110 of file emulate/arp.cc. Referenced by ArpAgent(), find(), and insert(). |
|
|
Definition at line 102 of file emulate/arp.cc. Referenced by command(), dispatch(), sendreq(), and sendresp(). |
|
|
Definition at line 112 of file emulate/arp.cc. |
|
|
Definition at line 108 of file emulate/arp.cc. Referenced by ArpAgent(), dispatch(), and ~ArpAgent(). |
1.3.3