Menu

Computer Networks - (LAB PROGRAMS)


Aim:

 Take an example subnet of hosts and obtain a broadcast tree for the subnet.

Solution :

Week 5

Implement Broadcast Tree


Input Graph:


Source Code:

File Name: broadcast.c

#include<stdio.h>

#define MAX 10

int adjacencyMatrix[MAX][MAX];
int numNodes;

// Function to display adjacent nodes of a given node
void displayAdjacentNodes(int rootNode) {
    int i;

    printf("\nAdjacent nodes of node %d:\n", rootNode);

    for (i = 1; i <= numNodes; i++) {
        if (adjacencyMatrix[rootNode][i] == 1 || adjacencyMatrix[i][rootNode] == 1) {
            printf("%d\t", i);
        }
    }

    printf("\n");
}

int main() {
    int i, j, rootNode;

    // Input number of nodes
    printf("Enter number of nodes: ");
    scanf("%d", &numNodes);

    // Input the adjacency matrix
    printf("Enter adjacency matrix:\n");
    for (i = 1; i <= numNodes; i++) {
        for (j = 1; j <= numNodes; j++) {
            printf("Is there a connection from node %d to node %d (1=yes, 0=no): ", i, j);
            scanf("%d", &adjacencyMatrix[i][j]);
        }
    }

    // Input the root node
    printf("Enter root node (1 to %d): ", numNodes);
    scanf("%d", &rootNode);

    // Display adjacent nodes
    displayAdjacentNodes(rootNode);

    return 0;
}


Output:


$ gcc broadcast.c
$ ./a.out
Enter number of nodes: 5
Enter adjacency matrix:
Is there a connection from node 1 to node 1 (1=yes, 0=no): 0
Is there a connection from node 1 to node 2 (1=yes, 0=no): 1
Is there a connection from node 1 to node 3 (1=yes, 0=no): 0
Is there a connection from node 1 to node 4 (1=yes, 0=no): 1
Is there a connection from node 1 to node 5 (1=yes, 0=no): 0
Is there a connection from node 2 to node 1 (1=yes, 0=no): 1
Is there a connection from node 2 to node 2 (1=yes, 0=no): 0
Is there a connection from node 2 to node 3 (1=yes, 0=no): 1
Is there a connection from node 2 to node 4 (1=yes, 0=no): 0
Is there a connection from node 2 to node 5 (1=yes, 0=no): 1
Is there a connection from node 3 to node 1 (1=yes, 0=no): 0
Is there a connection from node 3 to node 2 (1=yes, 0=no): 1
Is there a connection from node 3 to node 3 (1=yes, 0=no): 0
Is there a connection from node 3 to node 4 (1=yes, 0=no): 1
Is there a connection from node 3 to node 5 (1=yes, 0=no): 0
Is there a connection from node 4 to node 1 (1=yes, 0=no): 1
Is there a connection from node 4 to node 2 (1=yes, 0=no): 0
Is there a connection from node 4 to node 3 (1=yes, 0=no): 1
Is there a connection from node 4 to node 4 (1=yes, 0=no): 0
Is there a connection from node 4 to node 5 (1=yes, 0=no): 1
Is there a connection from node 5 to node 1 (1=yes, 0=no): 0
Is there a connection from node 5 to node 2 (1=yes, 0=no): 1
Is there a connection from node 5 to node 3 (1=yes, 0=no): 0
Is there a connection from node 5 to node 4 (1=yes, 0=no): 1
Is there a connection from node 5 to node 5 (1=yes, 0=no): 0
Enter root node (1 to 5): 4

Adjacent nodes of node 4:
1       3       5




Related Content :

Computer Networks Lab Programs

1) Implement the data link layer framing methods such as character, character-stuffing and bit stuffing.   View Solution

2) Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP   View Solution

3) Develop a simple data link layer that performs the flow control using the sliding window protocol, and loss recovery using the Go-Back-N mechanism.   View Solution

4) Implement Dijsktra’s algorithm to compute the shortest path through a network   View Solution

5) Take an example subnet of hosts and obtain a broadcast tree for the subnet.   View Solution

6) Implement distance vector routing algorithm for obtaining routing tables at each node.   View Solution

7) Implement data encryption and data decryption   View Solution

8) Write a program for congestion control using Leaky bucket algorithm.   View Solution

9) Write a program for frame sorting techniques used in buffers.   View Solution

10) Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv.Analysis and Statistics & Filters.
  View Solution

11) How to run Nmap scan   View Solution

12) Operating System Detection using Nmap   View Solution

13) Do the following using NS2 Simulator
i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate & Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to Transmission of Packets
  View Solution