Computer Networks Lab · OMNeT++
Packet Forwarding with Forwarding Tables (LUT)
5-node directed network · C++ map-based LUT · End-to-end delay measurement
Assignment Tasks
Task 1 — Network Design
- Network name: forwardingNetwork
- 5 nodes with directed links
- Gate arrays (allowunconnected)
- Delays: 100ms / 200ms per link
Task 2 — Behavioural Design
- Source/Dest defined in omnetpp.ini
- Each node forwards via LUT or accepts
- LUT using std::map
- End-to-end delay at destination
Network Topology
Faster path: 0 → 1 → 2 → 4 (400ms) |
Alternate: 0 → 1 → 3 → 4 (500ms)
Corrections Applied
⚠ What was fixed
Node.ned
Fixed gate arrays — gIn[3] → gIn[] (auto-sized by connections)
N_PDU.msg
Removed redundant Address field (duplicate of Source)
Node.h
Removed unused cGate* in and cGate* out variables
Node.cc
LUT trimmed — only destination-relevant entries per node
Node.cc
Added missing setSource() and setDest() on packet
Node.cc
Fixed delay: getArrivalTime() → simTime()
Network.ned
✓ Connections, delays, parameters — all correct, no changes needed
Forwarding Tables (LUT) per Node
Node 0 · Source
dest 4 → gOut[0]
→ Node 1
Node 1 · Fork
dest 4 → gOut[1]
→ Node 2 (faster)
Node 2
dest 4 → gOut[1]
→ Node 4
Node 3
dest 4 → gOut[1]
→ Node 4
Node 4 · Dest
No forwarding
Print delay
Corrected Source Code
NED · Node.ned
simple Node
{
parameters:
int address;
int source_address;
int dest_address;
gates:
input gIn[]; // auto-sized by connections
output gOut[];
}
NED · forwardingNetwork.ned
network ForwardingNetwork
{
parameters:
int source_address;
int dest_address;
@display("bgb=400,200");
submodules:
N[5]: Node {
address = index;
source_address = source_address;
dest_address = dest_address;
}
connections allowunconnected:
// 0 <-> 1 (100ms)
N[0].gIn[0] <-- { delay = 100ms; } <-- N[1].gOut[0];
N[0].gOut[0] --> { delay = 100ms; } --> N[1].gIn[0];
// 1 <-> 2 (200ms)
N[1].gIn[1] <-- { delay = 200ms; } <-- N[2].gOut[0];
N[1].gOut[1] --> { delay = 200ms; } --> N[2].gIn[0];
// 2 <-> 4 (100ms)
N[2].gIn[1] <-- { delay = 100ms; } <-- N[4].gOut[0];
N[2].gOut[1] --> { delay = 100ms; } --> N[4].gIn[0];
// 1 <-> 3 (200ms)
N[1].gIn[2] <-- { delay = 200ms; } <-- N[3].gOut[0];
N[1].gOut[2] --> { delay = 200ms; } --> N[3].gIn[0];
// 3 <-> 4 (200ms)
N[3].gIn[1] <-- { delay = 200ms; } <-- N[4].gOut[1];
N[3].gOut[1] --> { delay = 200ms; } --> N[4].gIn[1];
}
MSG · N_PDU.msg
packet N_PDU
{
int Source; // sender node address
int Dest; // final destination address
simtime_t Start; // send time — used to compute delay
}
C++ Header · Node.h
#ifndef __FOURTH_CN_LAB_NODE_H_
#define __FOURTH_CN_LAB_NODE_H_
#include <omnetpp.h>
#include <map>
#include "N_PDU_m.h"
using namespace omnetpp;
using namespace std;
class Node : public cSimpleModule
{
protected:
int address;
int source_address;
int dest_address;
map<int,int> LUT;
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
#endif
C++ Source · Node.cc
#include "node.h"
Define_Module(Node);
void Node::initialize()
{
dest_address = par("dest_address");
source_address = par("source_address");
address = par("address");
if (address == 0)
LUT = { {4, 0} }; // dest 4 → gOut[0] → Node 1
else if (address == 1)
LUT = { {4, 1} }; // dest 4 → gOut[1] → Node 2
else if (address == 2)
LUT = { {4, 1} }; // dest 4 → gOut[1] → Node 4
else if (address == 3)
LUT = { {4, 1} }; // dest 4 → gOut[1] → Node 4
// Node 4 = destination, no LUT needed
if (address == source_address) {
cMessage* event = new cMessage();
scheduleAt(0, event);
}
}
void Node::handleMessage(cMessage *msg)
{
if (msg->isSelfMessage()) {
N_PDU* data = new N_PDU();
data->setSource(address);
data->setDest(dest_address);
data->setStart(simTime());
delete msg; // free self-message
send(data, "gOut", LUT.at(dest_address));
}
else {
N_PDU* data = check_and_cast<N_PDU*>(msg);
if (address == dest_address) {
EV << "Delay: " << simTime() - data->getStart();
delete data;
}
else {
send(data, "gOut", LUT.at(dest_address));
}
}
}
No comments: