Skip to content

Layered Model

grant_____ edited this page Feb 5, 2020 · 11 revisions

Layered Model

To conceptualize the disaster radio firmware, we created a layered model based largely on the OSI model used in teaching classical computer networking.

Layer 1 - Layer 2 - Layer 3 - Layer 4
raw data -> packet -> datagram -> message
raw data <- packet <- datagram <- message

Layer 1

LoRa (or simulated LoRa) physical layer, This is interfaced by the LoRa transceiver developed by Semtech, which handles the physical modulation and encoding of radio waves. In our code, we interface with the transceiver through the arduino-LoRa library, which is further abstracted by Layer1_LoRa (which exists mostly to allow the Layer 2 code to be tested in our simulator) Layer 1 receives raw data from the LoRa transceiver and sends packets to Layer2 to be interpreted,

    char incoming[PACKET_LENGTH];
    int incomingLength = 0;
    while (LoRa.available()) { 
        incoming[incomingLength] = (char)LoRa.read(); 
        incomingLength++;
    }
    LL2.packetReceived(incoming, incomingLength);
}

Layer 1 receives packets from Layer2 and sends raw data to the LoRa transceiver, Like so

    if(LoRa.beginPacket()){
        for( int i = 0 ; i < len ; i++){
            LoRa.write(data[i]);
        }
        LoRa.endPacket(1);
        LoRa.receive();
    }

Layer 2

The routing layer. This is the LoRaLayer2 code which creates an ad-hoc packet switching network of nodes. Detailed information on the packet structure and routing protocol used by this layer can be found in the Protocol documentation https://github.com/sudomesh/disaster-radio/wiki/Protocol

struct Packet {
    uint8_t ttl;
    uint8_t totalLength;
    uint8_t source[ADDR_LENGTH];
    uint8_t nextHop[ADDR_LENGTH];
    uint8_t sequence;
    boolean routing; //one bit flag to signify a routing table packet
    uint8_t datagram[240];
};

Layer 2 receives packets from Layer 1, interprets the header, and either forwards the packet by sending the packet back down to Layer 1 or it sends the packet to Layer 3 to be consumed by a service/application.

Layer 2 receives datagrams from Layer 3 along with information at about the destination address, appends a header to the front, creating a packet, and sends that packet to Layer 1.

Layer 3

The transport layer. This has some similarities to UDP. It made up of what we have typically referred to as the "firmware." That is, an arduino sketch that joins any number of clients/services and allows them to communicate, e.g. it allows a telnet session to send a message over the LoRa transceiver.

struct Datagram {
    uint8_t destination[ADDR_LENGTH]; // all zeros for loopback, all Fs for broadcast
    uint8_t type; // similar function to UDP port number
    uint8_t message[233];
};

Layer 3 receives datagrams from Layer 2, interprets datagram header, determines if a certain client is the intended recipent using the destination port, and sends the datagram to Layer 4

Layer 3 receives messages from Layer 4 along with information about the destination address and port, using this creates a datagram that is sent to Layer 2

Layer 4

The application layer. Can be anything from a Serial console to a WebSocket application to a BLE-connected Android application. This is message that must be interpreted by the application. Any format can be used for the remaining 233 bytes as long as the intended recipient understands it (e.g. a type 'c' message intended for the chat app may be formatted differently from a type 'm' message intended mapping app).

Clone this wiki locally