n pm final record
TRANSCRIPT
-
7/28/2019 n Pm Final Record
1/69
1(a). CLIENT SERVER CHAT USING TCP
PROGRAM FOR SERVER:
#include
#include
#include
#include
#include
main()
{
int sid,cid,i=0,j=0,m;
char c,mesg[100],mesg2[100];
sid=socket(AF_INET,SOCK_STREAM,0);
printf("the socket id is %d:",sid);
if(sid
-
7/28/2019 n Pm Final Record
2/69
PROGRAM FOR CLIENT:
#include
#include
#include#include
main()
{
int sid,cid,aid,n,i=0,j=0,m;
char c,mesg[100],mesg2[100];
sid=socket(AF_INET,SOCK_STREAM,0);
printf("the socket id is%d",sid);
if(sid
-
7/28/2019 n Pm Final Record
3/69
}
while(c!='\n');
mesg2[j]='\0';
send(aid,mesg2,sizeof(mesg2),0);
printf("\n");
j=0;
for(i=0;i
-
7/28/2019 n Pm Final Record
4/69
OUTPUT:
SERVER
CLIENT
-
7/28/2019 n Pm Final Record
5/69
-
7/28/2019 n Pm Final Record
6/69
-
7/28/2019 n Pm Final Record
7/69
PROGRAM FOR CLIENT
#include"stdio.h"
#include"sys/types.h"
#include"netinet/in.h"
#include"string.h"
#include"sys/socket.h"
#include"stdlib.h"
#include"unistd.h"
int main()
{
int sd,i,con,port;
char content[30];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocket Problem");
return 0;
}
bzero((char*)&cli,sizeof(cli));
cli.sin_family=AF_INET;
printf("\nENTER PORT NO:");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
if(con==-1)
{
printf("\nConnection Error");
return 0;
}
i=recv(sd,content,30,0);
printf("\nReceived from server %s\n",content);
close(sd);
return 0;
}
-
7/28/2019 n Pm Final Record
8/69
OUTPUT:
SERVER
CLIENT
1(c) .ECHO CLIENT SERVER USING TCP
-
7/28/2019 n Pm Final Record
9/69
PROGRAM FOR SERVER
#include"stdio.h"
#include"sys/types.h"
#include"netinet/in.h"#include"string.h"
#include"sys/socket.h"gny
#include"stdlib.h"
#include"unistd.h"
#include"time.h"
main()
{
int sd,i,len,bi,nsd,port;
char content[30],buff[30],last_received[30];
struct sockaddr_in ser,cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocket Problem");
return 0;
}
printf("\n Socket Created\n");
bzero((char*)&cli,sizeof(ser));
printf("\nENTER PORT NO:");
scanf("%d",&port);
printf("\n Port Address is %d\n",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser));
if(bi==-1)
{
printf("\nBind Error,PortBusy,Plz change port in client and server");
return 0;
}
i=sizeof(cli);
listen(sd,5);
nsd=accept(sd,((struct sockaddr *)&cli),&i);
if(nsd==-1)
{
printf("\nCheck the description parameter\n");
return 0;
}
-
7/28/2019 n Pm Final Record
10/69
printf("\nConnection Accepted");
i=recv(nsd,content,30,0);
send(nsd,content,30,0);
while(strcmp(content,"exit")!=0)
{
printf("\nReceived from client and echoeing it...");
i=recv(nsd,content,30,0);
send(nsd,content,30,0);
}
printf("Bye.......");
send(nsd,"EOF",4,0);
close(sd);
close(nsd);
return 0;
}
PROGRAM FOR CLIENT
#include"stdio.h"
#include"sys/types.h"
-
7/28/2019 n Pm Final Record
11/69
#include"netinet/in.h"
#include"string.h"
#include"sys/socket.h"
#include"stdlib.h"
#include"unistd.h"
int main()
{
int sd,i,con,port;
char content[30];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocket Problem");
return 0;
}bzero((char*)&cli,sizeof(cli));
cli.sin_family=AF_INET;
printf("\nENTER PORT NO:");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
if(fork())
{
printf("\nEnter the data to be send:");
scanf("%s",content);
while(strcmp(content,"exit")!=0){
send(sd,content,30,0);
scanf("%s",content);
}
send(sd,"exit",5,0);
}else
{
i=recv(sd,content,30,0);
while(strcmp(content,"exit")!=0)
{
printf("Data Echoed From server:%s\n",content);
i=recv(sd,content,30,0);
}send(sd,"exit",5,0);
}close(sd);
return 0;
}
OUTPUT:
SERVER
-
7/28/2019 n Pm Final Record
12/69
CLIENT
2.SLIDING WINDOW PROTOCOLS
PROGRAM FOR SERVER
-
7/28/2019 n Pm Final Record
13/69
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main()
{
int c,sd,f[15],i,j,ack,n,len,bi,nsd,port,wl,wr;
char content[30];
struct sockaddr_in ser,cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocketProblem");
return 0;
}
printf("\nSocket Created");
bzero((char *)&cli,sizeof(ser));
printf("\nEnter The PortNo:");
scanf("%d",&port);
printf("\nPort Address is %d\n",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser));
if(bi==-1)
{
printf("\nBind Error,PortBusy,Plz Change Port in client&server");
return 0;
}
i=sizeof(cli);
listen(sd,5);
nsd=accept(sd,((struct sockaddr *)&cli),&i);
if(nsd==-1)
{
printf("\nCheck the Description Parameter");
return 0;
}
printf("\nConnection Accepted");
printf("\nEnter n:");
-
7/28/2019 n Pm Final Record
14/69
scanf("%d",&n);
wl=0;
wr=n-2;
i=0;c=1;
len=1;
ack=0;
for(j=0;j
-
7/28/2019 n Pm Final Record
15/69
#include
#include
#include
#include
int main()
{
int c,fd,p,n,wl,wr,sd,con,port,i,f[15];
char content[30];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocketProblem");
return 0;
}
bzero((char *)&cli,sizeof(cli));
cli.sin_family=AF_INET;
printf("\nEnter The PortNo:");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr *)&cli,sizeof(cli));
if(con==-1)
{
printf("\nConnection Error");
return 0;
}
printf("\nEnter the number of frames to be transmitted:");
scanf("%d",&p);
printf("\nEnter n:");
scanf("%d",&n);
printf("Size of Windows:%d",n-1);
printf("\nThe Frames are numbered 0-%d",n-2);
wl=0;
wr=n-2;
printf("\nFrames to be sent");
for(i=0;i
-
7/28/2019 n Pm Final Record
16/69
{
printf("\nFrames in Window");
for(i=wl;i
-
7/28/2019 n Pm Final Record
17/69
CLIENT
3.DOMAIN NAME SYSTEM
PROGRAM
-
7/28/2019 n Pm Final Record
18/69
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[1])
{
struct hostent *hen;
if(argc!=2)
{
fprintf(stderr,"Enter the hostname \n");
exit(1);
}
hen=gethostbyname(argv[1]);
if(hen==NULL)
{
fprintf(stderr,"Host not found \n");
}
printf("Hostname is %s \n",hen->h_name);
printf("IP address is %s \n",inet_ntoa(*((struct in_addr *)hen->h_addr)));
}
-
7/28/2019 n Pm Final Record
19/69
OUTPUT:
PACKET CAPTURING USING RAW SOCKET
PROGRAM:
-
7/28/2019 n Pm Final Record
20/69
#include
#include
#include
#include
#include
#include
#define PCKT_LEN 8192
struct ipheader
{
unsigned char iph_ihl:5,iph_ver:4;
unsigned char iph_tos;
unsigned short int iph_len;
unsigned short int iph_ident;
unsigned char iph_flag;
unsigned short int iph_offset;
unsigned char iph_ttl;
unsigned char iph_protocol;
unsigned short int iph_chksum;
unsigned int iph_sourceip;
unsigned int iph_destip;
};
struct udpheader{
unsigned short int udph_srcport;
unsigned short int udph_destport;
unsigned short int udph_len;
unsigned short int udph_chksum;
};
unsigned short csum(unsigned short *buf,int nwords)
{
unsigned long sum;
for(sum=0;nwords>0;nwords--)
sum +=*buf++;
sum=(sum>>16)+(sum&0xffff);
sum+=(sum>>16);
return(unsigned short)(~sum);
}
int main(int argc,char *argv[])
{
int sd;
char buffer[PCKT_LEN];
struct ipheader *ip=(struct ipheader *)buffer;
struct udpheader *udp=(struct udpheader *)(buffer + sizeof(struct ipheader));
struct sockaddr_in sin,din;
int one=1;
const int *val=&one;
memset(buffer,0,PCKT_LEN);
-
7/28/2019 n Pm Final Record
21/69
sd=socket(PF_INET,SOCK_RAW,IPPROTO_UDP);
if(sd>0)
{
perror("\nSocket()error");
}
else
printf("socket() - Using SOCK_RAW socket and UDP protocol is OK.\n");
sin.sin_family = AF_INET;
din.sin_family = AF_INET;
sin.sin_port = htons(atoi(argv[2]));
din.sin_port = htons(atoi(argv[4]));
sin.sin_addr.s_addr = inet_addr(argv[1]);
din.sin_addr.s_addr = inet_addr(argv[3]);
ip->iph_ihl = 5;
ip->iph_ver = 4;
ip->iph_tos = 16;
ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader);
ip->iph_ident = htons(54321);
ip->iph_ttl = 64; // hops
ip->iph_protocol = 17; // UDP
ip->iph_sourceip = inet_addr(argv[1]);//Source IP address
ip->iph_destip = inet_addr(argv[3]);// destination IP address
udp->udph_srcport = htons(atoi(argv[2]));//source port
udp->udph_destport = htons(atoi(argv[4]));//destination port
udp->udph_len = htons(sizeof(struct udpheader));
ip->iph_chksum = csum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof
(struct udpheader));
if(setsockopt(sd,IPPROTO_IP,IP_HDRINCL,val,sizeof(one))>0)
{
perror("setsockopt() error");
}
else
printf("setsockopt() is OK.\n");
printf("Using raw socket and UDP protocol\n");
printf("Using Source IP: %s port: %u, Target IP: %s port: %u.\n",argv[1],atoi(ar
gv[2]),argv[3],atoi(argv[4])); 28,1 60%
int count;
for(count = 1; count iph_len,0,(struct sockaddr *)&sin,sizeof(sin))>0)
{
perror("sendto() error");
}
else
{
printf("Count #%u - sendto() is OK.\n", count);
-
7/28/2019 n Pm Final Record
22/69
sleep(2);
}
}
close(sd);
return 0;
}
-
7/28/2019 n Pm Final Record
23/69
OUTPUT:
-
7/28/2019 n Pm Final Record
24/69
PROGRAM USING RPC
PROGRAM FOR SERVER#include#include#include#include#include#include
int add(int x,int y)
{return (x+y);}int main(int argc,char * argv[]){socklen_t len;int sfd,n;struct sockaddr_in servaddr,cliaddr;char a[6],b[6],c[6];sfd=socket(AF_INET,SOCK_DGRAM,0);bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;servaddr.sin_addr.s_addr=htonl(INADDR_ANY);servaddr.sin_port=htons(7890);bind(sfd,(struct sockaddr *)&servaddr,sizeof(servaddr));len=sizeof(servaddr);recvfrom(sfd,a,6,0,(struct sockaddr *)&servaddr,&len);recvfrom(sfd,b,6,0,(struct sockaddr *)&servaddr,&len);printf("FROM CLIENT:\n Given respective integers a and b:\n %s %s\n",a,b);sprintf(c,"%d",(add(atoi(a),atoi(b))));printf("SERVER:\n Sent the sum %s to client\n",c);sendto(sfd,c,sizeof(c),0,(struct sockaddr*)&servaddr,len);
return 0;getch();}
-
7/28/2019 n Pm Final Record
25/69
PROGRAM FOR CLIENT#include#include#include#include#include#includeint main(int argc,char *argv[]){socklen_t len;int sfd,n;struct sockaddr_in servaddr;char a[6],b[6],c[6];sfd=socket(AF_INET,SOCK_DGRAM,0);bzero(&servaddr,sizeof(servaddr));servaddr.sin_family=AF_INET;servaddr.sin_port=htons(7890);servaddr.sin_addr.s_addr=inet_addr(argv[1]);connect(sfd,(struct sockaddr*)&servaddr,sizeof(servaddr));len=sizeof(servaddr);printf("CLIENT:\n Enter the two numbers:");
scanf("%s%s",a,b);sendto(sfd,a,sizeof(a),0,(struct sockaddr*)&servaddr,len);sendto(sfd,b,sizeof(b),0,(struct sockaddr*)&servaddr,len);recvfrom(sfd,c,6,0,(struct sockaddr*)&servaddr,&len);printf("FROM SERVER: \n the sum of two number is %s\n",c);return 0;}
-
7/28/2019 n Pm Final Record
26/69
OUTPUT :CLIENT
SERVER
-
7/28/2019 n Pm Final Record
27/69
PERFORMANCE COMPARISION OF ROUTING PROTOCOLS USING OPNET
PROGRAM
#include
int a[20][20];
main()
{
int n,i,j,k,cost[20][20];printf("\n Enter the number of vertices");
scanf("%d",&n);
printf("\n Enter the distance table");
for(i=1;i
-
7/28/2019 n Pm Final Record
28/69
{
printf("\n H%d\t\t%d\t\tH%d\n",i,a[i][j],j);
}
}
}
OUTPUT:
-
7/28/2019 n Pm Final Record
29/69
PROGRAM BASED ON MAC PROTOCOL
PROGRAM
#include#includestatic char *logical[]={"192.168.3.9","192.148.3.115"};static char *physical[]={"00.13.21.B4.4A.68","00.0F.FE.A4.91.56"};int protocol;int k,s,i;char padd[20],ladd[15];int x,j;
main(){printf(" 1.RARP\n");printf(" 2.ARP\n");printf(" Enter ur choice\n");scanf("%d",&protocol);switch(protocol){case 1:printf(" U are rarp");printf("\n Enter ur physical address");
scanf("%s",&padd);for(i=0;i
-
7/28/2019 n Pm Final Record
30/69
}}break;case 2:printf("\n u are in arp");
printf("\n\n Enter ur logical address");scanf("%s",&ladd);for(j=0;j
-
7/28/2019 n Pm Final Record
31/69
OUTPUT
-
7/28/2019 n Pm Final Record
32/69
STUDY OF UDP PERFORMANCE
Introduction
Most network games use the User Datagram Protocol (UDP) as the underlying transport
protocol. The Transport Control Protocol (TCP), which is what most Internet traffic relies on, is
a reliable connection-oriented protocol that allows datastreams coming from a machineconnected to the Internet to be received without error by any other machine on the Internet. UDP
however, is an unreliable connectionless protocol that does not guarantee accurate or
unduplicated delivery of data.
Why do games use UDP?
TCP has proved too complex and too slow to sustain real-time game-play. UDP allowsgaming application programs to send messages to other programs with the minimum of protocol
mechanism. Games do not rely upon ordered reliable delivery of data streams.What is moreimportant to gaming applications is the prompt delivery of data
Fields
The source and destination ports identify the end points within the source and destinationmachines.
-
7/28/2019 n Pm Final Record
33/69
The source port indicates the port of the sending process and unless otherwise stated it istheport to which a reply should be sent to. A zero is inserted into it if it is not used.
The UDP Length field shows the length of the datagram in octets. It includes the 8-byte headerand the data to be sent.
The UDP checksum field contains the UDP header, UDP data and the pseudo-header shown
above. The pseudo-header contains the 32-bit IP addresses of the source and destinationmachines, the UDP protocol number and the byte count for the UDP segment.
The pseudo-header helps to find undelivered packets or packets that arrive at the wrong address.
However the pseudo-header violates the protocol hierarchy because the IP addresses which areused in it belong to the IP layer and not to the UDP layer.
The effects of UDP
'network friendly applications deploying adaptive congestion control'.While TCP implements a form of flow control to stop the network from flooding there isno such concept in UDP. This is because UDP does not rely on acknowledgements to
signal successful delivery of data. Packets are simply transmitted one after another withcomplete disregard to event of the receiver being flooded. UDP affects TCP throughputin much the same way as digitized speech over IP does
All onesBy setting the broadcast address to all ones (255.255.255.255), all hosts on
the network receive the broadcast. NetworkBy setting the broadcast address to a specific network number in the network SubnetBy setting the broadcast address to a specific network number and a specificsubnet number, all hosts on the specified subnet receive the broadcast
Implementing IP Helper Addressing
IP helper addressing is a form of static addressing that uses directed broadcasts to
forward local and all-nets broadcasts to desired destinations within the internetwork. To
configure helper addressing, you must specify the ip helper-address command on every
interface on every router that receives a broadcast that needs to be forwarded.
Implementing UDP FloodingAlthough IP helper addressing is well-suited to nonredundant, nonparallel topologies that do not
require a mechanism for controlling broadcast loops, in view of these drawbacks, IP helper
addressing does not work well in this topology. To improve performance, network designersconsidered several other alternatives: Setting the broadcast address on the TIC servers to all ones (255.255.255.255)
Setting the broadcast address of the TIC servers to the major net broadcast
-
7/28/2019 n Pm Final Record
34/69
(164.53.0.0)Eliminating the subnets and letting the workstations use Address Resolution Protocol(ARP) to learn addresses
6-1Internetworking Case Studies
The bridge protocol command can specify either the dec keyword (for the DECspanning-tree protocol) or the ieee keyword (for the IEEE Ethernet protocol). All routersin the network must enable the same spanning tree protocol. The ip forward-protocolspanning tree command uses the database created by the bridge protocol command.Only one broadcast packet arrives at each segment, and UDP broadcasts can traverse thenetwork in both directions.IRDP is preferred over the Routing Information Protocol (RIP) anddefault gateways for thefollowing reasons: RIP takes longer to converge, typically from one to two minutes. Configuration of Router A as the default gateway on each Sun workstation on the trader
networks would allow those Sun workstations to send unicast traffic to Router A, but would not provide an alternative route if Router A becomes unavailable.
6-2 Implementing UDP FloodingThis topology is broadcast intensivebroadcasts sometimes consume 20 percent of theEthernet bandwidth. However, this is a favorable percentage when compared to the configuration
of IP helper addressing, which, in the same network, causes broadcasts to consume up to 50
percent of the Ethernet bandwidth.
If the hosts on the trader networks do not support IRDP, the Hot Standby Routing Protocol
(HSRP) can be used to select which router will handle unicast traffic. HSRP allows the standby
router to take over quickly if the primary router becomes unavailable.
6-3 Internetworking Case StudiesTurbo flooding increases the amount of processing that is done at interrupt level, which
increases the CPU load on the router. Turbo flooding may not be appropriate on routers that are
already under high CPU load or that must also perform other CPUintensive activities.
The following commands configure UDP flooding on Router A. Because this configurationdoes not specify a lower path cost than the default and because the configuration of Router B
specifies a lower cost than the default with regard to UDP flooding, Router A acts as a backup to
Router B. Because this configuration specifies an IRDP preference of 100 and because Router B
specifies a IRDP preference of 90 (ip irdppreference 90), Router A forwards unicast trafficfrom the trader networks, and Router B is the backup for unicast traffic forwarding.
-
7/28/2019 n Pm Final Record
35/69
The following commands configure UDP flooding on Router B. Because this configuration
specifies a lower path cost than the default (bridge-group 1 path-cost 50) and because the
configuration of Router A accepts the default, Router B forwards UDP packets. Because thisconfiguration specifies an IRDP preference of 90 (ip irdp preference 90) and because Router A
specifies a IRDP preference of 100, Router B acts as the backup for Router A for forwarding
unicast traffic from the trader networks.
!Router Bip forward-protocol spanning-treeip forward-protocol udp 111ip forward-protocol udp 3001ip forward-protocol udp 3002ip forward-protocol udp 3003ip forward-protocol udp 3004ip forward-protocol udp 3005ip forward-protocol udp 3006ip forward-protocol udp 5020
ip forward-protocol udp 5021
ip forward-protocol udp 5030ip forward-protocol udp 5002ip forward-protocol udp 1027ip forward-protocol udp 657!interface ethernet 0
ip address 200.200.200.62 255.255.255.0ip broadcast-address 200.200.200.255
no mop enabled!interface ethernet 1ip address 164.53.7.62 255.255.255.192ip broadcast-address 164.53.7.63ip irdpip irdp maxadvertinterval 60ip irdp minadvertinterval 45ip irdp holdtime 60
6-4Internetworking Case Studies
ip irdp preference 90bridge-group 1bridge-group 1 path-cost 50bridge-group 1 input-type-list 201no mop enabled
-
7/28/2019 n Pm Final Record
36/69
!interface ethernet 2ip address 164.53.8.62 255.255.255.192ip broadcast-address 164.53.8.63ip irdp
ip irdp maxadvertinterval 60ip irdp minadvertinterval 45ip irdp holdtime 60ip irdp preference 90bridge-group 1bridge-group 1 path-cost 50bridge-group 1 input-type-list 201no mop enabled!interface ethernet 3ip address 164.53.9.62 255.255.255.192
ip broadcast-address 164.53.9.63
ip irdpip irdp maxadvertinterval 60ip irdp minadvertinterval 45ip irdp holdtime 60ip irdp preference 90bridge-group 1
bridge-group 1 path-cost 50
bridge-group 1 input-type-list 201no mop enabled!interface ethernet 4ip address 164.53.10.62 255.255.255.192ip broadcast-address 164.53.10.63ip irdpip irdp maxadvertinterval 60ip irdp minadvertinterval 45ip irdp holdtime 60ip irdp preference 90
bridge-group 1bridge-group 1 path-cost 50bridge-group 1 input-type-list 201no mop enabled!router igrp 1network 164.53.0.0!
-
7/28/2019 n Pm Final Record
37/69
ip name-server 255.255.255.255snmp-server community public RWsnmp-server host 164.53.7.15 publicbridge 1 protocol decbridge 1 priority 255
access-list 201 deny 0xFFFF 0x0000
STUDY OF TCP PERFORMANCE
IntroductionThe Transmission Control Protocol(TCP) and the User Datagram Protocol (UDP) are
both IP transport-layer protocols. UDP is a lightweight protocol that allows applicationsto make direct use of the unreliable datagram service provided by the underlying IPservice. UDP is commonly used to support applications that use simple query/responsetransactions, or applications that support real-time communications. TCP provides areliable data-transfer service, and is used for both bulk data transfer and interactive data
applicationsOverview of TCP
TCP is the embodiment of reliable end-to-end transmission functionality in the
overall Internet architecture.
TCP has the following functional characteristics:Unicast protocol : TCP is based on a unicast network model, and supports data
exchange between precisely two parties. It does not support broadcast or multicast
-
7/28/2019 n Pm Final Record
38/69
network models.Connection state: Rather than impose a state within the network to support the
connection, TCP uses synchronized state between the two endpointsReliable: Reliability implies that the stream of octets passed to the TCP driver at
one end of the connection will be transmitted across the network so that the
stream is presented to the remote process as the same sequence of octets, in thesame order as that generated by the sender.. Full duplex: TCP is a full-duplex protocol; it allows both parties to send andreceive data within the context of the single TCP connection.
Streaming : Although TCP uses a packet structure for network transmission, TCPis a true streaming protocol, and application-level network operations are nottransparent.
Rate adaptation: TCP is also a rate-adaptive protocol, in that the rate of datatransfer is intended to adapt to the prevailing load conditions within the networkand adapt to the processing capacity of the receiver.
The TCP Protocal HeaderThe TCP header structure, uses a pair of 16-bit source and destinationPort addresses. The next field is a 32-bit sequence number, which identifies the sequence number
of the first data octet in this packet.
Maximum-receive-segment-size option: This option is used when the connectionis being opened. It is intended to inform the remote end of the maximum segmentsize, measured in octets, that the sender is willing to receive on the TCPconnection.
Window-scale option: This option is intended to address the issue of themaximum window size in the face of paths that exhibit a high-delay bandwidthproduct. This option allows the window size advertisement to be right-shifted bythe amount specified (
SACK-permitted option andSACKoption: This option alters theacknowledgment behavior of TCP. SACK is an acronym forselectiveacknowledgment. The SACK-permitted option is offered to the remote endduring TCP setup as an option to an opening SYN packet.
TCP Operation
The first phase of a TCP session is establishment of the connection. This requires a threewayhandshake, ensuring that both sides of the connection have an unambiguous understanding of the
sequence number space of the remote side for this session. The operation of the connection is asfollows:
The local system sends the remote end an initial sequence number to the remoteport, using a SYN packet.
The remote system responds with an ACK of the initial sequence number and theinitial sequence number of the remote end in a response SYN packet.
-
7/28/2019 n Pm Final Record
39/69
The local end responds with an ACK of this remote sequence number.The connection is opened.
Another critical aspect is that TCP is an adaptive flow-control protocol. TCP uses abasic flow-control algorithm of increasing the data-flow rate until the network signals that some
form of saturation level has been reached (normally indicated by data loss). When the senderreceives an indication of data loss, the TCP flow rate is reduced; when reliable transmission is
reestablished, the flow rate slowly increases again. If no reliable flow is reestablished, the flowrate backs further off to an initial probe of a single packet, and the entire adaptive flow-control
process starts again..
Interactive TCPInteractive protocols are typically directed at supporting single character interactions,
where each character is carried in a single packet, as is its echo
TCP Volume Transfer
The objective for this application is to maximize the efficiency of the data transfer,implying that TCP should endeavor to locate the point of dynamic equilibrium of maximum
network efficiency, where the sending data rate is maximized just prior to the onset of sustainedpacket loss. Further increasing the sending rate from such a point will run the risk of generating a
congestion condition within the network, with rapidly increasing packet-loss levels.
Window size (le or eq) Bandwidth (bytes/sec) (times) Round-trip time (sec)The 16-bit field within the TCP header can contain values up to 65,535, imposing an
upper limit on the available window size of 65,535 bytes. This imposes an upper limit on TCP
performance of some 64 KB per RTT, even when both end systems have arbitrarily large send
and receive buffers. This limit can be modified by the use of a window-scale option, described inRFC 1323, effectively increasing the size of the window to a 30-bit
TCP Slow StartThe starting value of the cwndwindow (the Initial Window, or IW) is set to that of the
Sender Maximum Segment Size (SMSS) value. This SMSS value is based on thereceiver's maximum segment size, obtained during the SYN handshake, the discoveredpath MTU (if used), the MTU of the sending interface, or, in the absence of otherinformation, 536 bytes.
TCP has to undertake many functions:The packet loss has to be detected by the sender.The missing data has to be retransmitted.The sending data rate should be adjusted to reduce the probability of further
packet loss.
-
7/28/2019 n Pm Final Record
40/69
Congestion AvoidanceCompared to Slow Start, congestion avoidance is a more tentative probing of the
network to discover the point of threshold of packet loss. Where Slow Startuses anexponential increase in the sending rate to find a first-level approximation of the lossthreshold, congestion avoidance uses a linear growth function.
When the value ofcwndis greater thanssthresh , the sender increments the value ofcwnd
by the value SMSS X SMSS/cwnd, in response to each received nonduplicate ACK ensuring thatthe congestion window opens by one segment within each RTT time interval.
The congestion window continues to open in this fashion until packet loss occurs. If the
packet loss is isolated to a single packet within a packet sequence, the resultant duplicate ACKs
will trigger the sender to halve the sending rate and continue a linear growth of the congestionwindow from this new point, as described above in fast recovery.
Assisting TCP Performance Network-RED and ECNAlthough TCP is an end-to-end protocol, it is possible for the network to assist
TCP in optimizing performance. One approach is to alter the queue behaviour of the network
through the use ofRandom Early Detection (RED). RED permits a network router to discard a
packet even when there is additional space in the queue.
Tuning TCP. Use a good TCP protocol stack : Many of the performance pathologies thatexist in the network today are not necessarily the byproduct of oversubscribednetworks and consequent congestion.
Implement a TCP Selective Acknowledgment(SACK) mechanism: SACK, combined with a selective repeat-transmission policy, can help
overcome the
limitation that traditional TCP experiences when a sender can learn only about asingle lost packet per RTT.
Implement larger buffers with TCP window-scalingoptions : The TCP flow algorithm attempts to work at a data rate that is the minimum of thedelaybandwidthproduct of the end-to-end network path and the available buffer space of the sender.
Support TCP ECN negotiation: ECN enables thehost to be explicitly informed of conditions relating to the onset of congestion without having toinfer such acondition from the reserve stream of ACK packets from the receiver.
Use a higher initial TCP slow-start rate than thecurrent 1 MSS: A size that seems feasible is an initial burst of 2 MSS segments. The assumptionis that there will be adequate queuing capability to manage this initial packet burst;
-
7/28/2019 n Pm Final Record
41/69
Conclusion
TCP is not a predictive protocol. It is an adaptive protocol that attempts to operate the network
at the point of greatest efficiency. Tuning TCP is not a case of making TCP pass more packets
into the network.Tuning TCP involves recognizing how TCP senses current network load conditions, workingthrough the inevitable compromise between making TCP highly sensitive to transient network
conditions, and making TCP resilient to what can be regarded as noise signals.
If the performance of end-to-end TCP is the perceived problem, the most effective answer isnot necessarily to add QoS service differentiation into the network.
TO DISPLAY LOCAL MACHINE INET ADDRESS
Coding:PROGRAM
import java.net.*;import java.io.*;
-
7/28/2019 n Pm Final Record
42/69
import java.util.*;class IP{public static void main(String args[])throws Exception{
InetAddress ia=InetAddress.getLocalHost();System.out.println("Host and Address"+ia);System.out.println("Host Name "+ia.getHostName());String S=ia.toString();System.out.println("IP address "+S.substring(S.indexOf("/")+1));}}
OUTPUT:
-
7/28/2019 n Pm Final Record
43/69
TO DISPAY IP ADDRESS OF DOMAIN NAME SERVER
-
7/28/2019 n Pm Final Record
44/69
CODING:Import java.net.*;Import java.io.*;Class dom{
Public static void main(String args[])throws Exception{System.out.println(enter the Host name);String s=new DatainputStraem(System.in).readLine();InetAddress i=InetAddress.getByName(s);System.out.println(IP Address:+i);}}
-
7/28/2019 n Pm Final Record
45/69
OUTPUT:
-
7/28/2019 n Pm Final Record
46/69
DISPLAY PORT NO
PROGRAM
import java.net.*;
import java.io.*;class por{public static void main(String args[]){for(int port=1024;port
-
7/28/2019 n Pm Final Record
47/69
OUTPUT:
-
7/28/2019 n Pm Final Record
48/69
TCL script for UDP communicationDescription:
This network consists of 6 nodes. The duplex links between nodes are configured with
the specific bandwidth and delay. Each link uses a DropTail queue. A "TCP" agent is
attached to n0 and a connection is established to a tcp "sink" agent attached to n4. As
default, the maximum size of a packet that a "TCP" agent can generate is 1KByte. A
"TCPSink" agent generates and sends ACK packets to the sender (tcp agent) and frees
the received packets. An "UDP" agent is attached to n1 and a connection is established
to udp "Null" agent attached to n5. "TCP" agent is attached with "FTP" application and
"UDP" agent is attached with "CBR" traffic for packet generation. The ftp is set to start
at 1.0 sec and stop at 10.5 sec. The cbr is set to start at 0.1 sec and stop at 10.0 sec.
File name: tcpred4.tcl
#-------Event scheduler object creation--------#
set ns [new Simulator]
#---Open the Trace files---#
set file1 [open Tcpred4.tr w]
$ns trace-all $file1
#--Open the NAM trace file----#
set file2 [open Tcpred4.nam w]
$ns namtrace-all $file2
-
7/28/2019 n Pm Final Record
49/69
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 20
#Setup a TCP connection
-
7/28/2019 n Pm Final Record
50/69
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"$ns at 1.0 "$ftp start"
$ns at 10.0 "$ftp stop"
$ns at 10.5 "$cbr stop"
#Define a 'finish' procedure
proc finish {} {
-
7/28/2019 n Pm Final Record
51/69
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam Tcpred4.nam &
exit 0
}
$ns at 12.0 "finish"
$ns run
#----------How to run----------#
$ns tcpred4.tcl
#--------Snapshot--------#
OUTPUT:
-
7/28/2019 n Pm Final Record
52/69
TCL script for TCP communication between two Clients and a Endserver
-
7/28/2019 n Pm Final Record
53/69
Description:
This network consists of 4 nodes (Client1, Client2, Router1, Rounter2 and
Endserver1). The duplex links between Client1 Client2 and Router1have 2 Mbps of
bandwidth and 100 ms of delay. The duplex link between Router1 and Router2 has 2Mbps
of bandwidth and 100 ms of delay. The duplex link between Router2 and Endserver1 has
200Kbps of bandwidth and 100 ms of delay. Each link uses a Drop Tail queue. A "TCP"
agent is attached to Client1, and Client2. "TCPSink" agent is attached to Endserver1. Both
the agents are connected. As default, the maximum size of a packet that a "TCP" agent can
generate is 1000bytes. A "TCPSink" agent generates and sends ACK packets to the
sender (tcp agent) and frees the received packets. The ftp is set to start at 0.5 sec and
stop at 5.5 sec.
File name: tcpred1.tcl
#-------Event scheduler object creation--------#
set ns [new Simulator]
#----------creating nam objects----------------#
set nf [open tcpred1.nam w]
$ns namtrace-all $nf
#open the trace file
set nt [open tcpred1.tr w]
$ns trace-all $nt
set proto rlm
$ns color 1 blue
$ns color 2 yellow
$ns color 3 red
#---------- creating client- router- end server node----------------#
set Client1 [$ns node]
set Client2 [$ns node]
set Router1 [$ns node]
set Router2 [$ns node]
set Endserver1 [$ns node]
-
7/28/2019 n Pm Final Record
54/69
#---creating duplex link---------#
$ns duplex-link $Client1 $Router1 2Mb 100ms DropTail
$ns duplex-link $Client2 $Router1 2Mb 100ms DropTail
$ns duplex-link $Router1 $Router2 2Mb 100ms DropTail
$ns duplex-link $Router2 $Endserver1 200Kb 100ms DropTail
#----------------creating orientation------------------#
$ns duplex-link-op $Client1 $Router1 orient down
$ns duplex-link-op $Client2 $Router1 orient right
$ns duplex-link-op $Router1 $Router2 orient right
$ns duplex-link-op $Router2 $Endserver1 orient down
#------------Labelling----------------#
$ns at 0.0 "$Client1 label Client1"
$ns at 0.0 "$Client2 label Client2"
$ns at 0.0 "$Router1 label Router1"
$ns at 0.0 "$Router2 label Router2"
$ns at 0.0 "$Endserver1 label Endserver1"
#-----------Configuring nodes------------#
$Endserver1 shape hexagon
$Router1 shape square$Router2 shape square
#----------------Establishing queues---------#
$ns duplex-link-op $Client1 $Router1 queuePos 0.1
$ns duplex-link-op $Client2 $Router1 queuePos 0.1
-
7/28/2019 n Pm Final Record
55/69
$ns duplex-link-op $Router1 $Router2 queuePos 0.1
$ns duplex-link-op $Router2 $Endserver1 queuePos 0.5
#---------Establishing communication-------------#
#-------------Client1 to Endserver1---#
set tcp0 [new Agent/TCP]
$tcp0 set maxcwnd_ 16
$tcp0 set fid_ 1
$ns attach-agent $Client1 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $Endserver1 $sink0
$ns connect $tcp0 $sink0
set ftp0 [new Application/FTP]$ftp0 attach-agent $tcp0
$ns add-agent-trace $tcp0 tcp
$tcp0 tracevar cwnd_
$ns at 0.5 "$ftp0 start"
$ns at 5.5 "$ftp0 stop"
set tcp1 [new Agent/TCP]
$tcp1 set maxcwnd_ 16
$tcp1 set fid_ 2
$ns attach-agent $Client2 $tcp1
set sink1 [new Agent/TCPSink]
-
7/28/2019 n Pm Final Record
56/69
$ns attach-agent $Endserver1 $sink1
$ns connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns add-agent-trace $tcp1 tcp
$tcp1 tracevar cwnd_
$ns at 0.5 "$ftp1 start"
$ns at 5.5 "$ftp1 stop"
#---------finish procedure--------#
proc finish {} {
global ns nf nt
$ns flush-trace
close $nf
close $nt
puts "running nam..."
exec nam tcpred1.nam &
exit 0
}
#Calling finish procedure
$ns at 6.0 "finish"
$ns run
-
7/28/2019 n Pm Final Record
57/69
#-------- How to run-----------#
$ns tcpred2.tcl
#---------- snapshot-----------#
-
7/28/2019 n Pm Final Record
58/69
TCL script to create WWW trafficDescription:
This tcl script generates the two wired nodes n0 and .It use the duplex link for node
connection. Band width between the nodes n(0) and n(1) is 1 MBs and network delay is
10ms and it use Drop tail queue. .Here create the WWW traffic Between the nodes
n(0),n(1) . In this script we connect the n(0) with n(1) very high Bandwidth . Here we makethe communication from n(0) to n(1) 0.2 secs.
#Create a simulator object
set ns [new Simulator]
-
7/28/2019 n Pm Final Record
59/69
#Open a nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$n0 color blue
$n1 color red
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
proc www_traffic { node0 node1 } {
global ns
set www_UDP_agent [new Agent/UDP]
-
7/28/2019 n Pm Final Record
60/69
set www_UDP_sink [new Agent/Null]
$ns attach-agent $node0 $www_UDP_agent
$ns attach-agent $node1 $www_UDP_sink
$ns connect $www_UDP_agent $www_UDP_sink
set www_CBR_source [new Application/Traffic/CBR]
$www_CBR_source attach-agent $www_UDP_agent
$www_CBR_source set packetSize_ 48
$www_CBR_source set interval_ 50ms
$ns at 0.2 "$www_CBR_source start"
#$ns at 0.2 "$cbr0 start"
$ns at 4.5 "$www_CBR_source stop"
}
www_traffic $n0 $n1
$ns at 4.0 "finish"
$ns run
-
7/28/2019 n Pm Final Record
61/69
-
7/28/2019 n Pm Final Record
62/69
TCL script to create SMTP traffic.
Description:
This tcl script generates the two wired nodes n0 and n(1) .It uses the duplex link for
node connection. Bandwidth between the nodes n(0) and n(1) is 1 Mbps and network delay is
10ms and it uses Drop tail queue. Here we create the SMTP traffic between the nodes n(0)
and n(1) . In this script we connect the n(0) and n(1) with very high bandwidth . Here we
start the communication from n(0) to n(1) at 0.2 second.
#Create a simulator object
set ns [new Simulator]
#Open a nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
set n0 [$ns node]
-
7/28/2019 n Pm Final Record
63/69
set n1 [$ns node]
$n0 color blue
$n1 color red
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
proc smtp_traffic {node0 node1 } {
global ns
set smtp_UDP_agent [new Agent/UDP]
set smtp_UDP_sink [new Agent/UDP]
$ns attach-agent $node0 $smtp_UDP_agent
$ns attach-agent $node1 $smtp_UDP_sink
$ns connect $smtp_UDP_agent $smtp_UDP_sink
set smtp_UDP_source [new Application/Traffic/Exponential]
$smtp_UDP_source attach-agent $smtp_UDP_agent
$smtp_UDP_source set packetSize_ 210
$smtp_UDP_source set burst_time_ 50ms
$smtp_UDP_source set idle_time_ 50ms
-
7/28/2019 n Pm Final Record
64/69
$smtp_UDP_source set rate_ 100k
$ns at 0.2 "$smtp_UDP_source start"
$ns at 3.2 "$smtp_UDP_source stop"
}
smtp_traffic $n0 $n1
$ns at 4.0 "finish"
$ns run
Screen shows the packet movements form the node (0) to node (1).
-
7/28/2019 n Pm Final Record
65/69
OUTPUT:
-
7/28/2019 n Pm Final Record
66/69
TCL script to create telnet traffic.Description:
This tcl script generates two wired nodes n0 and .It uses the duplex link for the node
connection. Bandwidth between the nodes n(0) and n(1) is 1 Mbps and network delay is
10ms and it uses Drop tail queue. .Here we create the telnet traffic between the nodes n(0)
and n(1) . In this script we connect the n(0) n(1) with very high bandwidth . Here we start
the communication from n(0) to n(1) at 0.2 second.
#Create a simulator object
set ns [new Simulator]
#Open a nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
-
7/28/2019 n Pm Final Record
67/69
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$n0 color blue
$n1 color red
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
proc telnet_traffic {node0 node1 } {
global ns
set telnet_TCP_agent [new Agent/TCP]
set telnet_TCP_sink [new Agent/TCPSink]
-
7/28/2019 n Pm Final Record
68/69
$ns attach-agent $node0 $telnet_TCP_agent
$ns attach-agent $node1 $telnet_TCP_sink
$ns connect $telnet_TCP_agent $telnet_TCP_sink
set telnet_TELNET_source [new Application/Telnet]
$telnet_TELNET_source attach-agent $telnet_TCP_agent
$telnet_TELNET_source set interval_ 20
$ns at 0.2 "$telnet_TELNET_source start"
$ns at 4.0 "$telnet_TELNET_source stop"
}
telnet_traffic $n0 $n1
$ns at 7.0 "finish"
$ns run
OUTPUT:
-
7/28/2019 n Pm Final Record
69/69