According to the OSI model, the transport layer divides the data into segments and then attaches the source IP and destination IP along with the port numbers. Also it is said that the network layer does the logical addressing which means the mapping of a address to a unique device on the network. Since IP's are associated already in the transport layer what is the network layer doing with the so called logical addressing. I am confused and would appreciate any kind of help.
Source and destination addresses are found in the IP packet, belonging to the network layer. A transport layer datagram or segment that uses port numbers (=host subaddresses) is wrapped into an IP packet and transported by it.
The network layer uses the IP packet information to transport the packet across the network (routing). Arriving at the destination host, the host's IP stack uses the transport layer information (port number) to pass the information to the application.
IP addresses (and port numbers of course) are referred to as logical addresses because they are assigned to a host by the network (or its administrator) and are used to structure a network. This is in contrast to physical addresses like Ethernet MAC addresses that are assigned by the manufacturer.
I'm afraid you're mistaken on some points. But first, remember two things:
- The OSI model is theoretical model. Nothing actually follows it.
- TCP/IP addressing, used almost everywhere today, uses the TCP/IP model.
Internet Protocol (IP) addressing is a function of the network layer (Internetwork layer in the TCP/IP model). The transport layer is where you find port numbers. The data link addresses (MAC addresses) are used only on the local network.
The transport-layer protocol provides for logical communication between application processes, a network layer protocol provides for logical communication between hosts. Transport layer protocols are implemented in end systems and not in network routers.
Each application process has an associated socket identified by a unique port number. When a process needs to send data the transport layer encapsulates the application data and necessary headers(such as source and destination port number) into segment and forwards it to the network layer. The network layer encapsulates the segment into a IP datagram(with headers such as source and destination IP address) and makes its best effort to transfer the datagram to the correct host.
At the end systems the Transport layer protocols use the IP address for transport layer multiplexing or demultiplexing. When a segment arrives at the host the transport layer depending on the type of protocol used(TCP or UDP) extracts the data and guides it to the correct socket(Demultiplexing).
Two UDP packets with the same destination IP address and port numbers but different source IP address and/or port number will be directed to the same destination socket. OTOH two TCP segments with different source IP address or port numbers will be directed to two different sockets.
Hence, we can conclude that at transport layer, IP addresses are used for multiplexing or demultiplexing the packets at the end systems whereas at the network layer IP addresses route the packet to the correct receiving host.