Constructor
Can be use to set message to NULL. Better not to skip defining the constructor.Destructor
Can be use to clear/delete messages using cancelAndDelete(). New version seems to be motivating to use a destructor so better not to skip.void initializeApp(int stage)
Can be used to initialize the application, read parameters from omnet.ini file, set statistic collectors, GUI display variables, start timers, set UDP port, etc.
- stage - Indicate which stage your are in. MIN_STAGE_APP indicates this module is being created while MAX_STAGE_APP indicates all modules were created. We typically need MIN_STAGE_APP to initialize application & variables.
void finishApp()
Called when application is terminating. Can be used to summarize stat. New version seems to be motivating us to delete messages in the destructor.void handleTimerEvent(cMessage* msg)
Handle event timer. Use to generate new periodic messages, other events, or check for lost messages. Better not to generate messages until underlay is initialized (unless you need this specific behavior) void deliver(OverlayKey& key, cMessage* msg)
Handle messages delivered from overlay. Called only at the node that is believed to be the application responsible for the key.
- key - Destination key
- msg - Dynamically cast msg before using because message type is cPacket. Delete msg if no longer needed. Latency can be determined from msg->getCreationTime(). Use control data (msg->removeControlInfo()) to extract hop count using getHopCount() method.
void forward(OverlayKey* key, cPacket** msg, NodeHandle* nextHopNode)
Handle messages from overlay to be forwarded. Call in each intermediate node along the path. Can skip this if you don't need to do anything. Useful for appending list of visited nodes or to look up local cache. Also useful while implementing malicious nodes that drop messages.- key - Destination key
- nextHopNode - Node to be used as the next hop
Handle messages delivered directly through UDP.
- msg - Dynamically cast msg before using because message type is cPacket. Delete msg if no longer needed.
bool handleRpcCall(BaseCallMessage* msg)
Handle RPC call message from another node or upper layer. Use many predefined functions to easily handle the message.- Return true if RPC is handled
void handleRpcResponse(BaseResponseMessage* msg, cPolymorphic* context, int rpcId, simtime_t rtt)
Handle RPC response from callee. - msg - Use msg->getCallHopCount()to determine number of hops that call message took. Use control data (msg->removeControlInfo() or msg->getControlInfo()) to extract response message's hop count using getCallHopCount() method. To determine latency context->requestTime() can be used.
- context - Pointer to an optional state object.
- rpcId - RPC identifier.
- rtt - Round trip time for RPC call & corresponding response.
void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest, cPolymorphic* context, int rpcId, const OverlayKey& destKey)
Handle RPC timeout event. Can be used to retry by generating new call or indicate failure. - dest - Destination node
- context - Pointer to an optional state object.
- rpcId - RPC identifier.
- destKey - Destination key
This method gets call when node waits some time before leaving (kill) the network. Delay in Seconds is set using **.gracefulLeaveDelay. Can be use to call any node clean up call & advice node not to issue any more messages.
Comments
At first, I would like to say thank you. Your articles about Oversim are great and very useful.
I have some questions about it.
There are 2 main layers in KBRTestApp -> overlay (it could be kademlia, pastry, whatever else) and application itself. Where is the line between these two layers? Or is there any line at all? I mean with communication. What is each layer responsible for? For example: each layer has method handleRpcCall. I'm not quite sure what should be taken care of in each of these methods.
Thank you for any ideas.
Martin Ladecky
In terms of implementation, line is defined whether you implement your code inside src/application or src/overlay directories.
At each layer, you are expected handle messages send to that layer using handleRpcCall(). Which layer to send the message is indicated when you call sendRouteRpcCall().
For e.g., if you say sendRouteRpcCall(TIER1_COMP, dest.first, call, context);
it will automatically call handleRpcCall() in application (TIER1_COMP) layer. Also see Chord example.
I am new in using the OverSim and Omnetpp,
I have A Question, that whether we can implement our project using only Applciation layer by not envoling Overlay layer,i.e. Connecting Applcaition Nodes, and Sending and Receiving Message by not envolving the Overlay layer.
Thanks in Advance
Thx again!