Tuesday

OMNeT++ tictoc10.ned, txc10.cc Solution

TicToc10 Exercise Question:
You'll notice that this simple "routing" is not very efficient: often the packet keeps bouncing between two nodes for a while before it is sent to a different direction. This can be improved somewhat if nodes don't send the packet back to the sender. Implement this.
Hints: cMessage::getArrivalGate(), cGate::getIndex().
Note that if the message didn't arrive via a gate but was a self-message, then getArrivalGate() returns NULL.
Source: http://www.omnetpp.org/doc/omnetpp/tictoc-tutorial/part3.html

TicToc10 Solution:
void Txc10::forwardMessage(cMessage *msg)
{
    // In this example, we just pick a random gate (gate outs size) to send it on.
    // We draw a random number between 0 and the size of gate `out[]'.
    int n = gateSize("out");
    int k = intuniform(0,n-1);
     
    cGate *arrivalGate = msg->getArrivalGate();
    //int arrivalGateIndex = arrivalGate->getIndex(); // null pointer exception runtime error
                                          // because the first message sent by scheduleAt is a self-message
    
    if (arrivalGate == NULL) //self-message, do what?  
    {  
        // In this case, you may want to actually do something once the self
        // message "fires". Otherwise, as you've seen, the simulation ends there. 
        // In short, you could just send the self message.       
        EV << "Forwarding self message " << msg << " on port out[" << k << "]\n";
        send(msg, "out", k);         
    } 
    else if (arrivalGate != NULL)  // if it is not a self-message, get arrivalGateIndex
    {
        int arrivalGateIndex = arrivalGate->getIndex();
        
        if (n >= 2) //if out gates are more than 1, easy
                    //this line is needed to avoid infinite loop because you can send back to the sender
                    //if there is only one output gate
        {
            while (arrivalGateIndex == k)  
            {
                k = intuniform(0,n-1);
            }
        }
        
        EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
        send(msg, "out", k); 
    } 
}

Wednesday

OMNeT++ and MANET Routing (aodv, dsr, etc) using INETMANET Framework

Download and install WinPcap v4.1.2 from
http://www.winpcap.org/install/default.htm.
Winpcap is used by INET to capture network packets from external interfaces.
This step will install Driver and DLL files like C:\Windows\System32\wpcap.dll.
Q: How can I see if WinPcap is currently running on my Win2K/XP/2k3/Win7 machine?
A: Click on the Start button and then on run. Type msinfo32. The System Information panel will show up. Choose Software Environment, then System Drivers. The entry NPF should appear there. If you launched a WinPcap application previously, the state should be running. Remember that WinPcap should have been run at least one time in order to appear in this list.
Name: npf
Description: NetGroup Packet Filter Driver
File: c:\windows\system32\drivers\npf.sys
Type: Kernel Driver
Started: Yes
Start Mode: Auto
State: Running

Download and extract WinPcap 4.1.2 Developer's Pack from
http://www.winpcap.org/devel.htm.

Copy all files from D:\WinpcapDeveloperPack_4_1_2\WpdPack\Include to
C:\omnetpp-4.1-rc2-src-windows\mingw\include and
C:\omnetpp-4.1-rc2-src-windows\mingw\lib\gcc\mingw32\4.5.0\include.

Copy all files from D:\WinpcapDeveloperPack_4_1_2\WpdPack\Lib to
C:\omnetpp-4.1-rc2-src-windows\mingw\lib and
C:\omnetpp-4.1-rc2-src-windows\mingw\lib\gcc\mingw32\4.5.0.

Make a copy of D:\WinpcapDeveloperPack_4_1_2\WpdPack\Lib\wpcap.lib.
Name the new copy as pcap.lib.
Copy to C:\omnetpp-4.1-rc2-src-windows\mingw\lib\pcap.lib.

Make a copy of D:\WinpcapDeveloperPack_4_1_2\WpdPack\Lib\libwpcap.a.
Name the new copy as libpcap.a.
Copy to C:\omnetpp-4.1-rc2-src-windows\mingw\lib\libpcap.lib.

Download inetmanet-20101013-src.tgz for OMNeT++ from
https://github.com/inetmanet/inetmanet.
If you intend to use inetmanet-2.0-integration.zip, download it from
https://github.com/aarizaq/inetmanet-2.0.

Extract inetmanet-20101013-src.tgz into OMNeT++ workspace directory
C:\omnetpp-4.1-rc2-src-windows\samples\inetmanet-20101013-src.
The extracted directory must be a subdirectory of the workspace directory.

Double-click to open OMNeT++ IDE.

Import the project using: File | Import... | General | Existing Projects into Workspace.
Select root directory: C:\omnetpp-4.1-rc2-src-windows\samples.
Make sure "inetmanet-20101013-src" project is checked.
Be sure NOT to check the "Copy projects into workspace" box.
Click Finish.

Open the "inetmanet-20101013-src" project if it is not open and wait until the indexer finishes.
Build the inetmanet project by pressing Ctrl+B (Project | Build all). Wait until it finish building.
If you get not enough memory error, restart your PC first.

To run an example from the OMNeT++ IDE open the example's directory in the Project Explorer view, find the corresponding omnetpp.ini file. Right click on it and select Run As / OMNeT++ Simulation. This should create a Launch Configuration with two Simulator windows (Network Animation and Timeline) for this example.

If the build was successful, you may try running the OMNeT++ Demo Simulations from the MSYS Bash Shell.
Welcome to OMNeT++ 4.1!
$ cd samples
$ pwd
/c/omnetpp-4.1-rc2-src-windows/samples
$ cd inetmanet-20101013-src
$ cd examples/
{username}@{computername} ~/samples/inetmanet-20101013-src/examples
$ ./rundemo
{username}@{computername} ~/samples/inetmanet-20101013-src/examples
$

Notes:
Recognized Environment Variables:
%WINDIR% = %SYSTEMROOT% = C:\Windows
%WINDIR%\system32 = C:\Windows\System32 //32-bit system
%WINDIR%\system = C:\Windows\system //16-bit system
%USERPROFILE% = C:\Users\{username}
%TEMP% = %TMP% = C:\Users\{username}\AppData\Local\Temp

C:\>echo %path%
D:\xerces-c-2.8.0-vc-8.0\bin;C:\Qt\2010.05\qt\bin;C:\Qt\2010.05\mingw\bin;
C:\Perl\bin;C:\Program Files\Java\jdk1.6.0_24\bin;
C:\Python26;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Program Files\Notepad++;

C:\>echo %comspec%
C:\Windows\system32\cmd.exe

C:\>echo %date%
Wed 11/05/2011

C:\>echo %cd%
C:\

C:\>echo %random% //returns a random number between 0 and 32767
27081

C:\>echo %time%
8:57:25.75

%AppData% = C:\Users\{username}\AppData\Roaming
%SystemDrive% = C:\
%ProgramFiles% = C:\Program Files
%CommonProgramFiles% = C:\Program Files\Common Files

[solved] OMNeT++ and WinPcap c:/mingw32/bin/ld.exe: cannot find -lpcap, error: 'PCAP_SRC_IF_STRING' undeclared

Problem 1:
On the MSYS Bash Shell,
$ gcc -o testprog testprog.c -lpcap
c:/omnetpp-4.1-rc2-src-windows/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: cannot find -lpcap

Solution. Change from -lpcap to -lwpcap:
$ gcc -o testprog testprog.c -lwpcap
This is because
C:\omnetpp-4.1-rc2-src-windows\mingw\lib\wpcap.lib and
C:\omnetpp-4.1-rc2-src-windows\mingw\lib\libwpcap.a.

Problem 2:
$ gcc -o testprog testprog.c -lwpcap
testprog.c: In function 'main':
testprog.c:12:29: error: 'PCAP_SRC_IF_STRING' undeclared (first use in this function)

Solution:
Change from
//if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
to
if (pcap_findalldevs_ex("127.0.0.1", NULL, &alldevs, errbuf) == -1)
{
...
}
The 127.0.0.1 is the localhost IP number.

Run it. On my Windows 7 workstation, the obtained result is:
$ testprog
1. rpcap://\Device\NPF_{88888888-4444-4444-4444-48D0E52A0B83} (Network adapter 'Atheros(NDIS6.20)' on local host)
2. rpcap://\Device\NPF_{88888888-4444-4444-4444-8B5EC6C7F430} (Network adapter 'Sun' on local host)

Tuesday

OMNeT++ v4.1, v4.1 rc2, v4.2.2, v4.3 or v4.3.1, how to install and run

Download and install Java from http://www.java.com or http://www.oracle.com/technetwork/java/javase/downloads/index.html. Use Java SE 6, Java SE 7 or later.

Download OMNeT++ source code (omnetpp-4.1-src-windows.zip) from http://omnetpp.org.
no: OMNeT++ 4.1 (source + IDE, tgz).
yes: OMNeT++ 4.1 win32 (source + IDE + MINGW, zip). Download this one. Do not use OMNeT++ v4.2.1 or later. You can not build inetmanet-20101013-src in OMNeT v4.2.1.

Extract the zip file to C drive. Rename the resulting directory to
omnetpp-4.1-rc2-src-windows.
Make sure your directory does not contain any space. For example, do not put OMNeT++ under Program Files.

Execute mingwenv.cmd in the omnetpp-4.1-rc2-src-windows directory by double-clicking it in Windows Explorer. It will bring up a console with the MSYS bash shell, where the path is already set to include the
omnetpp-4.1-rc2-src-windows\bin directory.

On the MSYS bash shell, enter the following commands:
$ ./configure
$ make
The build process with "make" will create both debug and release binaries.

On the MSYS bash shell, test all samples and check they run correctly. As an example, the dyna example is started by entering the following commands:
$ cd samples/dyna
$ ./dyna

If you get the error message, "Failed to create Java Virtual Machine." by double-clicking omnetpp.exe at C:\omnetpp-4.3\ide\omnetpp.exe with OMNeT++ v4.3, type the "$ omnetpp" in the mingwenv.cmd terminal to open OMNeT++ IDE. A better solution is by restart your PC before double-clicking the omnetpp.exe executable file.

OMNeT++ comes with an Eclipse-based Simulation IDE. You should be able to start the OMNeT++ IDE by double-clicking C:\omnetpp-4.1-rc2-src-windows\ide\omnetpp.exe.

It is recommended that you create a shortcut on the desktop for starting the OMNeT++ IDE by right-click omnetpp.exe program in the omnetpp-4.1/ide directory and choose Send To > Desktop (create shortcut) from the menu. On Windows 7, you can right-click the taskbar icon while the IDE is running, and select Pin this program to taskbar from the context menu.

Set OMNeT++ Workspace: C:\omnetpp-4.1-rc2-src-windows\samples.
Many projects for you to test from the samples folder.
[Ticked] Use this as the default and do not ask again.

Click "Workbench" icon from the Welcome page.

Open any project from the IDE Project Explorer window, right-click omnetpp.ini file and select Run As OMNeT++ simulation.

Notes
RC = release candidate.
OMNeT++ = Objective Modular Network Testbed in C++.
OMNeST = Objective Modular Network and Sensor Testbed in C++ (not sure).
opp = OMNeT++.
NeD = Network Description.

NeD Abbreviations and its Full Form
annotation / metadata annotation / NeD property / property
PER = packet error rate
BER = bit error rate
eed = end-to-end delay
ls = line style and color
t = text
tt = tooltip
m = connection routing orientation, positioning
b = object border, shape, colo
i = icon
is = icon size

If a hater attacked your age and not the goodness of you

Whether young or old, I've always been known what endures. I've known the very idea of people that were all created equal and deserv...