• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/apps/worm.h

00001 // worm propagation model
00002 
00003 #ifndef ns_worm_h
00004 #define ns_worm_h
00005 
00006 #include "timer-handler.h"
00007 #include "app.h"
00008 
00009 class WormApp;
00010 
00011 // timer to control worm scan rate, etc
00012 class ProbingTimer : public TimerHandler {
00013  public:
00014   ProbingTimer(WormApp* t) : TimerHandler(), t_(t) {};
00015   inline virtual void expire(Event*);
00016  protected:
00017   WormApp* t_;
00018 };
00019 
00020 // base class, by default hosts are NOT vulnerable
00021 class WormApp : public  Application {
00022  public:
00023   WormApp();
00024 
00025   // timer handler
00026   virtual void timeout();
00027   // agent call back function
00028   void process_data(int, AppData*);
00029 
00030   virtual int command(int argc, const char*const* argv);
00031 
00032  protected:
00033   // need to define recv and timeout 
00034   virtual void recv(int nbytes);
00035 
00036   // id of the node attached
00037   unsigned long  my_addr_;
00038 
00039   // the toal Internet address space
00040   static double total_addr_;
00041   // flag to record first probe
00042   static int first_probe_;
00043 
00044   // configs for worm probing behavior
00045   double scan_rate_;
00046   int scan_port_;
00047   int p_size_;
00048 };
00049 
00050 // model invulnerable hosts in detailed networks
00051 class DnhWormApp : public WormApp {
00052  public:
00053   DnhWormApp();
00054 
00055   // timer handler
00056   void timeout();
00057 
00058   int command(int argc, const char*const* argv);
00059 
00060  protected:
00061   void recv(int nbytes);
00062 
00063   void send_probe();
00064   void probe();
00065 
00066   bool infected_;
00067   static unsigned long infect_total_;
00068 
00069   ProbingTimer *timer_;
00070 
00071   // control the rate of probing
00072   double p_inv_;
00073 
00074   // the address space of my networks
00075   static unsigned long addr_low_, addr_high_;
00076   
00077   // the probability to scan local hosts
00078   static float local_p_;
00079   
00080   // the access point to other networks like AN
00081   static unsigned long default_gw_;
00082 };
00083 
00084 // model a network with SIR model
00085 class AnWormApp : public WormApp {
00086  public:
00087   AnWormApp();
00088 
00089   // timer handler
00090   void timeout();
00091 
00092   int command(int argc, const char*const* argv);
00093 
00094  protected:
00095   void start();
00096   void update();
00097  
00098   void recv(int nbytes);
00099 
00100   void probe(int);
00101 
00102   ProbingTimer *timer_;
00103 
00104   int time_step_;
00105 
00106   // the address space of my networks
00107   unsigned long addr_low_, addr_high_;
00108   unsigned long dn_low_, dn_high_;
00109 
00110   // SIR model states:
00111   double s_, i_, r_, s_max_, n_;
00112   double v_percentage_;
00113   double beta_, gamma_;
00114 
00115   // interaction with DN
00116   double probe_in, probe_recv;
00117   double probe_out;
00118 };
00119 
00120 
00121 #endif

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