To implement the fisheye state routing (FSR) protocol in ns3 that has numerous steps. Even after reading the procedures if you face difficulties contact ns3simulation.com , we give you brief explanation.
The given below are the procedures on how to implement the FSR protocol in ns3.
Prerequisites
- ns3 Installation: Make sure ns3 is installed in the system.
- C++ Programming: understanding of C++ is required.
- Understanding of ns-3: knowledge with ns3 modules, particularly the IPv4 stack.
Steps to Implement FSR Protocol
- Set Up the Development Environment
Make sure that you have installed ns3 in the computer. If not installed then download it from official website.
- Create a New Protocol Module
Navigate to the src directory in ns-3 and create a new directory for your protocol.
cd ns-3.XX/src
mkdir fsr
cd fsr
mkdir model helper test
3. Define the Protocol Classes and Headers
Create header and implementation files for your protocol in the model directory.
fsr-routing-protocol.h
#ifndef FSR_ROUTING_PROTOCOL_H
#define FSR_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”
namespace ns3 {
class FsrRoutingProtocol : public Ipv4RoutingProtocol {
public:
static TypeId GetTypeId (void);
FsrRoutingProtocol ();
virtual ~FsrRoutingProtocol ();
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:
// Define internal states and methods here
Ptr<Ipv4> m_ipv4;
// Additional internal states and methods for FSR
};
} // namespace ns3
#endif // FSR_ROUTING_PROTOCOL_H
fsr-routing-protocol.cc
#include “fsr-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 (“FsrRoutingProtocol”);
NS_OBJECT_ENSURE_REGISTERED (FsrRoutingProtocol);
TypeId FsrRoutingProtocol::GetTypeId (void) {
static TypeId tid = TypeId (“ns3::FsrRoutingProtocol”)
.SetParent<Ipv4RoutingProtocol> ()
.SetGroupName (“Internet”)
.AddConstructor<FsrRoutingProtocol> ();
return tid;
}
FsrRoutingProtocol::FsrRoutingProtocol () {
NS_LOG_FUNCTION (this);
}
FsrRoutingProtocol::~FsrRoutingProtocol () {
NS_LOG_FUNCTION (this);
}
void FsrRoutingProtocol::DoDispose () {
NS_LOG_FUNCTION (this);
Ipv4RoutingProtocol::DoDispose ();
}
Ptr<Ipv4Route> FsrRoutingProtocol::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
return Ptr<Ipv4Route> ();
}
bool FsrRoutingProtocol::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
return false;
}
void FsrRoutingProtocol::NotifyInterfaceUp (uint32_t interface) {
NS_LOG_FUNCTION (this << interface);
}
void FsrRoutingProtocol::NotifyInterfaceDown (uint32_t interface) {
NS_LOG_FUNCTION (this << interface);
}
void FsrRoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {
NS_LOG_FUNCTION (this << interface << address);
}
void FsrRoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {
NS_LOG_FUNCTION (this << interface << address);
}
void FsrRoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4) {
NS_LOG_FUNCTION (this << ipv4);
m_ipv4 = ipv4;
}
} // namespace ns3
4. Integrate with ns-3 Build System
Update the wscript file in the src directory to include your new protocol.
src/fsr/wscript
def build(bld):
module = bld.create_ns3_module(‘fsr’, [‘core’, ‘network’, ‘internet’])
module.source = [
‘model/fsr-routing-protocol.cc’,
]
headers = bld(features=’ns3header’)
headers.module = ‘fsr’
headers.source = [
‘model/fsr-routing-protocol.h’,
]
5. Create Helper and Test Classes
Create helper and test classes to facilitate the usage and testing of your protocol.
fsr-helper.h
#ifndef FSR_HELPER_H
#define FSR_HELPER_H
#include “ns3/fsr-routing-protocol.h”
#include “ns3/node-container.h”
#include “ns3/ipv4-routing-helper.h”
namespace ns3 {
class FsrHelper : public Ipv4RoutingHelper {
public:
FsrHelper ();
FsrHelper* Copy (void) const;
virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
private:
};
} // namespace ns3
#endif // FSR_HELPER_H
fsr-helper.cc
#include “fsr-helper.h”
#include “ns3/fsr-routing-protocol.h”
#include “ns3/ipv4-routing-protocol.h”
#include “ns3/ipv4-list-routing.h”
#include “ns3/log.h”
namespace ns3 {
NS_LOG_COMPONENT_DEFINE (“FsrHelper”);
FsrHelper::FsrHelper () {
}
FsrHelper* FsrHelper::Copy (void) const {
return new FsrHelper (*this);
}
Ptr<Ipv4RoutingProtocol> FsrHelper::Create (Ptr<Node> node) const {
Ptr<FsrRoutingProtocol> agent = CreateObject<FsrRoutingProtocol> ();
node->AggregateObject (agent);
return agent;
}
} // namespace ns3
- Build and Test
- Rebuild ns-3 to include your new protocol.
./waf configure
./waf build
- Create test scripts to verify the implementation of your protocol.
scratch/test-fsr.cc
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/fsr-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 (2);
InternetStackHelper internet;
FsrHelper fsr;
Ipv4ListRoutingHelper list;
list.Add (fsr, 10);
internet.SetRoutingHelper (list);
internet.Install (nodes);
// Add additional setup code here
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
7. Run and Debug
Run your test script and debug any issues that arise.
./waf –run scratch/test-fsr
Overall, we had implemented the fisheye state routing protocol in ns3simualtion and we also provide further system development help about FSR protocol, connect with us for best results.