I have created two apps one UdpBasicApp and another UdpSink. My purpose is to send from sender to receiver and then add a pcap recording to see the packet content. I am getting this error:
Module not found on path 'interfaceTable' defined by par 'MyNetwork.receiver.interfaceTableModule' -- in module (inet::UdpSink) MyNetwork.receiver (id=3), at t=0s, event #1
I have created MySenderApp module that extends a UdpBasicApp
import inet.applications.udpapp.UdpBasicApp;
module MySenderApp extends UdpBasicApp {
}
This is the header of MySenderApp moduke
#ifndef MYSENDERAPP_H_
#define MYSENDERAPP_H_
#include <omnetpp.h>
using namespace omnetpp;
class MySenderApp : public cSimpleModule {
public:
MySenderApp();
virtual ~MySenderApp();
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage* msg) override;
};
#endif /* MYSENDERAPP_H_ */
And this is the c++ code that I have used to send packets to the receiver:
#include "MySenderApp.h"
#include <omnetpp.h>
using namespace omnetpp;
Define_Module(MySenderApp);
MySenderApp::MySenderApp() {
// Constructor
}
MySenderApp::~MySenderApp() {
// Destructor
}
void MySenderApp::initialize() {
// Initialization code, if needed
// Example: schedule a self-message to send a UDP packet
//server =getModuleByPath("MyReceiverApp");
cMessage* msg = new cMessage("SendUDP");
scheduleAt(simTime() + 1.0, msg);
}
void MySenderApp::handleMessage(cMessage* msg) {
if (msg->isSelfMessage()) {
// Create and send a UDP packet
cPacket* packet = new cPacket("MyPacket");
send(packet,"socketOut");
delete msg; // Delete the self-message
}
}
Similarly, I have created a module MyReceiverApp.ned that extends UdpSink
import inet.applications.udpapp.UdpSink;
import inet.networklayer.common.InterfaceTable;
module MyReceiverApp extends UdpSink {
parameters:
interfaceTableModule = "^";
}
And this is the c++ code:
#include "MyReceiverApp.h"
#include <omnetpp.h>
using namespace omnetpp;
Define_Module(MyReceiverApp);
MyReceiverApp::MyReceiverApp() {
// Constructor
}
MyReceiverApp::~MyReceiverApp() {
// Destructor
}
void MyReceiverApp::initialize() {
// Initialization code, if needed
}
void MyReceiverApp::handleMessage(cMessage* msg) {
// Handle incoming UDP packets here
EV << "Received UDP packet: " << msg->getName() << endl;
delete msg;
}
My network ned file is as shown below:
network MyNetwork
{
@display("bgb=341,381");
submodules:
sender: MySenderApp {
@display("p=85,76");
@networkNode;
}
receiver: MyReceiverApp {
@display("p=290,178");
@networkNode;
}
connections allowunconnected:
sender.socketOut --> receiver.socketIn;
receiver.socketOut --> sender.socketIn;
}
And my omnetpp.ini file is:
[General]
network = MyNetwork
debug-on-errors = true
sim-time-limit = 5s
record-eventlog = true
I think the error deals with the interface table, but I couldn't figure out how to solve it.
A UDPApp
cannot be used as a host. You must use StandardHost
or WirelessHost
and add your UDP application to instances of these hosts.
Take a look at Wireless Tutorial, especially at inet/tutorials/wireless/WirelessA.ned
and section [Config Wireless01]
in inet/tutorials/wireless/omnetpp.ini
.
In short you should:
Create simple module (called for example MyUDPApp
) for your UDP application (look at examples in inet/src/inet/applications/udpapp
).
Create your network using WirelessHost
.
Add your application for hosts you want by writing in omnetpp.ini
at least:
**.host1.numUdpApps = 1
**.host1.udpApp[0].typename = "MyUDPApp"
# other parameters of the application