How to Implement PUEA Detection in NS2

To implement PUEA detection in NS2 has requires mimicking a cognitive radio network; that executes the primary user emulation attack (PUEA), and then implement detection mechanisms that differentiate among legitimate primary users and replicated the primary users (attackers). Basically Primary User Emulation Attack (PUEA) detection in a Cognitive Radio Network (CRN) denotes to the process of classifying malicious secondary users that act as primary users to conquer the spectrum and mitigate legitimate secondary users from accessing it. Looking for more guidance then ns2project.com will be your best partner. The below is the brief approach to implement the PUEA detection in ns2:

Key Steps to Implement PUEA Detection in NS2:

  1. Set up a Cognitive Radio Network (CRN) with primary users (PUs) and secondary users (SUs).
  2. Simulate a Primary User Emulation Attack (PUEA) in which malicious secondary users mimic primary users.
  3. Implement a detection mechanism to classify PUEA.
  4. Simulate traffic and measure the performance of the detection mechanism.
  1. NS2 Setup for Cognitive Radio Network (CRN)

The first step is to configure a Cognitive Radio Network (CRN) with primary users (PUs) and secondary users (SUs) in NS2.

# Create an NS2 simulator instance

set ns [new Simulator]

# Open trace files for logging the simulation

set tracefile [open “puea_detection.tr” w]

set namfile [open “puea_detection.nam” w]

$ns trace-all $tracefile

$ns namtrace-all-wireless $namfile 1000 1000

# Define the wireless channel for communication

set chan_1_ [new Channel/WirelessChannel]

# Define a topography for wireless communication

set topo [new Topography]

$topo load_flatgrid 1000 1000

# Define propagation and network parameters

set prop [new Propagation/TwoRayGround]   ;# Propagation model

set netif [new Phy/WirelessPhy]

set mac [new Mac/802_11]                  ;# MAC protocol

set ll [new LL]                           ;# Link layer

set ifq [new Queue/DropTail/PriQueue]     ;# Priority queue

set ant [new Antenna/OmniAntenna]

# Configure node settings (for both primary and secondary users)

$ns node-config -llType $ll \

-macType $mac \

-ifqType $ifq \

-ifqLen 50 \

-antType $ant \

-propType $prop \

-phyType $netif \

-channel $chan_1_ \

-topoInstance $topo

  1. Define Primary and Secondary Users

We describe primary users (PUs) that legitimately occupy the spectrum and secondary users (SUs) that can only access the spectrum when it’s not occupied by PUs.

# Define Primary Users (PUs)

set pu1 [$ns node]

set pu2 [$ns node]

# Define legitimate Secondary Users (SUs)

set su1 [$ns node]

set su2 [$ns node]

# Define a malicious Secondary User (Attacker)

set malicious_su [$ns node]

# Position the nodes (PUs and SUs)

$pu1 set X_ 200

$pu1 set Y_ 200

$pu2 set X_ 800

$pu2 set Y_ 800

$su1 set X_ 100

$su1 set Y_ 100

$su2 set X_ 300

$su2 set Y_ 300

$malicious_su set X_ 500

$malicious_su set Y_ 500

  1. Simulate Primary User Emulation Attack (PUEA)

The malicious secondary user (attacker) act as a primary user and transfer out signals that replicate the primary user’s transmissions to make legitimate secondary users believe the spectrum is occupied.

Example: Emulate Primary User by the Malicious Secondary User

# Procedure to emulate primary user transmission by the malicious secondary user

proc emulate_primary_user {malicious_su start_time stop_time} {

global ns

puts “Malicious SU $malicious_su emulates a Primary User from $start_time to $stop_time”

$ns at $start_time “puts Malicious SU starts emulating PU”

$ns at $stop_time “puts Malicious SU stops emulating PU”

}

# Malicious secondary user emulates a primary user between 3.0 and 8.0 seconds

emulate_primary_user $malicious_su 3.0 8.0

The malicious secondary user will “emulate” the primary user during the particular time interval; mitigate legitimate secondary users from accessing the spectrum during this period.

  1. Implement PUEA Detection Mechanism

There are numerous approaches for classifying PUEA in cognitive radio networks, like signal strength analysis, location verification, or energy detection. For simplicity, we will use a simple signal strength threshold technique to classify whether the transmission is from a legitimate primary user or a secondary user pretending to be a primary user.

Example: Simple Signal Strength-Based Detection

We can assume that the primary users have higher signal strength than secondary users. If the signal strength detected is below a particular threshold, it can be flagged as an emulation attack.

# Procedure to detect PUEA based on signal strength threshold

proc detect_puea {su pu malicious_su threshold} {

global ns

# Assume we get the signal strength from each node

set su_signal_strength [expr rand() * 50]     ;# Simulated signal strength of SU

set pu_signal_strength [expr 70 + rand() * 30];# Simulated signal strength of PU

set malicious_signal_strength [expr rand() * 50] ;# Signal strength of malicious SU

# Check if the detected signal strength is below the threshold

if {$malicious_signal_strength < $threshold} {

puts “PUEA detected: Malicious SU $malicious_su emulating PU with signal strength: $malicious_signal_strength”

} else {

puts “No PUEA: Legitimate PU transmission detected.”

}

}

# Check for PUEA starting at 3.0 seconds (when the malicious SU starts emulating the PU)

$ns at 3.5 “detect_puea $su1 $pu1 $malicious_su 60”

In this detection mechanism, if the signal strength of the malicious secondary user is below the threshold (60 in this case), we assume that it is not a legitimate primary user and flag it as a PUEA.

  1. Traffic Setup for Primary and Secondary Users

To replicates normal traffic for both primary and secondary users. Use UDP traffic to denote real-time video or data streaming.

Example: Traffic for Primary and Secondary Users

# Create UDP agents for PU and SU communication

set udp_pu1 [new Agent/UDP]

set udp_su1 [new Agent/UDP]

set null_sink1 [new Agent/Null]

set null_sink2 [new Agent/Null]

# Attach agents to primary and secondary users

$ns attach-agent $pu1 $udp_pu1

$ns attach-agent $su1 $udp_su1

$ns attach-agent $su2 $null_sink1

$ns attach-agent $pu2 $null_sink2

# Connect PU and SU agents

$ns connect $udp_pu1 $null_sink2

$ns connect $udp_su1 $null_sink1

# Create CBR traffic for PU and SU

set cbr_pu [new Application/Traffic/CBR]

$cbr_pu attach-agent $udp_pu1

$cbr_pu set packetSize_ 512

$cbr_pu set rate_ 200Kb

set cbr_su [new Application/Traffic/CBR]

$cbr_su attach-agent $udp_su1

$cbr_su set packetSize_ 512

$cbr_su set rate_ 100Kb

# Start and stop traffic

$ns at 1.0 “$cbr_pu start”

$ns at 10.0 “$cbr_pu stop”

$ns at 2.0 “$cbr_su start”

$ns at 9.0 “$cbr_su stop”

  1. Running the Simulation

Set the simulation end time and executed it.

# Set the simulation end time

$ns at 20.0 “finish”

# Finish procedure to close trace files and end simulation

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exit 0

}

# Run the simulation

$ns run

  1. Analysing the Results

After the simulation, evaluate the trace files and network animation (NAM) to assess the performance of PUEA detection:

  • Detection Accuracy: verify how often the detection mechanism appropriate identifies the PUEA.
  • Throughput and Latency: Measure the effect of PUEA on the network’s overall performance.
  • False Positives/Negatives: Evaluate whether legitimate primary users were inappropriately flagged as attackers and if any attacks went unidentified.

In this technique we clearly expanded the complete information about how to execute and analyses the results for PUEA detection that were executed using ns2 tool and also we deliver additional details regarding the PUEA detection.