0% found this document useful (0 votes)
14 views22 pages

UDP Client-Server Simulation in NS-3

The document discusses setting up a client-server network simulation using NS-3 and UDP. It describes creating nodes and network interfaces, installing applications and network stacks, and running the simulation. Example code for a basic UDP client-server program is also provided.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views22 pages

UDP Client-Server Simulation in NS-3

The document discusses setting up a client-server network simulation using NS-3 and UDP. It describes creating nodes and network interfaces, installing applications and network stacks, and running the simulation. Example code for a basic UDP client-server program is also provided.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 2

Client Server Network topology using NS-3

Shweta Waghmare
TIMSCDR
Topics

M2 : Client Server Network topology using NS-3


● Program to simulate UDP server client
● Program to simulate DHCP server and n clients
● Program to simulate FTP using TCP protocol
● Program to Create simple topology
○ [Link]
● Programs to different types of topologies
○ Bus([Link])
○ Mesh([Link])
○ Star([Link])
○ Hybrid([Link]) OR Wired-wireless n/w topology
○ Program for complex topologies
● Program for client server networks
○ Three-way handshake
○ DORA Cycle(discovery, offer,request, acknowledgement)
Steps to install ns-3

Steps for other OS : [Link]


Step 1: Install necessary packages (See the Updated Installation document)
Step 2: Download ns-allinone-3.32 zip file ([Link]
Step 3: Extract ns-allinone-3.32 from zip file
Step 4: Go to ns-allinone-3.32 via terminal and give following command:
./[Link] --enable-examples —-enable-tests
Step 5 (Optional): To test the installation, go to ns-3.32 and give
./[Link] -c core
Structure of a Program in ns-3

❑ Include necessary header files

❑ Use ns-3 namespace

❑ Enable Log for your program

❑ Begin the main function

❑ Enable Log for applications, if required

❑ Create nodes

❑ Create a channel and set it’s attributes

❑ Create NIC: this is done while assigning channels between nodes.


Structure of a Program in ns-3

❑ Install network stack on nodes (TCP/IP stack is called “Internet” stack)

❑ Select “network address” and “subnet mask”

❑ Create interfaces and assign IP address to each interface.

❑ Install applications in nodes

❑ Set application start and stop time

❑ Run the simulation

❑ Release resources (e.g., dynamically allocated memory)


The fundamental objects

Node: the motherboard of a computer with RAM, CPU, and, IO interfaces

Application: a packet generator and consumer which can run on a Node and
talk to a set of network stacks

NetDevice: a network card which can be plugged in an IO interface of a


Node

Channel: a physical connector between a set of NetDevice objects


A First ns-3 Script

ns-3 in a directory called repos under your home directory.


UDP

UDP: the Caché User Datagram Protocol (UDP) binding.


Provides two-way message transfer between a server and a
large number of clients.
UDP is not connection-based; each data packet transmission is
an independent event.
Provides fast and lightweight data transmission for local
packet broadcasts and remote multicasting.
Working with UDP DatagramSockets in Java

● Java provides DatagramSocket to communicate over UDP instead of TCP.

● It is also built on top of IP.

● DatagramSockets can be used to both send and receive packets over the
Internet.
Examples

● UDP is preferred over TCP is the live coverage of TV channels. In this aspect, we want to
transmit as many frames to live audience as possible not worrying about the loss of one or
two frames. TCP being a reliable protocol add its own overhead while transmission.
● Another example where UDP is preferred is online multiplayer gaming. In games like
counter-strike or call of duty, it is not necessary to relay all the information but the most
important ones.
● It should also be noted that most of the applications in real life uses careful blend of both
UDP and TCP; transmitting the critical data over TCP and rest of the data via UDP.
Creation of DatagramSocket:-

First, a datagramSocket object is created to carry the packet to the destination and to receive it
whenever the server sends any data. To create a datagramSocket following constructors can be used:

protected DatagramSocket DatagramSocket():


Syntax: public DatagramSocket()throws SocketException
Creates a datagramSocket and binds it to any available port on local machine. If this constructor is used,
the OS would assign any port to this socket.

protected DatagramSocket DatagramSocket(int port):-


Syntax: public DatagramSocket(int port)throws SocketException
Parameters: port - port to which socket is to be bound
Throws:SocketException - If the socket cannot be bound to the specific local port. Creates a
DatagramSocket and binds to the specified port on the local machine.
protected DatagramSocket DatagramSocket(int port, InetAddress inetaddress):-
Syntax: public DatagramSocket(int port, InetAddress inetaddress) throws SocketException
Parameters:
port - port to which socket is to be bound.
inetaddress - local address to which socket is to be bound.
Throws:
SocketException - If the socket cannot be bound to the specific local port. It creates a DatagramSocket
and binds it to specified port and ip-address.
Creation of DatagramPacket:
In this step, the packet for sending/receiving data via a datagramSocket is created.
Constructor to send data:
DatagramPacket(byte buf[], int length, InetAddress inetaddress, int port):-
Syntax: public DatagramPacket(byte[] buf, int offset, int length, SocketAddress address)
Parameters:
buf - the packet data.
offset - the packet data offset.
length - the packet data length.
address - the destination socket address.
Constructs a DatagramPacket for sending data at specified address and specified port.
Constructor to receive the data:
DatagramPacket(byte buf[], int length):-
Syntax: public DatagramPacket(byte buf[],int length)
Parameters:
buf - the packet data.
length - the packet data length.
Constructs a DatagramPacket for receiving the data of length length in the byte array buf.
Invoke a send() or receive() call on socket object
Syntax: void send(DatagramPacket packet) throws SocketException
Parameters:
packet - Datagrampacket to send.
Throws:
SocketException - If there is an error in binding.
IllegalArgumentException - if address is not supported by the socket.
Syntax: void receive(DatagramPacket packet)throws SocketException
Parameters:
packet - Datagrampacket to receive from this socket.
Throws:
SocketException - If there is an error in binding.
IllegalArgumentException - if address is not supported by the socket.
● Program to simulate UDP server client
Ns3 Code

[Link]

Folder path ⇒ Workspace ⇒ ns3allinone ⇒ ns3.32 ⇒ src ⇒ internet-apps


⇒ examples ⇒ udp-client-server ⇒ [Link]

Common questions

Powered by AI

UDP is favored over TCP in live broadcasting and online gaming as it provides lightweight, fast data transmission allowing multiple clients to receive data without concern for a few lost packets, thus ensuring lower latency and faster delivery. TCP's reliability introduces overhead which can delay packet transmission, unnecessary for scenarios where speed is more critical than accuracy .

Key components in ns-3 to set up a client-server network topology include Nodes, Applications, NetDevices, and Channels. Nodes act like computers with CPUs and RAM, where applications (like servers or clients) run and interface with the network stack. NetDevices function as network interfaces, connecting nodes to channels, which act as the physical media facilitating communication. For instance, in a UDP client-server simulation, a server application generates messages and a client application receives them via a channel with NetDevices plugged into participating nodes .

In ns-3, network protocols are handled by installing a 'network stack' on the nodes, commonly referred to as the 'Internet' stack encompassing TCP/IP. Nodes are assigned network addresses and subnet masks to identify interfaces, after which applications are installed, specifying start and stop times relative to the simulation .

ns-3 provides detailed, scalable simulation for network research, supporting complex topologies and protocols like TCP/UDP/FTP. Its open-source nature and detailed logging make it highly flexible and insightful for network research. However, its steep learning curve and reliance on programming knowledge can be drawbacks for beginners, potentially constraining its accessibility compared to more GUI-driven simulators .

In ns-3, bus topology connects all nodes to a single communication line, mesh topology provides multiple interconnections between nodes ensuring redundancy, and star topology connects all nodes to a central hub. Each topology serves specific network design needs: scalability and simplicity for bus, robustness for mesh, and centralization for star .

Setting up hybrid network topologies in ns-3 involves integrating both wired and wireless elements, which can be complex due to differing configurations like signal interference, range limits, and protocol divergence. Challenges include coordinating synchronization between disparate networks and ensuring seamless communication despite variations in speed and latency intrinsic to each medium .

The DORA cycle in DHCP entails Discovery, Offer, Request, and Acknowledgement phases. During simulations in ns-3, a client sends a discovery broadcast to find DHCP servers, upon which a server responds with an offer containing IP configuration. The client requests these settings, and the server acknowledges, finalizing the lease agreement, automating IP address allocation on networks .

ns-3 facilitates testing through its ./test.py script, which runs core tests ensuring the installation and functionality of components are correct. This plays a critical role in validating simulation setups, as errors or misconfigurations can affect results. By running example scripts or enabling logs, users can troubleshoot and verify each element's behavior, ensuring reliable, accurate outcomes .

The three-way handshake in TCP simulations within ns-3 establishes a reliable connection through a sequence of SYN, SYN-ACK, and ACK messages between client and server. This process confirms both parties are synchronized, agreeing on initial sequence numbers, thus ensuring data integrity and reliable communication .

In Java, DatagramSockets enable communication over UDP by creating a socket bound to a local port, allowing data sending and receiving. For sending, a DatagramPacket is constructed with the data, destination address, and port, and then dispatched via the socket. Similarly, data is received into a DatagramPacket by specifying a buffer and reading from the socket, handling network communication without the overhead of TCP connections .

You might also like