• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/common/agent.h

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

Generated on Tue Aug 10 2010 16:16:06 for ns-2.33 by  doxygen 1.7.1