To implement the data security in OMNeT++ encompasses mimicking a network situation where data privacy, integrity, and availability are protected over encryption, secure protocols, and other security measures. The following is an example of how to set up and implement data security in OMNeT++.
Step-by-Step Implementations:
Initially, describe a simple network topology that contains clients, a server, and a router. This setup will permit us to mimic data transmission and put on security measures to protect the data.
network DataSecurityNetwork
{
submodules:
client1: StandardHost {
@display(“p=100,100”);
}
client2: StandardHost {
@display(“p=100,200”);
}
router: Router {
@display(“p=300,150”);
}
server: StandardHost {
@display(“p=500,150”);
}
connections:
client1.ethg++ <–> Eth100M <–> router.ethg++;
client2.ethg++ <–> Eth100M <–> router.ethg++;
router.ethg++ <–> Eth100M <–> server.ethg++;
}
To make sure data confidentiality, execute a simple encryption mechanism that encrypts data before transmission and decrypts it upon receipt.
Encryption Module
// EncryptionModule.cc
#include <omnetpp.h>
#include “inet/common/INETDefs.h”
#include “inet/common/packet/Packet.h”
#include <string>
using namespace omnetpp;
using namespace inet;
class EncryptionModule : public cSimpleModule
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
std::string encrypt(const std::string &data);
std::string decrypt(const std::string &data);
};
Define_Module(EncryptionModule);
void EncryptionModule::initialize()
{
EV << “Encryption Module Initialized” << endl;
}
void EncryptionModule::handleMessage(cMessage *msg)
{
if (Packet *packet = dynamic_cast<Packet *>(msg)) {
const auto& payload = packet->peekData();
std::string originalData(payload->str());
// Encrypt the data before sending
std::string encryptedData = encrypt(originalData);
EV << “Original Data: ” << originalData << ” | Encrypted Data: ” << encryptedData << endl;
// Modify the packet with the encrypted data (for simplicity, assuming direct modification)
packet->removeAtFront(payload->getChunkLength());
packet->insertAtFront(makeShared<BytesChunk>(encryptedData.c_str(), encryptedData.size()));
send(packet, “out”);
} else {
send(msg, “out”);
}
}
std::string EncryptionModule::encrypt(const std::string &data)
{
std::string encrypted = data;
// Simple XOR encryption for demonstration (not secure in practice)
char key = ‘K’; // Simple key
for (size_t i = 0; i < data.size(); ++i) {
encrypted[i] ^= key;
}
return encrypted;
}
std::string EncryptionModule::decrypt(const std::string &data)
{
return encrypt(data); // XOR encryption is symmetric
}
Enlarge the network to contain secure communication channels using protocols like TLS/SSL. We’ll mimic a secure channel by make sure that data is constantly encrypted during transmission for simplicity.
Secure Client Application
// SecureClientApp.cc
#include <omnetpp.h>
#include “inet/applications/tcpapp/TcpAppBase.h”
using namespace omnetpp;
using namespace inet;
class SecureClientApp : public TcpAppBase
{
protected:
virtual void initialize(int stage) override;
virtual void handleMessageWhenUp(cMessage *msg) override;
void sendSecureRequest();
};
Define_Module(SecureClientApp);
void SecureClientApp::initialize(int stage)
{
TcpAppBase::initialize(stage);
if (stage == inet::INITSTAGE_APPLICATION_LAYER) {
scheduleAt(simTime() + 1, new cMessage(“sendSecureRequest”));
}
}
void SecureClientApp::handleMessageWhenUp(cMessage *msg)
{
if (strcmp(msg->getName(), “sendSecureRequest”) == 0) {
sendSecureRequest();
delete msg;
} else {
TcpAppBase::handleMessageWhenUp(msg);
}
}
void SecureClientApp::sendSecureRequest()
{
EV << “Sending secure request to server…” << endl;
sendRequest(“GET /secureData HTTP/1.1\r\nHost: server\r\n\r\n”);
}
To make sure data integrity, execute a simple hash function that computes a hash value before transmission and check it upon receipt.
Hash Module
// HashModule.cc
#include <omnetpp.h>
#include “inet/common/INETDefs.h”
#include “inet/common/packet/Packet.h”
#include <string>
#include <sstream>
#include <iomanip>
#include <openssl/sha.h>
using namespace omnetpp;
using namespace inet;
class HashModule : public cSimpleModule
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
std::string calculateHash(const std::string &data);
bool verifyHash(const std::string &data, const std::string &hash);
};
Define_Module(HashModule);
void HashModule::initialize()
{
EV << “Hash Module Initialized” << endl;
}
void HashModule::handleMessage(cMessage *msg)
{
if (Packet *packet = dynamic_cast<Packet *>(msg)) {
const auto& payload = packet->peekData();
std::string data(payload->str());
// Calculate hash before sending
std::string hash = calculateHash(data);
EV << “Data: ” << data << ” | Hash: ” << hash << endl;
// Simulate sending hash along with data
send(packet, “out”);
// On the receiver side, verify hash (simplified, normally you’d compare against received hash)
if (verifyHash(data, hash)) {
EV << “Data integrity verified.” << endl;
} else {
EV << “Data integrity check failed!” << endl;
}
} else {
send(msg, “out”);
}
}
std::string HashModule::calculateHash(const std::string &data)
{
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, data.c_str(), data.size());
SHA256_Final(hash, &sha256);
std::stringstream ss;
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
ss << std::hex << std::setw(2) << std::setfill(‘0’) << (int)hash[i];
}
return ss.str();
}
bool HashModule::verifyHash(const std::string &data, const std::string &hash)
{
return calculateHash(data) == hash;
}
Perform the EncryptionModule, SecureClientApp, and HashModule into the network to secure data transmission.
network DataSecurityNetwork
{
submodules:
client1: SecureClientApp {
@display(“p=100,100”);
}
client2: SecureClientApp {
@display(“p=100,200”);
}
router: Router {
@display(“p=300,150”);
}
server: StandardHost {
@display(“p=500,150”);
}
encryptionModule: EncryptionModule {
@display(“p=300,250”);
}
hashModule: HashModule {
@display(“p=500,250”);
}
connections:
client1.ethg++ <–> Eth100M <–> encryptionModule.in++;
encryptionModule.out++ <–> router.ethg++;
client2.ethg++ <–> Eth100M <–> router.ethg++;
router.ethg++ <–> Eth100M <–> hashModule.in++;
hashModule.out++ <–> server.ethg++;
}
Compile and run the simulation in OMNeT++. Before transmission the EncryptionModule will encrypt data, and the HashModule will check data integrity. The SecureClientApp will mimic secure requests to the server.
Verify the OMNeT++ simulation log to watch the encryption and hash estimates. Check that the data is encrypted before transmission and that the integrity of the data is kept through the transmission.
We can extend this setup by:
This paper was explained the way how to implement and set up the Data Security using the tool OMNeT++. We will give more details regarding this in various tool.
Do you face struggles to Implement Data Security in OMNeT++. Please let us know about your needs, and we will assist you with best comparison analysis results.