close
Warning:
BrowserModule failed with ConfigurationError: Look in the Trac log for more information.
- Timestamp:
-
Apr 20, 2009, 10:10:38 AM (17 years ago)
- Author:
-
heep
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
|
v16
|
v17
|
|
| 40 | 40 | |
| 41 | 41 | {{{ |
| 42 | | |
| | 42 | #!cpp |
| 43 | 43 | // sets the package, the name must match the path to the module (from src/ upwards) |
| 44 | 44 | package oversim.overlay.myoverlay; |
| … |
… |
|
| 63 | 63 | |
| 64 | 64 | {{{ |
| | 65 | #!cpp |
| 65 | 66 | // sets the package, the name must match the path to the module (from src/ upwards) |
| 66 | 67 | package oversim.applications.myapplication; |
| … |
… |
|
| 93 | 94 | |
| 94 | 95 | {{{ |
| | 96 | #!cpp |
| 95 | 97 | import oversim.common.IOverlay; |
| 96 | 98 | |
| … |
… |
|
| 121 | 123 | |
| 122 | 124 | {{{ |
| | 125 | #!cpp |
| 123 | 126 | import oversim.common.ITier; |
| 124 | 127 | |
| … |
… |
|
| 157 | 160 | |
| 158 | 161 | {{{ |
| 159 | | |
| | 162 | #!cpp |
| 160 | 163 | // Import the C++ TransportAddress class |
| 161 | 164 | |
| … |
… |
|
| 197 | 200 | Its value can be set in different ways when it's being initialized:[[BR]] |
| 198 | 201 | {{{ |
| 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 |
| | 203 | OverlayKey(); // initializes the key as UNSPECIFIED. While in this value, most of the key operations are invalid! |
| | 204 | OverlayKey(5); // initializes the value as an 32-bit integer. |
| | 205 | OverlayKey(buffer, 32); // initializes the value from the first 32 bytes of buffer. |
| | 206 | OverlayKey().random(); // initializes the value as a random bit array. |
| 203 | 207 | }}} |
| 204 | 208 | OverlayKey operations include equality (==), order (<, >) and range (isBetween(key1, key2)).[[BR]] |
| … |
… |
|
| 217 | 221 | |
| 218 | 222 | {{{ |
| | 223 | #!cpp |
| 219 | 224 | class MyApplication : public BaseApp |
| 220 | 225 | { |
| … |
… |
|
| 243 | 248 | |
| 244 | 249 | {{{ |
| 245 | | |
| | 250 | #!cpp |
| 246 | 251 | // This line tells the simulator that MyApplication is going to be extended using C++ code. |
| 247 | 252 | // It *must* be present (only once) somewhere in your code, outside a function, for each module you'll be extending. |
| … |
… |
|
| 302 | 307 | // handleTimerEvent is called when a timer event triggers |
| 303 | 308 | |
| 304 | | void MyApplication::handleTimerEvent(cMessage* msg) { |
| 305 | | |
| | 309 | void MyApplication::handleTimerEvent(cMessage* msg) |
| | 310 | { |
| 306 | 311 | if (msg == timerMsg) { // is this our timer? |
| 307 | 312 | |
| … |
… |
|
| 325 | 330 | callRoute(randomKey, myMessage); // send it to the overlay |
| 326 | 331 | } |
| 327 | | |
| 328 | 332 | } else { |
| 329 | | |
| 330 | 333 | delete msg; // who knows what this packet is? |
| 331 | | |
| 332 | 334 | } |
| 333 | 335 | } |
| … |
… |
|
| 336 | 338 | // Unhandled or unknown packets can be safely deleted here. |
| 337 | 339 | |
| 338 | | void MyApplication::deliver(OverlayKey& key, cMessage* msg) { |
| 339 | | |
| | 340 | void MyApplication::deliver(OverlayKey& key, cMessage* msg) |
| | 341 | { |
| 340 | 342 | // we are only expecting messages of type MyMessage, throw away any other |
| 341 | 343 | |
| … |
… |
|
| 352 | 354 | myMsg->setType(MYMSG_PONG); // change type |
| 353 | 355 | sendMessageToUDP(myMsg->getSenderAddress(), myMsg); // send it back to its owner |
| 354 | | |
| 355 | 356 | } else { |
| 356 | | |
| 357 | 357 | delete msg; // unhandled! |
| 358 | | |
| 359 | 358 | } |
| 360 | 359 | } |
| … |
… |
|
| 364 | 363 | |
| 365 | 364 | void MyApplication::handleUDPMessage(cMessage* msg) { |
| 366 | | |
| 367 | 365 | // we are only expecting messages of type MyMessage |
| 368 | 366 | |
| … |
… |
|
| 370 | 368 | |
| 371 | 369 | if (myMsg && myMsg->getType() == MYMSG_PONG) { |
| 372 | | |
| 373 | 370 | numReceived++; |
| 374 | | |
| 375 | 371 | } |
| 376 | 372 | |
| … |
… |
|
| 379 | 375 | delete msg; |
| 380 | 376 | } |
| 381 | | |
| 382 | 377 | }}} |
| 383 | 378 | |
| … |
… |
|
| 390 | 385 | |
| 391 | 386 | {{{ |
| | 387 | #!cpp |
| 392 | 388 | class MyOverlay : public BaseOverlay { |
| 393 | 389 | public: |
| … |
… |
|
| 435 | 431 | |
| 436 | 432 | {{{ |
| | 433 | #!cpp |
| 437 | 434 | // Important! This line must be present for each module you extend (see MyApplication) |
| 438 | 435 | Define_Module(MyOverlay); |
| … |
… |
|
| 442 | 439 | |
| 443 | 440 | // Called when the module is being initialized |
| 444 | | void MyOverlay::initializeOverlay(int stage) { |
| 445 | | |
| | 441 | void MyOverlay::initializeOverlay(int stage) |
| | 442 | { |
| 446 | 443 | if (stage != MIN_STAGE_OVERLAY) return; // see BaseApp.cc |
| 447 | 444 | |
| … |
… |
|
| 458 | 455 | |
| 459 | 456 | // Called to set our own overlay key (optional) |
| 460 | | void MyOverlay::setOwnNodeID() { |
| | 457 | void MyOverlay::setOwnNodeID() |
| | 458 | { |
| 461 | 459 | thisNode.key = OverlayKey(myKey); // create the corresponding overlay key |
| 462 | 460 | } |
| 463 | 461 | |
| 464 | 462 | // Called when the module is ready to join the overlay |
| 465 | | void MyOverlay::joinOverlay() { |
| 466 | | |
| | 463 | void MyOverlay::joinOverlay() |
| | 464 | { |
| 467 | 465 | // Set the information of the previous step in the chain |
| 468 | 466 | prevNode.ip = IPAddress(BIGBIT | (myKey - 1)); |
| … |
… |
|
| 518 | 516 | |
| 519 | 517 | // Called when the module is about to be destroyed |
| 520 | | void MyOverlay::finalizeOverlay() { |
| | 518 | void MyOverlay::finalizeOverlay() |
| | 519 | { |
| 521 | 520 | // remove this node from the overlay |
| 522 | 521 | setOverlayReady(false); |
| … |
… |
|
| 527 | 526 | |
| 528 | 527 | // Return the max amount of siblings that can be queried about |
| 529 | | int MyOverlay::getMaxNumSiblings() { |
| | 528 | int MyOverlay::getMaxNumSiblings() |
| | 529 | { |
| 530 | 530 | return 1; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // Return the max amount of redundant that can be queried about |
| 534 | | int MyOverlay::getMaxNumRedundantNodes() { |
| | 534 | int MyOverlay::getMaxNumRedundantNodes() |
| | 535 | { |
| 535 | 536 | return 1; |
| 536 | 537 | } |
| … |
… |
|
| 546 | 547 | |
| 547 | 548 | {{{ |
| | 549 | #!cpp |
| 548 | 550 | SimpleOverlay.overlayTerminal[5].overlay.myOverlay.enableDrops = true |
| 549 | 551 | }}} |
| … |
… |
|
| 554 | 556 | |
| 555 | 557 | {{{ |
| | 558 | #!cpp |
| 556 | 559 | *.overlayTerminal[5].overlay.myOverlay.enableDrops = true |
| 557 | 560 | **.overlay.myOverlay.enableDrops = true |
| … |
… |
|
| 570 | 573 | Therefore, the last line of omnetpp.ini should look like this: |
| 571 | 574 | {{{ |
| | 575 | #!cpp |
| 572 | 576 | include ./default.ini |
| 573 | 577 | }}} |
| … |
… |
|
| 578 | 582 | |
| 579 | 583 | {{{ |
| | 584 | #!cpp |
| 580 | 585 | [General] |
| 581 | 586 | sim-time-limit = 1000s // set all simulations to last 1000 seconds |
| … |
… |
|
| 594 | 599 | |
| 595 | 600 | {{{ |
| | 601 | #!cpp |
| 596 | 602 | [Config ExampleConf] |
| 597 | 603 | description = MyOverlay test (SimpleUnderlayNetwork) |
| … |
… |
|
| 611 | 617 | **.myApplication.numToSend = 1 |
| 612 | 618 | **.myApplication.largestKey = 10 |
| 613 | | |
| 614 | 619 | }}} |
| 615 | 620 | |
| … |
… |
|
| 617 | 622 | |
| 618 | 623 | {{{ |
| 619 | | |
| | 624 | #!cpp |
| 620 | 625 | [Config ExampleA] |
| 621 | 626 | extends = ExampleConf |
| … |
… |
|
| 627 | 632 | **.myOverlay.dropChance = 0.5 |
| 628 | 633 | **.myApplication.sendPeriod = 2s |
| 629 | | |
| 630 | 634 | }}} |
| 631 | 635 | |
| … |
… |
|
| 635 | 639 | |
| 636 | 640 | {{{ |
| 637 | | |
| | 641 | #!cpp |
| 638 | 642 | [Config ExampleC] |
| 639 | 643 | extends = Example |
| 640 | 644 | **.myOverlay.dropChance = ${Drop=0.1, 0.3, 0.5, 0.7} |
| 641 | 645 | **.myApplication.sendPeriod = 1s |
| 642 | | |
| 643 | 646 | }}} |
| 644 | 647 | |
| … |
… |
|
| 650 | 653 | |
| 651 | 654 | {{{ |
| 652 | | |
| | 655 | #!cpp |
| 653 | 656 | ... |
| 654 | 657 | **.application.sendPeriod = ${Period=1s, 2s, 5s} |
| 655 | | |
| 656 | 658 | }}} |
| 657 | 659 | |
| … |
… |
|
| 659 | 661 | |
| 660 | 662 | {{{ |
| 661 | | |
| | 663 | #!cpp |
| 662 | 664 | repeat = 3 |
| 663 | | |
| 664 | 665 | }}} |
| 665 | 666 | |
| … |
… |
|
| 684 | 685 | |
| 685 | 686 | {{{ |
| | 687 | #!sh |
| 686 | 688 | ../src/OverSim [-u Tkenv | CmdEnv] [-f customConfigFile] -c configName [-r runNumber] |
| 687 | 689 | }}} |
| … |
… |
|
| 697 | 699 | |
| 698 | 700 | {{{ |
| | 701 | #!cpp |
| 699 | 702 | class MyOverlay : public BaseOverlay { |
| 700 | 703 | ... |
| … |
… |
|
| 737 | 740 | |
| 738 | 741 | {{{ |
| 739 | | |
| | 742 | #!cpp |
| 740 | 743 | cplusplus {{ |
| 741 | 744 | #include <NodeHandle.h> |
| … |
… |
|
| 767 | 770 | |
| 768 | 771 | {{{ |
| | 772 | #!cpp |
| 769 | 773 | void MyOverlay::getNeighbors(const OverlayKey &neighborKey) { |
| 770 | 774 | MyNeighborCall *msg = new MyNeighborCall(); |
| … |
… |
|
| 782 | 786 | |
| 783 | 787 | {{{ |
| 784 | | |
| | 788 | #!cpp |
| 785 | 789 | // Handle an incoming Call message |
| 786 | 790 | // Only delete msg if the RPC is handled here, and you won't respond using sendRpcResponse! |
| … |
… |
|
| 862 | 866 | RPC_SWITCH_END(); |
| 863 | 867 | } |
| 864 | | |
| 865 | 868 | }}} |
| 866 | 869 | |