CSCE 515: Computer Network IP – Network Layer Programming TCP/IP Wenyuan Xu Department of Computer Science and Engineering University of South Carolina IP Datagrams IP Datagram � IP is the network layer 1 byte 1 byte 1 byte 1 byte VERS HL Service Total Length � packet delivery service (host-to-host). Datagram ID FLAG Fragment Offset � translation between different data-link TTL Protocol Header Checksum protocols. Source Address Destination Address Options (if any) Data CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming IP Addresses IP Addresses � IP addresses are not the same as the underlying � IP addresses are logical addresses (not data-link (MAC) addresses. WHY? physical) � 32 bits. � IP Addresses are usually shown in dotted decimal � IP is a network layer - it must be capable of notation: 1.2.3.4 providing communication between hosts on � Includes a network ID and a host ID. different kinds of networks (different data-link � Every host must have a unique IP address. implementations). � IP addresses are assigned by a central authority ( American Registry for Internet Numbers for North � The address must include information about America). what network the receiving host is on. This is � http://www.iana.org/ipaddress/ip-addresses.htm what makes routing feasible. CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Class A Class A Class A The four for mats of IP Addresses � 128 possible network IDs � 128 possible network IDs Class Class � over 16M host IDs per network ID � over 16M host IDs per network ID A A 0 NetID HostID Class B Class B B B 10 NetID HostID � 16K possible network IDs � 64K host IDs per network ID C 110 HostID C NetID Class C Class C D D 1110 Multicast Address � over 2 million possible network IDs 8 bits 8 bits 8 bits 8 bits � about 256 host IDs per network ID CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Network and Host IDs IP Addresses � A Network ID is assigned to an � IP Addresses are usually shown in dotted decimal notation: organization by a global authority. 1.2.3.4 00000001 00000010 00000011 00000100 � cse.sc.edu is 129.252.138.8 � Host IDs are assigned locally by a system 10000001 11111100 10001010 00001000 administrator. CSE has a class B network CSE has a class B network CSE has a class B network CSE has a class B network � Both the Network ID and the Host ID are used for routing. CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Host and Network Addresses Special IP addresses � A single network interface is assigned a � An IP broadcast addresses has a host ID single IP address called the host address. of all 1s. � A host may have multiple interfaces, and � An IP address that has a host ID of all 0s therefore multiple host addresses. is called a network address and refers to an entire network. � Hosts that share a network all have the same IP network address (the network ID). � localhost: 127.0.0.1 CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Subnet Addresses Subnetting router � An organization can subdivide it’s host address space into groups called subnets. Subnet 1 Subnet 2 Subnet 3 128.213.1.x 128.213.2.x 128.213.3.x � The subnet ID is generally used to group hosts based on the physical network topology. 10 NetID SubnetID HostID CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Subnetting Subnet Mask � Subnets can simplify routing. � How do we know how many bits are allocate for subnet ID, how many bits are � IP subnet broadcasts have a hostID of all allocated for host ID? 1s. � Example: subnet mask: 255.255.255.0 � It is possible to have a single wire network with multiple subnets? � Question: what is the subnet id for 129.252.138.8 if subnet is: � 255.255.255.0 � 255.255.255.192 � 255.255.127.0 CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Subnet mask IP Routing � Question: if the subnet mask is 255.255.255.128, are � Q: How do you get a packet from one 129.252.138.8 and 129.252.138.127 on the same network to another? subnet? � Calculate the subnet ID � If the subnet IDs are the same => Yes � Otherwise => No 255. 255. 255. 128 11111111 11111111 11111111 10000000 or 10000001 11111100 10001010 00000100 129.252.138.8 10000001 11111100 10001010 00000000 129.252.138.0 Yes 129.252.138.127 129.252.138.0 2007 CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Mapping IP Addresses to Hardware Routing table Addresses � Destination IP address. Either host address or a network � IP Addresses are not recognized by address hardware. � IP address of the next hop Router � Flags � If we know the IP address of a host, how � Network interface do we find out the hardware address ? � The process of finding the hardware � /sbin/route address of a host given the IP address is Destination Gateway Genmask Flags Metric Ref Use Iface called 129.252.130.0 * 255.255.255.0 U 0 0 0 eth1 loopback * 255.0.0.0 U 0 0 0 lo default SWG130.cse.sc.edu 0.0.0.0 UG 1 0 0 eth1 Address Resolution Address Resolution 2007 CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming ARP ARP conversation � The Address Resolution Protocol is used by a sending host when it knows HEY - Everyone please listen! the IP address of the destination but needs the Ethernet (or whatever) Will 128.213.1.5 please send me address. his/her Ethernet address? � ARP is a broadcast protocol - every host on the network receives the request. � Each host checks the request against it’s IP address - the right one responds. Ethernet Ethernet Sender Sender Target Target op type Ethernet addr IP addr Ethernet addr D. addr S. addr IP addr not me Ethernet header 28 byte ARP request/reply Hi Green! I’m 128.213.1.5, and my Ethernet address is 87:A2:15:35:02:C3 CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Example– Proxy ARP Example– routing Proxy ARP 129.252.138.0 129.252.138.0 129.252.138.0 129.252.10.0 H1 H2 H3 H4 H5 H6 H1 H2 H3 H4 H5 H6 E1 E2 E3 E4 E6 E1 E2 E3 E4 E6 E5 E5 129.252.138.6 129.252.10.169 129.252.138.3 129.252.138.4 129.252.138.10 129.252.138.40 Sender Sender Target Ethernet Ethernet Target D. S. IP addr type op Ethernet Ethernet D. addr S. addr Ethernet addr IP addr Ethernet addr IP addr size Data IP addr. D. addr S. addr Ethernet header 28 byte ARP request/reply IP header Ethernet header CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Reverse Address Resolution RARP conversation � The process of finding out the IP address HEY - Everyone please listen! My Ethernet address is of a host given a hardware address is 22:BC:66:17:01:75. Does anyone know my IP address ? called Reverse Address Resolution Reverse Address Resolution � Reverse address resolution is needed by diskless workstations when booting (which not me used to be quite common). Hi Green! Your IP address is 128.213.1.17 . CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Services provided by IP IP Datagram � Connectionless Delivery (each datagram 1 byte 1 byte 1 byte 1 byte is treated individually). VERS HL Service Fragment Length Datagram ID FLAG Fragment Offset � Unreliable (delivery is not guaranteed). TTL Protocol Header Checksum � Fragmentation / Reassembly (based on Source Address hardware MTU). Destination Address � Routing. Options (if any) � Error detection. Data CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming IP Datagram Fragmentation IP Flow Control & Error Detection � If packets arrive too fast - the receiver � Each fragment (packet) has the same discards excessive packets and sends an structure as the IP datagram. ICMP message to the sender (SOURCE � IP specifies that datagram reassembly is QUENCH). done only at the destination (not on a hop- � If an error is found (header checksum by-hop basis). problem) the packet is discarded and an � If any of the fragments are lost - the entire ICMP message is sent to the sender. datagram is discarded (and an ICMP message is sent to the sender). CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Recommend
More recommend