Lab 1 - Embedded Internet
David E. Culler
Jan 28, 2008
This lab is designed to be interactive. It is should be done in
After each section, there will be discussion, Q&A and
Within each section are links to background reading
Table of Contents
This part of be determined.
A group should form around each machine in the lab. Log on
The Internet is comprised of collections of client
applications that issue requests to services on servers which in term
provide responses and the communication between these participants
involves transfering packets across a potentially wide variety of links
interconnected by routers. The most common example today
is, of course, your web browser client issuing http GET and POST
requests to a web server. The initial portion of the URL
identifies the server and the port on which the service is
running. The remainder of the URL is essentially arguments to
that service, identifying the document of interest or input
generation of dynamic content. In this class we are going to
introduce a new class of clients and servers which are embedded deeply
in the physical world and we will utilize a new low power wireless link
developed for such embedded devices, but it will all fit together as a
natural extension of the distributed system we know as the Internet and
the Web. In this first lab, we will get acquainted with several
of the basic concepts that stitch the internet together. Some of
this may be a (pragmatic) review of your networking class. But it
will certainly involve some new twists.
To bring sanity to this widely complex global organism, it is
organized into layers forming the Internet
Protocol suite. There is a wide variety of applications and
application protocols. The complementation parts of a distributed
application (or service) communicate with each other
using a transport protocol (TCP or UDP) that operates on an end-to-end
basis. TCP provides a reliable byte stream while UDP offers
simple datagrams. The transport is built up best-effort packet
delivery across one or more particular networks or links.. This
"narrow-waist" is the IP layer (layer 3) which provides homogeneous
naming and routing over a wide diversity of links with different
physical layers, different media access control (MAC) protocols,
different frame formats, and different physical media. The most
common, of course, are ethernet (in its many variants), wifi (in its
variants), and point-to-point connections.
There is a deep connection between networking and operating systems,
since the protocols that make a network function are implemented within
the operating system or upon the operating system of the various
machines. At the endpoints, ports
are what associate services with the application process that provides
service. The port number is essentially the address of the
service on the particular host. For example, http is on port 80,
whereas SSH is on port
22. See this
link for a relatively complete list of ports.
In addition to the familiar services over the familiar transports, IP
includes a collection of low level capabilities, call the Internet
Control Message Protocol (ICMP), which support IP, including
discovery and formation of networks, error processing, etc. The
basic ICMP tool is ping, which tests the reachability of a particular
Generally, we think of IP addresses as identifying machines. A
machine as a hostname
which is translated to a global IP
by a internet-wide service called DNS (domain name service). In
a machine can be attached to several network links through interfaces. Each interface on a
has an IP address.
It will show you the network configuration associated with each
on that machine. You should see the "Ethernet adapter Local Area
- On your windows machine in the lab open a command shell and
IP networking routes packets based on their destination IP
Each packet is originated at a source,
passes through zero or more
routers, to eventually arrive at its destination. Each of the hops
way decides on which interface to send the packet out. They don't
how to get all the way to the destination, just how to get one hop
They make this decision based on a local routing table.
- What is its MAC address? IP address? Subnet mask?
- What other adapters are present? (More on those virtual ethernets
- To see
the routing table on your windows box looks like, run route
- What addresses get routed where?
- What is 127.0.0.0
- What goes to the Default Gateway?
- What does "subnet" mean?
Since IP networks are inherently spread out over large spaces and
involve priviledged operating systems functions, they are a bit at odds
with the carefully controlled, high quality instruction laboratory
facility. We are going to solve both problems with a trick called
We are going to run a little IP network within your windows machine
a Virtual Machine provided by VMWare. It runs a complete
within a user application process on your windows box. However,
functions like a completely separate machine that can talk to your
machine over a virtual ethernet. One nice thing is that you will have
access to your virtual machine linux OS. So, we can do some real
networking in this not-so-real setting.
We have configured the VM so that it and the Virtual Ethernet adapter
the windows system both sit behind a virtual NAT (network address
You may notice that NTP (network time protocol) fails when linux boots.
If so, try sudo
/etc/init.d/ntpd restart. The passwd is the same as your user
- Start VMware/VMWare Player. It will ask you for
a virtual machine to
load. We will put one on a UCB flash drive called eecs194.
Browset to that one or to where it is copied on your local disk.
- In the VM, after linux boots login as username: eecs194 with
Looks like a Linux machine, doesn't it?
- Run a terminal in your VM
(Applications/Accessories/Terminal). It will give you a
click-thru EULA for the LoWPAN networking tools that are built into
- To look at its network
- What is its eth1 ip address? Local loop back?
- ping the VM from windows.
- ping the windows from the VM.
- Try out a few other network applications between the two:
tracert, netstat, route.
Here is what is going on. A "virtual ethernet" connects the
native machine and the virtual linux machine. Both are sitting
a "virtual NAT" (Network Address Translation) much like the cable or
router/firewall/NAT that you have at home. The "uplink" of the
is back through the windows machine, so it all lives behind a single
- Notice that one or the other machine is active at a time.
determines which machine gets key strokes and clicks, as well as other
including the USB.
- Notice also that your virtual machine is configured to run IPv6,
newest suite of internet protocols, in addition to IPv4. IPv6 was
to support billions and billions of IP devices. Notice how
the addresses are.
The 192.168.116.00 virtual ethernet is a private network, in that it is not
directly accessible from other parts of the internet. That's why
we can make up the addresses and they don't have to be unique.
Communication outside this network looks as if it came from the
18.104.22.168 "global" ip address.
Network Applications and Services
There are basically two kinds of network applications: remote
terminals and services. Let's play a little with both. The
classic remote terminal is telnet.
Its more modern, more
is SSH. In either case,
you are issuing
directly to the remote operating system (through the shell) and just
the terminal IO across the network. This is very
handy. You can use it wihtin scripts. You can try things
out by hand.
This is how you move files over the (virtual) network between the
windows and linux machines. Just like a network, isn't it.
- On the windows side, SSH into
the linux VM.
- Run the SSH secure file transfer client and connect to your
You could try
to go the other way, but you'd probably find that the windows side is
not running a remote shell service.
The more general case is services.
In fact, your remote terminal is
invoking the remote shell service. Ping is communicating with the
remote ICMP echo service implemented within the network stack.
Your browser comnunicates with the
remote HTTP server (i.e., the web server on port 80). Your file
transfer client works in tandem with a file transfer service.
In fact, let's use telnet to connect to the HTTP port, issue the GET
request to the server, and display the sequence of (HTML) characters
that come back.
- telnet -nologin inst.eecs.berkeley.edu 80
Here's another general purpose networking application - nc
(netcat). Some call it the swiss army knife of networking.
It pretty much just opens a tcp or udp socket to an
ip address and port and transfers data. For example, if on a
machine with ip address
XYZ you run nc
-l 7171 it will start listening on port 7171. On another
machine, such as your linux vm run nc
XYZ 7171. What you type in to nc will appear on the listening
side. It is a simple tool to get at low level networking without
programming. (We'll do some of too in just a little bit.)
- nc inst.eecs.berkeley.edu 80
We are going to use the (virtual) linux machine as an IP router
supports a new kind of wireless link for embedded applications -
- Low Power Wireless Personal Area Network). First, let's
understand a little bit about this new class of network embedded
Berkeley TelosB Mote
The physical LoWPAN interface is going to be provided by a Berkeley
Mote, shown below. This was the sixth in the series of UCB motes.
were done as open source hardware, so the details are on line and
are manufactured by numerous companies around the world. We will
using the newest generation mote, called EPIC,
the course. But today we'll use Telos. Both Telos and EPIC
a CC2420 2.4 GHz IEEE 802.15.4 radio supported by a TI MSP430
and flash. Telos plugs directly into a USB port and has on-board
for a variety of environmental sensors. The antenna is embedded
in the PCB.
You have a Berkeley telos mote that contains IEEE 802.15.4 NIC
firmware provided by Arch Rock.
It is the one with no battery pack attached.
This is a new link. You are familiar with IEEE 802.3
and IEEE 802.11
This interface is a new wireless communication standard, IEEE 802.15.4.
recently became an IP link using the 6LoWPAN
We'll learn a lot more about this later. Today, we'll get some
- With the virtual machine active, plug
your UCB TelosB NIC into
USB slot. (The VM needs to be active so the device will be
to the linux side, rather than the windows side.)
- In the VM run motelist
until you see the device show up.
- Run ifconfig.
Notice that you have a new tun0 interface.
With WiFi you configure your network link by setting the SSID,
channel and the security key. Optionally, you may set various
other link level
features. Similarly, IEEE 802.15.4 support a number of
In the 2.4 GHz spectrum these are 11 - 26. In addition, a logical
shares a PANID and an AES128 key.
In this tutorial each group will have a private LoWPAN subnet -
- Your LoWPAN router provides a simple web management interface
similar to what you find on a WiFi router.
- To onfigure LowPAN Router: run firefox and open http://localhost::7673.
- Go to the Router Settings tab and set the LoWPAN channel and PAN
ID as instructed in class.
You can change this with SUDO by editiing
/opt/rosetta/conf/rosetta.conf. Then run sudo
Each group should have two other 15.4 mote devices with battery packs.
devices, these utilize the microcontroller and its ADCs, DACs, and
for sensing and controlling various apparati.
These motes are currently unassociated. They are not part of any
PAN. Note that they have a 64 bit
mac address printed on the label on the side. To bring the node
into your network run the following, except with the last few hex pairs
replaced by the ones for you node.
Associate both of your motes.
Your LoWPAN is what we used to call a Class B network, with 16-bit
(which you configured) and a 16-bit interface identifier.
is your router NIC.
you can see the state of your LoPWAN network. Click on the
Neighbor Table to see the link quality of nodes that are within range
of the NIC. The DHCP Address Assignment tab should show you the
IP address of your newly associated node. Notice, they have an
IPv6 address as well as a classic IPv4 address. The IPv6 address has a
64-bit IPv6 prefix and a 64-bit IPv6 interface
identifier. These big identifiers get squeezed down to just a few
bits by the
IEEE 802.15.4 introduces a "short MAC address"
is 16 bits in length, in addition to the 64-bit EUID. Obviously
is not globally unique, but is assigned to be unique over the PAN.
If the LoWPAN network extends beyond the range of a single radio hop.
routing is used to communicate over multiple hops, just as in the rest
of the internet. You can see the routing table from the NIC
gateway to the other nodes with the Routing Table tab.
Congratulations, you now have an embedded internet. It looks something
In a real setting we would nto have any of this virtualization
We'd have a collection of real machines and real routers tying
real networks. For the lab settting, we've got a real LoWPAN
and have created the rest of it "in a box". Later in the course,
use a more real setting.
Simple IP network
The standard IP networking utilities can now be used to for the network
devices. Let's do a little poking around.
Lets go ahead and open up a remote shell onto that little
- From linux, try ping 10.97.0.0.
This pings the LoWPAN interface on the router using ICMP.
- In http://localhost:7673,
can see the IP addresses for the other nodes on your PAN link.
- From linux, ping
for your nodes. You'll see the red LED light up when you ping
them. Note that this is accessing the ICMP echo service on the
remote device, in this case the mote.
- From linux, sudo tracert 10.97.YY.YY and
compare it to tracert for various hosts
- Embedded device can provide
various network services. For example, to connect to the echo
service on port 7 on one of your motes, try telnet 10.97.YY.YY 7. or nc 10.97.YY.YY 7. What happens
when you type strings at your motes?
opens a TCP connection to the telnet service (TCP port 23) on the
embedded device. The prompt that you see is coming back from the
node over this TCP socket. type '?'. It is quite a
more limited than your typical shell.
- From linux run telnet 10.97.YY.YY. or telnet
FEC0:0:0:97::ZZZZ. using the IPv6 address.
The other critical thing that embedded devices do is actuate, i.e.,
- As with any remote shell, we are issuing commands directly to the
local OS (in this case TinyOS) but the keystrokes and display are going
across the network.
- Try ifconfig.
Notice, the embedded nodes are IPv6
devices. Since IPv6 is still rolling out, the two internets hook
together with 6-to-4 translation. Here that is happening in the
- One important thing that embedded devices do is sense.
sensor are attached to the microcontroller through Analog-to-Digital
Converters or through digital interfaces so they can be sampled.
- type energy
to sample the battery voltage level.
- type dump
to get the current readings from all the sensors.
- As a simple binary actuation, type leds
on r . Then leds
off r. Just leds will give you status and usage.
Let's explore a little more of IPv6.
- Notice that IPv6 addresses are 128 bits. The upper 64 bits is the
prefix; this is essentially the generalization of an IPv4 subnet or
link. The lower 64 bits are the interface identifier. This
generalizes the machine number used in IPv4 subnets. The address
space is big enough that devices can assign themselves addresses
without any special consultation with higher authorities. DHCP is
also an integral part of IPv6.
- ping6 is the IPv6-icmp version of ping.
- In linux, ping the IPv6 LoWPAN interface with ping8
- In linux, ping the IPv6 motes using their IPv6 addresses shown in
- You can record these in environment variables in you linux bash
shell with export NODE1="fec0:0:0:97::5FE4" and then use ping6 $NODE1.
- Open a remote shell on one of the motes using its IPv6 address,
eg. telnet FEC0:0:0:97::8bd.
- From there ping the 6LoWPAN interface of the route, ie. ping
- exist the telosh
- IPv6 utilizes multicast groups as a fundamental organizational
principle. For example FF02::1 is the all nodes link local
multicast group. This can be used to discover all nodes on the
link associated with a particular interface. On linux, try ping8
-I tun0 FF02::1
Let's do a little more with the remote shell on the embedded mote.
Multicast is a foundational concept in IPv6, rather than an add on as
it is in IPv4. The various link level facilities that we use to
bring up IPv4 networks, like ARP, RARP, BOOTP, DHCP, are provided
instead at the IP level in a link independent manner with multicast
groups. For example, FF02::1 is the "Link Local All Nodes"
You will see responses from all the other nodes in range of the mote
issuing the ping. This is the link local scope.
- In the telosh on a mote try ping
Notice the source address of the responses. Search the web to
find the meaning of the FE80 prefix.
The ping response also give the Receive Signal Strength Indicator
(RSSI) of the incoming packet. These particular radios have
a transmit power of 0 dBm or about 1 mw. (WiFi is about 100
mW and so is your cell phone.) They have a receive sensitivity
about -92 dBm.
- In the telosh on o mote, ping one of the link local unicast
addresses that responded to the "all nodes" solicitation.
- ping fe80:0:0:17:3b00:c82:6b1f
Now its time to do some connectivity testing with low power wireless
networks embedded in physical space. With one mote in reasonable
proximity of the NIC you can move the other own to various places,
distances, through walls, behind objects, in your pocket. How
does the connectivity vary? Did you get to a multiple
network? (Look at the Routing Table.)
OS networking APIs
- Implementing Clients and Servers
Network applications, including clients, servers, routers, proxies, and
overlays, are implemented on the networking APIs made available by the
operating systems on the particular machines. In Unix the API is
primarily BSD Sockets and on Windows WINSOCK. These applications
are also concurrency intensive, managing multiple connections,
etc. So the API is closely related to the OS concurrency
model. Embedded devices are mostly event driven, with collections
of state machines responding to changes in their environment and taking
actions, rather than long threads of sequential processing. We
will be using an event-driven, modular socket-like API in TinyOS.
We could build our embedded web service applications over the shell by
scripting commands. And this is indeed quite common. Or we
could implement services that are tailored to the usage that we have in
mind. On class of such services is a pull model where we issue
requests to an embedded server and get responses - just like a web
The simplest of these is echo, so let's start by building and uploading
a simple ECHO server onto one of your nodes "Over the Air".
Now we should have TCP and UDP echo services running on port 7.
Let's try it out. For the TCP services, we could use our old
- cd to $APPS/Echo
- You may want to browse the code you see there, but we'll explain
it later. If you want to compare it to traditional sockets
programming, a much more primitive TCP echo server example is here.
- run make telosb
to create an executible in ./build/telosb.
- Notice that we are cross compiling in our linux environment for
the mote using gcc for the msp430. Actually, we are using an
extension to C for networking called NesC which produces C code.
- Ping nearby node’s swupdate status:
- Erase image from nearby node: swupdate
- Inject image to nearby node:
-t build/telosb/tos_image.xml i fec0:0:0:97::6cc0
- Reprogram to injected image at node:
To exercise the UDP services, we'll need NC
- telnet $NODEIP 7 or our new
In order to permit inexpensive, low power implementations. IEEE
802.15.4 packets are very limtied in size. The total MTU (media
transfer unit) is 128 bytes. Let's do a little experiment that
will show the difference in the transport protocols: TCP and UDP.
Perhaps its time to get a little more serious about network
programming. Here's an example of a very simple TCP client that issues a request
and prints the response.
- In Linux, us NC to open an tcp connection to the echo service on
a node. Type short lines and long lines see how
it behaves. Be sure to exceed 128 characters.
- Use NC to send UDP datagrams to the ECHO
service. See what it does if the payload is too large to fit.
- Use this client to send messages to the echo service on the mote
from linux using its IPv4 address.
- Modify this client to issue repeated requests, each time opening
and new connection (like http).
- Modify it to issue multiple requests and print the response
within a single session (like persistent http).
Packet Formats at each layer
Now lets see what is really going on under the covers. We'll set
up a packet sniffer watching your channel. So the same
- What does the IEEE 802.15.4 frame format look like? What is
the overhead of TCP vs UDP headers?
- To see more of what is going on at the IP level, run ethereal on
The web is still in the process of standardizing event-driven or push
based services, since command/response is so deep in http and other
protocols. We have RSS and many variants that open a conection
and allow the remote end to "push" more and more onto the
document. In the embedded space, periodic reporting and
unscheduled alarms are very common. So push is a natural.
A "model push service" akin to echo is provided for you ine
$APPS/Count. This is a UDP based push service, so it is easiest
to think of it as a client. It uses a timer to keep track of time
going by and count the ticks. Each tick it sends a UDP packet to
listener service on a particular port on a particular IP address.
- cd to $apps/Count and make telosb
- upload the resulting executible to one of your nodes.
- Can you use NC to provide the listener service?
- Study and build the following listener.
Embedded Server TinyOS
We'll walk you through the TinyOS code for the applications and give
you a set of test problems to implement yourself.