0% found this document useful (0 votes)
4 views4 pages

Computer Networks Assignment

This documentation outlines the implementation of an AreaNetwork simulation in OMNeT++, featuring two hosts and a central router. It details the network topology defined in two files, including the Computer module for hosts and the Router for forwarding messages, along with the logic for sending and receiving packets. The simulation includes a 100ms delay for network links and logs for packet forwarding and reception events.

Uploaded by

aaditya biswas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Computer Networks Assignment

This documentation outlines the implementation of an AreaNetwork simulation in OMNeT++, featuring two hosts and a central router. It details the network topology defined in two files, including the Computer module for hosts and the Router for forwarding messages, along with the logic for sending and receiving packets. The simulation includes a 100ms delay for network links and logs for packet forwarding and reception events.

Uploaded by

aaditya biswas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

This documentation provides the implementation details for the AreaNetwork simulation in

OMNeT++, consisting of two hosts and a central router.

(a) & (b) Network Topology and Module Definitions

The structure is defined across two files within the areanetwork package. The Computer module
serves as the host, and the ComputerNetwork defines the topology.

File: [Link]

package areanetwork;

simple Computer
{
gates:
input in;
output out;
}

File: simulations/[Link]

package [Link];
import [Link];
import [Link];

network ComputerNetwork
{
submodules:
computer_A: Computer;
computer_B: Computer;
router_A: Router {
gates:
in[1];
out[1];
}
connections:
// (g) Delay of 100ms added to each link
computer_A.out --> {delay = 100ms;} --> router_A.in[0];
router_A.out[0] --> {delay = 100ms;} --> computer_B.in;
}
(c) & (f) Host Logic: Sending 5 Packets

The Computer class handles packet generation for computer_A and message reception for
computer_B . A loop is utilized to schedule five distinct events.

File: [Link]

#include <string.h>
#include <omnetpp.h>

using namespace omnetpp;

class Computer : public cSimpleModule {


protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Computer);

void Computer::initialize() {
// Logic to send 5 packets from the source host
if (strcmp(getName(), "computer_A") == 0) {
for (int i = 0; i < 5; i++) {
cMessage *msg = new cMessage("DataPacket");
scheduleAt(simTime() + (double)i, msg);
}
}
}

void Computer::handleMessage(cMessage *msg) {


if (strcmp(getName(), "computer_A") == 0) {
if (msg->isSelfMessage()) {
send(msg, "out");
}
} else if (strcmp(getName(), "computer_B") == 0) {
// (e) Output requirement for reception
EV << "Message received at hostB" << endl;
delete msg;
}
}
(d) Router Logic: Forwarding

The Router class intercepts incoming messages and directs them to the appropriate output gate.

File: [Link]

#include <omnetpp.h>

using namespace omnetpp;

class Router : public cSimpleModule {


protected:
virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Router);

void Router::handleMessage(cMessage *msg) {


// (e) Output requirement for forwarding
EV << "Router forwarding packet..." << endl;

// Directs packets from the input array to the output array


send(msg, "out", 0);
}

Simulation Summary

Requirement Implementation Detail

Packet Count computer_A initiates 5 packets via scheduleAt .

Network Delay Links are configured with 100ms delay in the .ned file.

Forwarding The Router logs "Router forwarding packet..." upon message


Output arrival.

The destination logs "Message received at hostB" upon message


Reception Output
arrival.

Screenshots

You might also like