9 telecommunication network software design
Download
Report
Transcript 9 telecommunication network software design
TASHKENT UNIVERSITY OF INFORMATION
TECHNOLOGIES
THE DEPARTMENT OF
DATA COMMUNICATION NETWORKS AND SYSTEMS
Lecture №9
Broadcast network software design
Lector: Aliyev H.U.
Introduction
•
•
•
•
•
In 1994, you may recall, the Rolling Stones transmitted a live concert over the
Internet for free. This was made possible due to multicasting, the same technology
that makes it possible to watch astronauts in space, to hold meetings over the
Internet, and more.
Unicasting would be inappropriate for these applications, as for events attended by
thousands of clients, the load on the server and the network would be excessive.
Multicasting means that the server only has to send messages just once, and they
will be distributed to a whole group of clients. Only systems that are members of
the group participate in the network transfers.
In the last few lessons, we discussed socket programming using connection-oriented
and connectionless protocols.
Multicasts can be used for group communications over the Internet, where every
node participating in the multicast has to join the group set up for the purpose.
Routers can forward messages to all interested nodes.
In this lesson, we will design network applications using broadcasting features. With
one application it will be possible to chat with multiple systems, where everyone is
both a sender and a receiver.
The Mean of Unicasts, Broadcasts,
and Multicasts
•
•
•
•
•
•
The terms unicast and multicast make the most sense when also considering the more
common term broadcast. Where broadcast means to send to everyone, for example,
radio, television, satellite, and so on, the other two terms cover a more restrained set of
receivers.
Unicast is the opposite of broadcast and means that a transmission is sent to only one
user, hence "uni-" (one) combined with "-cast" (to send). Multicast is therefore the
transmission to "multi-", that is, more than one but not everyone.
In the radio or television world, a broadcast does not truly go to everyone. In most
broadcasts, each station has a "footprint" in which its signal can be received. This
footprint is considered the entire network, and so every user has the potential to receive
this signal.
Television uses a combination of satellites, relays, cable plants, and so on to create a
broadcast network. Traditional broadcast networks are designed to efficiently deliver a
signal to everyone.
While they can also technically deliver a unicast transmission by sending a broadcast
signal but expecting only one user to receive and process the data--the signal itself is not
truly unicast. Multicast in these networks is accomplished the same way: a broadcast
signal is sent to everyone, but only a subset of receivers is expected to receive and
process the signal.
Unicasts, Broadcasts, and
Multicasts
•
•
•
•
•
•
The Internet Protocol supports three kinds of IP addresses:
Unicast- unicast network packets are sent to a single destination
Broadcast- broadcast datagrams are sent to all nodes in a subnetwork
Multicast- multicast datagrams are sent to all nodes, possibly on different subnets,
that belong to a group
The TCP protocol provides a connection-oriented communication where two
systems communicate with each other; with this protocol, we can only send
unicast messages. If multiple clients connect to a single server, all clients maintain
a separate connection on the server. The server needs resources for each of these
simultaneous connections, and must communicate individually with every client.
Don't forget that the UDP protocol can also be used to send unicast messages,
where, unlike TCP, connectionless communication is used, making it is faster than
TCP, although without TCP's reliability.
Sending unicast messages with TCP is covered in .
Broadcasting
•
•
•
Broadcast addresses are identified by IP addresses where all bits of the host are set to 1. For
instance, to send messages to all hosts in a subnet with a mask of 255.255.255.0 in a network
with the address 192.168.0, the broadcast address would be 192.168.0.255. Any host with an
IP address beginning 192.168.0 will then receive the broadcast messages. Broadcasts are
always performed with connectionless communication using the UDP protocol. The server
sends the data regardless of whether any client is listening. Performance reasons mean it
wouldn't be possible to set up a separate connection to every client. Connection-less
communication means that the server does not have to allocate resources for every single
client-no matter how many clients are listening, the same server resources will be consumed.
Of course, there are disadvantages to the connection-less mechanism. For one, there is no
guarantee that the data is received by anyone. If we wanted to add reliability, we would have
to add a handshaking mechanism of our own at a higher level than UDP.
Broadcasts introduce a performance issue for every system on the destination subnet,
because each system on that subnet has to check whether the receiving packet is of interest.
A broadcast can be of interest to any system in the network, and it passes all the way up to
the transport layer in the protocol stack of each system before its relevancy can be
determined. There is another issue with broadcasts: they don't cross subnets. Routers don't
let broadcasts cross them-we would soon reach network saturation if routers forwarded
broadcasts, so this is desired behavior. Thus, broadcasts can be only used inside a particular
subnet.
Broadcast networking
IP broadcasting
•
•
•
•
IP broadcasting is used by network devices to send a single packet of information
that can be accessible by every device on the network. Because TCP
communication requires that two devices have a dedicated connection, it is not
possible to send broadcast messages in a strictly TCP environment. Instead, UDP
packets must be used because that protocol has the capability of sending
messages without a specific connection being defined.
Broadcast messages contain a special destination IP address. The IP address format
allows for two types of broadcast message addresses: local broadcasts and global
broadcasts.
Network programmers use the local broadcast address to send a broadcast
message destined for all devices on a particular subnet. The idea is to localize a
broadcast message so that other networks are not affected by the broadcast.
As discussed, IP Programming Basics, an IP address is divided into two parts, a
network address and a host address. The standard network address part makes up
the first part of the local broadcast address, and all 1s are used for the host part of
the address (which is the decimal value 255 in the address octet). This is
demonstrated in Figure 10.1. Thus, for the class B network 192.168.0.0, using a
subnet mask of 255.255.0.0, the local broadcast address would be
192.168.255.255.
The IP network and host address
parts of a local broadcast address
IP broadcasting
•
•
•
Similarly, if the subnet is further divided using a subnet mask of 255.255.255.0,
each subnet would have its own local broadcast address. The subnet 192.168.1.0
would have a broadcast address of 192.168.1.255, and so on up to the subnet
192.168.254.0, which would have the broadcast address 192.168.254.255.
The global broadcast was originally intended to allow a device to send a packet to
all devices on an internetwork. It uses all 1s in the IP address, creating an address
of 255.255.255.255. This special broadcast address indicates that the destination
of the packet is all devices on all networks accessible from the device sending the
message.
The vast size and burgeoning popularity of the Internet, of course, meant that this
behavior had to be modified. Otherwise, it would be easy for a rogue programmer
to create a stream of global broadcasts that would propagate to all networks on
the Internet, effectively clogging the worldwide system with bogus broadcasts and
stopping normal traffic. To eliminate this possibility, routers do not send global IP
broadcasts to other networks unless specifically configured to do so (which is
practically never). Instead, they silently ignore global broadcasts, effectively
turning them into local broadcasts that are seen only on the local network over
which they were sent.
Implementing Broadcasting with
.NET
• The .NET network library contains elements for sending and
receiving broadcast packets. This section describes the
techniques necessary to handle broadcast pack.
• Sending Broadcast Packets
• By default, sockets are not allowed to send broadcast
messages. You can test this by running the simple program
• shown in Listing 9.1.
• Listing 9.1: The BadBroadcast.cs programs in your network
application programs.
The Broadcst.cs program
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class Broadcst
{ public static void Main()
{ Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
IPEndPoint iep1 = new IPEndPoint(IPAddress.Broadcast, 9050);
IPEndPoint iep2 = new IPEndPoint(IPAddress.Parse("192.168.1.255"), 9050);
string hostname = Dns.GetHostName();
byte[] data = Encoding.ASCII.GetBytes(hostname);
sock.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
sock.SendTo(data, iep1);
sock.SendTo(data, iep2);
sock.Close();
}}
The Broadcst.cs program
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class Broadcst
{
public static void Main()
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
IPEndPoint iep1 = new IPEndPoint(IPAddress.Broadcast, 9050);
IPEndPoint iep2 = new IPEndPoint(IPAddress.Parse("192.168.1.255"), 9050);
string hostname = Dns.GetHostName();
byte[] data = Encoding.ASCII.GetBytes(hostname);
sock.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
sock.SendTo(data, iep1);
sock.SendTo(data, iep2);
sock.Close();
}
}
Receiving Broadcast Packets
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class RecvBroadcst
{ public static void Main()
{ Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050);
sock.Bind(iep);
EndPoint ep = (EndPoint)iep;
Console.WriteLine("Ready to receive ");
byte[] data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref ep);
string stringData = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine("received: {0} from: {1}",
stringData, ep.ToString());
data = new byte[1024];
recv = sock.ReceiveFrom(data, ref ep);
stringData = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine("received: {0} from: {1}",
stringData, ep.ToString());
Q&A?