Presentation is loading. Please wait.

Presentation is loading. Please wait.

UDP. User Datagram Protocol (UDP)  Unreliable and unordered datagram service  Adds multiplexing  No flow control  Endpoints identified by ports 

Similar presentations


Presentation on theme: "UDP. User Datagram Protocol (UDP)  Unreliable and unordered datagram service  Adds multiplexing  No flow control  Endpoints identified by ports "— Presentation transcript:

1 UDP

2 User Datagram Protocol (UDP)  Unreliable and unordered datagram service  Adds multiplexing  No flow control  Endpoints identified by ports  servers have well-known ports  see /etc/services on Unix  Optional checksum  pseudo header + udp header + data  Header format

3 Initiating a Session  Client initiates the connection and sends the clients port in the message header  Server port is contained in /etc/services  DNS=53  talk=517  Connectionless  Primary purpose demux (demultiplex)

4 Demux Process Application process Application process Application process UDP Packets arrive Ports Queues Packets demultiplexed Port 2000 Port 3000 Port 3100

5 Using it  TCP  s=socket(AF_INET, SOC_STREAM,0)  bind  listen  accept  connect  read/write  UDP  S=socket(AF_INET, SOCK_DGRAM, 0)  bind (receiver)  sendto, recvfrom

6 Broadcasting with UDP  You have to enable broadcasting on the socket  Set up the address you will be passing to “sendto” to refer to 255.255.255.255 (0xffffffff)  Anyone in the broadcast domain will be able to read the packet.  A broadcast domain will generally be machines on one port of a router

7 What is a broadcast domain?  Networks are built from hubs (not used much anymore), ethernet switches and routers  Packets from machines on different ports of a hub will collide (A hub is like tying the wires together)  The collision domain for a network built from hubs is all of the ports on the hub  Broadcast packets from machines on different ports of a ethernet switch will be seen on all ports of the switch  The broadcast domain for a network built from switches is all of the ports on the switch

8 How does a ethernet switch work?  When you try to connect to mail.cs.byu.edu, your ethernet card doesn’t know which ethernet address to put into the destination  So it sends an Address Resolution Protocol (ARP) packet to the broadcast ethernet address asking if anyone knows about mail.cs.byu.edu  Everyone else will ignore it, mail.cs.byu.edu should respond with a packet indicating what his ethernet address is  Your machine then puts this address into the destination field

9 Ethernet switches  An ethernet switch learns where certain ethernet addresses are by looking at source addresses  It starts by behaving like a hub, and forwards all packets out every port  When it sees a new source ethernet address on a port, it adds that address to a cache of known addresses  When this ethernet address appears in the destination address of a packet, the switch sends it only to the port where this address was seen as a source address

10 Broadcast Addresses  When you send a packet to the broadcast IP address, the broadcast ethernet address is placed in the destination address for the packet.  Switches forward packets that are sent to the broadcast ethernet address to all of their ports.  Routers ignore these packets, and only forward packets that are sent directly to their address  That is why you have to configure a gateway

11 Where do I send packets?  Check to see if the destination IP address is in your broadcast domain  Look at the network mask and see if you both resolve to the same network  If the destination is not in the same network, send it to the gateway  If the destination is in the same network, then ARP to find the ethernet address

12 ARP Tables  You can use /sbin/arp to see current arp table  $ /sbin/arp -a  cs-private-2.cs.byu.edu (192.168.2.1) at 00:E0:B1:62:C8:2C [ether] on eth0  You can look at your network mask with ifconfig  $ /sbin/ifconfig  eth0 Link encap:Ethernet HWaddr 00:08:74:30:AD:2F  inet addr:192.168.2.210 Bcast:192.168.2.255 Mask:255.255.255.0  inet6 addr: fe80::208:74ff:fe30:ad2f/64 Scope:Link  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1  RX packets:35618047 errors:0 dropped:0 overruns:0 frame:0  TX packets:34395541 errors:0 dropped:0 overruns:0 carrier:0  collisions:0 txqueuelen:100  RX bytes:1641338780 (1.5 GiB) TX bytes:2883262518 (2.6 GiB)

13 Example (router R2) Network MaskNetwork NumberNext Hop 255.255.255.0128.187.1R3 (128.187.4.1) 255.255.255.0128.187.2R1 (128.187.3.1) 255.255.255.255128.187.4.1 (R3)Interface 0 0.0.0.0 R1 (128.187.3.1) 255.255.255.255128.187.3.1 (R1)Interface 1 Dst=128.187.2.3 Dst=128.187.4.8 Dst=128.187.1.5

14 Routers? Hubs? Switches H1 H2H3 H4 H5H6 H7 H8H9 H10 H11H12 Hub 128.187.171.X 128.187.172.X 128.187.173.X 128.187.174.X 171 172 173 174 Packet from H1 to H2 Packet from H1 to H10 Packet from H4 to broadcast Seen 171,172,173,174

15 Routers? Hubs? Switches/Bridges H1 H2H3 H4 H5H6 H7 H8H9 H10 H11H12 Switch 128.187.171.X 128.187.172.X 128.187.173.X 128.187.174.X 171 172 173 174 Packet from H1 to H2 Packet from H1 to H10 Packet from H4 to broadcast Seen 171 Seen 171,174 Seen 171,172,173,174 Learn from source Ethernet addresses (layer 2)

16 Routers? Hubs? Switches H1 H2H3 H4 H5H6 H7 H8H9 H10 H11H12 Router 128.187.171.X 128.187.172.X 128.187.173.X 128.187.174.X 171 172 173 174 Packet from H1 to H2 Packet from H1 to H10 Packet from H4 to broadcast Seen 171 Seen 171,174 Seen 172 Use routing protocols and static configurations (layer 3)

17 Routers? Hubs? Switches H1 H2H3 H4 H5H6 H7 H8H9 H10 H11H12 Hub D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 171 172 173 174 H10= IP 128.187.174.10, Ethernet 44.fe.34.56.32.d5 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29

18 Routers? Hubs? Switches H1 H2H3 H4 H5H6 H7 H8H9 H10 H11H12 Switch D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 171 172 173 174 H10= IP 128.187.174.10, Ethernet 44.fe.34.56.32.d5 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 Normally uses only Ethernet addresses

19 Routers? Hubs? Switches H1 H2H3 H4 H5H6 H7 H8H9 H10 H11H12 Router D 128.187.174.10 D 56.47.ef.c6.34.78 S 128.187.171.2 S fe.34.56.32.d5.29 171 172 173 174 H10= IP 128.187.174.10, Ethernet 44.fe.34.56.32.d5 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S 55.7e.c6.11.78.99 56.47.ef.c6.34.78 55.7e.c6.11.78.99 Default Gateway

20 Our Department  We have ethernet switches throughout the labs  We have a router on the edge between us and the university  Broadcast packets will be seen in most of the labs  They wont go outside of the department  Some administrators may block UDP broadcasts, because they fill every network link in the broadcast domain  If you have a really bad bug in your program, you may bring down the network

21 Perl Code  Sender  use IO::Socket::INET;  $MySocket=new IO::Socket::INET->new( PeerPort=>1234,Proto=>'udp',PeerAddr=>'localhost');  $msg="This is the message";  $MySocket->send($msg);  Receiver  $MySocket=new IO::Socket::INET->new( LocalPort=>1234, Proto=>'udp')  $MySocket->recv($text,128);  print "\nReceived message '", $text,"'\n";

22 # Client Program use IO::Socket::INET; print ">> Client Program <<"; # Create a new socket $MySocket=new IO::Socket::INET->new(PeerPort=>1234,Proto=>'udp',Broadcast=>1, PeerAddr=>inet_ntoa(INADDR_BROADCAST)); # Send messages $def_msg="Enter message to send to server : "; print "\n",$def_msg; while($msg= ) { chomp $msg; if($msg ne '') { print "\nSending message '",$msg,"'"; if($MySocket->send($msg)) { print "..... ","\n"; print $def_msg; } else { # Send an empty message to server and exit $MySocket->send(''); exit 1; } # Client Program use IO::Socket::INET; print ">> Client Program <<"; # Create a new socket $MySocket=new IO::Socket::INET->new(PeerPort=>1234,Proto=>'udp',Broadcast=>1, PeerAddr=>inet_ntoa(INADDR_BROADCAST)); # Send messages $def_msg="Enter message to send to server : "; print "\n",$def_msg; while($msg= ) { chomp $msg; if($msg ne '') { print "\nSending message '",$msg,"'"; if($MySocket->send($msg)) { print "..... ","\n"; print $def_msg; } else { # Send an empty message to server and exit $MySocket->send(''); exit 1; } # Server Program use IO::Socket::INET; print ">> Server Program <<\n"; # Create a new socket $MySocket=new IO::Socket::INET->new(LocalPort=>1234,Proto=>'udp'); # Keep receiving messages from client $def_msg="\nReceiving message from client.....\n"; while(1) { $MySocket->recv($text,128); if($text ne '') { print "\nReceived message '", $text,"'\n"; } # If client message is empty exit else { print "Cilent has exited!"; exit 1; } # Server Program use IO::Socket::INET; print ">> Server Program <<\n"; # Create a new socket $MySocket=new IO::Socket::INET->new(LocalPort=>1234,Proto=>'udp'); # Keep receiving messages from client $def_msg="\nReceiving message from client.....\n"; while(1) { $MySocket->recv($text,128); if($text ne '') { print "\nReceived message '", $text,"'\n"; } # If client message is empty exit else { print "Cilent has exited!"; exit 1; }

23 C Code  Create a dgram socket  sock = socket( AF_INET, SOCK_DGRAM, 0 )  Set the broadcast bit  setsockopt(sock, SOL_SOCKET, SO_BROADCAST,(char *) &one, sizeof(one));  Bind to the port you want to receive on  Recvfrom provides sender information in caller  recvfrom( sock, buf, sizeof buf,0, (struct sockaddr *) &caller,&caller_len)  Sendto parameter contains destination in socketname  sendto(socket, buff,sendflags,(struct sockaddr *)&socketname, sizeof socketname );  Can be broadcast address

24 Local URL Resolution Protocol  Peer-to-Peer web-cache  Bootstrapping & Peer Discovery  UDP broadcast  Content Location  UDP broadcast for content  Content Delivery  Direct Download from single peer

25


Download ppt "UDP. User Datagram Protocol (UDP)  Unreliable and unordered datagram service  Adds multiplexing  No flow control  Endpoints identified by ports "

Similar presentations


Ads by Google