0% found this document useful (0 votes)
494 views

Experiment 1: Fabrication of Cables

The document provides instructions for installing and configuring a network interface card (NIC) and configuring TCP/IP settings on Windows. It describes adding a new NIC using the Network Control Panel, configuring the adapter's basic settings in the Adapter Properties dialog box, and setting up TCP/IP using the Microsoft TCP/IP Properties dialog box. It recommends using DHCP to automatically assign IP addresses and configure DNS and WINS settings, and provides steps to enable DHCP or change other TCP/IP settings.

Uploaded by

rock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
494 views

Experiment 1: Fabrication of Cables

The document provides instructions for installing and configuring a network interface card (NIC) and configuring TCP/IP settings on Windows. It describes adding a new NIC using the Network Control Panel, configuring the adapter's basic settings in the Adapter Properties dialog box, and setting up TCP/IP using the Microsoft TCP/IP Properties dialog box. It recommends using DHCP to automatically assign IP addresses and configure DNS and WINS settings, and provides steps to enable DHCP or change other TCP/IP settings.

Uploaded by

rock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

EXPERIMENT 1:

Fabrication of Cables
Aim
1) To practice the colour code for different cables.
2) Observe the LAN Tester and make the decision accordingly.
Theory
A twisted pair consists of two insulated conductors twisted together in the shape of a spiral.
It can be shielded or unshielded. The unshielded twisted pair cables are very cheap and easy
to install. But they are very badly affected by the electromagnetic noise interference.
Twisting of wires will reduce the effect of noise or external interference. The induced emf
into the two wires due to interference tends to cancel each other due to twisting.
Number of twists per unit length will determine the quality of cable. More twists
means better quality.
There are 3 types of UTP cables:-
1) Straight-through cable
2) Cross-over cable
3) Roll-over cable

A. Straight-through cable
Straight-Through refers to cables that have the pin assignments on each end of the cable. In
other words Pin 1 connector A goes to Pin 1 on connector B, Pin 2 connector A goes to to
Pin 2 connector B ect. Straight-Through wired cables are most commonly used to connect a
host to client. When we talk about cat5e patch cables, the Straight-Through wired cat5e
patch cable is used to connect computers, printers and other network client devices to the
router, switch or hub (the host device in this instance).

B. Crossover cable
Crossover wired cables (commonly called crossover cables) are very much like Straight-
Through cables with the exception that TX and RX lines are crossed (they are at oposite
positions on either end of the cable. Using the 568-B standard as an example below you will
see that Pin 1 on connector A goes to Pin 3 on connector B. Pin 2 on connector A goes to Pin
6 on connector B ect. Crossover cables are most commonly used to connect two hosts
directly. Examples would be connecting a computer directly to another computer,
connecting a switch directly to another switch, or connecting a router to a
router.
Note: While in the past when connecting two host devices directly a crossover cable was
required. Now days most devices have auto sensing technology that detects the cable and
device and crosses pairs when needed.

C. Roll-over cable
Rollover wired cables most commonly called rollover cables, have opposite Pin assignments
on each end of the cable or in other words it is "rolled over". Pin 1 of connector A would be
connected to Pin 8 of connector B. Pin 2 of connector A would be connected to Pin 7 of
connector B and so on. Rollover cables, sometimes referred to as Yost cables are most
commonly used to connect to devices console port to make programming changes to the
device. Unlike crossover and straight-wired cables, rollover cables are not intended to carry
data but instead create an interface with the device.

Procedure
1) The aim is to Fabricate a UTP Cable.
2) To perform the experiment follow the below steps
3) A choice list would be give that which type of cable is to be fabricated
4) Select the choice out of the three choices given
5) Once a selection is done then the user have to make the cable read
2) y
6) In-order to do so select the color codes on both the sides i.e Switch port and PC port.
7) After assigning the color codes click on the Start button to observe that the cable made is
correct or not.
8) Based on the observations made select if cable made is correct or not.

EXPERIMENT 2
Peer to Peer Topology
Aim
1) To construct Peer to Peer Topology

Theory
The word physical network topology is used to explain the manner in which a network is
physically connected. Devices or nodes in a network get connected to each other via
communication links and all these links are related to each other in one way or the other.
The geometric representation of such a relationship of links and nodes is known as the
topology of that network.
These topologies can be classifies into two types:-
1. Peer to peer
2. Primary - Secondary

Peer to peer is the relationship where the devices share the link equally. The examples are
ring and mesh topologies.
In Primary - Secondary relationship, one device controls and the other devices have to
transmit through it. For example star and tree topology.

Features of Peer to peer:-


In peer to peer architecture every node is connected to other node directly.
Every computer node is referred as peer.
Every peer provides services to other peers as well as uses services of them.
There is no central server present.

Advantages of Peer to peer:-


1) It is easy to install and so is the configuration of computers on this network,
2) All the resources and contents are shared by all the peers
3) P2P is more reliable as central dependency is eliminated. Failure of one peer doesn’t
affect the functioning of other peers.
4) There is no need for full-time System Administrator. Every user is the administrator of his
machine. User can control their shared resources.

Disadvantages of Peer to peer:-


1) In this network, the whole system is decentralised thus it is difficult to administer. That is
one person cannot determine the whole accessibility setting of whole network.
2) Data recovery or backup is very difficult. Each computer should have its own back-up
system

Procedure
1) The aim is to Create the topology.

2) To perform the experiment follow the below steps

3)A blank square area would be given which defines the working area

4)A series of components would be given

5)In order to build a topology first select on the component and then immediately click on
the working area to place it

6)To draw a line between two components first select the line click on the port of first
component and then immediately click on the port of second component

7)Once the topology is build then click on the Submit button to test whether the give
topology is built correctly or not.

EXPERIMENT 3
Installation of NIC Card & using TCP/IP
Aim: Install and configure network adapters by doing the following:
(Network adapters are hardware devices, such as network interface cards, that are used
to communicateon networks)
Procedure :

• Configure the network adapter card following the manufacturer's instructions. For
example, we may need to set jumpers on the adapter board.
• Disconnect the computer and unplug it, then install the adapter board into the
appropriate slot on the computer. When we're finished, boot the system.
• Tell Windows NT about the new network adapter card by means of the Network Control
Panel utility. Start the utility by double-clicking on the Network icon in the Control Panel

Select the Adapters tab to display the dialog box shown in Figure. The fields of this tab
areused as follows:

• Network Adapters Shows the currently installed network adapters.


• Add Adds network adapters to the system.
• Remove Removes network adapters.
• Properties Sets the properties of the currently selected network adapter.
• Update Updates the drivers for an adapter card. If we have difficulty updating an
adapter's drivers, we may want to remove the adapter and then put it back. This ensures
that the adapter's new drivers are properly installed.
• Item Notes Shows additional information for the currently selected adapter.

Figure: The Adapter Properties dialog box lets us change the adapter's basic settings and
test it. Thetest only works if we have installed the TCP/IP protocol service.

• If the new network adapter isn't shown in the Network Adapters list box, click on the
Add button.
• Using the Select Network Adapter dialog box, select the appropriate network adapter.
Ifwe don't see the adapter we installed, click on the Have Disk button and insert the
adapter's installation disk when prompted.

Note: Adding the adapter also installs the drivers for the adapter. Because of this, be sure
that you usethe correct installation disk.

• The dialog boxwe see next depends on the type of adapter we're installing. With most
network interface cards, we see the Adapter Properties dialog box shown in Figure.
• Click on the Change button, then configure the adapter's basic settings, such as network
speed and duplex mode. If we've already configured the TCP/IP protocol service and the
computer is attached to the network, you can use the Test button to test the network
card. Click OK to continue.
• Close the Network properties dialog box by clicking on the Close button. Windows NT
installs the network bindings for the network adapter. Afterward, if TCP/IP is installed on
the computer, we'll see the Microsoft TCP/IP Properties dialog box. We use this dialog
box to configure the TCP/IP protocol service as detailed in the section of this chapter
titled "Configuring TCP/IP Networking."

Change TCP/IP settings


TCP/IP defines how your computer communicates with other computers.
To make it easier to manage TCP/IP settings, we recommend using automated Dynamic
Host Configuration Protocol (DHCP). DHCP automatically assigns Internet Protocol (IP)
addresses to the computers on your network, if your network supports it. If you use DHCP,
then you don't have to change your TCP/IP settings if you move your computer to another
location, and DHCP doesn't require you to manually configure TCP/IP settings, such as
Domain Name System (DNS) and Windows Internet Name Service (WINS). To enable DHCP
or change other TCP/IP settings, follow these steps:
1. Open Network Connections by clicking the Start button , and then clicking Control
Panel. In the search box, type adapter, and then, under Network and Sharing Center,
click View network connections.
2. Right-click the connection that you want to change, and then click Properties. If you're
prompted for an administrator password or confirmation, type the password or provide
confirmation.
3. Click the Networking tab. Under This connection uses the following items, click
either Internet Protocol Version 4 (TCP/IPv4) or Internet Protocol Version 6 (TCP/IPv6),
and then click Properties.
The Network Connection Properties dialog box
4. To specify IPv4 IP address settings, do one of the following:
• To get IP settings automatically using DHCP, click Obtain an IP address automatically,
and then click OK.
• To specify an IP address, click Use the following IP address, and then, in the IP
address, Subnet mask, and Default gateway boxes, type the IP address settings.
5. To specify IPv6 IP address settings, do one of the following:
• To get IP settings automatically using DHCP, click Obtain an IPv6 address
automatically, and then click OK.
• To specify an IP address, click Use the following IPv6 address, and then, in the IPv6
address, Subnet prefix length, and Default gateway boxes, type the IP address
settings.
6. To specify DNS server address settings, do one of the following:
• To get a DNS server address automatically using DHCP, click Obtain DNS server
address automatically, and then click OK.
• To specify a DNS server address, click Use the following DNS server addresses, and
then, in the Preferred DNS server and Alternate DNS server boxes, type the
addresses of
the primary and secondary DNS servers.

The Internet Protocol Version 4 (TCP/IPv4) Properties dialog box


7. To change advanced DNS, WINS, and IP settings, click Advanced.

EXPERIMENT 4

Configure A Router With Packet Tracer

Computer networking professionals getting started with Packet Tracer may find the
interface to be flustered. Being a development program, this is only natural. However,
learning how to configure a router with Packet Tracer will put professionals on the right
track to mastering the program in about half an hour.

By this time, you should already have the Packet Tracer download and have it installed on
your computer. Open the program and select the router from the lower left-hand corner,
and drag it into the center of the sandbox screen as seen below. (Click for larger picture)
We will be setting up a very basic network that allows two computers to communicate, so
the next step is to select end devices from the bottom left-hand corner and drag it to the
sandbox screen. Do this twice to make two computers appear below the router.

Now select connections from the same bottom left-hand corner. When you connect like-
devices(Such as a router and computer) you use a crossover cable, so you should select
copper cross-over cable from the second menu to the immediate right. Click on Router0,
and connect the cable via FastEthernet0/0 as seen below:

Now click the PC0 and select FastEthernet. You will notice that although a link is established,
it is not functional. You can tell by the red dots that are present on both ends of the
connection. Once the router is configured correctly, the red dots will turn green to indicate
the devices are able to communicate.

Do the same operation to PC1, only this time connect the cable to FastEthernet0/1 since
FastEthernet0/0 is already taken by PC0. Your network should be similar to the one below at
this point:
Configuring The Router In Packet Tracer

A router that is turned off doesn’t work very well! Click on your router to bring up the
configuration menu and verify that it is turned on.When on, there will be a small green light
below the switch as seen in the diagram.

Next we have to open the Ethernet ports to allow communication. Although they are
physically connected, they are in a state that is known as being in administrative shut
down. Now click on the CLI tab to access the configuration menu. If you’ve used the Cisco
IOS before, you will notice it looks and acts the same way.

1. Press RETURN to start the session

2. Type enable to get to privileged mode (this gives you more options in configuring the
router)

3. Type config terminal (or config t for short) to access the configuration menu.

4. Type interface fastethernet0/0 to access Ethernet0/0

5. Type ip address 192.168.10.1 255.255.255.0 to assign an IP address and subnet mask to


the interface.
6. Type no shutdown to open the interface up for business.

That’s it! You should now see a message similar to the following:

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up


%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Now we have to do the same thing for fastethernet0/1. If you don’t, there still won’t be a
connection to PC1! Make sure to enter the IP address carefully as seen below:

1. Press Ctrl + Z to go back to the previous mode.

1. Type interface fastethernet0/1

2. Type ip address 192.168.20.1 255.255.255.0

3. Type no shutdown

At this point our router is configured properly. If you test out a ping, you will notice that the
computers still don’t communicate, however!

Configuring The Gateway In Packet Tracer

Our last step is to configure the gateway on each desktop computer. The gateway is the
address we assigned to the Ethernet port that the desktop is connected to. It will allow the
computer to interface with another network, so our ping won’t work without it!

Click on PC0 to bring up the configuration menu. Under global settings you will find a field
for the gateway. Enter the corresponding IP address of the router’s interface, which is
192.168.10.1. Then click the FastEthernet tab on the left column to set the actual
computer’s IP address to be on the network. Use 192.168.10.2 for the IP address, and
255.255.255.0 for the subnet mask.
Do the same thing for PC1, only use 192.168.20.1 for the gateway address, 192.168.20.2 for
the IP address, and 255.255.255.0 for the subnet mask. You can confirm that your network
works by sending out a packet of information from PC0 to PC1, and vice versa. Click the
packet icon on the right menu as seen below:

Click on PC0 and then click PC1. On the lower right of the screen you will see a message box
that says “Successful.” If it doesn’t, you may have had a syntax error when putting in an IP
address or router configuration command. Review your work or ask for help among the
community if you are stuck.

Closing Comments

Congratulations! You have a small working network. A real-world application of this very
network would be to have two computers connected to the Internet, whereas the router
would then be connected to your telecommunications company. (Or what we would call the
“cloud”)

More advanced devices and topologies won’t be so easy, but you’re now on the right path
to becoming qualified for the CCNA certification exam.

EXPERIMENT 5
BIT STUFFING AND DESTUFFING
AIM: Implement the data link layer framing methods such as bit stuffing and destuffing.
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
//decaring the three string arrays for storing the input frame(in str1) ,stuffed frame(in str2)
and destuffed frame(in str3)
char str1[20],str2[20],str3[20],ch;
int i,j=0,m,n,c=0; //initializing the count value as zero
printf("Enter Input Frame:(0's & 1's only)\n");
scanf("%s",str1);
n=strlen(str1); //calculating the input string size.
for(i=0;i<n;i++)
{
ch=str1[i]; //copying the each character into ch variable
str2[j++]=ch; //copy each character into string2 which consists stuffed
string.
m=ch-48; //48 is the ascii equalent value of ‘0’.
//Converting the character value(ch) into interger value by subtracting 48
form ch.
if(m==1)//comparing the character with ‘1’
c++; //if character is ‘1’ then incrementing the count value
else
c=0;//if the character is not a ‘1’. Then count should be zero.
if(c==5)
//if count value equals to 5
{
str2[j++]='0';
c=0;//After five consecutive 1’s adding the ‘0’ to string2
}
}

str2[j]='\0';// end of string str2(string contains ‘\0’ at the end)


printf("After the bit stuffing Frame is:\n");
puts(str2);
//logic for destuffing bits
c=0;
j=0;
n=strlen(str2);//calculating the size of the stuffed string
for(i=0;i<n;i++)//loop will executes n times
{

ch=str2[i];
str3[j++]=ch;
m=ch-48;
if(m==1)
c++;
else
c=0;
if(c==5)
{
c=0;

i++; //incrementing the string2 index to remove ‘0’ in destuffing.


}
}
str3[j]='\0';//end of the string
printf("After the bit destuffing the Frame is\n");
puts(str3);
getch();
}
OUTPUT:
EXPERIMENT 6
CHARACTER STUFFING AND DESTUFFING
AIM: Implement the data link layer framing methods such as character stuffing and
destuffing.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i=0,j=0,n;
char src[20],dest[50],rev[50];
clrscr();
printf("\n Enter Any string\n");
scanf("%s",&src); // src is an array which stores input data
n=strlen(src); // n holds length of the string
//dest is an array which holds the stuffed frame
dest[0]='D';
dest[1]='L';
dest[2]='E';
dest[3]='S';
dest[4]='T';
dest[5]='X';
j=6;//Jth variables will begins from 6th index onwards
//code for stuffing
while(i<n)//to copy to the dest loop execution ends with the consideration of length of the
i/p string
{
if(src[i]=='d' && src[i+1]=='l' && src[i+2]=='e') // checking whether continuously dle occurs
or not
{
dest[j]='d';
dest[j+1]='l';
dest[j+2]='e';
j=j+3;
}

dest[j]=src[i];// the source copied into dest


i++;
j++;
}
//insertion of frame end flags followed as
dest[j]='D';
dest[j+1]='L';
dest[j+2]='E';
dest[j+3]='E';
dest[j+4]='T';
dest[j+5]='X';
dest[j+6]='\0';
printf("\n Frame After Stuffing:\n");
printf("%s",dest);

j=0;//again j variable initialized with zero for destuffing


n=strlen(dest);
for(i=6;i<n-6;i++)//to remove flag bits in rev frame loop will starts from 6th location and
ends n-6
{
if(dest[i]=='d'&&dest[i+1]=='l'&&dest[i+2]=='e')
{
i=i+3;//leave 3 positions to remove flag dle
rev[j++]=dest[i]; //destuffed strings copied into rev
}
else
rev[j++]=dest[i];//to copy irrespective of flag
}
rev[j]='\0';
printf("after destuffing\n");
printf("%s",rev);
getch();
}
OUTPUT:
Enter Any string
kmit
Frame After Stuffing:
DLESTXkmitDLEETX
After destuffing
kmit

EXPERIMENT 7
CRC
AIM: Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and
CRC CCIP .
PROGRAM:
#include<stdio.h>
void main()
{
int f[150],g[150],r[150],t[150],i,j,k,m,n,c=0;
printf("\nEnter frame size: ");
scanf("%d",&n);
printf("\nEnter frame(dividend): ");
for(i=0;i<n;i++)
{
scanf("%d",&f[i]);
t[i]=f[i];
}
printf("\nEnter divisor size: ");
scanf("%d",&m);
printf("\nEnter g(divisor): ");
for(i=0;i<m;i++)
{
scanf("%d",&g[i]);
}
for(i=n;i<n+m;i++)
t[i]=0;
for(i=0;i<n;i++)
{
k=i;
if(t[i]==1)
{
for(j=0;j<m;j++,k++)
{
if(t[k]==g[j])
t[k]=0;
else
t[k]=1;
}
}
}
printf("\nCheck sum is : ");
for(i=n;i<m+n-1;i++)
{
printf(" %d ",t[i]);
f[i]=t[i];
}
printf("\n\nCodeword : ");
for(i=0;i<m+n-1;i++)
printf(" %d ",f[i]);
printf("\n\nEnter received data : \n");
for(i=0;i<m+n-1;i++)
scanf("%d",&r[i]);
for(i=0;i<n;i++)
{
k=i;
if(r[i]==1)
{
for(j=0;j<m;j++,k++)
{
if(r[k]==g[j])
r[k]=0;
else
r[k]=1;
}
}
}
for(i=n;i<m+n-1;i++)
{
printf("%d",r[i]);
if(r[i]!=0)
c=1;
}
if(c==1)
printf("\nError ");
else
printf("\nNO error");
}
OUTPUT:
CRC – 4
Enter frame size: 4
Enter frame(dividend): 1 1 1 0
Enter divisor size: 5
Enter g(divisor): 1 0 0 1 1
Check sum is : 0 0 0 1
Codeword : 1 1 1 0 0 0 0 1
Enter received data :
11100001
0000
NO error
CRC-8
Enter frame size: 4
Enter frame(dividend): 1 1 1 0
Enter divisor size: 9
Enter g(divisor): 1 0 1 0 0 0 1 0 1
Check sum is : 0 1 1 1 1 0 0 1
Codeword : 1 1 1 0 0 1 1 1 1 0 0 1
Enter received data :
111001111001
00000000
NO error
CRC-12
Enter frame size: 4
Enter frame(dividend): 1 1 1 0
Enter divisor size: 13
Enter g(divisor): 1 1 1 1 0 0 1 0 1 0 1 0 0
Check sum is : 1 1 0 0 1 1 1 1 0 1 0 0
Codeword : 1 1 1 0 1 1 0 0 1 1 1 1 0 1 0 0
Enter received data :
1110110011110100
000000000000
NO error

EXPERIMENT 8
DVR(DISTANCE VECTOR ROUTING)
AIM: Take an example subnet graph with weights indicating delay between nodes. Now
obtain Routing table art each node using distance vector routing algorithm
PROGRAM:
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct
distance from the node i to k using the cost matrix
//and add the distance from k to node j
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{//We calculate the minimum distance
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
OUTPUT:
Enter the number of nodes :
3
Enter the cost matrix :
027
201
710
For router 1
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
For router 2
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
For router 3
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0

EXPERIMENT 9
SHORTEST PATH
AIM: Implement Dijkstra‘s algorithm to compute the Shortest path thru a graph.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define INFINITY 9999
#define MAX 10

void dijkstra(int G[MAX][MAX],int n,int startnode);

int main()
{
int G[MAX][MAX],i,j,n,u;
printf("Enter no. of vertices:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");

for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);

printf("\nEnter the starting node:");


scanf("%d",&u);
dijkstra(G,n,u);

return 0;
}

void dijkstra(int G[MAX][MAX],int n,int startnode)


{
int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;

//pred[] stores the predecessor of each node


//count gives the number of nodes seen so far
//create the cost matrix
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];

//initialize pred[],distance[] and visited[]


for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}

distance[startnode]=0;
visited[startnode]=1;
count=1;

while(count<n-1)
{
mindistance=INFINITY;
//nextnode gives the node at minimum distance
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];
nextnode=i;
}

//check if a better path exists through nextnode


visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}

//print the path and distance of each node


for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);

j=i;
do
{
j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}
OUTPUT:
Enter no. of vertices:5
Enter the adjacency matrix:
0 10 0 30 100
10 0 50 0 0
0 50 0 20 10
30 0 20 0 60
100 0 10 60 0
Enter the starting node:0
Distance of node1=10
Path=1<-0
Distance of node2=50
Path=2<-3<-0
Distance of node3=30
Path=3<-0
Distance of node4=60
Path=4<-2<-3<-0

EXPERIMENT 10
BROADCAST ROUTING
AIM: Take an example subnet of hosts. Obtain broadcast tree for it.
PROGRAM:
#include<stdio.h>
int max( );
int distance[20];
int n;
main( )
{
int adj[20][20],adj1[20][20],flag[30];
int i,j,root,x;
int source,count=1,y=0;
printf(“Enter no.of nodes”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf(“%d”,&adj[i][j]);
}
printf(“Enter the source of broadcasting”);
scanf(“%d”,&source);
for(i=0;i<n;i++)
{
flag[i]=0;
}
for(root=0;root<n;root++)
{
for(i=0;i<n;i++)
distance[i]=adj[root][i];
x=min();
for(i=0;i<n;i++)
{
if(distance[i]= =x)
{
adj1[root][i]=x;
adj1[i][root]=x;
}
else
adj1[root][i]=0;
}
}

printf( “Given Adjacency matrix is”);


for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf(“%d”,adj[i][j]);
printf(“\n”);
}
printf(“Minimal spanning tree”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf(“%d”,adj[i][j]);
printf(“\n”);
}
root=source;
flag[root]=1;
while(count!=y)
{
for(i=0;i<n;i++)
{
if(adj1[root][i]!=0 &&flag[root]= =1 && flag[i]!=1)
{
printf(“%d sends message to %d”,root,i);
flag[i]=1;
}
}
if(root<n-1)
{
root++;
}
else
root=0;
for(i=0;i<n;i++)
{
if(flag[i]= =0)
break;
}
if(i= =n)
{
count=y;
}
}
}
int min( )
{
int i,j=0;
int mini;
int distance1[10];
for(i=0;i<n;i++)
{
if(distance[i]!=0)
{
distance1[j]=distance[i];
j++;
}
}
mini=distance1[10];
for(i=1;i<j;i++)
{
if(distance1[i]<mini)
{
mini=distance1[i];
}
}
return(mini);
}
OUTPUT:
Enter no.of nodes 2
Enter the adjacency matrix
0 2

2 0
Enter the source for broadcasting 1
0 2
2 0
Minimal spanning tree is
0 2
2 0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy