This is a fantastic project. Building a "toy" version is the best way to learn. Let's make a plan.
The key is to not build everything at once. We'll separate the project into two main parts: the Data Plane (getting a ping to work) and the Control Plane (managing the user and session).
We'll start with the Data Plane, and we'll "hard-code" all the connections first, just to make data flow.
Here is a 4-milestone plan.
Your first goal is to build the "GTP-U Tunnel." This is two programs that shuffle data between a virtual "internet" and a virtual "radio" network.
-
Component 1: The
pgw(P-GW)- Job: This program is your "exit ramp" to the internet.
- Task:
- Create a TUN/TAP device (e.g.,
tun0). This is your "internet." - Listen on a UDP port (e.g., 2152) for "GTP-U" packets.
- Forwarding (Uplink): When a packet arrives, de-capsulate it (strip the GTP-U header) and write the inner IP packet to
tun0. - Forwarding (Downlink): When an IP packet arrives from
tun0(like a ping reply), en-capsulate it (wrap it in a GTP-U header) and send it over UDP to the S-GW's address.
- Create a TUN/TAP device (e.g.,
-
Component 2: The
sgw(S-GW)- Job: For V1, this is a simple "data router."
- Task:
- Listen on one UDP port for the eNodeB (e.g., 2153).
- Listen on another for the P-GW (e.g., 2154).
- Forwarding (Uplink): When a packet arrives from the eNodeB, forward it to the P-GW.
- Forwarding (Downlink): When a packet arrives from the P-GW, forward it to the eNodeB.
✅ End of Milestone 1: You can send a GTP-U packet to your sgw and see it come out the pgw's tun0 device.
Now we build the two ends of the "radio" link. We'll use a simple UDP socket as our "simulated air."
-
Component 3: The
ue(Phone)- Job: This is the "client" machine.
- Task:
- Create its own
tun0device. This is the "phone's" IP stack. - Forwarding (Uplink): When an IP packet (like a
ping) arrives from itstun0, send this raw IP packet over a UDP socket (our "air") to the eNodeB. - Forwarding (Downlink): When a packet arrives from the "air," write it to
tun0.
- Create its own
-
Component 4: The
enb(eNodeB)- Job: This is your "tower." It's the bridge between the "air" and the "core."
- Task:
- Listen on a UDP port for the "air" (from the
ue). - Forwarding (Uplink): When a raw IP packet arrives from the
ue, en-capsulate it into a GTP-U packet and send it to thesgw's UDP port. - Forwarding (Downlink): When a GTP-U packet arrives from the
sgw, de-capsulate it and send the inner IP packet to theueover the "air" (UDP).
- Listen on a UDP port for the "air" (from the
✅ End of Milestone 2: You can ping from the ue's tun0 device, and the ping will go all the way through enb -> sgw -> pgw -> pgw's tun0 and back!
Right now, all the IP addresses are hard-coded. Now we add the "brains" to set up the session automatically. This is the "Control Plane."
-
Component 5: The
hss(Database)- Job: A simple user database.
- Task: Create a simple server (e.g., TCP) that listens for a "user ID" and responds with "OK, here are their security keys." (We can skip the complex
Diameterprotocol and just invent our own simple JSON-based API).
-
Component 6: The
mme(Orchestrator)- Job: This is the most complex part. It manages the "Attach Procedure."
- Task:
- Listen for connections from the
enb(this is the S1-MME interface). - When the
ueconnects, theenbwill forward its "Attach Request" to themme. - The
mmethen performs the "login" sequence:- Asks the
hssif the user is valid. - Tells the
sgwandpgwto "Create Session" (using the GTP-C protocol—a new protocol you'll need to implement!). - Tells the
enbto activate the "radio bearer" (the pipe) for theue.
- Asks the
- Listen for connections from the
✅ End of Milestone 3: A user can "boot" the ue program, and it will automatically attach and get an IP address, without hard-coding.
Finally, we make our "simulated air" (the UDP socket) imperfect.
- Job: Go back into the
ueandenbprograms. - Task:
- Instead of just sending the IP packet over UDP, you first pass it to a PDCP "library" (which you write) to encrypt it.
- Then, you pass it to an RLC "library" (which you write) to segment it (slice it into smaller pieces).
- This is when you can use the
tc(Traffic Control) tool we discussed. You'll runtcon yourenb's "air" link to randomly drop 5% of packets. - You can then test if your RLC layer's re-transmission logic kicks in and successfully re-sends the lost pieces.
✅ End of Milestone 4: You have a working, miniature LTE network that can handle packet loss, just like the real thing.
This is a big, exciting, and very rewarding project.
Does it make sense to start with Milestone 1, just focusing on building that pgw and sgw data tunnel?