(Layered Architecture) Learn communication in layered environment OMNet
Tasks 1: Network Design
1. Create a network (name “layerNetwork”) with two nodes, where each node has two layers: network, and data-link layer. Both nodes are connected with delay channel of 100ms (check simulation manual of OMNeT++ or tic-toc tutorials 3.1). (Hint: design layers as simple module, and node as compound module).
2. Each layer communicates through protocol data unit (PDU). The network layer PDU is N_PDU, and data-link layer PDU is DL_PDU. Create a packet for each PDU. Both layers communicate
through addresses (source and destination). (Hint: design all PDU's as packet type message definition)
3. Communication will start from the network layer of the source node to next bottom layer then this node transfer this DL_PDU to the destination node.
Tasks 2: Protocol Design and Simulation
1. Define source, destination address and number of packets as parameters in omnetpp.ini file.
2. Enable event logging in omnetpp.ini file and visualise packet tracing.
3. (Network Layer Communication) Source Node (SN) sends 10 packets with id 1 to 10 to destination node (DN) with delay of RTT. DN receives each packet and deletes it.
4. (Data-link Layer Communication) In SN, for each received PDU from upper layer, it encapsulate in a new data-link layer PDU (type as “Data”) and assigns id in modulo-2 (0 and 1) manner i.e. id of the first PDU will be 0 then second PDU will be 1 then again 0 and so on. In DN, data-link layer sends “Ack” to SN and also forwards the decapsulated PDU to upper layer.
Solution:
simple Nl_node
{
parameters:
int nl_id;
int remaining_packets;
int source;
gates:
input nl_in;
output nl_out;
}
simple Dll_node
{
parameters:
int dll_id;
gates:
input dlln_in;
output dlln_out;
input dllc_in;
output dllc_out;
}
module Comp
{
parameters:
int c_id;
gates:
input c_in;
output c_out;
submodules:
Nl: Nl_node{nl_id=c_id;}
Dll: Dll_node{dll_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;
}
network Comp_network
{
parameters:
int source;
int dest;
submodules:
C1: Comp{c_id=1;}
C2: Comp{c_id=2;}
connections:
C1.c_in <-- {delay=100ms;} <-- C2.c_out;
C1.c_out --> {delay=100ms;} --> C2.c_in;
}
packet Nl_pkt{
int Nl_pkt_id;
int Nl_pkt_type;
}
packet Dll_pkt {
int Dll_pkt_id;
int Dll_pkt_type;
}
#ifndef __NLDLL_NL_NODE_H_
#define __NLDLL_NL_NODE_H_
#include <omnetpp.h>
#include <nl_pkt_m.h>
using namespace omnetpp;
/**
* TODO - Generated class
*/
class Nl_node : public cSimpleModule
{
protected:
int id;
cGate* in;
cGate* out;
int remaining_packets;
int source;
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
#endif
#include "nl_node.h"
Define_Module(Nl_node);
void Nl_node::initialize()
{
remaining_packets = par("remaining_packets");
// TODO - Generated method body
id = par("nl_id");
in = gate("nl_in");
source = par("source");
out = gate("nl_out");
if (id==source){
cMessage* event = new cMessage();
scheduleAt(0, event);
}
}
void Nl_node::handleMessage(cMessage *msg)
{
// TODO - Generated method body
if (msg->isSelfMessage()){
Nl_pkt* data = new Nl_pkt();
if (remaining_packets == 0){
return;
}
data->setNl_pkt_id(remaining_packets--);
data->setNl_pkt_type(1);
send(data, out);
cMessage* event = new cMessage();
scheduleAt(simTime() + 200, event);
}
else{
delete(msg);
}
}
#ifndef __NLDLL_DLL_NODE_H_
#define __NLDLL_DLL_NODE_H_
#include <omnetpp.h>
#include <dll_pkt_m.h>
#include <nl_pkt_m.h>
using namespace omnetpp;
/**
* TODO - Generated class
*/
class Dll_node : public cSimpleModule
{
protected:
int id;
cGate* in_n;
cGate* out_n;
cGate* in_c;
cGate* out_c;
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
#endif
#include "dll_node.h"
Define_Module(Dll_node);
void Dll_node::initialize()
{
// TODO - Generated method body
id = par("dll_id");
in_n = gate("dlln_in");
out_n = gate("dlln_out");
in_c = gate("dllc_in");
out_c = gate("dllc_out");
}
void Dll_node::handleMessage(cMessage *msg)
{
// TODO - Generated method body
if (msg->getArrivalGate()==in_n)
{
Dll_pkt* data = new Dll_pkt();
Nl_pkt* data_to_encapsulate = check_and_cast<Nl_pkt*>(msg);
data->encapsulate(data_to_encapsulate);
data->setDll_pkt_type(1);
send(data, out_c);
}
else if(msg->getArrivalGate()==in_c)
{
Dll_pkt* message = check_and_cast<Dll_pkt*>(msg);
if (message->getDll_pkt_type()==1)
{
message->decapsulate();
Dll_pkt* ack = new Dll_pkt();
ack->setDll_pkt_type(0);
send(message, out_n);
send(ack, out_c);
}
else{
delete(msg);
}
}
}
[General]
network = Comp_network
**.remaining_packets = 10
**.source = 1
**.dest = 2
No comments: