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.

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

And In HandleRead function of the UDP-Echo-Server we would add some
code and make it as following. 
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) =
                                Simulator::Schedule(Seconds(0.005), fp, this, socket, from,

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

1 Şubat 2011 Salı

Adding AES encryption and decryption to UDP Echo Application

I found a simple and compact solution for AES algorithm online. I was trying to develop a secure communication between mesh nodes and found cipher library.

You could find it here.

I put the source codes under the node folder of src folder. I also updated the wscript file and added the names of new source and header files. ./waf build system handles the rest. I made it so because in every application node module is used so I had no problem modifying example codes and I could use this cipher library in every example easily.

I choosed Udp Echo Application because it has built in SetFill function. Which is used for filling packet to send with data. This data is entered as a string parameter. The declaration of the function is given below.

UdpEchoClientHelper::SetFill (Ptr<Application> app, std::string fill);

I simply encrypted some string and put the ciphertext as a parameter to the function. For decryption we should look at Udp Echo Server application's HandleRead function, which works as some kind of an interrupt. When a node receives an Udp packet using Udp Echo Application, this function is fired. It is a siply callback.

31 Ocak 2011 Pazartesi


I will be doing wireless network simulations with NS-3 and I will be sharing the things I learn in this blog.

I merely hope that, the things I share would help someone to develop simulations in NS-3.

Can Leloglu