munotes®

Gateway Concepts

Get access to whole semester resourcesSemester Pass

Chapter Twenty-Two

Syllabus topic Module 1, "Introduction and Overview of WSNs: Gateway concepts" (and the paired practical, "Mote-to-PC Serial Communication Simulation")

Pages 121 to 125 of 862

In one line

A gateway is the node that joins a sensor network to another network, usually the Internet, translating between two different ways of addressing, routing and talking so that data can cross in both directions.

In the wording a student can write in an examination: a gateway connects a WSN to other networks. It is needed because the two sides differ in protocols (low-power radio and WSN routing against IP), in addressing (data-centric naming against IP addresses), and in availability (sleeping nodes against always-on hosts). Gateway concepts cover (1) WSN-to-Internet communication, where a node's data or alarm must reach an Internet host; (2) Internet-to-WSN communication, where an Internet user queries or tasks the WSN; and (3) WSN tunnelling, where two separate WSNs are joined through the Internet as if they were one.

Why a gateway is needed

If a sensor network spoke the Internet's protocols natively, every node could simply be a host. For most of the subject's history it could not, and even now there are reasons the two sides differ.

  1. Different protocols. The nodes run a low-power radio and a routing protocol built for the field; the outside world runs IP, TCP and HTTP. Something must translate.
  2. Different addressing. Inside the WSN, requests are data-centric (temperature in region A); outside, everything is addressed to a host. A node cannot be expected to know Internet addresses, and an Internet user should not need to know node numbers.
  3. Different availability. An Internet host answers whenever it is asked. A sensor node is asleep most of the time and may take seconds to minutes to answer; a TCP connection held open to a node would waste its battery.
  4. A boundary. Security, access control and accounting belong at the point where the WSN meets the outside world, and so does caching: a gateway can answer many users from one set of readings.

WSN to Internet

The situation. A node detects an event and the report must reach someone outside: an email to the farm manager, a message to a monitoring server, a record in a cloud database.

The problems, and how a gateway solves them.

  • Finding the gateway. The node does not know where the gateway is. In practice the gateway is (or sits beside) the sink, and the collection routing already leads every node towards it. With several gateways, the routing leads to the nearest.
  • Naming the destination. The node cannot hold Internet addresses for every possible receiver. So the node reports data-centrically (alarm, zone 7), and the gateway maps that to Internet destinations according to its configuration: this kind of alarm goes to this server and this person.
  • Translating the message. The gateway turns the WSN packet into an Internet message (an HTTP request, an email, a message to a broker), adding what the Internet side needs and the node could not afford to send, such as full timestamps and identifiers.
munotes.in121

Gateway Concepts

Internet to WSN

The situation. A user on the Internet wants something from the sensor network: the latest readings, or a new task.

The problems, and how a gateway solves them.

  • Which gateway to ask. The user must know an Internet address for the WSN. The gateway presents one: a web page, a web service, or a named endpoint.
  • Expressing the request. The user's request (a web request for average temperature, north-west quarter) must be turned into the WSN's own terms: an interest, a query or a task, sent into the field. The gateway is therefore an application-level gateway: it understands the meaning of requests, not only their packets.
  • Waiting for sleeping nodes. A request may take a long time to be answered inside the WSN. The gateway can answer from its cache of recent readings, and can collect one answer for many users, so the nodes are asked once.
  • Protecting the field. The gateway can refuse, rate-limit or authenticate requests, so that a busy website does not drain the batteries of a forest.

WSN tunnelling

The situation. Two sensor networks are far apart, a sensor field on each bank of a river, or two buildings of one campus, and should behave as one network. No radio link joins them.

The idea. Each island has a gateway on the Internet. When a packet in one island is addressed to something in the other, its gateway encapsulates the whole WSN packet inside an Internet packet and sends it to the other gateway, which unwraps it and injects it into its own island. The Internet is used as a long virtual link, a tunnel. To the WSN protocols the two islands look like one network with one long hop.

The humblest gateway: a base station mote on a serial cable

In a laboratory, and in the practical, the gateway is a base station mote connected to a PC by a USB or serial cable. The mote listens to the radio and passes what it hears to the PC; the PC runs the program that stores, displays or forwards the data.

TinyOS ships this as an application. Its own source comment says it plainly: "BaseStationP bridges packets between a serial channel and the radio." Packets from the radio are passed to the serial port; packets from the PC are sent out over the radio. Messages going from serial to radio are tagged with the group identity compiled into the base station, and radio messages are filtered by that same group, so a base station hears only its own network.

munotes.in122

Gateway Concepts

How the bytes cross the cable

A serial line carries a stream of bytes, with nothing to mark where one packet ends and the next begins. TinyOS's serial stack, specified in TEP 113, solves this in three levels: encoding, framing and a protocol level with acknowledgements and a CRC. Its framing uses the same encoding as the HDLC protocol:

  • 0x7e is reserved as the frame delimiter: it marks the start and end of every packet.
  • 0x7d is reserved as the escape byte.
  • If the data itself contains 0x7e or 0x7d, the sender sends 0x7d followed by the byte XORed with 0x20. TEP 113's example: "0x7e becomes 0x7d 0x5e".
  • The receiver, on seeing 0x7d, drops it and XORs the next byte with 0x20 to recover the original.

A CRC (cyclic redundancy check) at the protocol level lets the receiver detect a packet damaged on the cable.

Worked example: framing a packet

The program frames a five-byte payload that happens to contain both reserved bytes, then decodes it again. (The CRC is left out so that the framing can be seen on its own.)

# HDLC-style framing as TinyOS's serial stack uses it (TEP 113):
# 0x7e marks frame boundaries, 0x7d escapes, an escaped byte is XORed with 0x20.
FLAG, ESC = 0x7E, 0x7D

def frame(payload):
    out = [FLAG]
    for b in payload:
        if b in (FLAG, ESC):
            out += [ESC, b ^ 0x20]
        else:
            out.append(b)
    return out + [FLAG]

def unframe(stream):
    body, escaped = [], False
    for b in stream[1:-1]:                  # drop the two delimiters
        if escaped:
            body.append(b ^ 0x20)
            escaped = False
        elif b == ESC:
            escaped = True
        else:
            body.append(b)
    return body

payload = [0x12, 0x7E, 0x34, 0x7D, 0x56]
line = frame(payload)
print("payload:", " ".join("%02x" % b for b in payload))
print("on the wire:", " ".join("%02x" % b for b in line))
print("decoded:", " ".join("%02x" % b for b in unframe(line)))
print("round trip correct:", unframe(line) == payload)
payload: 12 7e 34 7d 56
on the wire: 7e 12 7d 5e 34 7d 5d 56 7e
decoded: 12 7e 34 7d 56
round trip correct: True

What happened to the two reserved bytes. 0x7e in the data became the pair 0x7d 0x5e (0x7e XOR 0x20 is 0x5e), exactly TEP 113's example, and 0x7d became 0x7d 0x5d. Only the two real delimiters, at the ends, appear as bare 0x7e, so the receiver always knows where a frame starts and stops. The frame is two bytes longer for the delimiters and two more for the escapes: framing costs a little size for certainty.

A real gateway: Great Duck Island

The deployment of [Applications of Wireless Sensor Networks] shows the full chain. Each patch of motes had a gateway node; a longer radio link, the transit network, carried data from the gateway to a base station with a database and a wide-area connection; and remote users read a replica of that database over the Internet. Every layer kept some persistent storage, because a disconnection could happen at any level. That is Internet-to-WSN communication done through a cache, which is how most real systems do it.

munotes.in123

Gateway Concepts

Distinctions

SinkGatewayRouter inside the WSN
IsWhere the WSN's data is collectedThe bridge to another networkA node forwarding packets
SpeaksThe WSN's protocolsBoth sides' protocolsThe WSN's protocols
TranslatesNoYes: protocols, addresses, requestsNo
Often combined withThe gatewayThe sinkEvery node
WSN to InternetInternet to WSNWSN tunnelling
StartsInside the fieldOutside, with a userIn one island, bound for another
Gateway's key jobMap data to Internet destinationsTranslate requests, cache answersEncapsulate and unwrap WSN packets
ExampleAn alarm emailed to the managerA web page showing the average moistureTwo fields on either side of a river as one network

What it does not mean

A gateway is not only a router. A router forwards packets of one protocol; a gateway translates between protocols and between ways of addressing, often at the level of meaning.

Internet-to-WSN does not mean a TCP connection to each node. The gateway answers for the network, from a cache or by collecting one answer for many users.

Tunnelling does not make the Internet part of the WSN. The Internet only carries the WSN's packets, wrapped, between two gateways.

The serial escape is not encryption. It only keeps the reserved bytes from being mistaken for delimiters.

Quick revision

  • Gateway: joins the WSN to another network; needed for different protocols, different addressing, different availability, and a boundary for security and caching.
  • WSN to Internet: node reports data-centrically to the gateway; gateway maps to Internet destinations and translates.
  • Internet to WSN: gateway gives the WSN an Internet address, translates requests into queries or interests (an application-level gateway), caches answers, protects the field.
  • WSN tunnelling: gateways encapsulate WSN packets in Internet packets to join two WSN islands.
  • Base station mote: TinyOS BaseStation "bridges packets between a serial channel and the radio", filtered by group identity.
  • TEP 113 framing: 0x7e delimiter, 0x7d escape, escaped byte XOR 0x20 (0x7e becomes 0x7d 0x5e), plus a CRC.

Test yourself

1. Why does a WSN need a gateway to reach the Internet? Because the two sides differ in protocols (low-power radio and WSN routing against IP), addressing (data-centric names against host addresses) and availability (sleeping nodes against always-on hosts), and because security, access control and caching belong at the boundary.

munotes.in124

Gateway Concepts

2. Explain Internet-to-WSN communication and the problems a gateway solves in it. An Internet user requests data or tasks the WSN. The gateway gives the WSN an Internet address, translates the request into the WSN's own query or interest, answers from a cache or gathers one answer for many users because nodes sleep, and protects the field by authenticating and rate-limiting requests.

3. What is WSN tunnelling? Joining two separate WSN islands through the Internet: each island's gateway encapsulates WSN packets bound for the other island in Internet packets, and the other gateway unwraps and injects them, so the Internet acts as one long virtual link.

4. How does TinyOS frame a packet on a serial line, and how is a data byte of 0x7e sent? With HDLC-style framing: 0x7e marks the start and end of each frame and 0x7d is the escape byte. A data byte of 0x7e is sent as 0x7d followed by 0x7e XOR 0x20, which is 0x5e.

5. What does the TinyOS BaseStation application do? It bridges packets between the radio and the serial port: radio packets of its group are passed to the PC, and packets from the PC are sent over the radio, tagged with the base station's group identity.

munotes.in125

The rest of this subject

These notes are cut from the University's printed syllabus. Open the syllabus itself for the same subject.

Issue
Done!