Challenges in Wireless Mesh Networks

Having understood the creation and working of the network and its topology, it is time to understand the problems one can face in this exercise and methods to overcome them. 

Implementing a wireless mesh network poses several challenges in terms of achieving high performance, scalability, security and so on.

Since in a wireless mesh, each node serves both as a user and router of the network, it opens up the network to a variety of attacks such as physical attacks
(theft of laptops and large number of access points) DOS attacks, Gray, Black and wormhole attacks etc, which need to be considered while designing the network.
These problems persist at all layers.

While implementing and testing the mesh network, we faced the following issues:

Coverage:

We found that the distance between nodes that can communicate as part of the network is not deterministic.It varies depending on the physical environment of the participating nodes.Between the same two nodes, the radius of coverage changes with physical parameters of the surrounding environment. Ideally, the network should account for change in such physical parameters so as to be able to function optimally in all environments. This is particularly useful as it eliminates the need to configure a network separately for each application.

Performance and Scalability:

We find that the delay in communication between any two nodes in the network increases with the total number of participating nodes. Thus, the performance of the network drops with the addition of more nodes due to the reasons explained above. This also means that the network is not suitable for applications where the total number of nodes in large and is susceptible to change over time(due to dynamic addition of nodes).

Interference due to external networks:

Since there is no physical separation of media, there is no simple mechanism to prevent
other networks from interfering with the one under observation. This affects the performance, coverage and scalability of the network as well.

Although our experiment did not involve study of security aspects of the network, it is evident that the communication within the network is not very secure. Also, employing a wireless mesh is only suitable for applications with sufficient resources at disposal. Since the effects of interference cannot be easily eliminated, there is a large possibility of poor performance of the network for most applications. While allotting separate channels or adding more spectrum for communication does help, given the number of wireless technologies around, this comes at a significant cost.

Thus, the wireless mesh mode of communication must be chosen wisely – keeping the above constraints and challenges  in mind for the intended application.

Diving into subnets

Now it is the time to check if the mesh will work in the similar fashion when we create subnets.

Again the basic idea remains the same, subnets are created and we try to communicate between two devices in different subnets.

Image courtesy: Google1

 The above picture gives a basic idea of what is expected from the subnet. As you can see two mesh networks have direct internet connectivity i.e mesh with network 192.168.12.0/24 and mesh with network 192.168.13.0/24 are connected at points A and B though the mesh with network 192.168.11.0/24 doesn’t have direct internet connectivity the clients in the third network will be able to use internet because of E and D (which in turn is connected to internet).

 Simple way to create subnets for topology as shown below

 

intermediate
fig.1

In the process of creating the mesh network as instructed in this post, we assign IPs also.

The connection A—-B is given a network of 10.10.10.0/24 ( 10.10.10.1 for A and 10.10.10.2 for B)

The connection B—-C is given a network of 20.20.20.0/24 (20.20.20.1 for B and 20.20.20.2 for C)

We enable IP forwarding in B which will act then act as a router.This can be done using the command

sudo sysctl -w net.ipv4.ip_forward=1

We then add routes in forwarding tables of A and C using

route add default gw 0.0.0.0 <logical-mesh-interface>

Note: We have to assign two ip adressess to the same interface in the system B, in order to make sure it is connected to two different networks.(i.e 10.10.10.2 and 20.20.20.1).

After this setup, we should be able to ping every node from every node.

What happens if we swap two adjacent nodes keeping the IPs intact as shown below?

swapped
fig.2

OBSERVATION:

  1. A can communicate with B. Ex: ping
    • Path followed is A–>C–>B for request.
    • Path is B–>C–>A for response.
  2. A can communicate with C. Ex: ping
    • Path followed is A–>C–>B–>C for request.
    • Path is C–>B–>C–>A for response.

How is this happening ?
Answer is bridging. Bridging, explained here, can happen between 2 subnets. The channel is same here in our example. Hence, bridging can happen. C acts as the bridge for A and B. Even if there is bridging, the route followed by communication is decided by B. It will be the same as before swapping.

 

Multi-Hop Communication

3-hosts

Hi! We will now share our learnings from using mesh networks in some topologies. The topologies were asked to be tested by our guide, Dr. Ram P Rustagi, PES University. In this post we will be discussing about:

  • Multi-hop communication with topology as in the above figure.
    • How it happens?
    • What is the performance?
  • Diamond Topology.

Consider the topology of 3 nodes above. The circular areas depict their coverage areas. We can observe that :

  • B can reach A and C
  • A can reach B
  • C can reach B
  • A cannot directly reach C
  • C cannot directly reach A

You should have also observed the text Bridge on node B. We will explain that soon. Now set up the network with 3 nodes and make sure the above topology is prevailed. You can deduce coverage of a node (it is a common sense solution, but let me tell anyway) by:

  • Set up two nodes next to each other.
  • Ping each node from the other.
  • Move one node away from the other. Keep one node stationary.
  • Just when each node is not able to ping the other, stop moving and bring the moving node back into coverage by taking a few steps back towards the stationary node.

You will have to use the same method for testing the scenarios in future posts. Using the above steps define a topology as in the diagram by maintaining sufficient distance between the nodes. Now the questions are:

  • Can A ping C and vice-versa ?
  • How are the response times at each node, when each node pings the other?
  • What is the packet loss rate ?
  • Can you see the route ?

Can A ping C and vice-versa ?

This happens because of the principle of bridging. A bridge, in this context, only forwards traffic to stations on the other side of the bridge if it has learned that that station is on the other side of the bridge. If it hasn’t seen the target MAC, it will send it over the bridge (flooding) or if it is a broadcast / multicast, it will also send it over the bridge. Without the bridge, people from one region cannot commute to other. Here, the packets in one subnet cannot reach the other without the node which acts as the bridge. Note that bridging is different from router’s routing. Routing involves more than one network. Bridging involves only one network in our case. A switch is a multi-interface/port bridge. A bridge generally functions over one interface.

How are the response times at each node, when each node pings the other?

There are two questions that can arise :

  • Suppose when you ping from A to C, you can notice that the sequence numbers(icmp_req) for some ping requests are not displayed. Why ?
  • This means that A did not receive response for that particular request. Also, to display ICMP errors, A should have received that. But why didn’t A throw an error ?
  • You can also notice that on A the ping responses do not have sequence number in order. Responses are arriving out of order. Why ?

The answer is responses received by A would collide with B’s forwarded ping. When A pings C, B receives it and sends it out in its coverage. C would receive the forwarded ping request and respond. B would send the response to A, but it will also collide with A’s requests generated at A and those forwarded by B. A would not detect any error or the response.

One more reason is the Hidden Terminal Problem. C is hidden terminal to A. A’s ping requests and C’s responses collide at B. Sometimes B would not receive C’s ping responses.What is the packet loss rate ?

The answer to this question is purely subjective. But there will be a noticeable amount of packet loss.

How to see the path to C from A ?

When we thought of this, the first thing that came to our mind was traceroute command line utility. However we are not communicating across networks. traceroute can be used only when we communicate across networks. To see the nodes reachable to you in the network use the following command:

sudo iw dev <name of logical mesh interface> station dump

 

To see the next hops for the nodes you have use the command:

sudo iw dev <name of logical mesh interface> mpath dump

The above command can also be used for configuring routing in mesh networks.


Diamond Topology

diamond

The above topology is called Diamond Topology. Now, after knowing principle of bridging, we know that D is reachable from C via A or B. Now bring B down. The communication between C and D happens via A. Bring A down. Bring B up. Now communication between C and D would experience some delay or errors. But after about 15-20 seconds(is generally below 30 seconds), the communication happens smoothly. This is because of the self-correcting nature of mesh networks! Yes. The same self correcting nature is also observed in this post.


That’s it for now folks. Thank you for reading through the blog.

Creating a Wireless Mesh Network using Ubuntu 14.04

Hi there! We have now started a series of blogs on the topic Wireless Mesh Networks. We begin with the assumption that you have a fair idea about mesh networks.

mesh

In this post, we will be implementing a Wireless Mesh Network. We’ll show you how to setup for basic use Ubuntu 14.04 or higher to create a mesh network and communicate based on what is explained here. We will limit to single hop communication in this post.

Prerequisites:

  • Ubuntu 14.04 or higher
  • 3 laptops minimum
  • Other requirements are mentioned here

Setting up and Joining a mesh network:

1. Turn down the default network-manager 

sudo service network-manager stop

2. Add another logical interface using wireless interface with the type as mp. In the code below mesh0 is the name of the logical interface.

sudo iw dev wlo1 interface add mesh0 type mp

Here, “type mp” indicates that the new interface will be associated to a mesh network.

3. Now bring the wifi interface down, so as to enable the mesh interface

sudo ip link set wlo1 down

4. Bring the mesh interface up

sudo ip link set mesh0 up

5. Now we join the mesh network where the name of mesh network is loopback.

sudo iw dev mesh0 mesh join loopback

6. Follow the same steps from 1 to 5 in other system to join the same mesh network for the other two systems.

7. Now you should be able to ping any system from any other system which are in the same mesh network. You can also see the devices which are reachable to your system by one hop using station dump.

sudo iw dev mesh0 station dump

We now recommend you to go to some open space and start experimenting with commands like nc, ping, traceroute. We will enumerate scenarios and discuss about them in the next post.

Our observations:

1. Just using two laptops we were able to ping(single-hop) over a distance of about 250 meters which was an open ground without much obstacles.

2. The coverage of a node decreases if there are obstacles such as walls or interference with other wireless networks. However, setting a different channel can help.

3. More parameters can be set as per need. They are explained here and here.

4. To monitor the network traffic, the monitoring node cannot behave as a communicating device. That is the only constraint. You have to change type of the interface to monitor and run the latest version of Wireshark. It can dissect all mesh frames in Open Mesh and unencrypted Management frames in Secured Mesh. A node with interface type set to monitor need not associate to any AP/network. It captures all the traffic. To communicate with nodes in a network, you will have to be a member of the network, which is not the case for a monitoring node. There are 7 types of modes, which we had found to be listed on wikipedia for an interface:

  • Managed
    • interface behaves as a transmitting and receiving device in the network
    • type managed” in iw dev
  • Mesh
    • node will behave as a mesh node via the interface
    • type mp” in iw dev
  • Ad-Hoc
    • node will behave as a node in ad-hoc network via the interface
    • type adhoc” in iw dev
  • Monitor
    • Makes that interface to monitor all traffic without joining a network
    • type monitor” in iw dev
  • Repeater
    • Makes node behave as a repeater
  • Master
    • Makes node behave as an AP through that interface
  • Promiscuous
    • Enables traffic monitoring on that node after associating to an AP/network

One more mode listed by documentation of iw is :

  • wds
    • Wireless Distribution System.
    • It can behave as a repeater as well as accept wireless clients connections.

We used iwconfig to change mode of interface as explained in this post, more clearly in the 17th line of code here. A node with interface in mode monitor cannot transmit packets because you are not associated with any network via an AP.


That’s it for now folks. Thank you for reading through the blog.

Running the Code

In the previous post, we had set up the environment and have the behaviour as discussed in this post, in an ad-hoc network. By now you should have downloaded the code from Google Drive link shared in previous post. This post is about how to run the same.

  • Download the code and place it in a folder in your system.
  • Open the terminal and change the present working directory to that folder.
  • Switch to root user. Enter the password in the process.
    • user@hostname:~$ sudo su
  • Give execute permissions to all scripts.
    • user@hostname:~$ chmod +x *.sh
    • user@hostname:~$ chmod +x *.py
  • Now, one node, should set up the network for others to join. The first node calls the program adhoc.py as shown below and gives the required parameters.
    • SSID
    • Passkey for WEP
  • Note that votrashi is the user of first node.

scan

  • It calls scan.sh to detect the network. It detects that there was no ad-hoc network of the same SSID. It just creates the network by calling create.sh.
  • Now the network is set up, let other nodes run the same program with same inputs.
  • The program will detect that there was already a network. It will show the networks with matching ESSIDs.
  • The next parts will be outputs of the daemons invoked in create.sh.
  • Note that sharoon is the user on the second node. The shell script receiver.sh tells the user that it is up and running and the create.sh gives the output during creation of default directory on the node for receiving data from senders during data transfer.

receiver

  • The program broadcastPing.py tells the user it is up and running by displaying

broadcast

  • The program sendUserName.py tells the user it is up and running by displaying

send-user-name

  • Now each node will be listening for neighbours, username requests and key sharing.
  • Now let us look at the status of Neighbour discovery process. Each node, as explained in the previous post, will be telling others about its presence as well as detecting other nodes by their broadcast pings. After detecting nodes for every few packets, each node, will get names of users logged in on each new IP (This is done for all IPs during the first neighbour discovery iteration).

neighbour-discovery

  • After getting the names of users, each node will move on to verify if the detected IPs are still active. The set of active IPs are shown to user before data transfer.

before-data-transfer

  • Let us select data transfer by choosing option 0.
  • After choosing data transfer, user is asked to select IPs to be sent data to. And after that, user selects the files in adhocDir to be sent. The output is as shown below.

data-transfer

  • Now the data transfer output is nothing but output of scp command. We will have to give in password for each transfer. We can overcome this by usage of cryptographic key system or other ways. This is not the focus, as of now.

data-transfer-stages

  • The ending line says that it took 12 seconds for the scp command to execute completely. When transferring data to a node for the first time, scp reports the time and it would seem that it took a lot of time. However, it is because we will have to approve connecting to the other node by choosing yes. Even this time is used by scp to calculate the total time. The throughput of the transfer for each file transferred.
  • Now, you can exit the program by selecting option 1 after neighbour discovery. The program then calls refresh.sh which kills all daemons launched by create.sh.

Thank you for reading this post. We hope you could comprehend the working of the code, the output and how the functionalities discussed here were met. Feel free to reach out to us. We look forward to improve the entire process by taking into account principles of product development and make the programs platform independent.

REGARDS,

TEAM LOOPBACK

Setting up,joining and interacting in a WiFi Ad-Hoc network (Ubuntu)

Hi. This post will be a tutorial on how to do ad-hoc networking in Ubuntu. Here’s what this post will focus on:

  • Setting up an Ad-Hoc network.
  • Scanning for Ad-Hoc networks and joining them.
  • Detecting neighbour nodes in the network, and also verify their presence every interval.
  • Data transfer between nodes in the network.
  • Learning and enumerating other scenarios.

The prerequisites:

  • Ubuntu OS, preferably 14.04 LTS and higher.
  • python3 and basic knowledge of shell scripts.

We will focus on the requirements posted in this blog post.


Scanning for the Ad-Hoc network

One node will setup the network. For other nodes to detect the network, the below shell script can be used to find Ad-Hoc networks of the same SSID. We will use nmcli and grep commands, former to scan for all wireless networks, latter to match an ad-hoc network of required SSID which is passed as first parameter while this program is invoked. Let us save the script below as scan.sh.


#!/bin/bash

# first param is ssid
echo "Scanning for ad-hoc $1..."

# Built-in seconds variable to show time elapsed to find the required network
SECONDS=0
searchResult=`nmcli dev wifi | grep -P -o '$1'.*?Ad-Hoc'`
echo "Took $SECONDS seconds to scan for network"
echo $searchResult # echo the matched networks


Creating/Joining the network

To set up the network, we will use some of the commands like ip, iwconfig,  ifconfig, service, awk and cut in Ubuntu. Let us write a shell script to achieve the same. What we would generally need to connect to / set-up a network would be:

  • Name/Identifier of the network – SSID of the network. To know more about SSIDs, click here.
  • Password for joining the network. An overview of various security algorithms can be found here.
    • We will use the WEP policy which employs a simple passkey login. To know more, click here.
  • The ethernet interface through which you will connect to the network. We will, in this tutorial, use wireless interface. Since the wireless interfaces are named differently on different machines (depends in manufacturers), we can find the name of the wireless interface using ifconfig and awk commands.
  • We will need to use a unique IP address. So, let us make use of IP addresses computed based on MAC address of the wireless interface.

The shell script below explains the process employed in creating/joining the network.

#!/bin/bash

#We will use the built-in SECONDS variable to find out time elapsed for the entire process
SECONDS=0

# Get the name of wireless interface
iface=`ifconfig -a | awk '/^w.[a-z]/{print $1}'`
# Get the MAC address of the interface
mac=`ifconfig -a | awk '/^w.[a-z]/{print $NF}'`

# There are 3 parameters that will be sent while invoking this script
# SSID, Passkey for network and Username of the user on the host
ssid=$1
password=$2
username=$3

# turn off network manager
sudo service network-manager stop
# deactivate the physical interface(wireless)
sudo ip link set "$iface" down

# set the interface's mode to Ad-Hoc
sudo iwconfig "$iface" mode ad-hoc
# make it decide channels automatically
sudo iwconfig "$iface" channel auto
# set the essid of the network to be same as the $ssid parameter
sudo iwconfig "$iface"; essid "$ssid"
# set the password as the $password parameter
sudo iwconfig "$iface" key "$password"

# activate the wireless interface
sudo ip link set "$iface" up

# compute the IP based on 4th, 5th and 6th octets of MAC address of the interface
str1=`echo $mac |cut -d':' -f4`
str2=`echo $mac |cut -d':' -f5`
str3=`echo $mac |cut -d':' -f6`

# convert the hexadecimal information to octets
o2=`echo $((0x$str1))`
o3=`echo $((0x$str2))`
o4=`echo $((0x$str3))`

# compute the IP
ip=10.$o2.$o3.$o4/8

# assign the IP to the interface
sudo ip addr add "$ip" dev "$iface"

# display the IP and interface
echo "$ip is the IP"
echo "$iface is the interface"
# show time elapsed till now
echo "It took $SECONDS seconds"
echo

sudo python3 sendUserName.py &
echo

sudo python3 broadcastPing.py &
echo

sudo ./receiver.sh "$username" &
echo

sudo mkdir /home/$username/adhocreceiver
sudo chmod 777 /home/$username/adhocreceiver

Let us name the above shell script as create.sh. The host can interact in the network soon /after the IP gets assigned in line 48. The same can be used for joining the network.

The lines 57, 60 and 63 invoke respectively the following programs:

  • sendUsername.py
    • Explained in Neighbor Discovery Section in the same post.
  • broadcastPing.py
    • Explained in Neighbor Discovery Section in the same post.
  • receiver.sh
    • Requires username as parameter.
    • Explained in Data Transfer section.

Lines 66 and 67 create a directory for receiving data, and set permissions for successful data transfer. The same directory will be used in programs for data transfer.


Neighbor Discovery

Neighbor discovery in any node in the network involves two parts:

  • The node telling other nodes about its presence.
  • The node detecting other nodes.

We will discuss one possible method to achieve the same.

Coming to the first part, the below python code helps us in telling other nodes in the network about our presence. We ping the broadcast address of the network – 10.255.255.255. We call a shell command via python and make it run quietly in the background. It sends 10 packets, in every call until the nodes leave the network. Let us save the below python code as broadcastPing.py.


import subprocess
import os,time

# redirect all outputs and errors to Null File Directory of the host
null_fd = open(os.devnull,"w")

def startBroadcast():
  while True:
    subprocess.call("sudo ping -q -b -c 10 10.255.255.255",shell=True,stdout=null_fd,stderr=null_fd)

print("\nPing broadcast started\n")
startBroadcast()

Each and every node will be running broadcastPing.py in the background after the node is in the network. – line 60 in create.sh. Now let us move on to the second part, detecting other nodes in the network.

The algorithm of detecting other nodes in the network is as shown below:

 Loop always:

  1. Usage of tcpdump and get only these broadcast packets in the channel.
  2. Make note of detected IPs.
  3. For each and every new IP detected, get the username of the host. This is required, later during data transfer.
  4. Finding out which nodes are active.

First we need a listener to be running on each node after joining the network to share the usernames which would be later required for data transfer. In line 57 of create.sh, we can see a call being made to sendUserName.py. The code of this program is as shown below. This registers a listener on each node on port 23000 (can be any port), answering “send” queries by other nodes with the hostname of each node. The process of registering the listener on the node will require the program to know the IP. The IP can be found out using the below shell script after the node is in the network. The same script also gives us the name of the wireless interface of the node.

Let us save the below shell script as print_ip_interface.sh.

#!/bin/bash

iface=`ifconfig -a | awk '/^w.[a-z]/{print $1}'`
mac=`ifconfig -a | awk '/^w.[a-z]/{print $NF}'`

str1=`echo $mac |cut -d':' -f4`
str2=`echo $mac |cut -d':' -f5`
str3=`echo $mac |cut -d':' -f6`

o2=`echo $((0x$str1))`
o3=`echo $((0x$str2))`
o4=`echo $((0x$str3))`

ip=10.$o2.$o3.$o4
echo $ip
echo $iface

The code for python program, sendUserName.py is as shown below.

import socket
import subprocess
import time

print("\nPreparing endpoint...")
print("Finding username...")
machine_username = subprocess.check_output(['who']).decode().split()[0]
print("Your username is...",machine_username)
print("Finding your IP...")
machine_ip,machine_interface = subprocess.check_output(['./print_ip_interface.sh']).decode("utf-8").strip().split()
print("Your IP is...",machine_ip)
print("\nAll done! Now waiting for username requests...\n")

def sendUserName():#on receiver
  send_hostname_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  send_hostname_socket.bind((machine_ip,23000))
  while True:
    data,sender_address = send_hostname_socket.recvfrom(512)
    data = data.decode()
    if data == "send":
      print("Received username request from ",sender_address[0])
      send_hostname_socket.sendto(machine_username.encode(),sender_address)
sendUserName()

The program sets up a port using UDP listener on each node. This will be invoked by create.sh and will be running in the background.

The python code below has implemented the algorithm mentioned above for detecting other nodes. Let us save the code below as detectNeighbours.py.

import subprocess
import socket
import time

ip_hostnames = dict()

def getHostNameNode(node_ip):#on sender
  get_hostname_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  print("Asking for username of ",node_ip," ......")
  get_hostname_socket.sendto("send".encode(),(node_ip,23000))
  node_hostname = get_hostname_socket.recvfrom(512)[0].decode()
  return node_hostname

def detectNeighbors():
  while True:
    tcpdump_output = subprocess.Popen("sudo tcpdump -c 30 \"broadcast\" | grep -P -o '([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*? >'",stdout=subprocess.PIPE,shell=True)
    output_ips = tcpdump_output.stdout.read().decode("utf-8").splitlines()
    output_ips = list(set(output_ips))
    output_ips = [ i.split()[0] for i in output_ips ]
    for each_ip in output_ips:
      if each_ip not in ip_hostnames.keys():
        print("Getting user name at ",each_ip)
        ip_hostnames[each_ip] = getHostNameNode(each_ip)
    copy_ip_hostnames = dict(ip_hostnames)
    for each_ip in copy_ip_hostnames: # removes nodes which are no longer in the network
      node_status = subprocess.call("ping "+each_ip,stdout=subprocess.DEVNULL,shell=True)
      if node_status != 1:
        ip_hostnames.pop(each_ip)

detectNeighbors()

For every unique IP detected in ping broadcast output by tcpdump, and among them, for every new IP that was detected, the code asks the node for the username of the node. Remember, sendUsername.py will be the listener running on each node to respond back with the username. And for all IPs in the dictionary maintained by the program, the presence of the node is verified again by pinging that node.

We will be making additions to the same function for data transfer process.


Data Transfer between nodes

Among many ways to transfer data between two nodes, let us see the implementation of the same using scp utility. To send data to other nodes using scp, we require the receiver to accept data from the sender. One way to achieve this is receiver confirming(indirectly) data transfer request by sharing the password only with the sender. The sender will then send the file to the default directory created by lines 66,67 in create.sh. There are other ways, which employ shared key system, or asymmetric key system. We look forward to implement the same in the future.

After detection of nodes in the network, we will ask the user whether he wants to transfer data or exit the program or else, continue the neighbour discovery process. If the user wants to do data transfer, we will ask him to choose the IPs he wants to send data to. After selection of the IPs, the user will be asked the files/folders that should be sent to each IP. We need to write two shell scripts, one for sender to send selected data and receiver to listen for keys being shared to it by other nodes. Although we are not using the key system as of now, we will in the future write a separate post to achieve data transfer safely using the key system.

The shell script below is for sending the specified file to the user at the specified IP. One parameter(the last parameter) is to indicate whether that node needs to be shared the key (before first transfer only). You can neglect the key sharing part in both shell scripts. Let us save the script below as sender.sh.

#!/bin/bash

recipientIP=$1
hostName=$2
file=$3
val=$4 #indicates whether to send public key or not

sender_name=`who`

port=10000
echo $recipientIP
z=0
if [ "$val" -eq "$z" ]; then
 # need to send public key
 nc "$recipientIP" "$port" /home/$sender_name/.ssh/id_rsa.pub #use tcp
fi

# Built-in variable to find out the time elapsed for transfer of each file to receiver.
SECONDS=0
scp -r adhocDir/$3 "$hostName"@"$recipientIP":/home/$hostName/adhocreceiver/
echo "It took $SECONDS seconds for transfer of $3 to $hostName@$recipientIP"

The shell script below sets up a listener on the every node to receive and store inbounb public keys. Let us save it as receiver.sh.

#!/bin/bash

echo "/home/$1/.ssh/authorized_keys will be the folder i will be placing keys in"

while :
do
 echo "Listening for keypairs...";
 nc -l 10000 >> /home/$1/.ssh/authorized_keys
done

The detectNeighbours function shown in Neighbour Discovery part, will have the following additions after line 28. The flow in this code was already explained above. Each node will have data to be sent in a directory called adhocDir whose contents are displayed by executing ls command via python. Be sure to create this directory and move data to be sent into this directory before selecting files to be sent.

    choice = int(input("Enter 0 for data transfer, 1 to exit:"))
    if choice == 1:
      subprocess.call("./refresh.sh",shell=True)
      break
    elif choice == 0:
      print("Detected IPs and users were shown above, choose whom to send.")
      #user chooses receivers #append it to receiver list
      receiver_ips = []
      while True:
        choice = input("Enter detected IPs of your choice (1 to stop):\t")
        if(choice == "1"):
          break
        receiver_ips.append(choice)
      print("Choose files/folder to select:")
      contents = subprocess.check_output("ls adhocDir",shell=True).decode().split()
      pprint.pprint(contents)
      #user will have selected directory or the files to be selected
      files_to_be_sent = []
      while True:
        choice = input("Enter files of your choice (1 to stop):\t")
        if(choice == "1"):
          break
        files_to_be_sent.append(choice)
      for each_ip in receiver_ips:
        node_status = subprocess.call("ping -c 5 "+each_ip,stdout=subprocess.DEVNULL,shell=True)
        if node_status == 0:
          #scp
          print("SCP stats are displayed for each transfer")
          for each_file in files_to_be_sent:
            if each_ip not in ip_pkey_received:
              ip_pkey_received.append(each_ip)
              subprocess.call("./sender.sh "+each_ip+" "+ip_hostnames[each_ip]+" "+each_file+" 0",shell=True)
            else:
              subprocess.call("./sender.sh "+each_ip+" "+ip_hostnames[each_ip]+" "+each_file+" 1",shell=True)

refresh.sh is a shell script that kills all launched daemons by create.sh. It also reverts changes made to interface’s IP and any changes that were reflected in networking processes run and maintained by each node. The code of refresh.sh is as shown below:

#!/bin/bash

echo "Before:"
ps aux | grep -P "sudo|10000"
echo "------------"

pid=`ps aux | grep -P "sudo ./receiver.sh" | awk '{print $2}' | head -n 1`
pid1=`ps aux | grep -P "nc -l 10000" | awk '{print $2}' | head -n 1`
echo "Killing keypair listener processes - $pid and $pid1..."
kill "$pid" "$pid1"
echo "...done!"
echo "------------"

pid=`ps aux | grep -P "sudo python3 broadcastPing.py" | awk '{print $2}' | head -n 1`
echo "Killing ping broadcaster process - $pid..."
kill "$pid"
echo "...done!"
echo "------------"

pid=`ps aux | grep -P "sudo python3 sendUserName.py" | awk '{print $2}' | head -n 1`
echo "Killing username listener process - $pid..."
kill "$pid";
echo "...done!";
echo "------------";

echo "After:";
sudo service network-manager start
ps aux | grep -P "sudo|10000";

Now the time has come to integrate all these features into one single master program. We have integrated all the codes, i.e., all the features are automatically invoked by calling one python program, adhoc.py which takes SSID of the network and passkey for the Ad-Hoc network as input. You can find the codes at Google Drive or on Github.


Learning

We hope you find this blog helpful. We learnt a lot in the process of achieving the requirements listed by Dr. Ram P Rustagi sir. Here is a small part of what we learnt in the entire process and under the guidance of RPR sir:

  • Looking into man pages and interpreting them.
  • Learnt many networking commands, which we were unaware of initially.
  • Each wireless network has a cell associated with them. Nodes in the same cell and same network are able to talk with each other.
    • If A initiates the network and B,C,D join the same, and then A leaves the network, B,C and D were able to talk with each other.
    • If A,B,C,D and E are in the same network, and A,B move far away from C,D and E, both groups will have same cell associated with them. A and B can talk with each other. C,D and E can talk with each other.
  • Pinging the sender during data transfer every 1 ms or less, affected the data transfer rate.

We achieved a throughput of 2MB/s using scp. We look forward achieve higher speeds and reduce power usage of each node while on the network. There are better ways for the neighbour discovery process and safer ways for exchanging data. Feel free to ask any questions that may occur to you after going through this blog post.


Regards,

TEAM LOOPBACK.

Functionalities of a basic WiFi Ad-Hoc network

The system will support the following functionalities:
1. A system initiator starts the ad hoc network taking the SSID as a parameter.
2. The groups members search for SSID availability and join the network.
3. IP addresses are assigned to the group members in the range 10.x.y.z where x,y,z are the last 3 octets of the MAC address of the systems.
4. Displays the neighbour nodes and their IP addresses to a user wanting to send a file.
5. Takes the directory, file and the nodes to which transfer is to be made from the sender as input.
6. Transfers the file to a pre-specified directory on the receiver.
7. Provides the statistics for data transfer such as the time taken to search for the network, time taken for file transfer, throughput etc.

 

Setting up an ad-hoc network using ubuntu 16.04

Hoping you will be working on ubuntu we shall give you step by step procedure about how to set up an ad-hoc network.

Functionalities:

  • one person in the group creates ad-hoc network
  • other members in the group join the network
  • look the IP address assignment (manual vs auto)
  • check if its reachable using ping
  • do concurrent data transfer
  • look at throughput
  • person who created the network will disconnect from the network
  • can the remaining members talk
1
Turn off wifi by deselecting enable wifi in the network settings
2
Click on edit connections, then select add to create new network (select wifi)
3
In the wifi tab give your network a name :ssid(adhoc) and select mode as Ad-hoc
4
Bind the mac address with the device, finally your wifi tab should look something like this.

The band is the bandwidth which can be opted for the ad-hoc network, it’s better to keep it automatic, as most of the computers wont support 5GHz bandwidth.next move to wi-fi security tab.

5
you can either skip this, or give a security password, when you select WEP 128-bit passphrase option, you can only use 5 or 13 alphabet password, or else other systems wont be able to connect to your ad-hoc network.
6
Move to ipv4 tab and here select shared to other computers, this will help other systems which will connect to your ad-hoc network to get an ip automatically by looking at your systems ip. You can also select manual and give it an ip but even other users who will later connect to your network will have to specify their ip manually(of course with the same ip range)
7
You’ll be able to see the created network in edit connections.
8
Now enable wifi and you should be able to see the adhoc network which you created.
9
now select connect to hidden network and connect to the ad-hoc network which you created
10
select your network
11
Fire up the terminal (cntrl+alt+t) and check ip (ifconfig) to see the ip address assigned to your system. If you’ve done the configuration manually you can see the ip set by yourself.
12
When other members are trying to connect to your network make sure they edit the connections and select security as WEP 128-bit passphrase, else you they wont be able to connect to your network. Also if you’ve given manual ip(ex:10.10.10.1) make sure other members also give manual ip in the same range(ex:10.10.10.2 etc). If you’ve used shared ip make sure others have also used shared ip in the edit connections option.

DHCP wont work for the following network because there wont be any dhcp server running in your network.