close Warning: BrowserModule failed with ConfigurationError: Look in the Trac log for more information.

Changes between Version 17 and Version 18 of OverSimDevelop


Ignore:
Timestamp:
Apr 20, 2009, 10:24:41 AM (16 years ago)
Author:
heep
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OverSimDevelop

    v17 v18  
    256256// initializeApp is called when the module is being created.
    257257// Use this function instead of the constructor for initializing variables.
    258 void MyApplication::initializeApp(int stage) {
    259 
     258void MyApplication::initializeApp(int stage)
     259{
    260260    // initializeApp will be called twice, each with a different stage.
    261261    // stage can be either MIN_STAGE_APP (this module is being created), or MAX_STAGE_APP (all modules were created).
     
    289289// finalize is called when the module is being destroyed
    290290
    291 void MyApplication::finishApp() {
    292 
     291void MyApplication::finishApp()
     292{
    293293    // first we'll delete our timer
    294294
     
    317317
    318318        for (int i = 0; i < numToSend; i++) {
    319 
    320319            OverlayKey randomKey(intuniform(1, largestKey)); // let's create a random key
    321320
     
    362361// Unhandled or unknown packets can be safely deleted here.
    363362
    364 void MyApplication::handleUDPMessage(cMessage* msg) {
     363void MyApplication::handleUDPMessage(cMessage* msg)
     364{
    365365    // we are only expecting messages of type MyMessage
    366366
     
    387387#!cpp
    388388class MyOverlay : public BaseOverlay {
    389 public:
    390 
     389  public:
    391390    // Routing parameters
    392391    int myKey;               // our overlay key
     
    408407    // obligatory: called when we need the next hop to route a packet to the given key
    409408    NodeVector* findNode(const OverlayKey& key,             // key to route to
    410                                  int numRedundantNodes,     // how many candidates for next hop we want (see getMaxNumSiblings)
    411                                  int numSiblings,           // how many siblings we'll return (?) (see getMaxRedundantNodes)
    412                                  BaseOverlayMessage* msg);  // message being routed
     409                         int numRedundantNodes,             // how many candidates for next hop we want (see getMaxNumSiblings)
     410                         int numSiblings,                   // how many siblings we'll return (?) (see getMaxRedundantNodes)
     411                         BaseOverlayMessage* msg);          // message being routed
    413412
    414413    // obligatory: In general, called when we need to know whether node is amongst numSiblings closest nodes to key.
    415414    // But normally it is called with node set to this node, and asking whether this node is responsible for key.
    416415    bool isSiblingFor(const NodeHandle& node,               // which node (usually thisNode) we're referring to
    417                                  const OverlayKey& key,     // key in question
    418                                  int numSiblings,           // how many siblings we're querying about
    419                                  bool* err);                // set to false when we couldn't determine the range
     416                      const OverlayKey& key,                // key in question
     417                      int numSiblings,                      // how many siblings we're querying about
     418                      bool* err);                           // set to false when we couldn't determine the range
    420419
    421420    // obligatory: Set the maximum number of siblings that can be queried about (usually 1)
     
    479478// Return whether we know if the given node is responsible for the key
    480479bool MyOverlay::isSiblingFor(const NodeHandle& node,
    481                                  const OverlayKey& key,
    482                                  int numSiblings,
    483                                  bool* err)
     480                             const OverlayKey& key,
     481                             int numSiblings,
     482                             bool* err)
    484483{
    485484    if (node == thisNode && key == thisNode.key) { // is it our node and our key?
     
    491490// Return the next step for the routing of the given message
    492491NodeVector *MyOverlay::findNode(const OverlayKey& key,
    493                                  int numRedundantNodes,
    494                                  int numSiblings,
    495                                  BaseOverlayMessage* msg)
     492                                int numRedundantNodes,
     493                                int numSiblings,
     494                                BaseOverlayMessage* msg)
    496495{
    497496    NodeVector* nextHops;
     
    674673Now we need to build !OverSim. There are two types of builds: debug (no optimizations, include debug information) and release (optimizations, with reduced debug information). Go to the root folder and type one of the following:
    675674
     675{{{
     676#!sh
    676677make MODE=release   # release mode
    677678make MODE=debug     # debug mode
    678679make                # also sets debug mode
     680}}}
    679681
    680682That should compile your new modules. To clear all compiled files, use make clean as usual.
     
    771773{{{
    772774#!cpp
    773     void MyOverlay::getNeighbors(const OverlayKey &neighborKey) {
    774         MyNeighborCall *msg = new MyNeighborCall();
    775         msg->setDestinationKey(neighborKey);
    776 
    777         // The function we'll be using to send an RPC is sendRouteRpcCall.
    778         // The first value is to which tier we'll be talking. Can be either OVERLAY_COMP, TIER1_COMP, TIER2_COMP, and so on.
    779         // The second parameter is the node to which we'll send the message. Can be either an OverlayKey or a TransportAddress.
    780         // The third parameter is the message.
    781         sendRouteRpcCall(OVERLAY_COMP, neighborKey, msg);
     775void MyOverlay::getNeighbors(const OverlayKey &neighborKey)
     776{
     777    MyNeighborCall *msg = new MyNeighborCall();
     778    msg->setDestinationKey(neighborKey);
     779
     780    // The function we'll be using to send an RPC is sendRouteRpcCall.
     781    // The first value is to which tier we'll be talking. Can be either OVERLAY_COMP, TIER1_COMP, TIER2_COMP, and so on.
     782    // The second parameter is the node to which we'll send the message. Can be either an OverlayKey or a TransportAddress.
     783    // The third parameter is the message.
     784    sendRouteRpcCall(OVERLAY_COMP, neighborKey, msg);
     785}
     786}}}
     787
     788Now, let's see how the RPC calls are implemented:
     789
     790{{{
     791#!cpp
     792// Handle an incoming Call message
     793// Only delete msg if the RPC is handled here, and you won't respond using sendRpcResponse!
     794
     795bool MyOverlay::handleRpcCall(BaseCallMessage *msg) {
     796   
     797    // There are many macros to simplify the handling of RPCs. The full list is in <OverSim>/src/common/RpcMacros.h.
     798   
     799    // start a switch
     800    RPC_SWITCH_START(msg);
     801       
     802    // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!)
     803    RPC_ON_CALL(MyNeighbor) {
     804        MyNeighborCall *mrpc = (MyNeighborCall*)msg;          // get Call message
     805        MyNeighborResponse *rrpc = new MyNeighborResponse();  // create response
     806        rrpc->setRespondingNode(thisNode);
     807        rrpc->setPrevNeighbor(prevNode);
     808        rrpc->setNextNeighbor(nextNode);
     809           
     810        // now send the response. sendRpcResponse can automatically tell where to send it to.
     811        // note that sendRpcResponse will delete mrpc (aka msg)!
     812        sendRpcResponse(mrpc, rrpc);
     813   
     814        RPC_HANDLED = true;  // set to true, since we did handle this RPC (default is false)
    782815    }
    783 }}}
    784 
    785 Now, let's see how the RPC calls are implemented:
    786 
    787 {{{
    788 #!cpp
    789     // Handle an incoming Call message
    790     // Only delete msg if the RPC is handled here, and you won't respond using sendRpcResponse!
    791 
    792     bool MyOverlay::handleRpcCall(BaseCallMessage *msg) {
    793        
    794         // There are many macros to simplify the handling of RPCs. The full list is in <OverSim>/src/common/RpcMacros.h.
    795        
    796         // start a switch
    797         RPC_SWITCH_START(msg);
    798        
    799         // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!)
    800         RPC_ON_CALL(MyNeighbor) {
    801             MyNeighborCall *mrpc = (MyNeighborCall*)msg;          // get Call message
    802 
    803             MyNeighborResponse *rrpc = new MyNeighborResponse();  // create response
    804             rrpc->setRespondingNode(thisNode);
    805             rrpc->setPrevNeighbor(prevNode);
    806             rrpc->setNextNeighbor(nextNode);
    807            
    808             // now send the response. sendRpcResponse can automatically tell where to send it to.
    809             // note that sendRpcResponse will delete mrpc (aka msg)!
    810             sendRpcResponse(mrpc, rrpc);
    811    
    812             RPC_HANDLED = true;  // set to true, since we did handle this RPC (default is false)
    813         }
    814 
    815         // end the switch
    816         RPC_SWITCH_END();
    817 
    818         // return whether we handled the message or not.
    819         // don't delete unhandled messages!
    820         return RPC_HANDLED;
    821     }
    822 
    823     // Called when an RPC we sent has timed out.
    824     // Don't delete msg here!
    825 
    826     void MyOverlay::handleRpcTimeout(BaseCallMessage* msg,
    827                              const TransportAddress& dest,
    828                              cPolymorphic* context, int rpcId,
    829                              const OverlayKey&)
    830     {
    831         // Same macros as in handleRpc
    832 
    833         // start a switch
    834         RPC_SWITCH_START(msg);
    835        
     816
     817    // end the switch
     818    RPC_SWITCH_END();
     819
     820    // return whether we handled the message or not.
     821    // don't delete unhandled messages!
     822    return RPC_HANDLED;
     823}
     824
     825// Called when an RPC we sent has timed out.
     826// Don't delete msg here!
     827void MyOverlay::handleRpcTimeout(BaseCallMessage* msg,
     828                                 const TransportAddress& dest,
     829                                 cPolymorphic* context, int rpcId,
     830                                 const OverlayKey&)
     831{
     832    // Same macros as in handleRpc
     833
     834    // start a switch
     835    RPC_SWITCH_START(msg);       
    836836        // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!)
    837837        RPC_ON_CALL(MyNeighbor) {
     
    839839            callbackTimeout(mrpc->getDestinationKey());           // call our interface function
    840840        }
    841         // end the switch
    842         RPC_SWITCH_END();
    843     }
     841    // end the switch
     842    RPC_SWITCH_END();
     843}
    844844
    845845    // Called when we receive an RPC response from another node.
    846846    // Don't delete msg here!
    847847
    848     void MyOverlay::handleRpcResponse(BaseResponseMessage* msg,
    849                               cPolymorphic* context,
    850                               int rpcId,
    851                               simtime_t rtt)
    852     {
    853         // The macros are here similar. Just use RPC_ON_RESPONSE instead of RPC_ON_CALL.
    854 
    855         // start a switch
    856         RPC_SWITCH_START(msg);
    857        
     848void MyOverlay::handleRpcResponse(BaseResponseMessage* msg,
     849                                  cPolymorphic* context,
     850                                  int rpcId,
     851                                  simtime_t rtt)
     852{
     853    // The macros are here similar. Just use RPC_ON_RESPONSE instead of RPC_ON_CALL.
     854
     855    // start a switch
     856    RPC_SWITCH_START(msg);       
    858857        // enters the following block if the message is of type MyNeighborResponse (note the shortened parameter!)
    859858        RPC_ON_RESPONSE(MyNeighbor) {
     
    863862                        mrpc->getNextNeighbor());                         // call our interface function
    864863        }
    865         // end the switch
    866         RPC_SWITCH_END();
    867     }
     864    // end the switch
     865    RPC_SWITCH_END();
     866}
    868867}}}
    869868