Principles in Network
Layering
- Functional components
- Only communicate with layer directly above and below
- Provide services to upper layer, using services provided by lower layer, and also doing its own private job
Advantages
- Each layer can be implemented independently, as long as they keep the interfaces unchanged
- Each layer can focus on its own job, and use lower layer’s abstracted service(For example API) easily without knowing what happens inside.
Example
- The programmers can write platform independent code.
- If the processor changes, they only need to change the toolchain they use rather than rewrite their codes
- If the programmers break the layering principle, for example, embed platform specific assembly code in C code when writing OS or kernel, there will be a huge cost
- The codes are no-longer portable, they must rewrite or at least modify the codes for different processors again and again.
- If you want to use layering, do NOT make any assumption about the lower layers
- Try not to break the layering principle, except you really really have to do so.
Reasons for layering
- Modularity
- Well defined service
- Reuse
- Separation of concerns
- Continuous improvement
- Peer-to-peer communication
Encapsulation
Encapsulation is how you can pack data into packages but preserve their layering information
- Encapsulation is how layering manifest in data representation
- Layer N data is the payload to Layer N-1
- Example
- HTTP data is payload for a TCP segment
- The TCP segment is payload for IP segment
- The IP segment is the payload for WIFI link frame
Encapsulation flexibility
Encapsulation allow you to layer recursively
For example, in a VPN
We have
- HTTP data inside a TCP segment
- inside an IP segment
- inside a TLS segment
- inside a TCP segment
- inside an IP segment
- inside the link frame
Tips
- Network protocals are ALL BIG endian
Convert between little endian and big endian in C:
1 |
|
1 |
|