Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Implement Network Telnet in ns3

To implement the network Telnet in ns3 has needs to simulate the network where Telnet traffic is generated and monitored. While ns3 does not have a built-in Telnet support so we need to mimic the telnet traffic by using the TCP applications that were implemented the Telnet behaviour like sending and receiving text-based commands over TCP.

The given below are the detailed procedures on how to implement the network telnet in ns3:

Step-by-Step Implementation:

Step 1: Setup ns3 Environment

Make certain ns3 is installed in the system.

Step 2: Include Necessary Modules

Include the necessary ns3 modules in your script:

#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/flow-monitor-module.h”

Step 3: Create the Simulation Script

  1. Setup Nodes and Network:

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“NetworkTelnetExample”);

class TelnetApplication : public Application

{

public:

TelnetApplication ();

virtual ~TelnetApplication ();

void Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate);

private:

virtual void StartApplication (void);

virtual void StopApplication (void);

void ScheduleTx (void);

void SendPacket (void);

Ptr<Socket>     m_socket;

Address         m_peer;

uint32_t        m_packetSize;

uint32_t        m_nPackets;

DataRate        m_dataRate;

EventId         m_sendEvent;

bool            m_running;

uint32_t        m_packetsSent;

};

TelnetApplication::TelnetApplication ()

: m_socket (0),

m_peer (),

m_packetSize (0),

m_nPackets (0),

m_dataRate (0),

m_sendEvent (),

m_running (false),

m_packetsSent (0)

{

}

TelnetApplication::~TelnetApplication ()

{

m_socket = 0;

}

void

TelnetApplication::Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate)

{

m_socket = socket;

m_peer = address;

m_packetSize = packetSize;

m_nPackets = nPackets;

m_dataRate = dataRate;

}

void

TelnetApplication::StartApplication (void)

{

m_running = true;

m_packetsSent = 0;

m_socket->Bind ();

m_socket->Connect (m_peer);

SendPacket ();

}

void

TelnetApplication::StopApplication (void)

{

m_running = false;

if (m_sendEvent.IsRunning ())

{

Simulator::Cancel (m_sendEvent);

}

if (m_socket)

{

m_socket->Close ();

}

}

void

TelnetApplication::SendPacket (void)

{

Ptr<Packet> packet = Create<Packet> (m_packetSize);

m_socket->Send (packet);

if (++m_packetsSent < m_nPackets)

{

ScheduleTx ();

}

}

void

TelnetApplication::ScheduleTx (void)

{

if (m_running)

{

Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));

m_sendEvent = Simulator::Schedule (tNext, &TelnetApplication::SendPacket, this);

}

}

int main (int argc, char *argv[])

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create (4);

// Create point-to-point links

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“10Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

NetDeviceContainer devices;

devices = pointToPoint.Install (NodeContainer (nodes.Get (0), nodes.Get (1)));

devices.Add (pointToPoint.Install (NodeContainer (nodes.Get (1), nodes.Get (2))));

devices.Add (pointToPoint.Install (NodeContainer (nodes.Get (2), nodes.Get (3))));

// Install Internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (devices);

// Set up applications

uint16_t port = 23;  // Telnet port

// Server application on node 3

Address serverAddress (InetSocketAddress (Ipv4Address::GetAny (), port));

PacketSinkHelper packetSinkHelper (“ns3::TcpSocketFactory”, serverAddress);

ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (3));

sinkApps.Start (Seconds (1.0));

sinkApps.Stop (Seconds (20.0));

// Client application on node 0

Ptr<Socket> source = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ());

Address remoteAddress (InetSocketAddress (interfaces.GetAddress (3), port));

Ptr<TelnetApplication> app = CreateObject<TelnetApplication> ();

app->Setup (source, remoteAddress, 1024, 1000, DataRate (“1Mbps”));

nodes.Get (0)->AddApplication (app);

app->SetStartTime (Seconds (2.0));

app->SetStopTime (Seconds (20.0));

Simulator::Stop (Seconds (20.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Step 4: Run the Simulation

Compile and run your simulation script:

./waf configure

./waf build

./waf –run NetworkTelnetExample

Explanation

  • Node Creation: Create nodes representing different devices in the network.
  • Point-to-Point Links: Configure point-to-point links between nodes with specified data rates and delays.
  • Internet Stack: Install the Internet stack on all nodes.
  • IP Configuration: Assign IP addresses to the interfaces.
  • Applications: Implement a custom application (TelnetApplication) that simulates Telnet traffic by sending text-based commands over TCP.
  • Traffic Generation: Use the custom TelnetApplication to generate traffic from a client node to a server node, simulating Telnet traffic.

Advanced Telnet Techniques

  1. Simulating Interactive Commands:

Extend the TelnetApplication to simulate interactive Telnet commands.

void

TelnetApplication::SendPacket (void)

{

std::string command = “ls\n”;  // Simulate a simple command

Ptr<Packet> packet = Create<Packet> ((uint8_t *)command.c_str (), command.size ());

m_socket->Send (packet);

if (++m_packetsSent < m_nPackets)

{

ScheduleTx ();

}

}

  1. Simulating Authentication:

Add simple authentication to the Telnet session.

void

TelnetApplication::SendPacket (void)

{

std::string login = “login: user\npassword: pass\n”;

Ptr<Packet> packet = Create<Packet> ((uint8_t *)login.c_str (), login.size ());

m_socket->Send (packet);

if (++m_packetsSent < m_nPackets)

{

ScheduleTx ();

}

}

  1. Traffic Analysis:

Use the FlowMonitor module to analyze Telnet traffic.

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll ();

// At the end of the simulation

monitor->SerializeToXmlFile (“telnet-flowmon-results.xml”, true, true);

  1. Security Enhancements:

Implement simple encryption for Telnet traffic.

void

TelnetApplication::SendPacket (void)

{

std::string command = “ls\n”;

// Simple XOR encryption for demonstration purposes

for (size_t i = 0; i < command.size (); ++i)

{

command[i] ^= ‘A’;  // Use ‘A’ as a simple key

}

Ptr<Packet> packet = Create<Packet> ((uint8_t *)command.c_str (), command.size ());

m_socket->Send (packet);

if (++m_packetsSent < m_nPackets)

{

ScheduleTx ();

}

}

From the above, we discussed about how to implement the network telnet in ns3 tool but ns3 does not has built-in support but it implemented successfully by using the TCP application in ns3. If you need any further details about the network telnet we will provide it.

The implementation of Network Telnet within the ns3 program has been executed by our team. We have integrated Telnet support, which necessitates the simulation of Telnet traffic through the utilization of TCP applications relevant to your projects. We invite you to connect with us to ensure your success.