18 Mart 2011 Cuma

How to add computation time to NS3 simulation for encryption and decryption purposes


As you would know there is no framework which would enable a NS3 simulation to add a fixed delay to operations.
That would be very necessary for network simulations involving encrypion, decryption or other kinds of cryptographic operations which could add considerable computation time to the overall system time.

The one or maybe the only way to do this is to schedule our operations according to a fixed delay.

I will give an example involving UdpEchoServer application which I believe you all are familiar.
That would be reasonable to have a dummy function which only serves to send a packet through a given socket by parameter. With this example you would also see how to schedule a function with parameters.


void
UdpEchoServer::sendBack(Ptr soc, Address from, Ptr
packet)
{
        soc -> SendTo(packet, 0, from); 

}
And In HandleRead function of the UDP-Echo-Server we would add some
code and make it as following. 
void
UdpEchoServer::HandleRead (Ptr socket)
{
  std::ofstream output;
  Ptr packet;
  Address from;
  while (packet = socket->RecvFrom (from))
    {
                     if (InetSocketAddress::IsMatchingType (from))
                        {
                                InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
                                Ipv4Address remote = address.GetIpv4(); 
                                NS_LOG_INFO ("Server received " << packet->GetSize() << " bytes
from " <<
                                                         address.GetIpv4()<<" at "<GetUid());
                                packet->RemoveAllPacketTags ();
                                packet->RemoveAllByteTags (); 
                                NS_LOG_LOGIC ("Echoing packet"); 
                                void (UdpEchoServer::*fp)(Ptr, Address, Ptr) =
&UdpEchoServer::sendBack;
                                Simulator::Schedule(Seconds(0.005), fp, this, socket, from,
packet);
                        }
    } 


That piece of code should add a delay 0.005 seconds for server application to echo a packet.