MpduGen.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Copyright (C) 2015 OpenSim Ltd.
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. //
  17. // Author: Benjamin Seregi
  18. //
  19. #ifndef __INET_MPDUGEN_H
  20. #define __INET_MPDUGEN_H
  21. #include "inet/common/INETDefs.h"
  22. #include "inet/applications/base/ApplicationBase.h"
  23. #include "inet/transportlayer/contract/udp/UDPSocket.h"
  24. namespace inet {
  25. /*
  26. * A very simple MPDU generator class.
  27. */
  28. class MpduGen : public ApplicationBase
  29. {
  30. protected:
  31. int localPort = -1, destPort = -1;
  32. UDPSocket socket;
  33. static simsignal_t sentPkSignal;
  34. static simsignal_t rcvdPkSignal;
  35. cMessage *selfMsg = nullptr;
  36. int numSent = 0;
  37. int numReceived = 0;
  38. protected:
  39. virtual int numInitStages() const override { return NUM_INIT_STAGES; }
  40. virtual void initialize(int stage) override;
  41. virtual void sendPackets();
  42. void processPacket(cPacket *pk);
  43. virtual void handleMessageWhenUp(cMessage* msg);
  44. public:
  45. MpduGen() {}
  46. ~MpduGen() { cancelAndDelete(selfMsg); }
  47. };
  48. }
  49. #endif