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.36 2003/10/05 06:20:30 xuanc 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     virtual void sendto(int sz, AppData*, const char* flags,
00088                 ns_addr_t dst);
00089 
00090     virtual void sendmsg(int nbytes, const char *flags = 0);
00091     virtual void send(int nbytes) { sendmsg(nbytes); }
00092     virtual void sendto(int nbytes, const char* flags, nsaddr_t dst);
00093     virtual void sendto(int nbytes, const char* flags, ns_addr_t dst);
00094     virtual void connect(nsaddr_t dst);
00095     virtual void close();
00096     virtual void listen();
00097     virtual void attachApp(Application* app);
00098     virtual int& size() { return size_; }
00099     inline nsaddr_t& addr() { return here_.addr_; }
00100     inline nsaddr_t& port() { return here_.port_; }
00101     inline nsaddr_t& daddr() { return dst_.addr_; }
00102     inline nsaddr_t& dport() { return dst_.port_; }
00103     void set_pkttype(packet_t pkttype) { type_ = pkttype; }
00104     inline packet_t get_pkttype() { return type_; }
00105 
00106  protected:
00107     int command(int argc, const char*const* argv);
00108     virtual void delay_bind_init_all();
00109     virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00110 
00111     virtual void recvBytes(int bytes);
00112     virtual void idle();
00113     Packet* allocpkt() const;   // alloc + set up new pkt
00114     Packet* allocpkt(int) const;    // same, but w/data buffer
00115     void initpkt(Packet*) const;    // set up fields in a pkt
00116 
00117     ns_addr_t here_;        // address of this agent
00118     ns_addr_t dst_;         // destination address for pkt flow
00119     int size_;          // fixed packet size
00120     packet_t type_;         // type to place in packet header
00121     int fid_;           // for IPv6 flow id field
00122     int prio_;          // for IPv6 prio field
00123     int flags_;         // for experiments (see ip.h)
00124     int defttl_;            // default ttl for outgoing pkts
00125 
00126 #ifdef notdef
00127     int seqno_;     /* current seqno */
00128     int class_;     /* class to place in packet header */
00129 #endif
00130 
00131     static int uidcnt_;
00132 
00133     Tcl_Channel channel_;
00134     char *traceName_;       // name used in agent traces
00135     OldValue *oldValueList_; 
00136 
00137     Application *app_;      // ptr to application for callback
00138 
00139     virtual void trace(TracedVar *v);
00140     void deleteAgentTrace();
00141     void addAgentTrace(const char *name);
00142     void monitorAgentTrace();
00143     OldValue* lookupOldValue(TracedVar *v);
00144     void insertOldValue(TracedVar *v, const char *value);
00145     void dumpTracedVars();
00146 
00147     /* support for event-tracing */
00148         EventTrace *et_;
00149         virtual void trace_event(char *eventtype){}
00150 
00151  private:
00152     void flushAVar(TracedVar *v);
00153 };
00154 
00155 #endif
00156 

Generated on Tue Mar 6 16:47:43 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6