I need to implement timer in Omnet++. Scenario : There are 2 nodes(Say A and B). Node A sends a msg to node B. Then a timer need to be started. If it doesnot receive any msg from node B within a specific period, the connection should end.
Asked
Active
Viewed 159 times
1
-
1I wonder how beneficial the C++ tag is to this question. It attracts a lot of extra eyes to the question, but relatively few will be able to help you because they aren't familiar, or familiar enough, with omnet. – user4581301 Feb 17 '22 at 00:12
1 Answers
4
In OMNeT++
timer is a message that is scheduled to trigger in the future in that module using scheduleAt()
. That message is called "selfmessage" and it is used to implement "timer".
When the selfmessage occurs, handleMessage()
is called - just like for any other message.
In short: to implement selfmessage one should:
- Declare and then create an instance of
cMessage
. - Schedule that message using:
scheduleAt(simTime() + somePeriod, someMessage)
where simTime()
returns current simulation time.
- In
handleMessage()
recognize that selfmessage, for example usingisSelfMessage()
, and call desired code.
Moreover, take a look at TicToc examples: TicToc doumentation - 3.6 Modeling processing delay

Jerzy D.
- 6,707
- 2
- 16
- 22