Networks Lab Manual

77
N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING NETWORK LAB MANUAL List of Experiments Index Sl.n o Experiments Page.No 1. Study of Networking Commands.(double) 2 2. Implementation of Socket Creation. 8 3. Implementation of Socket Binding. 10 4. Implementation of Socket Acceptance 12 5. Implementation of Socket Listen. 15 6. Implementation of Bit Stuffing Using CRC Computation. 17 7. Simulation of CRC Computation. 21 8. Simulation of Sliding Window Protocol. 24 9. To Find The IP Address For The Domain Name. 27 10. Implementation of Client Server 29 Prepared by A. Noble Mary Juliet-AP/CSE 1

Transcript of Networks Lab Manual

Page 1: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

List of Experiments

Index

Sl.no Experiments Page.No

1. Study of Networking Commands.(double) 2

2. Implementation of Socket Creation. 8

3. Implementation of Socket Binding. 10

4. Implementation of Socket Acceptance 12

5. Implementation of Socket Listen. 15

6. Implementation of Bit Stuffing Using CRC Computation. 17

7. Simulation of CRC Computation. 21

8. Simulation of Sliding Window Protocol. 24

9. To Find The IP Address For The Domain Name. 27

10. Implementation of Client Server Application for Chat . 29

11. Implementation of FTP Client-Server. 33

12. Simulation of OSPF Protocol. 37

13. Simulation of ARP. 41

14. Study of Network Simulator NS2.(double) 44

15. Study of Network Simulator OPNET.(double) 50

Prepared by A. Noble Mary Juliet-AP/CSE 1

Page 2: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO: 1 STUDY OF NETWORKING COMMANDS

Aim:

To study the set of programs used for network programming.

Commands

1. SOCKET

Name: Socket-create an endpoint for communication.

Syntax: #include<sys/types.h> #include<sys/socket.h> int socket(int domain,int type,int protocol);

Where,Domainspecifies the communication domainProtocolspecifies the protocol families to be used.

Explanation:Socket creates an end point for communication and returns a descriptor.

2. ACCEPT

Name: Accept –accept a connection on a socket.

Syntax:Int accept (int s,int *struct sockaddr *addr,socklen_t *addrlen);

Explanation:The accept function is used in connection based socket types-

SOCK_SEQPACKET and SOCK_RDM.It extracts the first connection request on the queue of the pending connection,creates a new connection socket with mostly the same properties as ‘s’ and allocates the new file descriptor for the socket which is returned.The newly created socket is no longer in the listing state.

The original socket S is unaffected by this call.Note that any per file descriptor flags (everything that can be set with the F_SETFL fcntl ,like non-blocking or asyncstate) are not inherited across an accept.

Prepared by A. Noble Mary Juliet-AP/CSE 2

Page 3: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

3. LISTEN

Name: Listen-listen for connections of socket.

Syntax:Int listen (int s,int blacklog);

Explanation: The accept connections,a socket is first created with socket(2),a willingness to accept incoming connections and queue limit for incoming connections are specified with listen,and then the connections are accepted with accept(2).

The backlog parameter defines the maximium length the queue of the pending connections may grow to.

4. CONNECT:

Name:Connect initiate a connection on a socket.

Syntax:Int connect (int sockfd,const struct sockaddr *servaddr,socklen_t addrlen);

Explanation: The file descriptor sockfd must refer to a socket. If the socket is of the type SOCK_DGRAM then the serv_addr is the address to which the datagram are send by default and the only address from which the datagram us received.

If the socket is of the type SOCK_STREAM or SOCK_SEQPACKET this call attempts to take a connection to another socket.The other socket is specified by serv_addr which is an addr of in the communication space of the socket.Each communication space interprets the serv_addr parameters in its own way.

Generally,connection based protocol sockets may successfully connect only once.connectionless protocol sockets may use the connection multiple times to change their association connectionless.

Socket may dissolve association by connecting to an addr with the sa_family member of the sock_addr set to AF_UNSPEC (unspecified).

5. GET HOST BY NAME, GET HOST BY ADDR:Name:

Sethostend,Endhostent,Herror,Hsterror.Get network host entry.#include<netdb.h>extern inth_errno;

Syntax:struct hostent *gethostbyname(constchar *name);struct hostent *gethostbyaddr(const char *addr,int len,int type);void sethostent(int stay open);void endhostent(void);void herror(const char *s);const char *hosterror(int error);

Prepared by A. Noble Mary Juliet-AP/CSE 3

Page 4: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Explanation: The gethostbyname function returns the structure of type hostent for the given host name.

Here the name is either a host name or IPV4 in the standard dot notation or IPV6address in the colon(possibly dot) notation.

If name is an IPV4 or IPV6 addressing look up is performed and field of the returned hostent structure.

If name doesn’t end in a dot the environment variable HOSTALIASES is set ,The ALIAS file pointed to by HOSTALIASES will be searched for the name. The current domain and its parents are searched unless the name ends in a dot.

6. SEND, SENDTO, SENDMESSAGE:

Name:Send a message from a socket.

Syntax:#include<sys/types.h>#include<sys/socket.h>Ssize_t(int S,const void *msg,size_t len,int flags);Ssize_t send to(int S,const void *msg,size_t len,int flags,const structsckaddr *to,socklen_t tolen);Ssize_t send msg_t(int S,const struct msghdr *msg,int flags);Explanation:

Send,sendto,sendmsg are used to transmit the message to another socket .

Send may be used only when the socket in the connected state while the other two may be used at any time.

7. RECEIVE [RECV, RecvFrom, RecvMsg]

Name: Receive a msg from a socket.Syntax: #include <sys/types.h>#include<sys/socket.h>Ssize_t recvfrom(int s, void*buf,size_t len, int flags,struct sockaddr*from,socklen_t*from len);ssize_t recvmsg(int s, struct msghdr*msg,int flags);Ssize_t recv (int s,void*buf,size_t len,int flags); Explanation: The recvform and recmsg calls are used to receive message from a socket and may be used to receive data on a socket whether or not it is connection oriented.

Prepared by A. Noble Mary Juliet-AP/CSE 4

Page 5: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

8. WRITE:

Name: To write a file descriptor.Syntax:#include<unistd.h>Ssize_t write (int fd,const void*buf,size_t count);

Explanation: Write attempts to write upto count bytes to the file referenced by the fd from the buffer starting at the buffer. POSIX requires that a read function which can be proved to occur a write function has returned returns a new data. 9. READ

Name: If reads from a file descriptor.

Syntax: #include <unistd.h> Ssize_t read (int fd, const void*buf,size_tcount);

Explanation:Read attempts to read upto count bytes from file disctriptor into the buffer

starting at the buffer. If counts is 0, read functions returns zero and has no other results. If count is greater than size_max, result is unspeacied.

10. NETSTAT:

Name:

Show the network status.Syntax: etsat [-aan] [-faddress-family] [-Mcore] [-Nsystem]etsat [-bd ghimnrs ] [-faddress-family] [–Mcore] [-Nsystem]netsat [-bdn] [-Inteface] [-Mcore] [-Nsystem] [-W wait]netsat [-protocal] [-M core] [-n system] Explanation: The net stat command symbolically displays the contents of various network related data structures. There are number of output formats, the second form represents the one of the other network data structures as per the options selected. Using the third form with the wait interval specified the net stat continuously displays the information regarding packet interface and the configured network interface the fourth form displays the static’s of the protocol.

11. FORK, VFORK:

Prepared by A. Noble Mary Juliet-AP/CSE 5

Page 6: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Name:Create a child process.

Syntax:Pid_t fork (void);Pid_vfork(void);

Explanation: Create a child process that differs from the parent process only in its pid and ppid and in the fact that resource utilization are set to zero to 0. File lock and pending signals are not inherited.

12. SOCKET FAMILY:

AF_INET IPV4 protocols (Address Family Internet)AF_INET6 IPV6 protocolsAF_LOCAL UNIX domain protocols AF_ROUTE Routing SocketsAF_KEY Key socket

13. SOCKET TYPE:

SOCK_STREAM Stream Socket used in TCP SOCK_DGRAM Datagram Socket used in UDPSOCK_RAW Raw socket used in IPv4 and IPv6

13 Inet_aton,inet_addr,inet_ntoa FUNCTIONS:

They convert internet address between ASCII strings and network byte ordered binary values.The values stored in socket address structure.

Syntax:

Inet_atonint inet_aton(const char*strptr,struct in_addr *addrptr);

It returns 1 if string was valid,0 on errorinet_addr

in_addr_t inet_addr(const char *strptr);It returns 32 bit binary network byte ordered IPv4 address INADDR_NONE if

errorinet_ntoa

char *inet_ntoa(struct in_addr inaddr);It returns pointer to dotted decimal string

14 Inet_pton and inet_ntop FUNCTIONS:

Prepared by A. Noble Mary Juliet-AP/CSE 6

Page 7: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

The letters p and n stand for presentation and numeric. The presentation format for an address is often an ASCII string and the numeric format is the binary value that goes into a socket address structure.

Syntax:Inet_pton

int inet_pton(int family,const char *strptr,void *addrptr);It returns 1 if ok,0 if input not a valid presentation format,-1 on error.

inet_ntopconst char *inet_ntop(int family,const void *addrptr,char *strptr,size_t len);It returns pointer to result if ok, NULL on error.

RESULT:

Thus the set of programs which are used for networking programs have been

studied.

Prepared by A. Noble Mary Juliet-AP/CSE 7

Page 8: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO: 2 Implementation of Socket Creation.

AIM:

To create a socket using c program.

ALGORITHM:

Step1: Start the program.

Step2: Initialize the required header files.

Step3: Declare the variables.

Step4: If condition is not satisfied,display “Socket creation error”

goto step 6.

Step5: If condition is satisfied, display “Socket created” goto step 6.

Step6: Terminate the program.

PROGRAM:#include<stdio.h>#include<sys/types.h>#include<netinet/in.h>#include<sys/socket.h>#include<arpa/inet.h>int main(){int fd1,fd2;fd1=socket(AF_INET,SOCK_STREAM,0);fd2=socket(PF_LOCAL,SOCK_DGRAM,0);if(fd1==-1)printf("socket1 creation error\n");else{printf("socket opened succesfully\n");printf("socket field descriptor is %d\n",fd1);}if(fd2==-1){printf("socket2 creation error\n");}elseprintf("socket created\n");printf("file descriptor value is %d",fd2);return 0;}

Prepared by A. Noble Mary Juliet-AP/CSE 8

Page 9: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

OUTPUT:

RESULT:

Thus, the program to create a Socket has been written and implemented and

the output has been verified.

EX.NO: 3 Implementation of Socket Binding

Prepared by A. Noble Mary Juliet-AP/CSE 9

Page 10: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

AIM:

To write a C program to implement Socket binding.

ALGORITHM:

Step1: Start the program.

Step2: Initialize the required header file.

Step3: Define a port 1500.

Step4: Open the port.

Step5: Generate the field descriptor value.

Step6: Display the output.

Step7: Terminate the program.

PROGRAM:

#include<stdio.h>#include<sys/types.h>#include<netinet/in.h>#include<sys/socket.h>#include<arpa/inet.h>#define PORT 1500int main(){int fd1;struct sockaddr_in myaddr;fd1=socket(AF_INET,SOCK_STREAM,0);if(fd1==1)printf("\nsocket1 creation error\n");else{printf("socket opened successfully\n");printf("\nsocket field descriptor is %d\n",fd1);}myaddr.sin_family=AF_INET;myaddr.sin_port=PORT;myaddr.sin_addr.s_addr=INADDR_ANY;bzero(&(myaddr.sin_zero),8);if(bind(fd1,(struct sockaddr *)&myaddr,sizeof(struct sockaddr))!=-1)printf("socket is binded at port %d\n",PORT);elseprintf("binding error"); return 0; }

Prepared by A. Noble Mary Juliet-AP/CSE 10

Page 11: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

OUTPUT:

RESULT:

Thus, the program for Socket binding has been written and implemented and the

output has been verified.

Prepared by A. Noble Mary Juliet-AP/CSE 11

Page 12: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO: 4 Implementation of Socket Acceptance

AIM:

To write a program to accept a socket.

ALGORITHM:

Step1: Start the program.

Step2: Initialize the required header file.

Step3: Define a port 2000.

Step4: Open the socket. If not opened, display “Socket creation error”.

Step5: Bind the socket.

Step6: Initialize the socket to accept.

Step7: Terminate the program.

PROGRAM:#include<stdio.h>#include<sys/types.h>#include<netinet/in.h>#include<sys/socket.h>#include<arpa/inet.h>#define PORT 2000#define QUEUELEN 5int main(){int fd1,a,fd2,fd;struct sockaddr_in server;struct sockaddr_in client;fd1=socket(AF_INET,SOCK_STREAM,0);if(fd1==1) printf("\n socket1 creation erropr\n");else{printf("\nsocket1 opened sucessfuly\n");printf("\n the socket file description is %d\n",fd1);}server.sin_family=AF_INET;server.sin_port=PORT;server.sin_addr.s_addr=INADDR_ANY;bzero(&(server.sin_zero),8);if((fd=bind(fd1,(struct sockaddr *)&server,sizeof(struct sockaddr_in)))!=-1)

Prepared by A. Noble Mary Juliet-AP/CSE 12

Page 13: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

printf("\nsocket is binded at port %d succesfully",PORT);else printf("\nbinding error");a=listen(fd1,QUEUELEN);if(a==-1){printf("listen error");exit(-1);}else printf("\nserver is in listener mode\n");

while(1){if((accept(fd1,(struct sockaddr *)&client,sizeof(struct sockaddr_in *)))==-1){printf("\naccept error");exit(-1);}else{printf("\nserver is in accept mode");printf("\nconnection mode with client %s",inet_ntoa(client.sin_addr));}close(fd2);}}

Prepared by A. Noble Mary Juliet-AP/CSE 13

Page 14: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

OUTPUT:

RESULT:Thus, the program to accept a Socket has been written and implemented and the

output has been verified.

Prepared by A. Noble Mary Juliet-AP/CSE 14

Page 15: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO: 5 Implementation of Socket Listen.

AIM:

To write a program to implement Socket listen.

ALGORITHM:

Step1: Start the program.

Step2: Initialize the required header files.

Step3: Define a port 1500.

Step4: Open the socket. If not opened, display “Socket creation error”.

Step5: Bind Socket. Then display “Socket is in listener mode”.

Step6: Terminate the program.

PROGRAM:

#include<sys/types.h>#include<netinet/in.h>#include<sys/socket.h>#include<arpa/inet.h>#define PORT 1500#define quelen 5int main(){int fd1,a;struct sockaddr_in myaddr;fd1=socket(AF_INET,SOCK_STREAM,0);if(fd1==-1)printf("socket creation error\n");else{printf("socket opened succesfully\n");printf("socket field descriptor is %d\n",fd1);}myaddr.sin_family=AF_INET;myaddr.sin_port=PORT;myaddr.sin_addr.s_addr=INADDR_ANY;bzero(&(myaddr.sin_zero),8);if(bind(fd1,(struct socketaddr*)&myaddr,sizeof(struct sockaddr))!=-1) printf("socket is binded at port succesfully %d\n",PORT);else printf("binding error");a=listen(fd1,quelen);if(a==-1){printf("listen error\n");

Prepared by A. Noble Mary Juliet-AP/CSE 15

Page 16: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

exit(-1);}else printf("server is in listener mode\n");return 0;}

OUTPUT:

RESULT:Thus, the program for Socket listen has been written and implemented and

the output has been verified.

EX.NO:6 Implementation of BIT STUFFING Using CRC ComputationAIM:

Prepared by A. Noble Mary Juliet-AP/CSE 16

Page 17: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

To implement the bit stuffing concept using C program.

ALGORITHM:

1. Start the program.

2. Declare the variables.

3. Get the input string from the user.

4. Check for five continuous 1’s in the input string.

5. If so, insert 0 after five continuous 1’s.

6. Continue the checking for five 1’s until ‘\0’ is encountered and repeat step5.

7. Stop the program.

PROGRAM:

#include<stdio.h>#include<conio.h>#include<string.h>char str[50],bin1[100],bin2[100],bin3[100];int i,len,len1,len2,len3,msg[50];static int l;void binary(int a){

int r;char bin[50];i=0;while(a!=0){

r=a%2;a=a/2;if(r==0)

bin[i]='0';else if(r==1)

bin[i]='1';i++;

}strrev(bin);len1=strlen(bin);for(i=0;i<len1;i++)

bin1[l++]=bin[i];}

void bitstuff(void){

int count=0;

Prepared by A. Noble Mary Juliet-AP/CSE 17

Page 18: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

int k=0;for(i=0;i<len2;i++){

if(count==5)bin2[k++]='0';

bin2[k++]=bin1[i];if(bin1[i]=='1')

count++;

if(bin1[i]=='0')count=0;

}}

void unstuff(void){

int count=0,k=0;for(i=0;i<len3;i++){

if(count==5)if(bin2[i]=='0')

i++;if(bin2[i]=='1')

count++;if(bin2[i]=='0')

count=0;bin3[k++]=bin2[i];

}}

void readmsg(void){

int k=0;for(i=0;i<len;i++)

msg[i]=0;i=-1;while(k<len3){

if((k%7)==0)i++;

if(bin3[k]=='1'){

switch(k%7){

case 0:msg[i]+=64;break;

case 1:

Prepared by A. Noble Mary Juliet-AP/CSE 18

Page 19: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

msg[i]+=32;break;

case 2:msg[i]+=16;break;

case 3:msg[i]+=8;break;

case 4:msg[i]+=4;break;

case 5:msg[i]+=2;break;

case 6:msg[i]+=1;

}}k++;

}}

void main(){

int j;clrscr();printf("Enter the String: ");scanf("%s",str);len=strlen(str);for(j=0;j<len;j++)

binary(str[j]);clrscr();printf("\nMessage at Sender Side.....\n%s",str);printf("\n\nMessage Before Stuffing....\n%s",bin1);len2=strlen(bin1);bitstuff();printf("\n\nAfter Stuffing.............\n%s",bin2);len3=strlen(bin2);unstuff();printf("\n\nAfter Unstuffing...........\n%s",bin3);readmsg();printf("\n\nMessage in Reciever Side...\n");for(i=0;i<len;i++)

printf("%c",msg[i]);getch();

}

Prepared by A. Noble Mary Juliet-AP/CSE 19

Page 20: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

OUTPUT:

RESULT:

Thus, the output for bit stuffing using CRC Computation is obtained and the output

is verified.

Prepared by A. Noble Mary Juliet-AP/CSE 20

Page 21: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO:7 SIMULATION OF CRC COMPUTATION

AIM:To write a c program for CRC computation.

ALGORITHM:

Start the program.

Declare and initialize the variable.

Enter the input to find the CRC and get the key.

Finally it will produce the message with CRC code.

Remove the n-1 code with CRC code.

Enter the input and key for checking CRC.

Print the result.

Terminate the program.

PROGRAM:

#include<string.h>

char text[20],key[20],rem[20];

void crc()

{

int i,j,keylen,textlen;

char temp[100];

strcpy(temp,text);

keylen=strlen(key);

for(i=0;i<keylen-1;i++)

strcat(temp,"0");

textlen=strlen(temp);

strncpy(rem,temp,keylen);

while(i!=textlen)

{

if(rem[0]=='0')

{

strcpy(rem,&rem[1]);

Prepared by A. Noble Mary Juliet-AP/CSE 21

Page 22: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

rem[keylen-1]=temp[++i];

rem[keylen]='\0';

continue;

}

for(j=0;j<keylen;j++)

rem[j]=((rem[j]-'0')^(key[j]-'0'))+'0';}}main(){

int i,choice;while(1){

printf("\n1.Find CRC\n2.Check CRC\n3.Quit\nEnter the choice:");scanf("%d",&choice);switch(choice){case 1:printf("Enter the i/p\n");scanf("%s",text);printf("Enter the key\n");scanf("%s",key);crc();printf("Msg %s \n",strcat(text,rem));break;case 2:printf("Enter the input");scanf("%s",text);printf("\nEnter key");scanf("%s",key);crc();for(i=0;i<strlen(key)-1;i++)if(rem[i]=='1')break;if(i==strlen(key)-1)printf("NO ERROR\n");elseprintf("ERROR");break;case 3:exit(0);}}

Prepared by A. Noble Mary Juliet-AP/CSE 22

Page 23: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

}

OUTPUT:

RESULT:

Thus a c program is been created for CRC computation and is executed.

EX.NO: 8 SIMULATION OF SLIDING WINDOW PROTOCOL

AIM:

Prepared by A. Noble Mary Juliet-AP/CSE 23

Page 24: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

To write a program to implement sliding window concept.

ALGORITHM:

Step1: Start the program.

Step2:Two options are given one is Selective Reject and another one is Go Back N.

Step3: Selective Reject.

Date and size of data is got.

If the data is received without ever the receives sends the acknowledge.

Else the only data for which NA is received is resent.

Step4: Go Back N

Data and size of the data is got from the user.

If the data is received, without ever the receiver sends the acknowledge.

Else the data from which the negative acknowledge is resent.

Step5: Stop the program.

PROGRAM:

#include<stdio.h>#include<stdlib.h>#include<error.h>#include<netdb.h>int main(){int data[5],rec[5];int m,n,a,i;char r1[5];printf("Enter the choice:\n");printf("1.Select Reject\n");printf("2.Go Back N\n");scanf("%d",&a);printf("Enter the size of data");scanf("%d",&n);printf("Enter the data one by one:\n");for(i=0;i<n;i++){scanf("%d",&data[i]);}printf("Data is Ready to send:\n");for(i=0;i<n;i++){

Prepared by A. Noble Mary Juliet-AP/CSE 24

Page 25: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

rec[i]=data[i];printf("%d is sent\n",data[i]);scanf("%s",r1);if (strcmp(r1,"n"))printf("Ack is rec%d\n",a);else if (strcmp(r1,"a"))printf("Negative Ack is received\n");printf("Enter the portion of the data to be sent again:");scanf("%d",&m);while(m>n){printf("\n Wrong Choice");printf("\n Enter the position of the data again");scanf("%d",&m);}if (a==1){printf("\n %d is sent again\n",data[m-1]);}else{for (i=m-1;i<n;i++){printf("%d\n",data[i]);}}}}return(0);}

OUTPUT:

Prepared by A. Noble Mary Juliet-AP/CSE 25

Page 26: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

RESULT:

Thus the sliding window concept by using C program was executed and the

output was verified.

EX.NO:9 TO FIND THE IP ADDRESS FOR THE DOMAIN NAMEAIM:

To find the IP address by giving host name.

ALGORITHM:

1. Start the program.

Prepared by A. Noble Mary Juliet-AP/CSE 26

Page 27: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

2. Create a pointer for the structure of host_ent(hen).

3. Call get host name function and pass a host name as pointer.

4. It returns the pointer to the structure of the type host int for the given host

name which is stored in the hen.

5. Print the host name and IP address of the system using hen pointer.

6. Terminate the pointer.

PROGRAM:

#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include<errno.h>int main(int argc,char *argv[1]){struct hostent *hen;if(argc!=2) {fprintf(stderr,"entrer the host name\n");exit(1);}hen=gethostbyname(argv[1]);if(hen==NULL){fprintf(stderr,"host not found\n");}printf("hostnameid%s\n",hen->h_name);printf("IP Address is %s\n",inet_ntoa(*((struct in_addr*)hen->h_addr)));}

OUTPUT:

[IT@localhost IT]$ cc ip.c

[IT@localhost IT]$ ./a.out localhost

hostnameidlocalhost.localdomain

IP Address is 127.0.0.1

Prepared by A. Noble Mary Juliet-AP/CSE 27

Page 28: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

RESULT:

Thus a C program to get the local host name by using Domain Name Server

has been written and the output was verified.

EX.NO:10 CLIENT SERVER APPLICATION FOR CHATAIM:

To implement the client-server chat application in TCP using a C-Program.

ALGORITHM:

Server:

1.Start the program.

2.Create a socket.

Prepared by A. Noble Mary Juliet-AP/CSE 28

Page 29: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

3.Bind the socket to the local port address.

4.Make it listen to the client requests.

5.Establish the connection and Accept the request.

6.Process the request.

7.Terminate the program after closing the client.

Client:

1.Start the program.

2.Create a socket.

3.Connect to the server and request for a process.

4.Once the process is processed, the response is received.

5.Close the socket.

6.Terminate the program.

PROGRAM:

TCP SERVER

#include<stdio.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<string.h>int main(){char buf[100];int sid,s;struct sockaddr_in ser;sid=socket(AF_INET,SOCK_STREAM,0);bzero(&ser,sizeof(ser));

Prepared by A. Noble Mary Juliet-AP/CSE 29

Page 30: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

ser.sin_family=AF_INET;ser.sin_port=htons(25000);ser.sin_addr.s_addr=inet_addr("127.0.0.1");bind(sid,(struct sockaddr*)&ser,sizeof(ser));listen(sid,5);printf("\t TCP SERVER \n");s=sizeof(ser);s=accept(sid,(struct sockaddr*)&ser,&s);for(;;){recv(s,buf,100,0);printf("\n MSG FROM CLIENT =%s",buf);if(strcmp(buf,"exit")==0)exit(0);printf("\nSERVER");scanf("%s",buf);send(s,buf,100,0);}close(sid);}

TCP CLIENT

#include<stdio.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<string.h>int main(){char buf[100];int sid;struct sockaddr_in s;s.sin_family=AF_INET;s.sin_port=htons(25000);s.sin_addr.s_addr=inet_addr("127.0.0.1");

Prepared by A. Noble Mary Juliet-AP/CSE 30

Page 31: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

sid=socket(AF_INET,SOCK_STREAM,0);connect(sid,(struct sockaddr*)&s,sizeof(s));printf("\t TCP CLIENT \n");for(;;){printf("\nCLIENT");scanf("%s",buf);send(sid,buf,100,0);if(strcmp(buf,"exit")==0)exit(0);recv(sid,buf,100,0);printf("\n MSG FROM SERVER =%s",buf);}close(sid);}

OUTPUT:

Prepared by A. Noble Mary Juliet-AP/CSE 31

Page 32: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

RESULT:

Thus the Client-Server Chat application is implemented in C-Language.

Prepared by A. Noble Mary Juliet-AP/CSE 32

Page 33: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO:11 FTP CLIENT-SERVER

AIM:

To implement the FTP Server-Client application Working in a C-Program.

ALGORITHM:

Server:

1.Start the program.

2.Create a socket.

3.Bind the socket to the local port address.

4.Make it listen to the client requests to transfer the file.

5.Establish the connection and Accept the request by getting the name of the

file..

6.Process the request and transfer the file.

7.Terminate the program after closing the client.

Client:

1.Start the program.

2.Create a socket.

3.Connect to the server and request for a process of transferring a file over

network by giving the file name.

4. Once the process of transferring is done, the response is received.

5. Close the socket.

6.Terminate the program.

Prepared by A. Noble Mary Juliet-AP/CSE 33

Page 34: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

PROGRAM:

FTP SERVER

#include<stdio.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<string.h>int main(){FILE*fptr;char buff[100];int sid,s,s1,i;struct sockaddr_in ser;sid=socket(AF_INET,SOCK_STREAM,0);bzero(&ser,sizeof(ser));ser.sin_family=AF_INET;ser.sin_port=htons(20000);ser.sin_addr.s_addr=inet_addr("127.0.0.1");bind(sid,(struct sockaddr*)&ser,sizeof(ser));listen(sid,5);printf("\t ftP SERVER \n");s1=sizeof(ser);s=accept(sid,(struct sockaddr*)&ser,&s);recv(s,buff,100,0);printf("\n MSG FROM CLIENT =%s",buff);fptr=fopen(buff,"r");while(!feof(fptr)){fgets(buff,sizeof(buff),fptr);printf("\n%s",buff);send(s,buff,100,0);}printf("file transferred successfully");close(sid);}

Prepared by A. Noble Mary Juliet-AP/CSE 34

Page 35: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

FTP CLIENT

#include<stdio.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<string.h>int main(){char buff[100];int sid,ch;FILE*fp;struct sockaddr_in s;s.sin_family=AF_INET;s.sin_port=htons(20000);s.sin_addr.s_addr=inet_addr("127.0.0.1");sid=socket(AF_INET,SOCK_STREAM,0);connect(sid,(struct sockaddr*)&s,sizeof(s));printf("FTP CLIENT\n");printf("Enter the file name that u want to transmit\n");scanf("%s",buff);send(sid,buff,100,0);fp=fopen("Final text","w");while(recv(sid,buff,100,0)){printf("%s",buff);fputs(buff,fp);}close(sid);}

Prepared by A. Noble Mary Juliet-AP/CSE 35

Page 36: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

OUTPUT:

RESULT:

Thus the required File transfer protocol is implemented in a C-Program.

EX.NO: 12 SIMULATION OF OSPF PROTOCOL

AIM:

To write a program for open shortest path first routing protocol.

Prepared by A. Noble Mary Juliet-AP/CSE 36

Page 37: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

ALGORITHM:

1. Start the program.

2. Get the number of nodes and distance between the host.

3. Print the distance between the host.

4. Calculate the shortest path for particular nodes.

5. Print the shortest path.

6. Terminate the program

PROGRAM

#include<stdio.h>int graph[15][15];int set[15],predecessor[15],mark[15],pathestimate[15];int s,n;void read1();void initialise();void printpath();void algorithm();void output();int minimum();int main(){read1();algorithm();output();}void read1(){int i,j;printf("Enter the no. of vertices:\n");scanf("%d",&n);while(n<0){printf("\nInvalid output:\n");printf("Give a valid input:\n");scanf("%d",&n);}printf("Enter the adjacent matrix:\n");for(i=1;i<=n;i++){printf("Enter the weight for the row->%d\n",i);for(j=1;j<=n;j++)

Prepared by A. Noble Mary Juliet-AP/CSE 37

Page 38: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

{scanf("%d",&graph[i][j]);while(graph[i][j]<0){printf("\nOnly positive weights||\nEnter the value again");scanf("%d",&n);}}}printf("Enter the source vertex\n");scanf("%d",&s);}

void initialise(){int i;for(i=1;i<n;i++){mark[i]=0;pathestimate[i]=999;predecessor[i]=0;}pathestimate[s]=0;}void algorithm(){int count=0,i,u;initialise();while(count<n){u=minimum();set[++count]=u;mark[u]=1;for(i=1;i<=n;i++){if(mark[i]!=1){if(pathestimate[i]>pathestimate[u]+graph[u][i]);{pathestimate[i]=pathestimate[u]+graph[u][i];predecessor[i]=u;}}}}}void printpath(int i){if(i==s){printf("%d",s);}else if(predecessor[i]==0)

Prepared by A. Noble Mary Juliet-AP/CSE 38

Page 39: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

printf(" path from %d to %d",s,i);else{printpath(predecessor[i]);printf("%d",i);}}

void output(){int i;for(i=1;i<=n;i++){printpath(i);if(pathestimate[i]!=999)printf("->(%d)\n",pathestimate[i]);}}int minimum(){int min=999,i,t;for(i=1;i<=n;i++){if(mark[i]!=1){if(min>=pathestimate[i]){min=pathestimate[i];t=i;}}}return t;}

OUTPUT:

Prepared by A. Noble Mary Juliet-AP/CSE 39

Page 40: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

RESULT:

Thus the program for implementing the OSPF protocol is created and the output is verified.

EX.NO:13 SIMULATION OF ARPDATE:

AIM:

Prepared by A. Noble Mary Juliet-AP/CSE 40

Page 41: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

To get the MAC (Medium Access Control) or Ethernet address for the given

IP address by using ARP.

ALGORITHM:1. Start the program.

2. Include the network, socket and arp protocol related header files

3. To get list of address, to call sin_addr to obtain the host’s IP

address and then loop through each address.

4. Print the IP address using inet_aton and then the address family return by

gethostbyname with the help of SIOCGARP request.

5. The arp_pa structure as an internet protocol socket address containing the IP

address, ioctl is called and the resulting hardware address is printed.

6. Through the SOCK_DGRAM the data’s are sending from source to destination.

7. Stop the program

PROGRAM:

# include <stdio.h> //Standard input/output functions # include <stdlib.h> //Standard library functions.# include <sys/types.h> // Contains data type definitions

Prepared by A. Noble Mary Juliet-AP/CSE 41

Page 42: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

# include <sys/socket.h> // Contains data definitions and socket structures# include <netdb.h> // Contains data definitions for socket subroutines# include <netinet/in.h> // Defines Internet constants and structures# include <unistd.h> //Unix standard functions# include <net/if_arp.h> //internet address # include <sys/ioctl.h> //device specific functions for character specific # include <arpa/inet.h> //Internet address translation subroutineint main(int argc, char *argv[]){

struct sockaddr_in sin={0};struct arpreq myarp={{0}};unsigned char *ptr;int sd;sin.sin_family=AF_INET;if(inet_aton(argv[1],&sin.sin_addr)==0){

printf("IP Address Entered : %s is not Valid\n",argv[1]);exit(0);}

memcpy(&myarp.arp_pa,&sin,sizeof(myarp.arp_pa));strcpy(myarp.arp_dev,"eth0");sd=socket(AF_INET,SOCK_DGRAM,0);if(ioctl(sd,SIOCGARP,&myarp)==1){

printf("No entry in ARP Cache for %s",argv[1]);exit(0);}ptr=&myarp.arp_ha.sa_data[0];printf("MAC Address for %s",argv[1]);printf("%X:%X:%X:%X:%X:%X\n",

*ptr,*(ptr+1),*(ptr+2),*(ptr+3),*(ptr+4),*(ptr+5));return(0);

}

OUTPUT:

Prepared by A. Noble Mary Juliet-AP/CSE 42

Page 43: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

RESULT:

Thus the output for Simulation of Address Resolution Protocol is obtained and

the output was verified.

Prepared by A. Noble Mary Juliet-AP/CSE 43

Page 44: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

EX.NO:14 STUDY OF NETWORK SIMULATOR NS2

AIM:

The study of network simulator NS 2

SRM USING NS-2

This section gives an overview of the implementation of SRM in NS. Running

an SRM simulation requires.

1. Creating and configuring the agent,

2. Attaching an application level data source (a traffic generator), and

3. Starting the agent and the traffic generator

The key steps in configuring a virgin SRM agent are to assign its multicast

group and attach it to a node. Other useful configuration parameters are to assign a

separate flow id to traffic originating from this agent, to open log file for statistics,

and trace file for trace data. The agent does not generate any application on its

own; instead the simulation user can connect any traffic generation module to any

SRM agent to generate data. The user can attach any traffic generator to the SRM

agent. The SRM agent will add the SRM headers, set the destination address to the

multicast group and deliver the packet to its target. SRM header contains the type

of message, identity of the sender, the sequence number of this message, the

round for which this message is being sent. Each data unit in SRM is identified

as<sender's id, message sequence number>.The SRM agent does not generate its

own data; it does not also keep track of the data sent except to record the

sequence number of the message received in the event that it has to do error

recovery. Since the agent has no actual record of the past data, it needs to know

what packet size to use for each repair message. The agent and the traffic

generator must be started separately using: $srm start $exp0 start

.At start, the agent joins the multicast group and starts generating the session

messagesEach agent tracks two sets of statistics: statistics to measure the

response to data loss and overall statistics for each request/repair

Prepared by A. Noble Mary Juliet-AP/CSE 44

Page 45: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

DATA LOSS:

The statistics to measure the response to data losses track the duplicate request

(and repair), and the average request (and repair) delay. Each new request (or

repair) starts a new request (or repair) period. During the request period, the agent

measures the number of first round duplicate requests (or repairs) until the round

terminate either due to receiving a request (or repairs) to due to the agent sending

one.

OVERALL STATISTICS:

In addition, each loss recovery and session object keeps a track of times and

statistics. In particular, each object records its start Time, distance, relevant to the

object; Start Time is the time that this object was created, service Time-time for this

object to complete its task and distance -one -way time to reach the remote peer.

For request objects, start Time is the time a packet loss id detected, service Time is

the time to finally receive that packet and distance is the distance to the original

sender of the packet. For repair objects, start Time is the time that a request for

retransmission is received, service Time is the time to send a repair and the

distance is the distance to the original requester. For both types of objects, the

service Time is normalized by distance. For the session object, start Time is the time

that the agent joins the multicast group; service Time and distance are not relevant.

Each object also maintains statistics particular to that type of object. Request

objects track the number of duplicate requests and repairs received, the number of

request sent, and the number times that this object had to back off before finally

receiving the data. Repair objects track the number of duplicate requests and

repairs, as well as whether or not this obj for this agent the repair.Session objs

simply record the number of session messages sent. The values of timers and the

statistics for each obj are written

to the log file every time an obj completes the error recovery function it was tasked

to do so.

TRACING:

Prepared by A. Noble Mary Juliet-AP/CSE 45

Page 46: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Each obj writes our trace information that can be used to track the progress of the

origin in its error recovery. Each trace entry is of the form:

<prefix><tag><type of entry><values>

The prefix is as described in the previous section for statistics. The tag is Q for

request objs, P for repair objs and S for session objs.

ARCHITECTURE AND INTERNALS:

The SRM agent implementation splits the protocol function into packet handling,

loss recovery, and session msg activity.

Packet handling consists of forwarding application data msgs, sending and receipt

of control msgs. These activities are executed by C++ methods.

Error detection done in C++ due to receipt of error msgs .However, loss recovery is

entirely done through instance procedure in Otcl.

Sending and processing of msgs is accomplished in C++; the policy about when

these msgs should be sent is decided by instance procedure in Otcl.

PACKET HANDLING:

Processing received msgs.

The recv () method can receive 4 types of msgs: data, request, repairs and session

msgs.

Data Packets:

The agent does not generate any data msgs. The user has to specify an external

agent to generate traffic. The recv () method must distinguish between locally

originated data, that must be sent to the multicast group, and the received from the

multicast group that must be processed. Therefore, the application agent must set

the packet's destination address to zero. For locally originated data, the agent adds

the appropriate SRM headers, sets the destination address to the multicast group

and forwards the packet to its target.

On receiving a data msg from the group, the receive (sender, msgid) will update its

state marking msg<sender,msgid>received, and possibly trigger requests if it

Prepared by A. Noble Mary Juliet-AP/CSE 46

Page 47: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

detects losses. In addition, if the msg was an older msg received out of order, and

then there must be a pending request or repair that must be cleared. In that case,

the compiled obj invokes the Otcl instance

procedure, recv_data {sender, msgid}

Currently, no provision for receivers to actually receive any application data. The

agent does not also store any of the user data. It only generates repair msgs of the

appropriate size, defined by instance variable packet Size. However, the agent

assumes that any application data is placed in the data portion of the packet,

pointed to by packet->accessdata().

Request Packets:

On receiving a request, recv rqst(sender, msgid) will check whether it needs to

schedule requests for other missing data. If it has received this request before it

was aware that the source had generated this data msg, and then the agent can

infer it is missing this, it schedules request for all of the missing data and returns.

On the other hand, the sequence number of request is less than the last known

sequence no. from the source, then the agent can be in 1 of the 3 states.

a). It does not have this data, and has a request pending for it.

b) It has the data and has seen an earlier request upon which it has a repair

pending for it or

c) It has data and it should instantiate a repair.

All of the these error recovery mechanisms are done in Octl; recv rqst() invokes the

instance procedure recv_rqst{sender, msgid, requester} for further processing.

Repair Packets:

On receiving repair packets, recv repr(sender, msgid) will check whether it needs to

schedule requests for other missing data. If it has received this repair before it was

aware that the source has generated this data msg, then the agent can infer that it

is missing all data between the last known sequence no. and that on the repair. It

schedules repair for all of the missing data and returns.

On the other hand, the sequence number of request is less than the last known

sequence no. From the source, then the agent can be in 1 of the 3 states:

a) It does not have this data, and has a request pending for it.

b) It has the data and has seen an earlier request upon which it has a repair

Prepared by A. Noble Mary Juliet-AP/CSE 47

Page 48: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

pending for it or

c) It has data and probably scheduled a repair for it at some time; after recovery it

holds down its timer expired, at which time is pending obj was cleared.

d) All of the these error recovery mechanisms are done in Octl; recv rqst() invokes

the instance procedure recv_rqst{sender, msgid, requester} for further

processing.

Session Packets:

On receiving a session msg, the agent updates its sequence no’s for all the active

sources and computes its instantaneous distance to the sending agent is possible.

Session msg processing is done in recv_sess(). The format of the session msg

is:<count of tuples in this msg, list of tuples>, Where each tuple indicates the

<sender id, last sequence no. from the source, time the last session msg was

received from this sender, time that the msg was sent>.

It is possible to trivially obtain 2 flavours of SRM based on whether the agents use

probalistic or deterministic suppression. The default request and repair timer

parameters for each SRM agent are

Agent/SRM set C1_2.0

Agent/SRM set C2_ 2.0

Agent/SRM set D1_2.0

Agent/SRM set D2_2.0

Deterministic suppressions:

Class Agent/SRM/Deterministic-super class Agent/SRM

Agent/SRM Deterministic set C2_0.0

Agent/SRM Deterministic set D2_0.0

Probablistic Suppression:

Class Agent/SRM/Probabilistic-super class Agent/SRM

Agent/SRM Probabilistic set C2_0.0

Agent/SRM Probabilistic set D2_0.0

LOSS DETECTION:

The SRM agent implementation splits the protocol functions into

1. Packet handling

Prepared by A. Noble Mary Juliet-AP/CSE 48

Page 49: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

2. Loss recovery and

3. Session msg activity.

The packet handling consists of forwarding applications data msgs, sending and

receipt of control msgs. These applications are executed by c++ methods

Error detection done in c++ due to receipt of error msgs. However, loss recovery is

entirely done through instance procedure in Otcl.

Sending and processing of msgs is accomplished in c++ ; the policy about when

these msgs should be sent is decided by instance procedure in Otcl.

A very small encapsulating class, entirely in c++, tracks a number of assorted state

information. Each member of group, ni,uses one SRM info block for every other

member of group. An SRM info object about group member nj at ni, contains

information about session messages received by ni from nj. Ni can use this

information to compute its distance to nj. If nj, sends is active in sending data

traffic, then the SRM info object will also contain information about the received

data, including a bit vector indicating all packets received from nj.

The agent keeps a list of SRM info object, one per group member, in its member

variable, sip_. Its method get_state(int sender) will return the object corresponding

to that sender, possibly creating that object, if it did not already exist. The class

SRM infor has 2 methods to access and set the bit vector, i.e.

If Received (int id) indicates whether the particular msg from the appropriate

sender, with id_id, was received at ni.

SetReceived(int id) to set the bit to indicate that the particular msg from the

appropriate sender, with id was received at ni.

The session msg variables to access timing are public; no encapsulating methods

are provided. These are:

Int 1sess;//# of the last session msg received

Int sendTime;//Time session msg # sent

Int recvTime_;//Time session msg # received

Double distance_;//Delay between nodes

Prepared by A. Noble Mary Juliet-AP/CSE 49

Page 50: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Int Idata ;//Data msgs

LOSS RECOVERY OBJECTS:

Timers are used to control when any particular ctrl msg is to be sent. The

SRM agent uses a separate class SRM to do the timer based processing. Class SRM

is used for sending periodic session msgs. SRM agents will instantiate an object to

recover from one lost data packet. Agents that detect the loss will instantiate an

object int the class SRM/request; agents that receive a request and have the

required data will instantiate an object in the class SRM/repair.

REQUEST MECHANISMS:

SRM agents detect the loss when they receive a msg, and infer the loss based on

the sequence no. on the msg received. Since packet reception is handled entirely by

the compiled obj, loss detection occurs in the c++ methods. Loss recvery, is

handled by instance procedures of the corresponding obj in otcl.

REPAIR MECHANISMS:

SRM agents will initiate a repeat if it receives a request for a packet, and it does

not have a request pending for that packet. The default repair obj belongs to the

class SRM/repair. Barring minor differences, the sequence of events and the instant

procedures in the class are identical to those for SRM/request.

SAMPLE CODE:

#STAR TOPOLOGY

source/usr/lib/ns-allinone-2.lb4/ns-2/tcl/mcast/srm-nam.tcl;#to separate$

source/usr/lib/ns-allinone-2.lb4/ns-2/tcl/mcast/srm-debug.tcl;#to trace del.$

Simulator set Number Interface 1

set ns[new simulator]

$ns color 0red;#data source

$ns color 40blue;#data session

$ns color 41red;#data request

$ns color 442red;#data repair

Prepared by A. Noble Mary Juliet-AP/CSE 50

Page 51: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

$ns color 4 red;#data node

#Creating The Nodes

set max 9

for {set 10}{$i<=$nmax}{incr1}{set n($i)[$ns node]}

$n(1) color “red”

#Creating the Links for{setIi}{$i=nmax}{incr i}{ $ns duplex-link $n($i)$n(0)1.5Mb 10ms Drop Tail }

$n1 color The Links

#Orientating The Link$ns duplex-link-op $n(0) $n(1)orient right

$n duplex-link-op $n(0) $n(2)orient right up

$n duplex-link-op $n(0) $n(3)orient up

$n duplex-link-op $n(0) $n(4)orient left up

$n duplex-link-op $n(0) $n(5)orient left

$n duplex-link-op $n(0) $n(6)orient left down

$n duplex-link-op $n(0) $n(7)orient down

$n duplex-link-op $n(0) $n(8)orientright down

set group 0x8000

set cmc[$ns mrtprotoCtrMcast{}]

$n at 0.3”$cmc switch-threetype $group”

#SRM TRACE EVENTS

setsrm stats[open srm Stats. tr w]

set srm events[open srmevents.tr w]

setfid0

for{set i 1}{$i<=$nmax}{incr i}{

Prepared by A. Noble Mary Juliet-AP/CSE 51

Page 52: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

set srm($i)[new agent/ARM/$srm sim type]

RESULT:

Thus the SRM using NS-2 is studied.

EX.NO:15 STUDY OF NETWORK SIMULATOR OPNET

AIM:

The study of network simulator OPNET

What’s OPNET?

OPNET Modeler is the industry’s leading simulator specialized for network

research and development. It allows you to design and study communication

networks, devices, protocols, and applications with great flexibility. It provides a

graphical editor interface to build models for various network entities from physical

layer modulator to application processes. All the components are modeled in an

object-oriented approach which gives intuitive easy mapping to your real systems.

It gives you a flexible platform to test your new ideas and solutions with low cost.

Programming in OPNET

OPNET is a simulator built on top of a discrete event system. It simulates the

system behavior by modeling each event happening in the system and processes it

by user-defined processes. It uses a hierarchical strategy to organize all the models

to build a whole network. The hierarchy models entities from physical link

transceivers, antennas, to CPU running processes to manage queues or running

protocols, to devices modeled by nodes with process modules and transceivers, to

network model that connects all different kinds of nodes together. OPNET also

provides programming tools for us to define any type of packet format we want to

use in our own protocols.

Programming in OPNET includes the following major tasks:

Prepared by A. Noble Mary Juliet-AP/CSE 52

Page 53: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Define protocol packet format,

Define the state transition machine for processes running the protocol,

Define process modules and transceiver modules we need in each device

node, finally define the network model by connecting the device nodes together

using user-defined link models.

INTRODUCTION:

• OPNET is a high level event based network level simulation tool

• Simulation operates at “packet-level”

• Originally built for the simulation of fixed networks

• OPNET contains a huge library of accurate models of commercially available

fixed network hardware and protocols

• Nowadays, the possibilities for wireless network simulations are also very

wide Accurate radio transmission pipeline stage for the modeling of the physical

layer (radio interface)

• The simulator has a lot of potentiality, but there exists typically a lack of

the recent wireless systems

• Much of the work considering new technologies must be done by oneself

• OPNET can be used as a research tool or as a network design/analysis tool

(end user)

• The threshold for the usage is high for the developer, but low for the end

user

THE STRUCTURE OF OPNET:

• OPNET consists of high level user interface, which is constructed from C and

C++ source code blocks with a huge library of OPNET specific functions

• Hierarchical structure, modeling is divided to three main domains:

• Network domain

Prepared by A. Noble Mary Juliet-AP/CSE 53

Page 54: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

• Networks + sub-networks, network topologies, geographical coordinates,

mobility

• Node domain

• Single network nodes (e.g., routers, workstations, mobile devices…)

• Process domain

• Single modules and source code inside network nodes(e.g., data traffic

source model)

• With OPNET it is also possible to run external code components (External

System Domain, ESD)

THE VARIOUS TOOLS OF OPNET:

• Source code editing environment

• Network model editor

• Node model editor

• Process model editor

• Antenna pattern editor

• Modulation curve editor (SNR – BER behavior)

• Packet format editor

• Analysis configuration tool

• Simulation tool

• ICI editor (Interface Control Information)

• Probe model tool (organization of result collection)

• Link model editor (properties of fixed link models)

• Path model editor (for routing and modeling virtual circuits)

• Demand model editor (wide scale application modeling)

• OPNET Animation viewer

Network Editor

The first editor is Network Editor, which graphically represents the topology

of a communication network. Networks consist of node (switch/router, server etc.)

and links model (Ethernet, ATM, FDDI etc.). It is possible manage complex network

with unlimited subnetwork nesting such as country, city, building, floor etc..

Prepared by A. Noble Mary Juliet-AP/CSE 54

Page 55: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Network editor provides geographical context, with physical characteristic of the

networks.

Node Editor

The second editor is Node Editor, which describe internal architecture of the

nodes by depicting the flow of data between functional elements, called “modules”.

The modules are processes, which can generate, send, and receive packets from

other modules to perform its function within the nodes. The modules represent

application, protocol layers, physical resources such as buffers, ports etc.

Process Editor

The third editor is the Process Editor uses a finite state machine (FSM) to

describe the protocols at any detail. State and transition graphically represent the

process behavior, where active state is changed in relation to incoming events.

Each state of process contains C/C++ code for control. Many libraries can be use for

protocol programming. To make own specific libraries, variables and statistics are

possible too. Loss of packets and node, bit error in each packets, request from

application with probability density function are allowed to simulate. Animations of

network behavior is possible to run after simulation, the smallest step time is Pico

seconds. The Network Domain is global Network Modeling

The Network Domain

Network domain specifies the overall scope of the system to be simulated

• It is a high-level description of the objects contained in the system

• Network model specifies the objects in the system as well as their physical

locations, interconnections and configurations

The Network Domain sub-networks

• An example of a sub-network

(WLAN)

Prepared by A. Noble Mary Juliet-AP/CSE 55

Page 56: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Fixed links

Sub-net network nodes

The Network Domain Mobility

• Mobility trajectory

• A node follows a predetermined trajectory during simulation (drawn or defined

step by step)

• Mobility vector

• A node moves according to a mobility vector defined with node attributes, which

can be modified during simulation

• Manipulation of node’s coordinates

• A processor module is created, which directly modifies node’s coordinates during

simulation according to the specified model

• OPNET supports wireless mobile nodes

• Also, satellite modeling is an inbuilt feature of OPNET

• Mobility can be realized in three different ways

Node Domain – Individual Network Node Modeling

• Example: From network to node domain (WLAN workstation)

Node Domain

• The node model specifies the internal structure of a network node

• Typical nodes include workstations, packet switches, satellite terminals, remote

sensors..

• Nodes can be fixed, mobile or satellite type

• A node can also be a special kind of node representing e.g., an entire Ethernet,

FDDI, or Token Ring network and its aggregate traffic as one entity

Node Domain:

Example (WLAN workstation)

Prepared by A. Noble Mary Juliet-AP/CSE 56

Page 57: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Notice the structure (OSI reference model):

• Application layer

• Presentation & session layers (Application interface)

• Transport layer (TCP & UDP)

• Network layer (IP)

• Link layer (ARP, WLAN-MAC)

• Physical layer (receiver, transmitter)

Process Domain (1/5) – Modeling Single Processor Entities, Algorithms, Protocols,

etc.

• Example: from node domain to process domain (TCP processor)

Process Domain (2/5)

• Process models are used to specify the behavior of a processor and queue

modules,

which exists in the Node Domain.

• A module is modeled as a finite state machine (FSM)

• FSM consists of states with transitions and conditions between them states

transitions

Process Domain (3/5) – The Source Code

• States consists of OPNET flavored C or C++ -code

• An example of “code level”

Process Domain (5/5) - Attributes

• Example: the parameters of 802.11 WLAN MAC

• An easy way for the user to modify model attributes

• “Promote” functionality enables the attribute modification in the upper domains

Simulations (1/3) - Simulation tool

Prepared by A. Noble Mary Juliet-AP/CSE 57

Page 58: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

• With OPNET’s simulation tool it is possible to combine several low level attributes

and make series of simulation iterations

qSimulations (2/3) – Running simulations

• The basic simulations with OPNET are done as a function of simulation time

• Accurate network behavior

• The level of event accuracy can be extended to be as detailed as needed

• Simulation results as a function of time are typically as such not suitable as

scientific

results, since statistical accuracy is needed • A certain situation can be first verified

with a simple simulation run, but then several runs should be done with different

random generator seed values.

• The typical scientific simulation results are graphs of average statistics drawn

from several simulation iterations. As such, the OPNET’s basic analysis tool is not

the best tool for drawing graphs like this, but it can be used to collecting statistics,

and exporting them to a third party software.

• BC-MAC (NSCD) with BCCA clearly outperforms the traditional 802.11

• Consider e.g., if an application desires packet losses below 10-3: BC-MAC

can offer over 20 times more capacity than 802.11!

Simulations (3/3) – A Result Example

1.0E-05

1.0E-04

1.0E-03

1.0E-02

1.0E-01

1.0E+00

0.0001 0.001 0.01 0.1 1 10

Normalized offered data traffic load

Packet loss ratio

BC-MAC (NSCD)

802.11

Prepared by A. Noble Mary Juliet-AP/CSE 58

Page 59: Networks Lab Manual

N.P.R. COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

NETWORK LAB MANUAL

Average packet loss ratio (data) as a function of normalized offered data traffic load

20 node random ad hoc network scenario with AODV routing protocol (Area: 500 m

x 500 m, effective radio range: 250 m)

External System Domain (ESD)

• An external system is OPNET’s representation of a model whose behavior is

determined by code external to OPNET

• Such a model can be anything from microchip to a model of user behavior pattern

• OPNET passes data to external system and receives data from it with no implicit

Knowledge of how the external code processed the data

RESULT:

Thus the OPNET network simulator studied.

Prepared by A. Noble Mary Juliet-AP/CSE 59