# TCP/IP



## tenchu (Feb 10, 2019)

I'm currently learning the basics of TCP/IP and am struggling with the whole 'model' thing.  I had the same problem with the OSI model when learning networking and still don't really get it.  I can understand that it conceptualises the procsess of sending somthing across a network and that each layer is modular i.e. can be improved/modified without messing with the other layers, but the actual process eludes me.  I mean from the second a user presses a key on the keyboard or clicks a mouse button, I cannot get my head round which layer is then doing what.  I've looked high and low for a good explanation for beginners that would describe each layer and what it does but have always been left more confused than when I started.  Can anyone gere help?


----------



## drhowarddrfine (Feb 10, 2019)

tenchu said:


> I mean from the second a user presses a key on the keyboard or clicks a mouse button, I cannot get my head round which layer is then doing what.


To be clear, you understand TCP/IP has nothing to do with any of that, right?


----------



## tenchu (Feb 10, 2019)

drhowarddrfine said:


> To be clear, you understand TCP/IP has nothing to do with any of that, right?


I'm well aware, but thanks for asking.  I was trying to over emphasise my point i.e. what specifically happens after an application sends data.


----------



## Emrion (Feb 10, 2019)

Models exist to account a very complex reality but they aren't reality. Maybe the DoD model is easier to understand and somewhat closer to the real world.

I think if you really want to understand the thing, you need to program some toys that use TCP/IP. A hard way if you never programmed before but that will certainly answer most of the questions you have.


----------



## tenchu (Feb 10, 2019)

Emrion said:


> Models exist to account a very complex reality but they aren't reality. Maybe the DoD model is easier to understand and somewhat closer to the real world.
> 
> I think if you really want to understand the thing, you need to program some toys that use TCP/IP. A hard way if you never programmed before but that will certainly answer most of the questions you have.


I've got a raspberry pi 2 and an arduino.  I bought them with the intention of learning such things as networking and low level programming.  I've not done too bad with the programming part because there are lots of 'hands on' exercises. However the networking side is more difficult because I've not come across any books or resources that provide hands on practice.  They all seem to be conceptual, which in practice has meant pages of text with no exercises.  I actually learnt a lot just from setting up BSD on a nackered old laptop with a lot of help from members on the forums here.  It's a shame there are no resources that have you doing practical exercises.


----------



## SirDice (Feb 11, 2019)

tenchu said:


> However the networking side is more difficult because I've not come across any books or resources that provide hands on practice.


Get all three volumes of "TCP/IP Illustrated" by W. Richard Stevens. Volume 1 will tell you everything you need to know about TCP/IP in excruciating detail. Volume 2 is more about socket programming and volume 3 is about things like SSL/TLS. All three volumes contain, besides a ton of information, a lot of examples and exercises. They're collectively known as the "Bible" of TCP/IP.


----------



## gkontos (Feb 11, 2019)

tenchu said:


> I mean from the second a user presses a key on the keyboard or clicks a mouse button, I cannot get my head round which layer is then doing what.



If TCP/IP is involved then this action takes place in the higher level, the application which triggers other actions to the below layers:


----------



## drhowarddrfine (Feb 11, 2019)

gkontos That's a nice graph.


----------



## drhowarddrfine (Feb 11, 2019)

SirDice said:


> Get all three volumes of "TCP/IP Illustrated" by W. Richard Stevens.


They sit on my bookshelf of honor


----------



## tommiie (Feb 11, 2019)

SirDice said:


> Get all three volumes of "TCP/IP Illustrated" by W. Richard Stevens.



Alternatively you can also get the three volumes of "Internetworking with TCP/IP" by Douglas E. Comer. They cover the same topics and its third volume even has a version specific to BSD UNIX.

I've often wondered whether Stevens' books or Comer's are "better" but never found a definitive answer.


----------



## shkhln (Feb 11, 2019)

gkontos said:


> <7 layer Internet diagram>











						OSI: The Internet That Wasn’t
					

How TCP/IP eclipsed the Open Systems Interconnection standards to become the global protocol for computer networking




					spectrum.ieee.org


----------



## SirDice (Feb 12, 2019)

Something that keeps tripping everyone up, OSI is a _model_ not a _standard_.


----------



## shkhln (Feb 12, 2019)

Well, OSI was published as ISO 7498, so it's literally a standard.  It wasn't intended as a simple conceptual model either, it was supposed to be implemented in software (probably not necessarily with all 7 layers per implementation). However, TCP/IP was never developed with OSI model in mind and does not map to it cleanly _by design_. One can think about Internet in OSI terms, but it is really quite pointless. (And the mapping on the diagram above is total bullshit, what with the mp3-sockets equivalence.)


----------



## usdmatt (Feb 12, 2019)

I tend to ignore the OSI model. As mentioned above, it doesn't really map cleanly to how networking is actually implemented. The 5 layer model is far more useful for visualising the various levels -

1 - Physical layer - the actual cable. Could be cat5 or fibre for example
2 - Data link - Defines the format for actually sending signals across the cable and talking to other locally connected devices. In most cases will be ethernet which makes use of MAC addresses to identify hosts.
3 - Network (IP) - Method for communicating across global networks. We use IPv4 & IPv6
4 - Transport Layer (TCP/UDP) - Additional layer over the top of IP which provide things like connection management, retransmission, packet ordering, etc
5 - Application layer - the actual HTTP/DNS/SMTP/ec traffic

It's obvious to see how these are separated and can be replaced without affecting other layers. You can use IPv6 instead of IPv4, or ATM instead of Ethernet, etc.

So a server sending a webpage for example would look like the following -

Layer 5 - Web server generates http data and passes that to the OS network functions to be sent
Layer 4 - Network stack puts html data into a TCP datagram
Layer 3 - TCP data gets IP header/footer added to allow delivery over the Internet
Layer 2 - IP packet gets put into an Ethernet frame to be transferred over the local network
Layer 1 - frame gets sent over wire to next hop


----------



## SirDice (Feb 12, 2019)

usdmatt said:


> 4 - Transport Layer (TCP/UDP) - Additional layer over the top of IP which provide things like connection management, retransmission, packet ordering, etc


That just shows how bad TCP/IP actually fits in these models. UDP doesn't belong here because it has no connection management, no retransmissions and no ordering.

I rarely use the OSI model, the only things I do use are layer 2, 3 and 7. Layer 2 is "on the wire" (but not the 'wire' itself), layer 3 is IP and layer 7 web or application proxies for example.


----------



## usdmatt (Feb 12, 2019)

To be fair my description was probably a bit off. Both TCP and UDP clearly sit at exactly the same point in the stack, just above IP, but below any application level. It seems IP was designed purely as a delivery/addressing protocol, then UDP/TCP to provide additional features on top, the most obvious being port numbers to allow multiple applications to run on the same address. That's about all UDP offers other than checksums for the data, with TCP providing more, but increased overhead with it.


----------

