
LONZARK
2023/04/26阅读:9主题:灵动蓝
CS | Computer Networks Notes (No.5)
CS | Computer Networks Notes (No.5)
-
1-6 Principle: Layering -
1.6.1 What is Layering? -
Example(1): Airplane Tickets -
Example(2): Layering in a computer system.
-
-
1.6.2 Summary: Reansons for layering
-
1-6 Principle: Layering
1.6.1 What is Layering?

Layering is the name we give to the organization of a system into a number of separate functional components, or layers. The layers are hierarchical, and they communicate sequentially, i.e., each layer has an interface only to the layer directly above or below. Each layer provides a well-defined service to the layer above, using the services provided by the layer(s) below and its own private processing.
There are many examples of layering in everyday life, particularly when one service is deliberately or naturally layered on top of another.
Example(1): Airplane Tickets
For example, if you are looking for airplane tickets you might visit a brokerage website such as Google Flights, Hipmunk or Kayak. These websites let you find tickets across a wide range of airlines by communicating with a single service.
You could, instead, go to the website of every airline to query what tickets they have available. A brokerage website provides a service layer on top of each airline, abstracting away the details of each airline’s website for you. Now, if we look under the covers of each airline, they fly different types of airplanes, over different routes.
The airline takes care of the details of providing the service and offers you the simple abstraction of a ticket valid for a particular flight to take you between two airports. They hide many other details too, such as how they provide the awful food they serve. In most cases, they have a few suppliers to provide meals, drinks, fuel and so on. Each of those are naturally hidden from us, the consumer.
This separation of concerns allows each layer in the hierarchy to focus on doing its job well, and provide a well defined service to the layer above.
Example(2): Layering in a computer system.

When we write programs, we create source code using a language that abstracts away the details of the operating system, how virtual memory works, and the low level details of the hardware. (OK, so C isn’t great at hiding the details – but many other languages, like Java and Python deliberately shield us from how the lower layers work).
As a programmer we communicate with the layer below – the compiler – by handing it our source code. The compiler is a self-contained functional component that is responsible for several tasks, such as: lexical analysis, parsing our code, preprocessing declarations, and then code generation and optimization. The compiler generates object code, which is then passes to the linker. The linker links together the compiled object files and libraries. It generates an executable file. The CPU (real or virtual) then executes the code.
If you have experience writing computer programs, the benefits of layering are fairly clear in this example.
Layering breaks down the overall problem of writing programs that execute on hardware into modules, or functional components, each with a well-defined role and providing a well defined service to the layer above. It also provides a clear separation of concerns: The compiler can focus on lexical analysis, parsing and so on; the linker can focus on efficiently piecing objects together. Neither has to worry about the job of the other, and each can be improved, upgraded and replaced over time as technology and know-how progress.
1.6.2 Summary: Reansons for layering

So in summary, there are five main reasons we use layering in computer systems:
-
Modularity: It breaks down the system into smaller, more manageable modules. -
Well defined service: Each layer provides a well defined service to the layer above. -
Reuse: A layer above can rely on all the hard work put in by others to implement the layers below. It saves us the time to rewrite each layer whenever we build a system. -
Separation of concerns: Each layer can focus on its own job, without having to worry about how other layers do theirs. The only communication is up-down the layers, so it helps keep one layer’s processing and data local and internal where possible, minimizing the complex interactions between layers. -
Continuous improvement: A 6th benefit is specific to layered communication systems, such as the Internet. -
Peer to peer communications. In the 4-layer Internet model we saw how each layer communicates with its peer on another system, using the delivery service provided by the layers below.
作者介绍

LONZARK
我爱学习,学习爱我