I was reading about the 'IP' in TCP/IP. Most of its functions seem to be for connecting different (types of) networks. Does this mean that network layer is not required for communication between computers in the same LAN? If not, what other functions are provided by network layer other than common addressing (in case of IP) and routing?
Network Layer – Importance and Functions
iplayer3Network
Related Solutions
A connection oriented network is one where the network layer (roughly equivalent to the IP layer) where the routing done is connection based (like X.25 or a telephone call).
So this is absolutely true:
In connection oriented networks, the source first establish connection with destination before sending packets.
but this misses the important word network:
in connection oriented [network] protocol, decision about route for sequence of packets can be made only once when the connection is established
So, a protocol like TCP has to add sequence numbers, acknowledgments and retries to ensure that it delivers data in the same order it was supplied. It works with the connectionless service the lower layer provides though.
At layer-2, the frames are delivered directly from host to host, meaning that each source host is on the same network as the destination host. In order to get from one network to another network (internet), we have layer-3 protocols, e.g. IP (Internet Protocol).
Hosts at layer-2 find each other by broadcasting, and switches flood frames where they do not know the destination, so that doesn't scale, and you have separate networks and protocols to connect the separate networks.
- Suppose you have an office with computers connected on a LAN. Why can't all the computers act as their own routers and have the office be a layer 3 topology? Why is layer 2 necessary at all?
In some ways, each host is a router and has layer-3 built into it., but each host probably only has one connection to the network. Routers route packets between networks, and they will have multiple interfaces. Routers are hosts on the network that know how to reach other networks. For traffic on the network, the layer-2 frame is addressed directly to the destination host, but to get to a different network, the frame is addresses with that of a router. If the router does not have a path to the destiantion network, it drops the packet.
- What prevents us from implementing, say, a firewall as a node in an arbitrary layer 3 topology instead of being at the interface of the network layer and the link layer?
A firewall is a node at the physical and data-link layer, and it probably has a network address for management and (in most cases) each interface, too. A network address is a layer-3 address, so the topology is layer-3.
- Why do we use different protocols (spanning trees vs. routing) to solve essentially the same problem?
Spanning tree and routing are very different protocols with different purposes. Spanning tree is designed to prevent layer-2 loops by setting up a single loop-free path on a single network to a root bridge. Routing is designed to send packets from one network to another network. Both layer-2 and layer-3 can have loops (very bad). Spanning tree is a protocol to prevent loops at layer-2 because layer-2 frames would just propagate and amplify until the network crashes (happens very quickly). IP (a layer-3 protocol) has a TTL that decrements when the packet is processed by a device, so a packet will not circulate forever the way a layer-2 frame does, but routing protocols generally try to prevent routing loops, but routers can still be configured to loop.
Remember that routing protocols do not route packets, they let routers exchange routing information. Routers route packets based on what is in their routing tables, which can be populated by routing protocols (also directly connected networks and statically configured routes can populate a routing table with more preference than the routes learned from a routing protocol). A better analogy is comparing a switch MAC address table to a routing table. Routers can use routing protocols to learn where destinations are from other routers. Switches learn destination interfaces directly from the frames passing through each switch, but do not communicate that to other switches.
Remember, too, that the different protocols were defined by different people for different purposes at different times, and they are maintained by different groups and standards bodies. What we use today (primarily ethernet, although being supplemented and replaced by Wi-Fi, and IPv4) is what the market chose. Bob Metcalfe (ethernet) and Vint Cerf (IP) really did not know each other or what the other was working on. Each developed a protocol for his own purposes.
Best Answer
That is correct - the IP layer is not required for communication within a LAN. On Ethernet for example, there's no reason a computer can't send an Ethernet frame addressed to some other computer with some non-IP data inside it.
However, now that the Internet is ubiquitous, TCP/IP is the most useful configuration and therefore the most work has gone into supporting it. There's rarely any reason for a commercial software vendor to make a protocol that runs directly over Ethernet, when they could make it run over IP instead, and have it be able to work on the Internet. I can't think of any protocols used by the average consumer that don't use IP, besides ARP. (NetBIOS used to be ubiquitous on Windows LANs).
However, professional networking gear does use such protocols. Two examples that came to mind are the IS-IS routing protocol, or STP used by Ethernet switches.
IS-IS could've run over IP, really (there's a similar protocol OSPF that does just that). STP runs on Ethernet switches, which might not even have IP addresses, so it really does need to run over Ethernet.
I imagine most protocols that run on IP (such as TCP) could be adapted to run over Ethernet, Token Ring, ATM, or whatever - but there would be no benefit to doing so.