EIGRP (Enhanced Interior Gateway Routing Protocol) is a Cisco proprietary protocol. ns3 does not support EIGRP natively. But we can simulate its behavior by utilizing custom routing protocol or by using existing routing modules, get in touch with us if you face any difficulties. Let us walk through the guidance on creating a custom EIGRP based routing protocol in ns3.
Steps to implement EIGRP in ns3
- Set up your environment
Make sure that ns3 is installed in the computer. If not, install it from the official ns3 website.
- Create a custom routing protocol
Let us create a custom routing protocol as ns3 does not support EIGRP module. On your ns3 installation, create a new directory for your custom module in the src directory.
cd ns-3.xx
mkdir -p src/eigrp
cd src/eigrp
touch CMakeLists.txt eigrp.h eigrp.cc eigrp-helper.h eigrp-helper.cc
- Create the protocol header file
Create the header file eigrp.h and eigrp-helper.h which includes the declaration of the class for your custom routing protocol and helper classes.
#ifndef EIGRP_H
#define EIGRP_H
#include “ns3/ipv4-routing-protocol.h”
#include “ns3/timer.h”
#include “ns3/ipv4-address.h”
#include “ns3/ipv4.h”
namespace ns3 {
class Eigrp : public Ipv4RoutingProtocol
{
public:
static TypeId GetTypeId (void);
Eigrp ();
virtual ~Eigrp ();
// Inherited 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);
virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
private:
Ptr<Ipv4> m_ipv4;
std::map<Ipv4Address, Ptr<Ipv4Route>> m_routingTable;
void SendEigrpPacket ();
void ReceiveEigrpPacket (Ptr<Socket> socket);
};
} // namespace ns3
#endif /* EIGRP_H */
eigrp-helper.h
#ifndef EIGRP_HELPER_H
#define EIGRP_HELPER_H
#include “ns3/ipv4-routing-helper.h”
#include “ns3/eigrp.h”
namespace ns3 {
class EigrpHelper : public Ipv4RoutingHelper
{
public:
EigrpHelper ();
virtual ~EigrpHelper ();
EigrpHelper* Copy (void) const;
virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
};
} // namespace ns3
#endif /* EIGRP_HELPER_H */
- Implement the Protocol
Implement the methods declared in the header files in eigrp.cc and eigrp-helper.cc.
#include “eigrp.h”
#include “ns3/log.h”
#include “ns3/ipv4-routing-table-entry.h”
#include “ns3/ipv4-interface.h”
#include “ns3/packet.h”
#include “ns3/socket.h”
#include “ns3/inet-socket-address.h”
namespace ns3 {
NS_LOG_COMPONENT_DEFINE (“Eigrp”);
NS_OBJECT_ENSURE_REGISTERED (Eigrp);
TypeId
Eigrp::GetTypeId (void)
{
static TypeId tid = TypeId (“ns3::Eigrp”)
.SetParent<Ipv4RoutingProtocol> ()
.SetGroupName (“Internet”)
.AddConstructor<Eigrp> ();
return tid;
}
Eigrp::Eigrp () {}
Eigrp::~Eigrp () {}
Ptr<Ipv4Route>
Eigrp::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr)
{
// Implement route output logic
return nullptr;
}
bool
Eigrp::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
{
// Implement route input logic
return false;
}
void
Eigrp::NotifyInterfaceUp (uint32_t interface)
{
// Implement interface up notification
}
void
Eigrp::NotifyInterfaceDown (uint32_t interface)
{
// Implement interface down notification
}
void
Eigrp::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
{
// Implement add address notification
}
void
Eigrp::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
{
// Implement remove address notification
}
void
Eigrp::SetIpv4 (Ptr<Ipv4> ipv4)
{
m_ipv4 = ipv4;
}
void
Eigrp::PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const
{
// Implement routing table printing
}
void
Eigrp::SendEigrpPacket ()
{
// Implement EIGRP packet sending
}
void
Eigrp::ReceiveEigrpPacket (Ptr<Socket> socket)
{
// Implement EIGRP packet receiving
}
} // namespace ns3
eigrp-helper.cc
#include “eigrp-helper.h”
#include “ns3/eigrp.h”
#include “ns3/node.h”
#include “ns3/ipv4-l3-protocol.h”
namespace ns3 {
EigrpHelper::EigrpHelper () {}
EigrpHelper::~EigrpHelper () {}
EigrpHelper*
EigrpHelper::Copy (void) const
{
return new EigrpHelper (*this);
}
Ptr<Ipv4RoutingProtocol>
EigrpHelper::Create (Ptr<Node> node) const
{
Ptr<Eigrp> eigrp = CreateObject<Eigrp> ();
node->AggregateObject (eigrp);
return eigrp;
}
} // namespace ns3
- Set up the network topology
To use the custom EIGRP routing protocol, create a simulation script in the scratch directory.
touch scratch/eigrp-simulation.cc
Include the necessary headers and set up the network topology:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/eigrp-helper.h”
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (3);
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)));
InternetStackHelper internet;
EigrpHelper eigrp;
internet.SetRoutingHelper (eigrp);
internet.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices.Get (0));
interfaces.Add (address.Assign (devices.Get (1)));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get (2)));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
- Build and run the simulation
Build and run your script after writing.
./waf build
./waf –run scratch/eigrp-simulation
- Analyze the results
You can analyze the results based on your needs after running the simulation. Also, you can add logging or tracing to observe the behavior of the EIGRP-like protocol.
Overall, we had a performance analysis on implementing EIGRP (Enhanced Interior Gateway Routing Protocol) in ns3 by simulating its similar behavior using custom routing protocols. Also, we provide more detailed information on EIGRP protocol with coding for your project.