TCPTester.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // Copyright (C) 2004 Andras Varga
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. //
  18. #ifndef __TCPTESTER_H
  19. #define __TCPTESTER_H
  20. #include "inet/common/INETDefs.h"
  21. #include "inet/networklayer/contract/ipv4/IPv4Address.h"
  22. #include "inet/networklayer/ipv4/IPv4Datagram_m.h"
  23. #include "inet/transportlayer/tcp_common/TCPSegment.h"
  24. #include "inet/common/packet/PacketDump.h"
  25. namespace inet {
  26. namespace tcp {
  27. /**
  28. * Base class for TCP testing modules.
  29. */
  30. class INET_API TCPTesterBase : public cSimpleModule
  31. {
  32. protected:
  33. int fromASeq;
  34. int fromBSeq;
  35. PacketDump tcpdump;
  36. protected:
  37. void dump(TCPSegment *seg, bool fromA, const char *comment=NULL);
  38. public:
  39. TCPTesterBase();
  40. virtual void initialize();
  41. virtual void finish();
  42. };
  43. /**
  44. * Dumps every packet using the PacketDump class, and in addition it can delete,
  45. * delay or duplicate TCP segments, and insert new segments.
  46. *
  47. * Script format: see NED documentation.
  48. */
  49. class INET_API TCPScriptableTester : public TCPTesterBase
  50. {
  51. protected:
  52. enum {CMD_DELETE,CMD_COPY}; // "delay" is same as "copy"
  53. typedef std::vector<simtime_t> DelayVector;
  54. struct Command
  55. {
  56. bool fromA; // direction
  57. int segno; // segment number
  58. int command; // CMD_DELETE, CMD_COPY
  59. DelayVector delays; // arg list
  60. };
  61. typedef std::vector<Command> CommandVector;
  62. CommandVector commands;
  63. protected:
  64. void parseScript(const char *script);
  65. void dispatchSegment(TCPSegment *seg);
  66. void processIncomingSegment(TCPSegment *seg, bool fromA);
  67. public:
  68. TCPScriptableTester() {}
  69. virtual void initialize();
  70. virtual void handleMessage(cMessage *msg);
  71. };
  72. /**
  73. * Randomly delete, delay etc packets.
  74. */
  75. class INET_API TCPRandomTester : public TCPTesterBase
  76. {
  77. protected:
  78. double pdelete;
  79. double pdelay;
  80. double pcopy;
  81. cPar *numCopies;
  82. cPar *delay;
  83. protected:
  84. void dispatchSegment(TCPSegment *seg);
  85. void processIncomingSegment(TCPSegment *seg, bool fromA);
  86. public:
  87. TCPRandomTester() {}
  88. virtual void initialize();
  89. virtual void handleMessage(cMessage *msg);
  90. };
  91. } // namespace tcp
  92. } // namespace inet
  93. #endif