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

TcpApp Class Reference

#include <tcpapp.h>

Inheritance diagram for TcpApp:

Inheritance graph
[legend]
Collaboration diagram for TcpApp:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TcpApp (Agent *tcp)
 ~TcpApp ()
virtual void recv (int nbytes)
virtual void send (int nbytes, AppData *data)
void connect (TcpApp *dst)
virtual void process_data (int size, AppData *data)
virtual AppDataget_data (int &, AppData *)
virtual void resume ()
virtual void send (int nbytes)
Process *& target ()
virtual void send_data (int size, AppData *data=0)

Protected Member Functions

virtual int command (int argc, const char *const *argv)
CBufrcvr_retrieve_data ()
virtual void start ()
virtual void stop ()

Protected Attributes

TcpAppdst_
CBufList cbuf_
CBufcurdata_
int curbytes_
Agentagent_
int enableRecv_
int enableResume_
Processtarget_

Constructor & Destructor Documentation

TcpApp::TcpApp Agent tcp  ) 
 

Definition at line 133 of file tcpapp.cc.

References Application::agent_, and Agent::attachApp().

00133                          : 
00134         Application(), curdata_(0), curbytes_(0)
00135 {
00136         agent_ = tcp;
00137         agent_->attachApp(this);
00138 }

Here is the call graph for this function:

TcpApp::~TcpApp  ) 
 

Definition at line 140 of file tcpapp.cc.

References Application::agent_, and Agent::attachApp().

00141 {
00142         // XXX Before we quit, let our agent know what we no longer exist
00143         // so that it won't give us a call later...
00144         agent_->attachApp(NULL);
00145 }

Here is the call graph for this function:


Member Function Documentation

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

Reimplemented from Application.

Reimplemented in HttpUInvalAgent.

Definition at line 219 of file tcpapp.cc.

References Application::command(), connect(), dst_, send(), and TcpAppString::set_string().

Referenced by HttpUInvalAgent::command().

00220 {
00221         Tcl& tcl = Tcl::instance();
00222 
00223         if (strcmp(argv[1], "connect") == 0) {
00224                 dst_ = (TcpApp *)TclObject::lookup(argv[2]);
00225                 if (dst_ == NULL) {
00226                         tcl.resultf("%s: connected to null object.", name_);
00227                         return (TCL_ERROR);
00228                 }
00229                 dst_->connect(this);
00230                 return (TCL_OK);
00231         } else if (strcmp(argv[1], "send") == 0) {
00232                 /*
00233                  * <app> send <size> <tcl_script>
00234                  */
00235                 int size = atoi(argv[2]);
00236                 if (argc == 3)
00237                         send(size, NULL);
00238                 else {
00239                         TcpAppString *tmp = new TcpAppString();
00240                         tmp->set_string(argv[3]);
00241                         send(size, tmp);
00242                 }
00243                 return (TCL_OK);
00244         } else if (strcmp(argv[1], "dst") == 0) {
00245                 tcl.resultf("%s", dst_->name());
00246                 return TCL_OK;
00247         }
00248         return Application::command(argc, argv);
00249 }

Here is the call graph for this function:

void TcpApp::connect TcpApp dst  )  [inline]
 

Definition at line 90 of file tcpapp.h.

References dst_.

Referenced by command().

00090 { dst_ = dst; }

virtual AppData* TcpApp::get_data int &  ,
AppData
[inline, virtual]
 

Reimplemented from Process.

Reimplemented in HttpUInvalAgent.

Definition at line 93 of file tcpapp.h.

References abort().

00093                                                   {
00094                 // Not supported
00095                 abort();
00096                 return NULL;
00097         }

Here is the call graph for this function:

void TcpApp::process_data int  size,
AppData data
[virtual]
 

Reimplemented from Process.

Reimplemented in HttpUInvalAgent.

Definition at line 251 of file tcpapp.cc.

References Process::send_data(), TcpAppString::str(), Process::target(), TCPAPP_STRING, and AppData::type().

Referenced by recv().

00252 {
00253         if (data == NULL)
00254                 return;
00255         // XXX Default behavior:
00256         // If there isn't a target, use tcl to evaluate the data
00257         if (target())
00258                 send_data(size, data);
00259         else if (data->type() == TCPAPP_STRING) {
00260                 TcpAppString *tmp = (TcpAppString*)data;
00261                 Tcl::instance().eval(tmp->str());
00262         }
00263 }

Here is the call graph for this function:

CBuf* TcpApp::rcvr_retrieve_data  )  [inline, protected]
 

Definition at line 104 of file tcpapp.h.

References cbuf_, and CBufList::detach().

Referenced by recv().

00104 { return cbuf_.detach(); }

Here is the call graph for this function:

void TcpApp::recv int  nbytes  )  [virtual]
 

Reimplemented from Application.

Definition at line 159 of file tcpapp.cc.

References abort(), CBuf::bytes(), curbytes_, curdata_, CBuf::data(), dst_, Scheduler::instance(), process_data(), rcvr_retrieve_data(), and CBuf::size().

00160 {
00161         // If it's the start of a new transmission, grab info from dest, 
00162         // and execute callback
00163         if (curdata_ == 0)
00164                 curdata_ = dst_->rcvr_retrieve_data();
00165         if (curdata_ == 0) {
00166                 fprintf(stderr, "[%g] %s receives a packet but no callback!\n",
00167                         Scheduler::instance().clock(), name_);
00168                 return;
00169         }
00170         curbytes_ += size;
00171 #ifdef TCPAPP_DEBUG
00172         fprintf(stderr, "[%g] %s gets data size %d, %s\n", 
00173                 Scheduler::instance().clock(), name(), curbytes_, 
00174                 curdata_->data());
00175 #endif
00176         if (curbytes_ == curdata_->bytes()) {
00177                 // We've got exactly the data we want
00178                 // If we've received all data, execute the callback
00179                 process_data(curdata_->size(), curdata_->data());
00180                 // Then cleanup this data transmission
00181                 delete curdata_;
00182                 curdata_ = NULL;
00183                 curbytes_ = 0;
00184         } else if (curbytes_ > curdata_->bytes()) {
00185                 // We've got more than we expected. Must contain other data.
00186                 // Continue process callbacks until the unfinished callback
00187                 while (curbytes_ >= curdata_->bytes()) {
00188                         process_data(curdata_->size(), curdata_->data());
00189                         curbytes_ -= curdata_->bytes();
00190 #ifdef TCPAPP_DEBUG
00191                         fprintf(stderr, 
00192                                 "[%g] %s gets data size %d(left %d)\n", 
00193                                 Scheduler::instance().clock(), 
00194                                 name(),
00195                                 curdata_->bytes(), curbytes_);
00196                                 //curdata_->data());
00197 #endif
00198                         delete curdata_;
00199                         curdata_ = dst_->rcvr_retrieve_data();
00200                         if (curdata_ != 0)
00201                                 continue;
00202                         if ((curdata_ == 0) && (curbytes_ > 0)) {
00203                                 fprintf(stderr, "[%g] %s gets extra data!\n",
00204                                         Scheduler::instance().clock(), name_);
00205                                 Tcl::instance().eval("[Simulator instance] flush-trace");
00206                                 abort();
00207                         } else
00208                                 // Get out of the look without doing a check
00209                                 break;
00210                 }
00211         }
00212 }

Here is the call graph for this function:

void TcpApp::resume  )  [virtual]
 

Reimplemented from Application.

Definition at line 214 of file tcpapp.cc.

00215 {
00216         // Do nothing
00217 }

void Application::send int  nbytes  )  [virtual, inherited]
 

Definition at line 109 of file app.cc.

References Application::agent_, and Agent::sendmsg().

Referenced by Application::command(), send(), and TrafficGenerator::timeout().

00110 {
00111         agent_->sendmsg(nbytes);
00112 }

Here is the call graph for this function:

void TcpApp::send int  nbytes,
AppData data
[virtual]
 

Reimplemented in HttpUInvalAgent.

Definition at line 148 of file tcpapp.cc.

References cbuf_, Scheduler::clock(), CBufList::insert(), Scheduler::instance(), and Application::send().

Referenced by command(), HttpApp::command(), and HttpUInvalAgent::send().

00149 {
00150         CBuf *p = new CBuf(cbk, nbytes);
00151 #ifdef TCPAPP_DEBUG
00152         p->time() = Scheduler::instance().clock();
00153 #endif
00154         cbuf_.insert(p);
00155         Application::send(nbytes);
00156 }

Here is the call graph for this function:

virtual void Process::send_data int  size,
AppData data = 0
[inline, virtual, inherited]
 

Definition at line 106 of file ns-process.h.

References Process::process_data(), and Process::target_.

Referenced by process_data(), and MediaApp::process_data().

00106                                                             {
00107                 if (target_)
00108                         target_->process_data(size, data);
00109         }

Here is the call graph for this function:

virtual void TcpApp::start void   )  [inline, protected, virtual]
 

Reimplemented from Application.

Definition at line 107 of file tcpapp.h.

References abort().

00107 { abort(); } 

Here is the call graph for this function:

virtual void TcpApp::stop void   )  [inline, protected, virtual]
 

Reimplemented from Application.

Definition at line 108 of file tcpapp.h.

References abort().

00108 { abort(); }

Here is the call graph for this function:

Process*& Process::target  )  [inline, inherited]
 

Definition at line 97 of file ns-process.h.

References Process::target_.

Referenced by QA::check_availability(), Process::command(), HttpApp::command(), MediaApp::get_data(), QA::output(), and process_data().

00097 { return target_; }


Member Data Documentation

Agent* Application::agent_ [protected, inherited]
 

Definition at line 60 of file app.h.

Referenced by Application::command(), RA_Traffic::init(), POO_Traffic::init(), EXPOO_Traffic::init(), CBR_Traffic::init(), CBR_PP_Traffic::init(), QA::rap(), MediaApp::rap(), Application::send(), TcpApp(), TrafficTrace::timeout(), TelnetApp::timeout(), EXPOO_Traffic::timeout(), CBR_PP_Traffic::timeout(), and ~TcpApp().

CBufList TcpApp::cbuf_ [protected]
 

Definition at line 111 of file tcpapp.h.

Referenced by rcvr_retrieve_data(), and send().

int TcpApp::curbytes_ [protected]
 

Definition at line 113 of file tcpapp.h.

Referenced by recv().

CBuf* TcpApp::curdata_ [protected]
 

Definition at line 112 of file tcpapp.h.

Referenced by recv().

TcpApp* TcpApp::dst_ [protected]
 

Definition at line 110 of file tcpapp.h.

Referenced by command(), connect(), and recv().

int Application::enableRecv_ [protected, inherited]
 

Definition at line 61 of file app.h.

Referenced by Application::command(), and Application::recv().

int Application::enableResume_ [protected, inherited]
 

Definition at line 62 of file app.h.

Referenced by Application::command(), and Application::resume().

Process* Process::target_ [protected, inherited]
 

Definition at line 113 of file ns-process.h.

Referenced by HttpUInvalAgent::command(), Process::Process(), HttpUInvalAgent::process_data(), Process::send_data(), and Process::target().


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