Skip to content

About

Educational C/UDP geolocation simulator exploring a custom client-server protocol and SCHED_RR scheduling on PREEMPT_RT Linux.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Geolocalizador-RT

A simulated geolocation protocol over UDP, scheduled with Real-Time Linux

Geolocalizador-RT is an educational distributed-systems prototype written in C. It models a mobile device sending coordinates to a central server, defines a compact request/response protocol and runs the server under Linux SCHED_RR real-time scheduling.

The project was created to explore three areas together:

  • POSIX socket programming in C.
  • Client-server protocol design over UDP.
  • Real-time process scheduling on Linux with PREEMPT_RT.

The current implementation deliberately simulates the geolocation layer. The client uses test coordinates, while the server generates or returns synthetic positions. A real GPS receiver and persistent database are proposed as future extensions.

Important

This is a historical academic prototype from 2018, not a production tracking system. It does not currently read a GPS, retain positions or protect location data. It also contains known input- and buffer-handling issues. Build and run it only in an isolated lab after reading Project status and limitations.

What this project demonstrates

  • Creating IPv4 UDP sockets with socket, bind, sendto and recvfrom.
  • Resolving a server name or IPv4 address from a C client.
  • Serving multiple independent datagrams without creating a connection per client.
  • Defining four application commands and positive/negative responses.
  • Parsing protocol messages and dispatching operations on the server.
  • Applying the SCHED_RR policy with a static real-time priority of 85.
  • Separating the interactive client from the continuously running server.
  • Reasoning about how GPS acquisition and storage could extend a simulation into a complete distributed application.

System overview

flowchart LR
    A["Client 1"] -->|"UDP :50005"| C["Geolocation server"]
    B["Client N"] -->|"UDP :50005"| C
    C --> D["Protocol dispatcher"]
    D --> E["SCHED_RR priority 85"]
Loading

The client represents a mobile device. It prepares protocol commands, sends them to the server and displays the replies through a terminal menu. The server binds to every local IPv4 interface on UDP port 50005, processes one datagram at a time and replies to the source address.

The original target was a Raspberry Pi running Raspbian with a PREEMPT_RT kernel. Client and server can also communicate through localhost for a controlled demonstration.

Current application flow

The client presents five operations:

Menu Action Current prototype behaviour
1 Save the current location Sends fixed coordinates 24.67, 31.94; the server validates the ID and returns OK, but does not store them
2 List recent locations Requests between 1 and 10 positions; the server generates that many random coordinate pairs
3 Show the last location The server returns the fixed test position 13.4, 12.5
4 Reset stored locations The server validates the ID and acknowledges the request, but no database is modified
5 Exit Closes the client socket and terminates the client

Both programs currently use the fixed device ID 373.

Application protocol

Messages are sent as individual UDP datagrams. Although the original report discusses IEEE 754 as a compact representation, the checked-in implementation serializes every command and coordinate as an ASCII string.

Requests

Command Wire format Intended meaning
SAV SAV <latitude> <longitude> <id> Save a position for a device
LST LST <id> <count> Return the last count positions, with count limited to 1–10 by the client
LSL LSL <id> Return the most recent position
RST RST <id> Delete the device's stored positions

Responses

Response Meaning
OK The simulated operation completed successfully
ER The supplied device ID was not accepted
LAT:<value> LON:<value> One simulated coordinate pair

LST returns one coordinate datagram per requested result, followed by a final OK. LSL returns one coordinate datagram followed by OK.

Repository guide

Path Contents
cliente_geo.c Interactive UDP client, menu and protocol request handling
servidor_geo.c UDP server, command dispatcher and real-time scheduler configuration
CRT-Proyecto-JA_Gumiel.pdf Original Spanish project report with architecture, protocol, screenshots and design rationale
LICENSE MIT License

The report is the most detailed record of the original experiment. It explains the intended Raspberry Pi setup, every menu operation, the four protocol commands and why round-robin real-time scheduling was selected.

Requirements

Basic communication demo

  • A Linux system.
  • GCC or another C compiler compatible with the POSIX networking interfaces.
  • IPv4 connectivity between client and server.
  • Permission to use UDP port 50005.

Original real-time experiment

  • A Linux kernel configured with PREEMPT_RT.
  • Permission to select a real-time scheduling policy, normally through root privileges, CAP_SYS_NICE or a suitable RLIMIT_RTPRIO.
  • An isolated test system where a high-priority process cannot disrupt unrelated workloads.

The code requests SCHED_RR unconditionally. If the process lacks the required permission, the server exits with:

sched_setscheduler() failed: Operation not permitted

Containers can produce the same error even when the process appears to run as root, because the required capability may not be available.

Build

Clone the repository and compile both translation units:

git clone https://github.com/jagumiel/Geolocalizador-RT.git
cd Geolocalizador-RT

cc -std=gnu11 -O2 -Wall -Wextra cliente_geo.c -o cliente_geo
cc -std=gnu11 -O2 -Wall -Wextra servidor_geo.c -o servidor_geo

The historical sources compile with a current GCC toolchain, but they produce warnings. Compilation success should not be interpreted as evidence that the known runtime issues have been corrected.

Run the local demonstration

Use two terminals on an isolated Linux system.

Terminal 1 — server

The simplest historical reproduction is to run the server with sufficient privileges:

sudo ./servidor_geo

Running an entire network process as root is not an appropriate production design. A modern revision should grant only the required capability, provide a non-real-time fallback and reduce privileges immediately after configuring the scheduler.

Terminal 2 — client

Connect through the loopback interface:

./cliente_geo 127.0.0.1

For a second host, replace 127.0.0.1 with the server's IPv4 address or a resolvable hostname. Do not expose the current protocol to an untrusted network.

The active policy and priority can be inspected from another terminal:

server_pid="$(pgrep -n servidor_geo)"
chrt -p "$server_pid"

Stop the server with Ctrl+C when the experiment is complete.

What “real time” means here

Real time does not simply mean “fast”. It means that timing behaviour is bounded and predictable enough for the application's deadlines.

This prototype asks Linux to schedule the server with:

param.sched_priority = 85;
sched_setscheduler(0, SCHED_RR, &param);

SCHED_RR gives runnable real-time tasks at the same priority a round-robin time quantum. A PREEMPT_RT kernel can reduce operating-system scheduling latency, while the elevated priority allows the server to pre-empt ordinary SCHED_OTHER work.

The current application does not, however, establish an end-to-end real-time guarantee:

  • UDP delivery time and packet loss are not controlled.
  • No deadline, period or worst-case execution time is defined.
  • The client is interactive and is not assigned a real-time policy.
  • There is no GPS acquisition loop with deterministic sampling.
  • Latency, jitter and deadline misses are not measured.

The repository should therefore be understood as an experiment with a real-time scheduling primitive, rather than a validated hard-real-time geolocation system.

Project status and limitations

The code is preserved as an educational snapshot. The following limitations are present in the checked-in implementation:

  • Coordinates and device identity are simulated; there is no GPS integration.
  • SAV and RST acknowledge requests without persisting or deleting data.
  • LST generates pseudo-random positions and LSL returns a fixed position.
  • The server cannot fall back to normal scheduling when SCHED_RR is denied.
  • The input function used to request the list length evaluates strlen on an uninitialized buffer, which is undefined behaviour.
  • Received datagrams are not consistently terminated and validated before being treated as C strings.
  • One server response sends the complete 1,024-byte buffer instead of the actual payload length.
  • Several return values, parsed-field counts and message boundaries are not checked rigorously.
  • An unknown command terminates the server instead of returning a protocol error and continuing.
  • The client can wait indefinitely because there are no socket timeouts, retries, sequence numbers or duplicate detection.
  • The implementation is IPv4-only and uses the legacy gethostbyname resolver.
  • The report's proposed binary floating-point representation does not match the ASCII wire format implemented in the source.
  • The protocol provides no authentication, encryption, replay protection or access control. Real location data would be sensitive personal data.
  • There is no build system, automated test suite, continuous integration or repeatable latency benchmark.

Learning extensions

If you are using this repository as a systems-programming lab, useful experiments include:

  1. Capture the four commands with Wireshark and document the actual datagrams.
  2. Compare UDP with a TCP implementation and explain the reliability trade-off.
  3. Add socket receive timeouts and simulate packet loss.
  4. Replace the fixed client coordinates with data from a GPS simulator.
  5. Measure round-trip latency under CPU and I/O load.
  6. Compare SCHED_OTHER, SCHED_RR and a PREEMPT_RT kernel using the same workload.

Resumen en español

Este repositorio implementa un prototipo académico cliente-servidor en C para simular el envío de coordenadas mediante sockets UDP. El servidor interpreta un protocolo propio con los comandos SAV, LST, LSL y RST, y solicita una política de planificación Linux SCHED_RR con prioridad 85.

La geolocalización es simulada: no existe integración con GPS ni persistencia en una base de datos. Su valor principal está en mostrar programación de sistemas, diseño de protocolos, comunicaciones distribuidas y una primera aproximación a Linux de tiempo real. La memoria técnica incluida documenta en español la arquitectura, las pruebas originales y la evolución prevista.

Further reading

License

This project is distributed under the MIT License.

Author

Jose Ángel Gumiel

About

Educational C/UDP geolocation simulator exploring a custom client-server protocol and SCHED_RR scheduling on PREEMPT_RT Linux.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages