network-programmingtcpiposidata-link-layer

Data link layer + Network layer connections


I'm reading up on networking and there is something about the layer 2+3 OSI model interaction i don't get. I want first to understand the basics so feel free to keep it simple.

Lets say we have a LAN - 5 computers all connected to a router which is connected to an ISP router.

1. one of the PC on the LAN wishes to send a message to another PC on the same LAN(they are both connected to the local router but not to each other directly) - is there layer 3 encapsulation in use here? if not - and we only use the layer 2 information, what is the path the message will go through? is it PC1->PC2 , or PC1->Router->PC2. if it is going through the router - what information is added in each message transaction? and if not - do PC's on the same LAN (connected to the same router in some layer 2 protocol) aware of each other? can they message each other although they are not connected directly

2. one of the PC on the LAN wishes to send a message to a PC outside the LAN (way way outside). i understand it goes PC1->Router->ISP Router -> ......... -> recipient local router -> recipient which entity adds the layer 3 data? is it the router? PC1? ISP router? when will this information be needed? since all single transaction is connected by devices who can talk between them self's in layer 2 protocols? (PC1 talks to it's router in level 2 protocol, so does Router to ISP router... etc?)

any further information worth adding will be appreciated. Thanks!


Solution

    1. Is there layer 3 encapsulation in use here? Yes it is! The two computers are connected in a network created by your router, which is a Network Layer Device. When the sender sends a packet it doesn't know where is the receiver (in LAN or in Internet), so it prepares to send the packet as usually. Then the router checks his table and knows that the receiver is connected with it, but until this happened everything was going on normally. So, the thing you have to understand is this: while it is a communication between two machines, all the protocols of each layer must be accomplished. If the computers would be connected with a switch, a Data Link Layer device, the authentication would be made with their MAC addresses instead of their IPs, so there is not a Network Layer here(obviously no layer 3 encapsulation ) but this is not your case.
    2. That's a long story to tell how the packets travel from sender to receiver. But in general, there are two important information that each packet should have: the address of the destination machine(Network Layer), and an identifier of the process that should receive the packet in the destination machine (Transport Layer). If it is the first time that the machines communicate with each other, the router connected with the sender broadcasts that packet in all its outbound lines, and so on with the routers which receive this packet, until the destination is reached. After the first packet has been sent the routers keep records on their tables how to locate each machine in the best way possible. This will make broadcast unnecessary next times. So, the packet reached the destination. The receiver probably has a lot of processes opened in that time (open your Task Manager -> Processes to see what I'm talking about). This is where T.L protocols appear. They use the identifier in the head of the packet to address the packet in the right process. And than the communications goes on with Application Layer Protocols. I hope that this is a useful information for you. If you really want to study this things I would suggest you Computer Networks of Andrew Tanenbaum.