File: worm.h

package info (click to toggle)
ns2 2.35%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,780 kB
  • ctags: 27,490
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (121 lines) | stat: -rw-r--r-- 2,264 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// worm propagation model

#ifndef ns_worm_h
#define ns_worm_h

#include "timer-handler.h"
#include "app.h"

class WormApp;

// timer to control worm scan rate, etc
class ProbingTimer : public TimerHandler {
 public:
  ProbingTimer(WormApp* t) : TimerHandler(), t_(t) {};
  inline virtual void expire(Event*);
 protected:
  WormApp* t_;
};

// base class, by default hosts are NOT vulnerable
class WormApp : public  Application {
 public:
  WormApp();

  // timer handler
  virtual void timeout();
  // agent call back function
  void process_data(int, AppData*);

  virtual int command(int argc, const char*const* argv);

 protected:
  // need to define recv and timeout 
  virtual void recv(int nbytes);

  // id of the node attached
  unsigned long  my_addr_;

  // the toal Internet address space
  static double total_addr_;
  // flag to record first probe
  static int first_probe_;

  // configs for worm probing behavior
  double scan_rate_;
  int scan_port_;
  int p_size_;
};

// model invulnerable hosts in detailed networks
class DnhWormApp : public WormApp {
 public:
  DnhWormApp();

  // timer handler
  void timeout();

  int command(int argc, const char*const* argv);

 protected:
  void recv(int nbytes);

  void send_probe();
  void probe();

  bool infected_;
  static unsigned long infect_total_;

  ProbingTimer *timer_;

  // control the rate of probing
  double p_inv_;

  // the address space of my networks
  static unsigned long addr_low_, addr_high_;
  
  // the probability to scan local hosts
  static float local_p_;
  
  // the access point to other networks like AN
  static unsigned long default_gw_;
};

// model a network with SIR model
class AnWormApp : public WormApp {
 public:
  AnWormApp();

  // timer handler
  void timeout();

  int command(int argc, const char*const* argv);

 protected:
  void start();
  void update();
 
  void recv(int nbytes);

  void probe(int);

  ProbingTimer *timer_;

  int time_step_;

  // the address space of my networks
  unsigned long addr_low_, addr_high_;
  unsigned long dn_low_, dn_high_;

  // SIR model states:
  double s_, i_, r_, s_max_, n_;
  double v_percentage_;
  double beta_, gamma_;

  // interaction with DN
  double probe_in, probe_recv;
  double probe_out;
};


#endif