Docstoc

Subnetting_ UDP Checksum_ and Java UDP Sockets

Document Sample
Subnetting_ UDP Checksum_ and Java UDP Sockets Powered By Docstoc
					            Subnetting, UDP Checksum, and Java UDP Sockets



1     Classful IP addresses
In the original IP addressing scheme, the 32-bit addresses are divided into three primary classes. These are
known as classful addresses.

    • Class A addresses have 8 bits prefix (0bbbbbbb) for network prefix and 24 bits suffix for host suffix.
    • Class B addresses have 16 bits prefix (first octet: 10bbbbbb) for network prefix and 16 bits suffix for
      host suffix.
    • Class C addresses have 24 bits (first octet: 110bbbbb) prefix for network prefix and 8 bits suffix for
      host suffix.

Fill out the following table
 First 4 bits of IP address         Class of address
 0000
 0001
 0010
 0011
 0010
 0011
 0100
 0101
 0110
 0111
 1000
 1001
 1010
 1011
 1100
 1101
 1110
 1111
Q: According the table, what class does a PolyU IP belong to? How about 66.218.71.198 (yahoo.com)?




cnit eie323 05/06                                                                                         1
                                                                                       2   SUBNETTING


2    Subnetting
An organization may divide the IP addresses of a class into several subnet classes.




Instead of dividing the network prefix and host suffix at the 8, 16, and 24 boundary, subnet addressing allows
the division between prefix and suffix to occur on an arbitrary bit boundary.
To indicate where the division occurs, an address mask or subnet mask, also of 32 bits, is used. An address
(subnet) mask has all 1’s in the network prefix portion and 0’s in other bit positions. Address (subnet)
masks can also be written in a dotted decimal format. Subnet mask is also referred to as netmask.
The number of 1’s in the netmask in principle can be from 2 to 32.
Basic idea: use host suffix bits as network prefix bits. These host bits that are used as network prefix are
known as subnet bits.
The number of subnets is 2# of subnet bits
Therefore, an IP address is specified by a pair: the IP address and the netmask. The netmask tells us to
which (sub)network the IP address belongs. This pair can also be used to specify a (sub)network.
Note: some legacy devices, when specifying a network, may require the IP address be a network address,
the host suffix bits must be zeros.
Suppose that the network address is 192.168.50.0 netmask 255.255.255.0 (class C).
If we use netmask 255.255.255.128 (11111111 11111111 11111111 10000000), we can have two (sub)networks:
192.168.50.0 netmask 255.255.255.128
and
192.168.50.128 netmask 255.255.255.128
For 192.168.50.0 netmask 255.255.255.128, the usable addresses are:
The number of usable address is:
For 192.168.50.128 netmask 255.255.255.128 the usable addresses are:
The number of usable address is:
Example: The network prefix has 23 bits. We have
Q. Find out the address (subnet) mask of the 15 bit network prefix:
Q. Complete the following table




cnit eie323 05/06                                                                                        2
                                                  3   CLASSLESS ADDRESSING AND SUPERNETTING


 number of bits in      in dotted decimal   number of host
 network prefix                              addresses available
                                            per network
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
The address mask enables easy calculation of the network prefix portion by a bit-by-bit “AND” (&) operation.
A router needs to extract this (network prefix) information to compare with the entries in the routing table.
(Recall a routing table only stores the network prefixes.)
Q. Fill out the following table
 IP address Netmask             Network number
 192.168.0.1 255.255.255.0
                255.255.254.0
 192.168.1.1 255.255.255.0
                255.255.254.0
Q. Fill out the following table
 IP address Netmask             Network prefix
 192.168.2.1 255.255.255.0
                255.255.254.0
 192.168.3.1 255.255.255.0
                255.255.254.0
Q. What network do you think does “0.0.0.0 netmask 0.0.0.0” represent?
Q. What does “158.132.151.162 netmask 255.255.255.255” represent?


3     Classless addressing and Supernetting
3.1    CIDR
Since the number of network prefix bits and the netmask uniquely determines each other, the CIDR (classless
internet domain routing) notation specifies a network by attaching a slash and the size of the mask in decimal,
e.g.,
128.10.0.0/16
158.132.161.129/23
By varying the host suffix bits, we’ll be able to obtain all the IP addresses for a particular network.
Q. List all the IP addresses in dotted decimal for the
                                             158.132.161.129/23
network. How many addresses are available?

cnit eie323 05/06                                                                                           3
3.2   Supernetting                                                      4   UDP AND TCP CHECKSUMS


Netmask (subnet mask) of different lengths can be mixed (variable-length subnet mask: VLSM).
Example: A company has 5 networks. One network has about (no fewer than) 100 hosts. The other four
networks have about 20 to 30 hosts each. Subnet a class C address for the 5 networks.
Given 158.132.161.0/24
Solution:
¡sn¿ 158.132.161.64/27, 158.132.161.32/27, 158.132.161.0/27
Note: some legacy devices have trouble with all 0 or all 1 subnet bits. The number of (sub)nets in these
cases would be 2# of subnet bits − 2.


3.2    Supernetting
Supernetting refers to aggregating multiple Internet addresses of the same class, for example, we can ag-
gregate two class C network addresses (192.168.2.0/24 and 192.168.3.0/24) to one bigger network address
(192.168.2.0/23).
Supernetting can further reduce the size of routing tables. It also provides a solution to the exhaustion of
Class B network addresses (refer to RFC 1519). RFC stands for the request for comments which is a set
of technical and organizational notes about the Internet. RFC is often considered as an authentic source of
information for various Internet protocols.


4     UDP and TCP Checksums
Source: TCP/IP Illustrated by W. Richard Stevens
The UDP and TCP 16-bit checksum covers bother the header and the data. If the number of the data bytes
is odd, pad bytes (0) will be added for checksum calculation purpose. An additional pseudo header is also
used as illustrated in the following figure.




cnit eie323 05/06                                                                                         4
                                                                5   JAVA UDP SOCKET PROGRAMMING


Verify the UDP check sum in the following capture.




5    Java UDP Socket Programming
Classes for datagram preparation and socket creation
DatagramPacket ( byte [ ] b u f f e r , i n t l e n g t h ) ;
DatagramSocket ( i n t p o r t ) ;

Listening for UDP packets using
DatagramSocket method
void receive(DatagramPacket packet) , e.g., (From Reilly and Reilly, Java Network Programming and
Distributed Computing)
DatagramPacket p a c k e t = new DatagramPacket ( new byte [ 2 5 6 ] , 2 5 6 ) ;
DatagramSocket s o c k e t = new DatagramSocket ( 2 0 0 0 ) ;
boolean f i n i s h e d = f a l s e ;
while ( ! f i n i s h e d )
{
socket . r e c e i v e ( packet ) ;
// p r o c e s s the packet
}
socket . close () ;

Sending UDP packets using DatagramSocket method
void send(DatagramPacket packet), the destination address and port can be set using the Datagram-
Packet method: methods
void setAddress(InetAddress addr) and
void setPort(int port)
InetAddress is a Java class to represent IP addresses with a few methods. The following method outputs an
InetAdress for a given hostname.

cnit eie323 05/06                                                                                      5
                                                                            5   JAVA UDP SOCKET PROGRAMMING


statis InetAddress getByName(String hostname)

The following snippet can be used to send UDP packets
I n e t A d d r e s s hostAddr =
              I n e t A d d r e s s . g e t ByName ( ‘ ‘ hamming . e i e . polyu . edu . hk ’ ’ ) ;
DatagramSocket s o c k e t = new DatagramSocket ( 2 0 0 0 ) ;
DatagramPacket p a c k e t = new DatagramPacket ( new byte [ 2 5 6 ] , 2 5 6 ) ;
p a c k e t . s e t A d d r e s s ( hostAddr ) ;
packet . setPort ( 2 0 0 0 ) ;
boolean f i n i s h e d = f a l s e ;
while ! f i n i s h e d )
{
/ / Write data t o p a c k e t b u f f e r
. . .
s o c k e t . send ( p a c k e t ) ;
/ / Do something e l s e , l i k e r e a d o t h e r p a c k e t s , o r check t o
/ / s e e i f no more p a c k e t s t o send
. . .
}
socket . close () ;




cnit eie323 05/06                                                                                         6

				
DOCUMENT INFO
Shared By:
Stats:
views:116
posted:1/4/2011
language:English
pages:6
Description: UDP (User Datagram Protocol) is the OSI reference model in a connectionless transport layer protocol provides a simple transaction-oriented transport service is not reliable information. It is the IETF RFC 768 UDP is the official specification.