How to Calculate Network Encryption and Decryption Time in NS2

To calculate the network encryption and decryption time using NS2 (Network Simulator 2), for network traffic contains replicating the processing delay launched by encryption and decryption algorithms when securing the transferred data. The simulation environment NS2 does not natively deliver support for mimicking the cryptographic operations such as encryption and decryption, however we can be modelled the delay introduced by these operations by appending more processing time to packet handling. We can follow the below given procedure to replicate and compute the encryption and decryption time in NS2:

Steps to Calculate Network Encryption and Decryption Time in NS2:

  1. Define Encryption and Decryption Delays:
    We can be allocated a fixed or variable delay to replicate the time taken for encryption and decryption at both the origin and terminus nodes. This delay will rely on the encryption algorithm used (e.g., AES, RSA) and the computational resources are obtainable (e.g., CPU speed).
  2. Modify NS2 Tcl Script to Introduce Delays:
    We can be appended the encryption and decryption delays by manually injecting the delays in packet transmission at the sender (for encryption) and packet reception at the receiver (for decryption).
  3. Track Encryption and Decryption Times:
    We can be logged the time when a packet is encrypted (just before sending) and when it is decrypted (just after reception) to compute the time spent in these processes.

Example Tcl Script to Simulate Encryption and Decryption Delay:

Given below is an instance Tcl script, which introduces artificial encryption and decryption delays to replicate the time taken for these operations.

# Create a new simulator instance

set ns [new Simulator]

# Open trace file to log events

set tracefile [open trace.tr w]

$ns trace-all $tracefile

# Define encryption and decryption delays (in seconds)

set encryption_delay 0.005  ;# 5ms encryption time

set decryption_delay 0.005  ;# 5ms decryption time

# Create two nodes

set node0 [$ns node]

set node1 [$ns node]

# Define a duplex link between node0 and node1

$ns duplex-link $node0 $node1 1Mb 10ms DropTail

# Attach UDP agents for traffic

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

$ns attach-agent $node0 $udp0

$ns attach-agent $node1 $null0

$ns connect $udp0 $null0

# Create traffic source (CBR)

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 512

$cbr0 set rate_ 1Mb

# Introduce encryption delay at the sender (node0)

proc add_encryption_delay {agent} {

global encryption_delay

set ns [Simulator instance]

$ns at [expr [$ns now] + $encryption_delay] “$agent send”

}

# Modify start of CBR to include encryption delay

$ns at 1.0 “add_encryption_delay $udp0”

# Introduce decryption delay at the receiver (node1)

proc add_decryption_delay {pkt node} {

global decryption_delay

set ns [Simulator instance]

$ns at [expr [$ns now] + $decryption_delay] “$node recv $pkt”

}

# Overwrite the packet reception function to add decryption delay

$node1 set ragent_ [new Agent/Null]

$node1 ragent_ instproc recv {pkt} {

global decryption_delay

add_decryption_delay $pkt $self

}

# End simulation after 6 seconds

$ns at 6.0 “finish”

# Finish procedure to close trace file and end the simulation

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Define Encryption and Decryption Delays:
    The script describes the encryption and decryption delays (encryption_delay and decryption_delay) as 5 milliseconds each. These values are replicate the time taken to encrypt and decrypt the packet.
  2. Modify the Send and Receive Processes:
    • At the sender node (node0), the add_encryption_delay function launches a delay before the packet is actually transmitted. This delay mimics the time taken for encryption.
    • At the receiver node (node1), the add_decryption_delay function launches a delay before the packet is processed after reception, mimicking decryption time.
  3. Log the Events:
    Encryption and decryption delays are applied by summing a time delay to the simulation. The actual transferring and receiving events are happen after the delays.
  1. Calculate Encryption and Decryption Time:

The encryption and decryption times are described openly in the script. If we need to create the delays more dynamic, rely on factors like packet size or the type of encryption algorithm, we can be changed the delay calculations consequently.

For sample, we can base the delay on the packet size or a predefined formula, which reflects the difficulty of the encryption algorithm:

# Example of dynamic encryption delay based on packet size

set packet_size [expr [$udp0 packetSize]]

set encryption_delay [expr 0.001 * $packet_size / 512.0] ;# Delay scales with packet size

  1. Measure Encryption and Decryption Time from the Trace File:

To log the encryption and decryption time more explicitly, we can be altered the script to print the timestamps when encryption and decryption are executed.

For example:

# Log the encryption time

proc add_encryption_delay {agent} {

global encryption_delay

set ns [Simulator instance]

set current_time [$ns now]

puts “Encryption started at: $current_time seconds”

$ns at [expr $current_time + $encryption_delay] “$agent send”

}

# Log the decryption time

proc add_decryption_delay {pkt node} {

global decryption_delay

set ns [Simulator instance]

set current_time [$ns now]

puts “Decryption started at: $current_time seconds”

$ns at [expr $current_time + $decryption_delay] “$node recv $pkt”

}

The encryption and decryption times will print in the end or can be redirected to a log file.

  1. Post-Simulation Analysis:

When the simulation is finished then we can be estimated the trace file to know the actual time it took for encryption and decryption, containing how the delays are affected the overall packet transmission time.

Summary of Steps:

  1. Configure encryption and decryption delays in the NS2 Tcl script to replicate the time required for these operations.
  2. Alter the send and receive processes to launch the artificial delays for encryption and decryption.
  3. Record encryption and decryption times by printing the time before and after these delays.
  4. Estimate the trace file or logs to compute the time taken for encryption and decryption.

As illustrated above, we had explained the calculation steps to compute and analyse the Network encryption and decryption time using NS2 simulation platform. Also we will present further informations regarding this topic as required. If you want to figure out the encryption and decryption time for your network using the NS2 tool, just send us your parameter details, and we’ll help you out with the performance analysis results.