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

Changes between Version 16 and Version 17 of OverSimDevelop


Ignore:
Timestamp:
Apr 20, 2009, 10:10:38 AM (15 years ago)
Author:
heep
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OverSimDevelop

    v16 v17  
    4040
    4141{{{
    42 
     42#!cpp
    4343// sets the package, the name must match the path to the module (from src/ upwards)
    4444package oversim.overlay.myoverlay;
     
    6363
    6464{{{
     65#!cpp
    6566// sets the package, the name must match the path to the module (from src/ upwards)
    6667package oversim.applications.myapplication;
     
    9394
    9495{{{
     96#!cpp
    9597import oversim.common.IOverlay;
    9698
     
    121123
    122124{{{
     125#!cpp
    123126import oversim.common.ITier;
    124127
     
    157160
    158161{{{
    159 
     162#!cpp
    160163// Import the C++ TransportAddress class
    161164
     
    197200                    Its value can be set in different ways when it's being initialized:[[BR]]
    198201{{{
    199 !OverlayKey();           // initializes the key as UNSPECIFIED. While in this value, most of the key operations are invalid! [[BR]]
    200 !OverlayKey(5);          // initializes the value as an 32-bit integer.[[BR]]
    201 !OverlayKey(buffer, 32); // initializes the value from the first 32 bytes of buffer.[[BR]]
    202 !OverlayKey().random();  // initializes the value as a random bit array.[[BR]]
     202#!cpp
     203OverlayKey();           // initializes the key as UNSPECIFIED. While in this value, most of the key operations are invalid!
     204OverlayKey(5);          // initializes the value as an 32-bit integer.
     205OverlayKey(buffer, 32); // initializes the value from the first 32 bytes of buffer.
     206OverlayKey().random();  // initializes the value as a random bit array.
    203207}}}
    204208                    OverlayKey operations include equality (==), order (<, >) and range (isBetween(key1, key2)).[[BR]]
     
    217221
    218222{{{
     223#!cpp
    219224class MyApplication : public BaseApp
    220225{
     
    243248
    244249{{{
    245 
     250#!cpp
    246251// This line tells the simulator that MyApplication is going to be extended using C++ code.
    247252// It *must* be present (only once) somewhere in your code, outside a function, for each module you'll be extending.
     
    302307// handleTimerEvent is called when a timer event triggers
    303308
    304 void MyApplication::handleTimerEvent(cMessage* msg) {
    305 
     309void MyApplication::handleTimerEvent(cMessage* msg)
     310{
    306311    if (msg == timerMsg) {    // is this our timer?
    307312
     
    325330            callRoute(randomKey, myMessage); // send it to the overlay
    326331        }
    327 
    328332    } else {
    329 
    330333        delete msg; // who knows what this packet is?
    331 
    332334    }
    333335}
     
    336338// Unhandled or unknown packets can be safely deleted here.
    337339
    338 void MyApplication::deliver(OverlayKey& key, cMessage* msg) {
    339 
     340void MyApplication::deliver(OverlayKey& key, cMessage* msg)
     341{
    340342    // we are only expecting messages of type MyMessage, throw away any other
    341343
     
    352354       myMsg->setType(MYMSG_PONG);                         // change type
    353355       sendMessageToUDP(myMsg->getSenderAddress(), myMsg); // send it back to its owner
    354 
    355356    } else {
    356 
    357357       delete msg;     // unhandled!
    358 
    359358    }
    360359}
     
    364363
    365364void MyApplication::handleUDPMessage(cMessage* msg) {
    366 
    367365    // we are only expecting messages of type MyMessage
    368366
     
    370368
    371369    if (myMsg && myMsg->getType() == MYMSG_PONG) {
    372 
    373370       numReceived++;
    374 
    375371    }
    376372
     
    379375    delete msg;
    380376}
    381 
    382377}}}
    383378
     
    390385
    391386{{{
     387#!cpp
    392388class MyOverlay : public BaseOverlay {
    393389public:
     
    435431
    436432{{{
     433#!cpp
    437434// Important! This line must be present for each module you extend (see MyApplication)
    438435Define_Module(MyOverlay);
     
    442439
    443440// Called when the module is being initialized
    444 void MyOverlay::initializeOverlay(int stage) {
    445 
     441void MyOverlay::initializeOverlay(int stage)
     442{
    446443    if (stage != MIN_STAGE_OVERLAY) return;         // see BaseApp.cc
    447444
     
    458455
    459456// Called to set our own overlay key (optional)
    460 void MyOverlay::setOwnNodeID() {
     457void MyOverlay::setOwnNodeID()
     458{
    461459    thisNode.key = OverlayKey(myKey);   // create the corresponding overlay key
    462460}
    463461
    464462// Called when the module is ready to join the overlay
    465 void MyOverlay::joinOverlay() {
    466 
     463void MyOverlay::joinOverlay()
     464{
    467465    // Set the information of the previous step in the chain
    468466    prevNode.ip = IPAddress(BIGBIT | (myKey - 1));
     
    518516
    519517// Called when the module is about to be destroyed
    520 void MyOverlay::finalizeOverlay() {
     518void MyOverlay::finalizeOverlay()
     519{
    521520    // remove this node from the overlay
    522521    setOverlayReady(false);
     
    527526
    528527// Return the max amount of siblings that can be queried about
    529 int MyOverlay::getMaxNumSiblings() {
     528int MyOverlay::getMaxNumSiblings()
     529{
    530530    return 1;
    531531}
    532532
    533533// Return the max amount of redundant that can be queried about
    534 int MyOverlay::getMaxNumRedundantNodes() {
     534int MyOverlay::getMaxNumRedundantNodes()
     535{
    535536    return 1;
    536537}
     
    546547
    547548{{{
     549#!cpp
    548550SimpleOverlay.overlayTerminal[5].overlay.myOverlay.enableDrops = true
    549551}}}
     
    554556
    555557{{{
     558#!cpp
    556559*.overlayTerminal[5].overlay.myOverlay.enableDrops = true
    557560**.overlay.myOverlay.enableDrops = true
     
    570573Therefore, the last line of omnetpp.ini should look like this:
    571574{{{
     575#!cpp
    572576include ./default.ini
    573577}}}
     
    578582
    579583{{{
     584#!cpp
    580585[General]
    581586sim-time-limit = 1000s                                              // set all simulations to last 1000 seconds
     
    594599
    595600{{{
     601#!cpp
    596602[Config ExampleConf]
    597603description = MyOverlay test (SimpleUnderlayNetwork)
     
    611617**.myApplication.numToSend = 1
    612618**.myApplication.largestKey = 10
    613 
    614619}}}
    615620
     
    617622
    618623{{{
    619 
     624#!cpp
    620625[Config ExampleA]
    621626extends = ExampleConf
     
    627632**.myOverlay.dropChance = 0.5
    628633**.myApplication.sendPeriod = 2s
    629 
    630634}}}
    631635
     
    635639
    636640{{{
    637 
     641#!cpp
    638642[Config ExampleC]
    639643extends = Example
    640644**.myOverlay.dropChance = ${Drop=0.1, 0.3, 0.5, 0.7}
    641645**.myApplication.sendPeriod = 1s
    642 
    643646}}}
    644647
     
    650653
    651654{{{
    652 
     655#!cpp
    653656...
    654657**.application.sendPeriod = ${Period=1s, 2s, 5s}
    655 
    656658}}}
    657659
     
    659661
    660662{{{
    661 
     663#!cpp
    662664repeat = 3
    663 
    664665}}}
    665666
     
    684685
    685686{{{
     687#!sh
    686688../src/OverSim [-u Tkenv | CmdEnv] [-f customConfigFile] -c configName [-r runNumber]
    687689}}}
     
    697699
    698700{{{
     701#!cpp
    699702class MyOverlay : public BaseOverlay {
    700703    ...
     
    737740
    738741{{{
    739 
     742#!cpp
    740743cplusplus {{
    741744#include <NodeHandle.h>
     
    767770
    768771{{{
     772#!cpp
    769773    void MyOverlay::getNeighbors(const OverlayKey &neighborKey) {
    770774        MyNeighborCall *msg = new MyNeighborCall();
     
    782786
    783787{{{
    784 
     788#!cpp
    785789    // Handle an incoming Call message
    786790    // Only delete msg if the RPC is handled here, and you won't respond using sendRpcResponse!
     
    862866        RPC_SWITCH_END();
    863867    }
    864 
    865868}}}
    866869