Thursday, June 26, 2008

SPOT Network Monitor

Task Description:
"Implement an application that collects coarse topology information about the network. Each sensor will discover its neighbors and report the number of neighbors it finds to an application running on the host computer attached to the base station. A superior implementation would track the IEEE address of the neighbors for each sensor."[1]

Analysis:
This task looks easier than the previous one and I can take advantage of some existing code. In my opinion, the important thing involved in this task is about work-flow design.

First of all, all free-range SPOTs broadcast a "alive" message to its neighbors and its neighbors can get its IEEE address by analyze this message. There is a hashtable stored in SPOT side that can maintain the information about neighbor SPOT. The SPOT will add one pair of key and value to this hashtable when it gets a new address. It will also delete the old information if it cannot get its neighbor's information in 5s.


Secondly, I need to discard the "broadcast" thing while making the free-range SPOT report its IEEE information to the base station. So every SPOT should know the base station's address before they transfer any message. The base station keeps all IEEE address information in a hashmap and it will print out the content when users input the word "print".

The following is my work-flow chart about communication:



Implementation:
1. How to get an IEEE address?
a. To get its own address
long ourAddr = Spot.getInstance().getRadioPolicyManager().getIEEEAddress();
You can use "IEEEAddress.toDottedHex(ourAddr)" to format the address as xxxx.xxxx.xxxx.xxxx

b. To get the message source's address
Datagram dg = null;
...
dgConnection.receive(dg);
String strAddress = dg.getAddress();

2. How to output all IEEE address?
if(!hmAddress.isEmpty()){
    Iterator iAddr = hmAddress.entrySet().iterator();
    ArrayList strAddrList;
    while(iAddr.hasNext()){
        Map.Entry entryAddr = (Map.Entry)iAddr.next();
        strAddrList = (ArrayList) hmAddress.get(entryAddr.getKey());
        if(strAddrList.isEmpty()){
            System.out.println("There is no neighbor information related             to sensor " + entryAddr.getKey().toString() +"\n");
        }
        else{
            System.out.println("IEEE address list of sensor " +                      entryAddr.getKey().toString() +"\n");
            for( int i=0; i1){
                strTotal+="s.";
            }
            else{
                strTotal+=".";
            }
            System.out.println(strTotal);
        }
        System.out.println("----------------------------------------------------------------\n\n");
    }
}
else{
    System.out.println("No IEEE address existing!\n");
}



2. How to get only neighbors?

((RadiogramConnection)dgConnection).setMaxBroadcastHops(1);
The above line can narrow down the number of neighbors. For example:



Spot 3 has only one neighbor: Spot 2;
Spot 4 has 4 neighbors including 1,2,5 and 6;
Spot 6's neighbor is Spot 4;

Difficulty and Challenge:
In general, I didn't encounter any problem except testing during the whole development process. Sometime the base station couldn't receive the message from a free-range SPOT. I found out the reason is about the router mode according to some experiments. For the previous task, I turned on their special router mode that caused radio malfunction.

Time Distribution:

Task

Description

Deadline

End Date

Total Time (hrs)

4

Collecting and tracking SPOT network information

06/27/2008

06/27/2008

20.2

Sub Task

Time

Requirement Analysis and work-flow Design

4.5

Create a Host application to implement a superior’s functionality

3

Create a Spot application to discover its neighbors

3.2

Debug and Test this task

7

Miscellaneous Task (updating the blog, documents and so on)

2.5



[1]Quoted from the section "Task 4" of Class Requirement Document
Written by Professor Sami Rollins