TOSSIM simulation CTP under TinyOS

The simulation of TinyOS is really a good thing. Follow the steps below to know what it means. The following is a general demonstration of the terminal under Ubuntu.
Excuting an order

cd /opt/tinyos-2.1.1/apps/tests/TestNetwork
make micaz sim    

The source code of the TestNetWork file contains the files required for the simulation, which will be explained later.
The TinyOS-2.1.1 I installed under Ubuntu12.04 will report an error at this step. Later, it was found that the gcc version is too high, so I lowered the gcc to gcc (Ubuntu/Linaro 4.5.3-12ubuntu2) 4.5.3 That's it, see this https://my.oschina.net/u/3744410/blog/1802019

The following success message will be displayed: ***Successfully built micaz TOSSIM library

Run test.py, i.e. enter:

export PYTHONPATH=$TOSROOT/support/sdk/python 
python test.py

If successful, the screen will display a bunch of messages similar to the one shown below:debug output

I will explain what the above information is for later. First, let’s talk about what test.py is used for. We need to configure the network topology so that the nodes in TOSSIM can communicate with each other. TOSSIM uses a signal strength-based model by default. , so the gain between every two nodes is required, which is implemented by the add() method in the radio object. The code is as follows:

t = Tossim([])
r = t.radio()
r.add(src, dest, gain);

Among them, the source node in src, dest is the destination node, and gain is the gain from source to destination. Since source-to-destination and destination-to-source gains may be different, they are specified separately. In general simulation, there will be at least hundreds of nodes in the network, and it is not realistic to manually add gains one by one. We use a file to record the gains between all pairs of nodes, one per line, and the format of each line is as follows:

gain <source node number> <destination node number> <gain>
<..> is replaced by a specific value.

These gain values ​​can be easily added to the radio object with a python script, the following code in the test.py file does just that.

f = open("sparse-grid.txt", "r")
lines = f.readlines()
for line in lines:
s = line.split()
if (len(s) > 0):
f s[0] == "gain":
r.add(int(s[1]), int(s[2]), float(s[3]))

Among them, in sparse-grid.txt, we see a statement similar to the following gain 0 1 -90.80, which indicates the gain from point 0 to point 1, generally -70 -80 can communicate, -120 or less cannot communicate.
In addition, TOSSIM uses the CPM algorithm to simulate the noise of the RF module. The algorithm needs to read in several noise records and then generate a noise model. We use the noise record meyer-heavy.txt provided by the Meyer lab at Stanford University, which is one noise value per line. The following test.py code adds noise values ​​to each of the 10 nodes:

noise = open("meyer-heavy.txt", "r")
lines = noise.readlines()
for line in lines:
str = line.strip()
if (str != ""):
val = int(str)
for i in range(0, 10):
m = t.getNode(i)
m.addNoiseTraceReading(val)

Then use the CPM algorithm to generate a noise model for each node:

for i in range(0,10):
    t.getNode(i).createNoiseModel()

So what are we doing all this stuff for? To put it bluntly, it is to construct virtual points to set the communication gain between them, and then use it to debug your code.
There is also the following code in test.py, which is to open the dbg channel. The following code indicates that the deg information of Forwarder and TestNetworkC will be printed out, and the DEBUG (x) printed on the terminal indicates the deg information of the xth node. If you want to add deg information at will, just bring the words, refer to the following code.

#t.addChannel("AM", sys.stdout)
#t.addChannel("TreeRouting", sys.stdout)
#t.addChannel("TestNetworkC", sys.stdout)
#t.addChannel("Route", sys.stdout)
#t.addChannel("PointerBug", sys.stdout)
#t.addChannel("QueueC", sys.stdout)
#t.addChannel("Gain", sys.stdout)
  t.addChannel("Forwarder", sys.stdout)
  t.addChannel("TestNetworkC", sys.stdout)
#t.addChannel("App", sys.stdout)
#t.addChannel("Traffic", sys.stdout)
#t.addChannel("Acks", sys.stdout)
while (t.time() < 1000 * t.ticksPerSecond()):
        t.runNextEvent()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324955715&siteId=291194637