CSE247 on YouTube

OMNeT Labs

Computer Networks Lab · OMNeT++ · The LNMIIT
OMNeT++ Lab Series — Complete Notes
Standardized code, variables & naming across all labs
Lab 1 · Two-Node Network Lab 2 · Layered Architecture Lab 3 · Packet Loss & Retransmission Lab 4 · Packet Forwarding (LUT)
📌 Standard Nomenclature Used Across All Labs
NED Modules
Node · Nl_node · Dll_node
Comp · TwoNode · Comp_network
ForwardingNetwork
Gates
gIn / gOut (Lab 1, 4)
nl_in / nl_out (NL layer)
dlln_in/out · dllc_in/out
Packets / PDUs
N_PDU (Lab 1, 4)
Nl_pkt · Dll_pkt (Lab 2, 3)
Fields: pID · pType · src · dest
C++ Variables
address · id · counter
remaining_packets · source
copy_message · timeoutEvent · LUT
Functions
initialize() · handleMessage()
scheduleAt() · send() · par()
encapsulate() · decapsulate()
ini Parameters
**.source · **.dest
**.remaining_packets
sim-time-limit · network
Jump to: Lab 1 Lab 2 Lab 3 Lab 4
Lab 1
Two Node Network Simulation
Stop-and-wait data exchange · 10 packets · ACK-based
Objective
Simulate a stop-and-wait exchange between two nodes. Node 1 sends DATA packets; Node 2 replies with ACK. Repeats 10 times then stops.
Tasks
1Create Node module with gIn / gOut gates and id parameter
2Create TwoNode network with N1 and N2 bidirectionally connected
3Define N_PDU packet with fields: pID, pType, src, dest
4Node 1 sends DATA → Node 2 replies ACK → repeat 10 times → endSimulation()
Source Code
NEDNode.ned
simple Node
{
    parameters:
        int id;            // 1 = Node1,  2 = Node2
    gates:
        input  gIn;        // incoming messages
        output gOut;       // outgoing messages
}
Lab 2
Layered Architecture — NL + DLL Communication
Network Layer · Data Link Layer · PDU Encapsulation · 100ms channel
Objective
Two-node network where each node has a Network Layer (Nl_node) and Data Link Layer (Dll_node). NL creates Nl_pkt → DLL encapsulates it into Dll_pkt → sends over channel → destination DLL decapsulates → passes to NL.
Source Code
NEDNl_node.ned · Dll_node.ned · Comp.ned · Comp_network.ned
// ── Nl_node.ned ──
simple Nl_node
{
    parameters:
        int id;                   // node id (1 or 2)
        int remaining_packets;    // from omnetpp.ini
        int source;               // which node starts sending
    gates:
        input  nl_in;
        output nl_out;
}

// ── Dll_node.ned ──
simple Dll_node
{
    parameters:
        int id;
    gates:
        input  dlln_in;   // from NL
        output dlln_out;  // to NL
        input  dllc_in;   // from channel
        output dllc_out;  // to channel
}

// ── Comp.ned — compound node ──
module Comp
{
    parameters:
        int c_id;
    gates:
        input  c_in;
        output c_out;
    submodules:
        Nl:  Nl_node  { id = c_id; }
        Dll: Dll_node { id = c_id; }
    connections:
        Nl.nl_in    <-- Dll.dlln_out;
        Nl.nl_out   --> Dll.dlln_in;
        Dll.dllc_in <-- c_in;
        Dll.dllc_out --> c_out;
}

// ── Comp_network.ned ──
network Comp_network
{
    submodules:
        C1: Comp { c_id = 1; }
        C2: Comp { c_id = 2; }
    connections:
        C1.c_out --> { delay = 100ms; } --> C2.c_in;
        C2.c_out --> { delay = 100ms; } --> C1.c_in;
}
Lab 3
Packet Loss · ACK · Timeout & Retransmission
10% loss · copy_message for retransmit · cancelEvent on ACK
What's New vs Lab 2
aDLL destination simulates 10% packet loss using uniform(0,1) < 0.1
bSource DLL saves copy_message and starts a timeoutEvent
cOn ACK → cancelEvent(timeoutEvent) · On timeout → retransmit copy_message.dup()
✓ 10% loss (was 80%) ✓ decapsulate() leak fixed ✓ copy_message = nullptr ✓ old copy deleted before new save ✓ self-event memory leak
Changed Files (NED / MSG / Nl_node same as Lab 2)
C++Dll_node.h — updated with copy_message & timeoutEvent
#ifndef DLL_NODE_H_
#define DLL_NODE_H_
#include <omnetpp.h>
#include "Dll_pkt_m.h"
#include "Nl_pkt_m.h"
using namespace omnetpp;

class Dll_node : public cSimpleModule
{
  protected:
    int    id;
    cGate* in_n;
    cGate* out_n;
    cGate* in_c;
    cGate* out_c;
    Dll_pkt*  copy_message;   // saved for retransmission
    cMessage* timeoutEvent;   // retransmit timer
    virtual void initialize();
    virtual void handleMessage(cMessage *msg);
};
#endif
Lab 4
Packet Forwarding with Forwarding Tables (LUT)
5-node directed network · std::map LUT · gate arrays · end-to-end delay
Topology & Objective
5-node directed network. Each node has a Forwarding Table (LUT) implemented as map<int,int> — maps destination address to output gate index. Source node sends one packet, it hops through the network, destination prints end-to-end delay.
100ms 200ms 200ms 100ms 200ms 0 source 1 fork 2 3 4 dest ✓ 400ms faster 500ms
Faster path: 0→1→2→4 (400ms) | Alternate: 0→1→3→4 (500ms)
Source Code
NEDNode.ned
simple Node
{
    parameters:
        int address;        // set to index in network
        int source;         // from omnetpp.ini
        int dest;           // from omnetpp.ini
    gates:
        input  gIn[];      // auto-sized gate array
        output gOut[];
}
omnetpp.ini (Lab 4)
omnetpp.ini
[General]
network = ForwardingNetwork
**.source = 0
**.dest   = 4

No comments:

Powered by Blogger.