To implement stenography in ns-3, we create an application which hides the information inside other data like embedding a hidden message inside the standard communication packet. Need help with stenography implementation in ns-3? Get in touch with us for expert assistance. Here is a complete step-by-step guide on setting up a basic network with stenographic functionalities in ns3.
Steps for implementing stenography
- Install ns-3
Make sure that ns-3 is installed in the computer. If not, install it from the official ns-3 website.
- Define the Network Topology
Define the network topology that contains:
- Sender node
- Receiver nodes
- Create Network Nodes
Using NodeContainer, create network nodes.
NodeContainer senderNode, receiverNode;
senderNode.Create(1);
receiverNode.Create(1);
- Set Up Network Devices
Use appropriate network interfaces to install network devices on the nodes, that includes Wi-Fi for wireless communication.
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211n_5GHZ);
WifiMacHelper mac;
mac.SetType(“ns3::AdhocWifiMac”);
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
phy.SetChannel(channel.Create());
NetDeviceContainer senderDevice = wifi.Install(phy, mac, senderNode);
NetDeviceContainer receiverDevice = wifi.Install(phy, mac, receiverNode);
- Configure Mobility Model
Set up the mobility model for the nodes using using MobilityHelper.
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(senderNode);
mobility.Install(receiverNode);
- Implement Steganography Application
To perform steganographic embedding and extraction, create an application. Here is an example of a basic steganographic application.
class SteganographyApplication : public Application {
public:
void StartApplication() override {
sendSocket = Socket::CreateSocket(GetNode(), UdpSocketFactory::GetTypeId());
sendSocket->Connect(InetSocketAddress(destAddress, destPort));
recvSocket = Socket::CreateSocket(GetNode(), UdpSocketFactory::GetTypeId());
recvSocket->Bind(InetSocketAddress(Ipv4Address::GetAny(), localPort));
recvSocket->SetRecvCallback(MakeCallback(&SteganographyApplication::ReceivePacket, this));
// Schedule the first packet send
SendPacket();
}
void SetRemote(Address address, uint16_t port) {
destAddress = address;
destPort = port;
}
void SetLocalPort(uint16_t port) {
localPort = port;
}
void SendPacket() {
std::string message = “Hello, this is a normal message”;
std::string hiddenMessage = “Secret”;
std::string stegoMessage = EmbedMessage(message, hiddenMessage);
Ptr<Packet> packet = Create<Packet>((uint8_t*) stegoMessage.c_str(), stegoMessage.size());
sendSocket->Send(packet);
// Schedule the next packet send
Simulator::Schedule(Seconds(1.0), &SteganographyApplication::SendPacket, this);
}
void ReceivePacket(Ptr<Socket> socket) {
Ptr<Packet> packet;
Address from;
while ((packet = socket->RecvFrom(from))) {
std::string stegoMessage = std::string((char*) packet->PeekData(), packet->GetSize());
std::string hiddenMessage = ExtractMessage(stegoMessage);
std::cout << “Received hidden message: ” << hiddenMessage << std::endl;
}
}
std::string EmbedMessage(const std::string& message, const std::string& hiddenMessage) {
// Simple example: append hidden message to normal message with a delimiter
return message + “|” + hiddenMessage;
}
std::string ExtractMessage(const std::string& stegoMessage) {
// Simple example: extract hidden message from stego message
size_t pos = stegoMessage.find(“|”);
if (pos != std::string::npos) {
return stegoMessage.substr(pos + 1);
}
return “”;
}
private:
Ptr<Socket> sendSocket;
Ptr<Socket> recvSocket;
Address destAddress;
uint16_t destPort;
uint16_t localPort;
};
- Set Up Applications
Install the applications on the nodes.
ApplicationContainer senderApp, receiverApp;
// Sender application
Ptr<SteganographyApplication> senderStegoApp = CreateObject<SteganographyApplication>();
senderStegoApp->SetRemote(receiverNode.Get(0)->GetObject<Ipv4>()->GetAddress(1, 0).GetLocal(), 9);
senderStegoApp->SetLocalPort(10);
senderNode.Get(0)->AddApplication(senderStegoApp);
senderStegoApp->SetStartTime(Seconds(1.0));
senderStegoApp->SetStopTime(Seconds(20.0));
senderApp.Add(senderStegoApp);
// Receiver application
Ptr<SteganographyApplication> receiverStegoApp = CreateObject<SteganographyApplication>();
receiverStegoApp->SetLocalPort(9);
receiverNode.Get(0)->AddApplication(receiverStegoApp);
receiverStegoApp->SetStartTime(Seconds(1.0));
receiverStegoApp->SetStopTime(Seconds(20.0));
receiverApp.Add(receiverStegoApp);
- Set Up Routing Protocols
Configure routing protocols for the network.
AodvHelper aodv;
InternetStackHelper internet;
internet.SetRoutingHelper(aodv);
internet.Install(senderNode);
internet.Install(receiverNode);
- Assign IP Addresses
Using Ipv4AddressHelper address, assign IP addresses to the network devices.
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer senderInterfaces = address.Assign(senderDevice);
Ipv4InterfaceContainer receiverInterfaces = address.Assign(receiverDevice);
- Run the Simulation
Define the simulation runtime and execute it.
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
Example of a basic Steganography Network Script
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
#include “ns3/applications-module.h”
#include “ns3/aodv-module.h”
using namespace ns3;
class SteganographyApplication : public Application {
public:
void StartApplication() override {
sendSocket = Socket::CreateSocket(GetNode(), UdpSocketFactory::GetTypeId());
sendSocket->Connect(InetSocketAddress(destAddress, destPort));
recvSocket = Socket::CreateSocket(GetNode(), UdpSocketFactory::GetTypeId());
recvSocket->Bind(InetSocketAddress(Ipv4Address::GetAny(), localPort));
recvSocket->SetRecvCallback(MakeCallback(&SteganographyApplication::ReceivePacket, this));
// Schedule the first packet send
SendPacket();
}
void SetRemote(Address address, uint16_t port) {
destAddress = address;
destPort = port;
}
void SetLocalPort(uint16_t port) {
localPort = port;
}
void SendPacket() {
std::string message = “Hello, this is a normal message”;
std::string hiddenMessage = “Secret”;
std::string stegoMessage = EmbedMessage(message, hiddenMessage);
Ptr<Packet> packet = Create<Packet>((uint8_t*) stegoMessage.c_str(), stegoMessage.size());
sendSocket->Send(packet);
// Schedule the next packet send
Simulator::Schedule(Seconds(1.0), &SteganographyApplication::SendPacket, this);
}
void ReceivePacket(Ptr<Socket> socket) {
Ptr<Packet> packet;
Address from;
while ((packet = socket->RecvFrom(from))) {
std::string stegoMessage = std::string((char*) packet->PeekData(), packet->GetSize());
std::string hiddenMessage = ExtractMessage(stegoMessage);
std::cout << “Received hidden message: ” << hiddenMessage << std::endl;
}
}
std::string EmbedMessage(const std::string& message, const std::string& hiddenMessage) {
// Simple example: append hidden message to normal message with a delimiter
return message + “|” + hiddenMessage;
}
std::string ExtractMessage(const std::string& stegoMessage) {
// Simple example: extract hidden message from stego message
size_t pos = stegoMessage.find(“|”);
if (pos != std::string::npos) {
return stegoMessage.substr(pos + 1);
}
return “”;
}
private:
Ptr<Socket> sendSocket;
Ptr<Socket> recvSocket;
Address destAddress;
uint16_t destPort;
uint16_t localPort;
};
int main(int argc, char *argv[]) {
NodeContainer senderNode, receiverNode;
senderNode.Create(1);
receiverNode.Create(1);
// WiFi setup
WifiHelper wifi; wifi.SetStandard(WIFI_PHY_STANDARD_80211n_5GHZ);
WifiMacHelper mac; mac.SetType(“ns3::AdhocWifiMac”);
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
phy.SetChannel(channel.Create());
NetDeviceContainer senderDevice = wifi.Install(phy, mac, senderNode);
NetDeviceContainer receiverDevice = wifi.Install(phy, mac, receiverNode);
// Mobility setup
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(senderNode);
mobility.Install(receiverNode);
// Internet stack and routing
AodvHelper aodv;
InternetStackHelper internet;
internet.SetRoutingHelper(aodv);
internet.Install(senderNode);
internet.Install(receiverNode);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer senderInterfaces = address.Assign(senderDevice);
Ipv4InterfaceContainer receiverInterfaces = address.Assign(receiverDevice);
// Install applications
ApplicationContainer senderApp, receiverApp;
// Sender application
Ptr<SteganographyApplication> senderStegoApp = CreateObject<SteganographyApplication>();
senderStegoApp->SetRemote(receiverNode.Get(0)->GetObject<Ipv4>()->GetAddress(1, 0).GetLocal(), 9);
senderStegoApp->SetLocalPort(10);
senderNode.Get(0)->AddApplication(senderStegoApp);
senderStegoApp->SetStartTime(Seconds(1.0));
senderStegoApp->SetStopTime(Seconds(20.0));
senderApp.Add(senderStegoApp);
// Receiver application
Ptr<SteganographyApplication> receiverStegoApp = CreateObject<SteganographyApplication>();
receiverStegoApp->SetLocalPort(9);
receiverNode.Get(0)->AddApplication(receiverStegoApp);
receiverStegoApp->SetStartTime(Seconds(1.0));
receiverStegoApp->SetStopTime(Seconds(20.0));
receiverApp.Add(receiverStegoApp);
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Overall, we had learned on implementing stenography in ns-3 by creating a basic network that hides information within data with stenographic functionalities. Also, we provide more related coding support on stenography thesis.