To implement the Enhanced Interior Gateway Routing Protocol (EIGRP) in ns-3 contains various steps. For effective routing in EIGRP, we incorporated the distance vector and link state protocols and it is a cisco proprietary protocol. Here below is the step by procedures to implement the EIGRP in ns3 environment
Prerequisites
- Ns3 Installation: Make certain ns3 is installed on your system.
- C++ Programming: Understanding of C++ is needed.
- Understanding of ns-3: Knowledge with ns-3 modules and basic simulation scripts.
Steps to Implement EIGRP in ns3
- Set Up the Development Environment
Make sure you have installed ns3 in the computer. Download and install it from official ns3 website.
- Create a New EIGRP Module
Navigate to the src directory in ns-3 and create a new directory for your EIGRP module.
cd ns-3.XX/src
mkdir eigrp
cd eigrp
mkdir model helper test
- Define EIGRP Classes and Headers
Create header and implementation files for EIGRP in the model directory.
eigrp-routing-protocol.h
#ifndef EIGRP_ROUTING_PROTOCOL_H
#define EIGRP_ROUTING_PROTOCOL_H
#include “ns3/ipv4-routing-protocol.h”
#include “ns3/ipv4-address.h”
#include “ns3/timer.h”
#include “ns3/node.h”
#include “ns3/socket.h”
#include “ns3/net-device.h”
#include “ns3/packet.h”
#include “ns3/nstime.h”
#include <map>
namespace ns3 {
class EigrpRoutingProtocol : public Ipv4RoutingProtocol {
public:
static TypeId GetTypeId (void);
EigrpRoutingProtocol ();
virtual ~EigrpRoutingProtocol ();
virtual void DoDispose (void);
// Implement required virtual functions from Ipv4RoutingProtocol
virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header,
Ptr<NetDevice> oif,
Socket::SocketErrno &sockerr);
virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header,
Ptr<const NetDevice> idev,
UnicastForwardCallback ucb,
MulticastForwardCallback mcb,
LocalDeliverCallback lcb,
ErrorCallback ecb);
virtual void NotifyInterfaceUp (uint32_t interface);
virtual void NotifyInterfaceDown (uint32_t interface);
virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
virtual void SetIpv4 (Ptr<Ipv4> ipv4);
private:
Ptr<Ipv4> m_ipv4;
std::map<Ipv4Address, Ptr<Ipv4Route>> m_routingTable;
// Additional methods for maintaining and updating routing table based on EIGRP
void UpdateRoutingTable (void);
void FindBestPaths (void);
};
} // namespace ns3
#endif // EIGRP_ROUTING_PROTOCOL_H
eigrp-routing-protocol.cc
#include “eigrp-routing-protocol.h”
#include “ns3/log.h”
#include “ns3/simulator.h”
#include “ns3/ipv4-header.h”
#include “ns3/ipv4-route.h”
#include “ns3/inet-socket-address.h”
#include “ns3/inet6-socket-address.h”
#include “ns3/udp-socket-factory.h”
#include “ns3/uinteger.h”
namespace ns3 {
NS_LOG_COMPONENT_DEFINE (“EigrpRoutingProtocol”);
NS_OBJECT_ENSURE_REGISTERED (EigrpRoutingProtocol);
TypeId EigrpRoutingProtocol::GetTypeId (void) {
static TypeId tid = TypeId (“ns3::EigrpRoutingProtocol”)
.SetParent<Ipv4RoutingProtocol> ()
.SetGroupName (“Internet”)
.AddConstructor<EigrpRoutingProtocol> ();
return tid;
}
EigrpRoutingProtocol::EigrpRoutingProtocol () {
NS_LOG_FUNCTION (this);
}
EigrpRoutingProtocol::~EigrpRoutingProtocol () {
NS_LOG_FUNCTION (this);
}
void EigrpRoutingProtocol::DoDispose () {
NS_LOG_FUNCTION (this);
Ipv4RoutingProtocol::DoDispose ();
}
Ptr<Ipv4Route> EigrpRoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) {
NS_LOG_FUNCTION (this << p << header << oif);
// Implement route output logic here
Ipv4Address dest = header.GetDestination();
auto it = m_routingTable.find(dest);
if (it != m_routingTable.end()) {
return it->second;
}
sockerr = Socket::ERROR_NOROUTETOHOST;
return Ptr<Ipv4Route> ();
}
bool EigrpRoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header,
Ptr<const NetDevice> idev, UnicastForwardCallback ucb,
MulticastForwardCallback mcb, LocalDeliverCallback lcb,
ErrorCallback ecb) {
NS_LOG_FUNCTION (this << p << header << idev);
// Implement route input logic here
Ipv4Address dest = header.GetDestination();
Ipv4Address local = m_ipv4->GetAddress(1, 0).GetLocal();
if (dest == local) {
lcb (p, header);
return true;
}
auto it = m_routingTable.find(dest);
if (it != m_routingTable.end()) {
ucb (it->second, p, header);
return true;
}
ecb (p, header, Socket::ERROR_NOROUTETOHOST);
return false;
}
void EigrpRoutingProtocol::NotifyInterfaceUp (uint32_t interface) {
NS_LOG_FUNCTION (this << interface);
}
void EigrpRoutingProtocol::NotifyInterfaceDown (uint32_t interface) {
NS_LOG_FUNCTION (this << interface);
}
void EigrpRoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {
NS_LOG_FUNCTION (this << interface << address);
}
void EigrpRoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {
NS_LOG_FUNCTION (this << interface << address);
}
void EigrpRoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4) {
NS_LOG_FUNCTION (this << ipv4);
m_ipv4 = ipv4;
}
void EigrpRoutingProtocol::UpdateRoutingTable (void) {
NS_LOG_FUNCTION (this);
// Implement logic to update the routing table based on EIGRP
}
void EigrpRoutingProtocol::FindBestPaths (void) {
NS_LOG_FUNCTION (this);
// Implement logic to find the best paths using EIGRP
}
} // namespace ns3
- Create EIGRP Helper and Forwarding Classes
Create helper and forwarding classes to facilitate the use and testing of EIGRP.
eigrp-helper.h
#ifndef EIGRP_HELPER_H
#define EIGRP_HELPER_H
#include “ns3/ipv4-routing-helper.h”
#include “ns3/eigrp-routing-protocol.h”
#include “ns3/node-container.h”
namespace ns3 {
class EigrpHelper : public Ipv4RoutingHelper {
public:
EigrpHelper ();
virtual ~EigrpHelper ();
EigrpHelper* Copy (void) const;
virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
private:
// Additional methods for EIGRP functionality
};
} // namespace ns3
#endif // EIGRP_HELPER_H
eigrp-helper.cc
#include “eigrp-helper.h”
#include “ns3/ipv4-list-routing.h”
#include “ns3/log.h”
namespace ns3 {
NS_LOG_COMPONENT_DEFINE (“EigrpHelper”);
EigrpHelper::EigrpHelper () {
}
EigrpHelper::~EigrpHelper () {
}
EigrpHelper* EigrpHelper::Copy (void) const {
return new EigrpHelper (*this);
}
Ptr<Ipv4RoutingProtocol> EigrpHelper::Create (Ptr<Node> node) const {
Ptr<EigrpRoutingProtocol> agent = CreateObject<EigrpRoutingProtocol> ();
node->AggregateObject (agent);
return agent;
}
} // namespace ns3
- Integrate EIGRP with ns3 Build System
Update the wscript file in the src directory to include your new EIGRP module.
src/eigrp/wscript
def build(bld):
module = bld.create_ns3_module(‘eigrp’, [‘core’, ‘network’, ‘internet’])
module.source = [
‘model/eigrp-routing-protocol.cc’,
‘helper/eigrp-helper.cc’,
]
headers = bld(features=’ns3header’)
headers.module = ‘eigrp’
headers.source = [
‘model/eigrp-routing-protocol.h’,
‘helper/eigrp-helper.h’,
]
- Build and Test
- Rebuild ns-3 to include your new EIGRP module.
./waf configure
./waf build
- Create test scripts to verify the implementation of your EIGRP protocol.
scratch/test-eigrp.cc
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/eigrp-helper.h”
#include “ns3/ipv4-static-routing-helper.h”
#include “ns3/ipv4-list-routing-helper.h”
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (4);
InternetStackHelper internet;
EigrpHelper eigrp;
Ipv4ListRoutingHelper list;
list.Add (eigrp, 10);
internet.SetRoutingHelper (list);
internet.Install (nodes);
// Create point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get (0), nodes.Get (1));
devices.Add (pointToPoint.Install (nodes.Get (1), nodes.Get (2)));
devices.Add (pointToPoint.Install (nodes.Get (2), nodes.Get (3)));
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// Add additional setup code for EIGRP here
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
- Run and Debug
Run your test script and debug any issues that arise.
./waf –run scratch/test-eigrp
Finally, we had knowledgeable on implementing EIGPR in ns-3 by creating a basic network for effective routing with EIGPR out of the box. Also, we provide more related information on EIGPR. Make use of our support for your Enhanced Interior Gateway Routing Protocol (EIGRP) and how to apply in your project.