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

agent.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1993-1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/agent.h,v 1.35 2002/12/22 16:43:24 sfloyd Exp $ (LBL)
00035  */
00036 
00037 #ifndef ns_agent_h
00038 #define ns_agent_h
00039 
00040 #include "connector.h"
00041 #include "packet.h"
00042 #include "timer-handler.h"
00043 #include "ns-process.h"
00044 #include "app.h"
00045 //#include "basetrace.h"
00046 #define TIME_FORMAT "%.15g"
00047 // TIME_FORMAT is in basetrace.h, but including that header leads to problems
00048 
00049 
00050 #define TIMER_IDLE 0
00051 #define TIMER_PENDING 1
00052 
00053 /* 
00054  * Note that timers are now implemented using timer-handler.{cc,h}
00055  */
00056 
00057 #define TRACEVAR_MAXVALUELENGTH 128
00058 
00059 class Application;
00060 
00061 
00062 // store old value of traced vars
00063 // work only for TracedVarTcl
00064 struct OldValue {
00065         TracedVar *var_;
00066         char val_[TRACEVAR_MAXVALUELENGTH];
00067         struct OldValue *next_;
00068 };
00069 
00070 class EventTrace;
00071 class Agent : public Connector {
00072  public:
00073         Agent(packet_t pktType);
00074         virtual ~Agent();
00075         void recv(Packet*, Handler*);
00076         
00077         //added for edrop tracing - ratul
00078         void recvOnly(Packet *) {};
00079 
00080         void send(Packet* p, Handler* h) { target_->recv(p, h); }
00081         virtual void timeout(int tno);
00082 
00083         virtual void sendmsg(int sz, AppData*, const char* flags = 0);
00084         virtual void send(int sz, AppData *data) { sendmsg(sz, data, 0); }
00085         virtual void sendto(int sz, AppData*, const char* flags,
00086                             nsaddr_t dst);
00087 
00088         virtual void sendmsg(int nbytes, const char *flags = 0);
00089         virtual void send(int nbytes) { sendmsg(nbytes); }
00090         virtual void sendto(int nbytes, const char* flags, nsaddr_t dst);
00091         virtual void connect(nsaddr_t dst);
00092         virtual void close();
00093         virtual void listen();
00094         virtual void attachApp(Application* app);
00095         virtual int& size() { return size_; }
00096         inline nsaddr_t& addr() { return here_.addr_; }
00097         inline nsaddr_t& port() { return here_.port_; }
00098         inline nsaddr_t& daddr() { return dst_.addr_; }
00099         inline nsaddr_t& dport() { return dst_.port_; }
00100         void set_pkttype(packet_t pkttype) { type_ = pkttype; }
00101         inline packet_t get_pkttype() { return type_; }
00102 
00103  protected:
00104         int command(int argc, const char*const* argv);
00105         virtual void delay_bind_init_all();
00106         virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00107 
00108         virtual void recvBytes(int bytes);
00109         virtual void idle();
00110         Packet* allocpkt() const;       // alloc + set up new pkt
00111         Packet* allocpkt(int) const;    // same, but w/data buffer
00112         void initpkt(Packet*) const;    // set up fields in a pkt
00113 
00114         ns_addr_t here_;                // address of this agent
00115         ns_addr_t dst_;                 // destination address for pkt flow
00116         int size_;                      // fixed packet size
00117         packet_t type_;                 // type to place in packet header
00118         int fid_;                       // for IPv6 flow id field
00119         int prio_;                      // for IPv6 prio field
00120         int flags_;                     // for experiments (see ip.h)
00121         int defttl_;                    // default ttl for outgoing pkts
00122 
00123 #ifdef notdef
00124         int seqno_;             /* current seqno */
00125         int class_;             /* class to place in packet header */
00126 #endif
00127 
00128         static int uidcnt_;
00129 
00130         Tcl_Channel channel_;
00131         char *traceName_;               // name used in agent traces
00132         OldValue *oldValueList_; 
00133 
00134         Application *app_;              // ptr to application for callback
00135 
00136         virtual void trace(TracedVar *v);
00137         void deleteAgentTrace();
00138         void addAgentTrace(const char *name);
00139         void monitorAgentTrace();
00140         OldValue* lookupOldValue(TracedVar *v);
00141         void insertOldValue(TracedVar *v, const char *value);
00142         void dumpTracedVars();
00143 
00144         /* support for event-tracing */
00145         EventTrace *et_;
00146         virtual void trace_event(char *eventtype){}
00147 
00148  private:
00149         void flushAVar(TracedVar *v);
00150 };
00151 
00152 #endif
00153 

Generated on Tue Apr 20 12:14:10 2004 for NS2.26SourcesOriginal by doxygen 1.3.3