Se & CN Lab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

St.

Martin's Engineering
College UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad-500 100
www.smec.ac.in

LAB MANUAL

YEAR : 2023-24

REGULATION : R22

COURSE NAME : SOFTWARE ENGINEERING & COMPUTER NETWORKS LAB

COURSE CODE: IT504PC

DEPARTMENT OF INFORMATION TECHNOLOGY


St. Martin's Engineering College
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad-500 100
www.smec.ac.in

INDEX

S.NO NAME OF PROGRAM

1 Vision and Mission of Institution and Department

2 COs, POs, PSOs & PEOs

3 Syllabus

4 List of Experiments

5 Programs

6 Contents beyond Syllabus


3

Vision and Mission of the Department and Institute

To become an institute of excellence by creating high quality and


innovating engineering and management professionals who would
Vision of the Institute
take the world into their stride through sustainable growth in
technology and management.

To instill moral values and promote technological, intellectual and


ethical environment to the students with an in-depth and exceptional
education that makes them employment ready as per the emerging

Mission of the Institute trends in industry and to invoke the desire of innovation as a process
of life•long learning for a successful career in engineering and
management.

To evolve the department of computer science and engineering as a


Vision of the center of academic excellence with latest technologies to transform
Department
students into innovative global leaders.

M1: To produce competitive graduates having creative skills and


ethical values to succeed in their fields as well as the foundation for
lifelong learning.
Mission of the
Department M2: By promoting research and development activities in
collaboration with reputed industries and laboratories.

M3: To analyze, design and develop high quality software systems


using the appropriate theory, principles, tools and processes.

Dept. of IT CS506PC: SE & CN LAB


4

COs, POs, PSOs & PEOs

S. NO. Course Objectives

1 To install and run the Python interpreter

2 To learn control structures

To Understand Lists, Dictionaries in python


3
4 To Handle Strings and Files in Python

Dept. of IT CS506PC: SE & CN LAB


5

Course Outcomes

S. NO. Course Outcomes BTL

CO1 Develop the application specific codes using python. L3

CO2 Understand Strings, Lists, Tuples and Dictionaries in Python L1


CO3 Verify programs using modular approach, file I/O, Python
L4
standard library
CO4 Implement Digital Systems using Python L2

CO5 To be able to work with different network tools L5

Dept. of IT CS506PC: SE & CN LAB


PROGRAM OUTCOMES

S. Program Outcomes Level Expertise a


ssessed by
NO.

Engineering knowledge: Apply the


knowledge of mathematics, science,
Assignment,
PO1 engineering fundamentals, and an engineering 3
Tutorials
specialization to the solution of complex
engineering problems.

Problem analysis: Identify, formulate,


review research literature, and analyze
complex engineering problems reaching Assignment,
PO2 3
substantiated conclusions using first Tutorials
principles of mathematics, natural sciences,
and engineering sciences.

Design/development of solutions: Design


solutions for complex engineering problems
and design system components or processes
Assignment,
PO3 that meet the specified needs with appropriate 3
Tutorials
consideration for the public health and safety,
and the cultural, societal, and environmental
considerations.

Conduct investigations of complex


problems: Use research-based knowledge
and research methods including design of
PO4 2 Assignments
experiments, analysis and interpretation of
data, and synthesis of the information to
provide valid conclusions.

Dept. of IT CS506PC: SE & CN LAB


7

Modern tool usage: Create, select, and apply


appropriate techniques, resources, and
modern engineering and IT tools including
PO5 2 Assignments
prediction and modeling to complex
engineering activities with an understanding
of the limitations.

The engineer and society: Apply reasoning


informed by the contextual knowledge to
assess societal, health, safety, legal and Assignment,
PO6 3
cultural issues and the consequent Tutorials
responsibilities relevant to the professional
engineering practice.

Environment and sustainability:


Understand the impact of the professional
engineering solutions in societal and
PO7 3 Guest Lectures
environmental contexts, and demonstrate the
knowledge of, and need for sustainable
development.

Ethics: Apply ethical principles and commit


PO8 to professional ethics and responsibilities and 1 --
norms of the engineering practice.

Individual and team work: Function


effectively as an individual, and as a member
PO9 1 --
or leader in diverse teams, and in
multidisciplinary settings

Communication: Communicate effectively


on complex engineering activities with the
PO10 engineering community and with society at 1 --
large, such as, being able to comprehend and
write effective reports and design

Dept. of IT CS506PC: SE & CN LAB


8

documentation, make effective presentations,


and give and receive clear instructions.

Project management and finance:


Demonstrate knowledge and understanding of
the engineering and management principles
PO11 and apply these to one’s own work, as a 1 --
member and leader in a team, to manage
projects and in multidisciplinary
environments

Life-long learning: Recognize the need for,


and have the preparation and ability to engage
PO12 3 Guest Lectures
in independent and life-long learning in the
broadest context of technological change.

1- None 2- Supportive 3- Highly Related

Dept. of IT CS506PC: SE & CN LAB


PROGRAM EDUCATIONAL OBJECTIVES

PEO No. Program Educational Objectives

To apply engineering processes and practices to software and hardware systems


PEO1
skillfully and efficiently.

Ability to understand and analyze engineering issues in a broader prospective


PEO2
with ethical responsibility.

To prepare students to fit into any industry associated with developing and
PEO3
implementation of software products or technologies.

To equip the graduates with ability to analyze, design and test the novel
PEO4
products.

PROGRAM SPECIFIC OUTCOMES

S. No. Program Specific Outcomes Level Expertise & assessed by

Proficiency skill: Potential to understand,


Implement and conduct research in various
PSO1 3 Lecture, Assignments
sub domains of Computer Science &
Engineering.

Analytical skills: Capability to apply


PSO2 theoretical knowledge to practical 3 Lecture, Assignments
implementation for a quality product.

Successful Career and


Entrepreneurship: Preparedness to adopt
PSO3 new technology with unprecedented ideas 1 ----
to be a successful entrepreneur besides a
zeal towards higher studies

1- None 2- Supportive 3- Highly Related

Dept. of IT CS506PC: SE & CN LAB


R22 B.TECH IT III YEAR
IT504PC: SOFTWARE ENGINEERING AND COMPUTER NETWORKS LAB
III Year B.Tech. IT II-Sem LTPC
0 02 1
Course Objectives

1. To install and run the Python interpreter


2. To learn control structures.
3. To Understand Lists, Dictionaries in python
4. To Handle Strings and Files in Python To understand the working principle of various
communication protocols.

Course Outcomes
1. Develop the application specific codes using python.
2. Understand Strings, Lists, Tuples and Dictionaries in Python
3. Verify programs using modular approach, file I/O, Python standard library
4. Implement Digital Systems using Python
5. To be able to work with different network tools

List of Experiments
Software Engineering List of Experiments:
1. Development of problem statements.
2. Preparation of Software Requirement Specification Document, Design Documents and
Testing Phase related documents.
3. Preparation of Software Configuration Management and Risk Management related
documents
4. Study and usage of any Design phase CASE tool
5. Performing the Design by using any Design phase CASE tools.
6. Develop test cases for unit testing and integration testing
7. Develop test cases for various white box and black box testing techniques.
Sample Projects: 1. Passport automation System 2. Book Bank 3. Online Exam
Registration

Computer Networks List of Experiments:


1. Implement the data link layer framing methods such as character, characterstuffing and bit
stuffing.
2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC
CCIP
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.
4. Implement Dijsktra’s algorithm to compute the shortest path through a network
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
6. Implement distance vector routing algorithm for obtaining routing tables at each node.
7. Implement data encryption and data decryption.
EXPERIMENT 1
1. Problem Statement: A Book Bank lends books and magazines to member, who is registered
in the system. Also it handles the purchase of new titles for the Book Bank. Popular titles are brought
into multiple copies. Old books and magazines are removed when they are out or date or poor in
condition. A member can reserve a book or magazine that is not currently available in the book bank,
so that when it is returned or purchased by the book bank, that person is notified. The book bank can
easily create, replace and delete information about the tiles, members, loans and reservations from the
system.

2. Preparation of Software Requirement Specification Document:

Users Characteristics:

Student: They are the people who desire to obtain the books and submit the information to the
database.

Librarian: He has the certain privileges to add the books and to approval of the reservation of books.

System Modules:

Log in: Secure registration of student and librarian by filling online registration form.

Book bank: Book bank contains all the books. New book added to the book bank with bookno, title
name, author, edition, publisher name details to the database. Any book is deleted if damaged. Update
of the book information also done.

Operations: student and administrator perform their operations like add book, delete book, update
information, view book details are implemented in log in WebPages.

Non-functional requirements:

Privacy: privacy maintained for each and every user by providing user credentials username and
password.

Portability: installation on multiple platforms and execution of software.

3. Preparation of Software Configuration Management


Software Requirements:

Operating sytem: windows 7/10

Front end : J2EE

Back end : My SQL Server

IDE used : Netbeans

Hardware Requirements:

Processor:i3 or higher

RAM : 4 GB

Hard Disk drive: 500 GB

1. Study and usage of any Design phase CASE tool


CASE Tool: STARUML

How to Install StarUML on Windows 10

Star UML is a UML (Unified Modeling Language) tool, introduce by MKLab. It is an open-source
modeling tool that supports the UML framework for system and software modeling. StarUML
is based on UML version 1.4, it provides 11 different types of diagram and it accepts UML 2.0
notation. Version 2.0 was released for beta testing under a property license.

StarUML is actively supporting the MDA (Model Driven Architecture). It approaches by


supporting the UML profile concept and allowing it to generate code for multiple languages. It
also provides a number of bug fixes and improved compatibility with the modern versions of
the Windows Operating System.

StarUML is mostly used by the Agile and small development teams, professional persons and
used by the educational institutes

Diagram Types in StarUML

1. Use Case Diagram

2.Class Diagram
3.Sequence Diagram

4.Collaboration Diagram

5.Statechart Diagram

6.Component Diagram

7.Deployment Diagram

8. Composite Structure Diagram

Features of StarUML

1. It supports multi-platform such as macOS, Windows, and Linux.

2. It involves UML 2.x.standard compliant.

3. Includes Entity-Relationship diagram (ERD), Data-flow diagram (DFD), and Flowchart


diagram.

4. It creates multiple windows.

5. It has modern UX and dark and light themes.

6. Featured with retina (High-DPI) display support.

7. Includes model-driven development.

8. It has open APIs.

9. Supports various third-party extensions.

10. Asynchronous model validation.


9
11. It can export to HTML docs.

Steps to Download and Install StarUML

Step 1: Go on the browser, type in the URL “StarUML”

Step 2: Click on the very first search “Download-StarUML”.

Step 3: There will be 3 Operating Systems (OS) options, click on the option as per the devise
OS.

Step 4: Now, right-click on the downloaded file, select “Show in Folder” option.

Step 5: Click on the open file, a popup window opens, click on the “Yes” button.

Step 6: Installation gets start. After installation popup opens to ask to buy a license. If you
want to click on the “Buy Now” button or else close that window. StarUML is ready to use.

2. Performing the Design by using any Design phase CASE tools

CASE Tool: StarUML

Use_Case Diagram:
The book bank use cases are:
1. book_issue

2. book_return

3. book_order

4. book_entry

5. search book_details

10
Actors Involved:
1. Student

11
2. Librarian
3. Vendor
Usecase Name : Search Book_Details
The librarian initiates this use case when any member returns or request the book and checking if the
book is available.
Precondition: The librarian should enter all Book details.
Normal Flow: Build message for librarian who search the book.
Post Condition: Send message to respective member who reserved the book.

Usecase Name : Book_ Issue


Initiated by librarian when any member wants to borrow the desired book. If the book is available,
the book is issued.
Precondition: Member should be valid member of library.
Normal Flow: Selected book will be issued to the member.
Alternative Flow: If book is not available then reserved book use case should be initiate. Post
Condition: Update the catalogue.

Usecase Name : Book_Order


Initiated by librarian when the requested book is not available in the library at that moment. The book
is reserved for the future and issued to the person when it is available.
Precondition: Initiated only when book is not available.
Normal Flow: It reserved the book if requested.
Post Condition : Mention the entry in catalogue for reservation.

Usecase Name : Book_Return


Invoked by the librarian when a member returns the book.
Precondition: Member should be valid member of library.
Normal Flow: Librarian enters bookid and system checks for return date of the book. Alternative
12
Flow: System checks for return date and if it returned late fine message will be displayed.

13
Post Condition: Check the status of reservation.

Usecase Name : Book_Entry


The purchase book use-case when new books invoke it or magazines are added to the library.
Precondition: Not available or more copies are required.
Normal Flow: Enter bookid,author information, publication information, purchased date, prize and
number of copies.
Post Condition: Update the information in catalogue.

Figure 1. Usecase diagram for Book Bank System

Activity Diagram:

Activity diagrams are graphical representations of workflows of stepwise activities and actions with
14
support for choice, iteration and concurrency. In the Unified Modeling Language, activity diagrams
can be used to describe the business and operational step-by-step workflows of components in a

system. An activity diagram shows the overall flow of control. An activity is shown as an rounded
box containing the name of the operation.
This activity diagram describes the behaviour of the system.

Figure 2. Activity Diagram for Book Bank System [borrow book]

15
Figure 3. Activity Diagram for Book Bank System [order book]

16
Figure 4. Activity Diagram for Book Bank System [Return book]

Sequence Diagram:

A sequence diagram represents the sequence and interactions of a given USE-CASE or scenario.
Sequence diagrams can capture most of the information about the system. Most object to object
interactions and operations are considered events and events include signals, inputs, decisions, interrupts,
transitions and actions to or from users or external devices.

An event also is considered to be any action by an object that sends information. The event line
represents a message sent from one object to another, in which the “form” object is requesting an
operation be performed by the “to” object. The “to” object performs the operation using a method that the
class contains.
17
It is also represented by the order in which things occur and how the objects in the system send
message to one another.

18
Figure 5. Sequence Diagram For Book Issue & Return

Figure 6. Collaboration Diagram For Book Issue & Return

Class Diagram:

The class diagram, also referred to as object modeling is the main static analysis diagram. The main
task of object modeling is to graphically show what each object will do in the problem domain. The
problem domain describes the structure and the relationships among objects.

19
The ATM system class diagram consists of four classes:

1. Student

2. Book

3. Issue

4. Return

5. Vendor

6. Details

1) Student:

It consists of twelve attributes and three operations. The attributes are enrollno, name, DOB,
fathername, address, dept name, batch and book limits. The operations of this class are addStInfo(),
deleteStInfo(), modifyStInfo().

2) Book:

It consists of ten attributes and four operations. This class is used to keep book information such as
author, title, vendor, price, etc

3) Issue:

It consists of eight attributes and two operations to maintain issue details such as, issue date, accno of
issued book, name of the student who borrowed book.

4) Return:

It consists of eight attributes and two operations to maintain issue details such as, issue date, accno of
issued book, name of the student who borrowed book.

5) Students:

The attributes of this class are name, dept ,year ,bcode no The operation is display students().

6) Detail:

20
The attributes of this class are book name, author, bcode no The operations are delete details().

Figure 7. Class Diagram For Book Bank System

State Chart Diagram


It consists of state, events and activities. State diagrams are a familiar technique to describe the
behavior of a system. They describe all of the possible states that a particular object can get into and
how the object's state changes as a result of events that reach the object.

21
Figure 8. State Chart Diagram for BookBank System

Deployment Diagram and Component Diagram

Deployment diagrams are used to visualize the topology of the physical components of a system where
the software components are deployed.

Figure 9: Deployment Diagram for Book Bank System

22
3. Develop test cases for unit testing and integration testing

4. Develop test cases for various white box and black box testing
techniques.

23
24
25
26
27
5. Preparation of Software Requirement Specification Document:

2.1 Users Characteristics:

Student: They are the people who desire to obtain the books and submit the information to
the database.

Librarian: He has the certain privileges to add the books and to approval of the reservation of
books.

System Modules:

Log in: Secure registration of student and librarian by filling online registration form.

Book bank: Book bank contains all the books. New book added to the book bank with
bookno, title name, author, edition, publisher name details to the database. Any book is
deleted if damaged. Update of the book information also done.

Operations: student and administrator perform their operations like add book, delete book,
update information, view book details are implemented in log in WebPages.

Non-functional requirements:

Privacy: privacy maintained for each and every user by providing user credentials username
and password.

Portability: installation on multiple platforms and execution of software.

3.Preparation of Software Configuration Management

Software Requirements:

Operating sytem: windows 7/10

Front end : J2EE

Back end : My SQL Server

IDE used : Netbeans

Hardware Requirements:
28
Processor:i3 or higher

RAM : 4 GB

Hard Disk drive: 500 GB

6. Study and usage of any Design phase CASE tool

CASE Tool: STARUML


How to Install StarUML on Windows 10

StarUML is a UML (Unified Modeling Language) tool, introduce by MKLab. It is an open-source


modeling tool that supports the UML framework for system and software modeling. StarUML
is based on UML version 1.4, it provides 11 different types of diagram and it accepts UML 2.0
notation. Version 2.0 was released for beta testing under a property license.

StarUML is actively supporting the MDA (Model Driven Architecture). It approaches by


supporting the UML profile concept and allowing it to generate code for multiple languages. It
also provides a number of bug fixes and improved compatibility with the modern versions of
the Windows Operating System.

StarUML is mostly used by the Agile and small development teams, professional persons and
used by the educational institutes

Diagram Types in StarUML

1. Use Case Diagram

2. Class Diagram

3. Sequence Diagram

4. Collaboration Diagram

5. Statechart Diagram

29
6. Component Diagram

7. Deployment Diagram

8. Composite Structure Diagram

Features of StarUML

1. It supports multi-platform such as macOS, Windows, and Linux.

2. It involves UML 2.x.standard compliant.

3. Includes Entity-Relationship diagram (ERD), Data-flow diagram (DFD), and Flowchart


diagram.

4. It creates multiple windows.

5. It has modern UX and dark and light themes.

6. Featured with retina (High-DPI) display support.

7. Includes model-driven development.

8. It has open APIs.

9. Supports various third-party extensions.

10. Asynchronous model validation.

11. It can export to HTML docs.

Steps to Download and Install StarUML

Step 1: Go on the browser, type in the URL “StarUML”

Step 2: Click on the very first search “Download-StarUML”.


30
Step 3: There will be 3 Operating Systems (OS) options, click on the option as per the devise
OS.

Step 4: Now, right-click on the downloaded file, select “Show in Folder” option.

Step 5: Click on the open file, a popup window opens, click on the “Yes” button.

Step 6: Installation gets start. After installation popup opens to ask to buy a license. If you
want to click on the “Buy Now” button or else close that window. StarUML is ready to use.

7. Performing the Design by using any Design phase CASE tools

CASE Tool: StarUML

Use_Case Diagram:
The book bank use cases are:
1. book_issue

2. book_return

3. book_order

4. book_entry

5. search book_details

Actors Involved:
1. Student
2. Librarian
3. Vendor

31
Usecase Name : Search Book_Details
The librarian initiates this use case when any member returns or request the book and checking if the
book is available.

Precondition: The librarian should enter all Book details.


Normal Flow: Build message for librarian who search the book.
Post Condition: Send message to respective member who reserved the book.

Usecase Name : Book_Issue


Initiated by librarian when any member wants to borrow the desired book. If the book is available, the
book is issued.
Precondition: Member should be valid member of library.
Normal Flow: Selected book will be issued to the member.
Alternative Flow: If book is not available then reserved book use case should be initiate. Post
Condition: Update the catalogue.

Usecase Name : Book_Order


Initiated by librarian when the requested book is not available in the library at that moment. The book
is reserved for the future and issued to the person when it is available.
Precondition: Initiated only when book is not available.
Normal Flow: It reserved the book if requested.
Post Condition : Mention the entry in catalogue for reservation.

Usecase Name : Book_Return


Invoked by the librarian when a member returns the book.
Precondition: Member should be valid member of library.
Normal Flow: Librarian enters bookid and system checks for return date of the book. Alternative
Flow: System checks for return date and if it returned late fine message will be displayed.
32
Post Condition: Check the status of reservation.

33
Usecase Name : Book_Entry
The purchase book use-case when new books invoke it or magazines are added to the library.
Precondition: Not available or more copies are required.

Normal Flow: Enter bookid,author information, publication information, purchased date, prize and
number of copies.
Post Condition: Update the information in catalogue.

Figure 1. Usecase diagram for Book Bank System

Activity Diagram:

Activity diagrams are graphical representations of workflows of stepwise activities and actions with
support for choice, iteration and concurrency. In the Unified Modeling Language, activity diagrams

34
can be used to describe the business and operational step-by-step workflows of components in a

35
system. An activity diagram shows the overall flow of control. An activity is shown as an rounded
box containing the name of the operation.
This activity diagram describes the behaviour of the system.

Figure 2. Activity Diagram for Book Bank System [borrow book]

36
Figure 3. Activity Diagram for Book Bank System [order book]

37
Figure 4. Activity Diagram for Book Bank System [Return book]

Sequence Diagram:

A sequence diagram represents the sequence and interactions of a given USE-CASE or


scenario. Sequence diagrams can capture most of the information about the system. Most object to
object interactions and operations are considered events and events include signals, inputs, decisions,
interrupts, transitions and actions to or from users or external devices.

An event also is considered to be any action by an object that sends information. The event
line represents a message sent from one object to another, in which the “form” object is requesting an
operation be performed by the “to” object. The “to” object performs the operation using a method that

38
the class contains.

It is also represented by the order in which things occur and how the objects in the system
send message to one another.

39
Figure 5. Sequence Diagram For Book Issue & Return

Figure 6. Collaboration Diagram For Book Issue & Return

Class Diagram:

The class diagram, also referred to as object modeling is the main static analysis diagram. The main
task of object modeling is to graphically show what each object will do in the problem domain. The
problem domain describes the structure and the relationships among objects.

40
The ATM system class diagram consists of four classes:

1. Student

2. Book

3. Issue

4. Return

5. Vendor

6. Details

1) Student:

It consists of twelve attributes and three operations. The attributes are enrollno, name, DOB,
fathername, address, dept name, batch and book limits. The operations of this class are addStInfo(),
deleteStInfo(), modifyStInfo().

2) Book:

It consists of ten attributes and four operations. This class is used to keep book information such as
author, title, vendor, price, etc

3) Issue:

It consists of eight attributes and two operations to maintain issue details such as, issue date, accno of
issued book, name of the student who borrowed book.

4) Return:

It consists of eight attributes and two operations to maintain issue details such as, issue date, accno of
issued book, name of the student who borrowed book.

5) Students:

The attributes of this class are name, dept ,year ,bcode no The operation is display students().

6) Detail:

41
The attributes of this class are book name, author, bcode no The operations are delete details().

Figure 7. Class Diagram For Book Bank System State

Chart Diagram
It consists of state, events and activities. State diagrams are a familiar technique to describe the
behavior of a system. They describe all of the possible states that a particular object can get into and
how the object's state changes as a result of events that reach the object.

42
Figure 8. State Chart Diagram for BookBank System

Deployment Diagram and Component Diagram

Deployment diagrams are used to visualize the topology of the physical components of a system
where the software components are deployed.

Figure 9: Deployment Diagram for Book Bank System

8. Develop test cases for unit testing and integration testing

9. Develop test cases for various white box and black box testing techniques.

43
44
45
46
47
Dept. of IT CS506PC: SE & CN LAB
1. Implement the data link layer framing methods such as character, character-stuffing
and bit stuffing
Write a C program to implement the data link layer framing methods
such as bit stuffing.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
printf("enter frame length:");
scanf("%d",&n);
pritf("enter input frame(0's&1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0;count=1;j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1&&k<n&&count<5;k ++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}

Dept. of IT CS506PC: SE & CN LAB


printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
getch();
}

Output:

Enter the number of


bits: 10
1
0
1
0
1
1
1
1
1
1
1
Data after stuffing: 10101111101
Write a C program to implement the data link layer framing method
such as character stuffing.
Program Code: //Program for Character Stuffing
#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("Enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("Enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);}
printf("Enter the character\n");
ch=getche();

Dept. of IT CS506PC: SE & CN LAB


b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
}
Program Output:
Enter string
MLRITM

Dept. of IT CS506PC: SE & CN LAB


Enter position
2
Enter the character
frame after stuffing:
dlestxMdldleLRITMdleetx

Dept. of IT CS506PC: SE & CN LAB


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

// program for Cyclic Redundancy Check


#include<stdio.h>
#include<conio.h>
int main(void)
{
int data[50],div[16],rem[16];
int datalen, divlen, i,j,k;
int ch;
clrscr();
printf("Enter the data: ");
i = 0;
while((ch = fgetc(stdin)) != '\n')
{
if(ch == '1')
data[i] = 1;
else
data[i] = 0;
i++;
}
datalen = i;
printf("\nEnter the divisor: ");
i = 0;
while((ch = fgetc(stdin)) != '\n')
{
if(ch == '1')
div[i] = 1;
else
div[i] = 0;
i++;
}
divlen = i;
for(i = datalen ; i < datalen + divlen - 1 ; i++)
data[i] = 0;
datalen = datalen + divlen - 1;
for(i = 0 ; i < divlen ; i++)
rem[i] = data[i];
k = divlen-1;
while(k < datalen)

Dept. of IT CS506PC: SE & CN LAB


if(rem[0] == 1)
{
for(i = 0 ; i < divlen ; i++)
rem[i] = rem[i] ^ div[i];
}
else
{
if(k == datalen-1)
break;
for(i = 0 ; i < divlen-1 ; i++)
{
rem[i] = rem[i+1];
printf("%d",rem[i]);
}
rem[i] = data[++k];
printf("%d\n",rem[i]);
}
j=1;
for(i = datalen - divlen + 1 ; i < datalen ; i++)
{
data[i] = rem[j++];
}
printf("\nThe data to be sent is\n");
for(i = 0 ; i < datalen ; i++)
printf("%d",data[i]);
getch();
return 0;
}
OUTPUT:
Enter the data: 10101111 Enter the divisor: 1011
0011
0111
1111
1001
0100
1000
0110
The data to be sent is 10101111110

Dept. of IT CS506PC: SE & CN LAB


Dept. of IT CS506PC: SE & CN LAB
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

SLIDING WINDOW PROTOCOL,


#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent == windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);

if(ack == windowsize)
break;
else
sent = ack;
}
return 0;
}

output:-

Output
Enter window size: 3
Enter number of frames to transmit: 5
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner (assuming
no corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the
receiver
12 5 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender

Dept. of IT CS506PC: SE & CN LAB


GO BACK N PROTOCOL
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent == windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);

if(ack == windowsize)
break;
else
sent = ack;
}
return 0;
}
output:-
enter window size
8
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received.
2
Frame 2 has been transmitted.
Frame 3 has been transmitted.

Dept. of IT CS506PC: SE & CN LAB


Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.

Please enter the last Acknowledgement received.


8

Dept. of IT CS506PC: SE & CN LAB


4. Implement Dijsktra’s algorithm to compute the shortest path through a network

Write a C program to Implement Dijkstra’s Algorithm to compute the


shortest path through a given path.

#include<stdio.h>
#include<conio.h>
#define INFINITY
#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;

Dept. of IT CS506PC: SE & CN LAB


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=dista
nce[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);
}
}

Dept. of IT CS506PC: SE & CN LAB


Dept. of IT CS506PC: SE & CN LAB
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
#include<stdio.h>
int a[10][10],n;
main()
{
int i,j,root; clrscr();
printf("Enter no.of nodes:");
scanf("%d",&n);
printf("Enter adjacent matrix\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("Enter connecting of %d>%d::",i,j);
scanf("%d",&a[i][j]);
}
printf("Enter root node:"); scanf("%d",&root);
adj(root);
}
adj(int k)
{
int i,j;
printf("Adjacent node of root node::\n");
printf("%d\n",k);
for(j=1;j<=n;j++)
{
if(a[k][j]==1 || a[j][k]==1) printf("%d\t",j);
}
printf("\n"); for(i=1;i<=n;i++)
{
if((a[k][j]==0) && (a[i][k]==0) && (i!=k))
printf("%d",i);
}
} OUTPUT:
Enter no.of nodes: 5 Enter adjacent matrix
Enter connecting of 1–>1::0 Enter connecting of 1–>2::1 Enter connecting of 1–>3::1
Enter connecting of 1–>4::0 Enter connecting of 1–>5::0 Enter connecting of 2–>1::1
Enter connecting of 2–>2::0 Enter connecting of 2–>3::1 Enter connecting of 2–>4::1
Enter connecting of 2–>5::0 Enter connecting of 3–>1::1 Enter connecting of 3–>2::1
Enter connecting of 3–>3::0 Enter connecting of 3–>4::0 Enter connecting of 3–>5::0
Enter connecting of 4–>1::0 Enter connecting of 4–>2::1 Enter connecting of 4–>3::0
Enter connecting of 4–>4::0 Enter connecting of 4–>5::1 Enter connecting of 5–>1::0
Enter connecting of 5–>2::0
Enter connecting of 5–>3::0 Enter connecting of 5–>4::1 Enter connecting of 5–>5::0
Enter root node:2
Adjacent node of root node:
2
134
5

Dept. of IT CS506PC: SE & CN LAB


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

#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int dmat[20][20];
int n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
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<n;i++)
{
printf("\n\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
{
printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
}

Dept. of IT CS506PC: SE & CN LAB


OUTPUT:
[cseb332@Insat5E ~]$ cc dst.c
[cseb332@Insat5E ~]$ ./a.out

Enter the number of nodes : 4


Enter the cost matrix:
0 3 5 99
3 0 99 1
5402
99 1 2 0
State value for router 1 is
node 1 via 1 Distance0
node 2 via 2 Distance3
node 3 via 3 Distance5
node 4 via 2 Distance4
State value for router 2 is
node 1 via 1 Distance3
node 2 via 2 Distance0
node 3 via 4 Distance3
node 4 via 4 Distance1
State value for router 3 is
node 1 via 1 Distance5
node 2 via 4 Distance3
node 3 via 3 Distance0
node 4 via 4 Distance2
State value for router 4 is
node 1 via 2 Distance4
node 2 via 2 Distance1
node 3 via 3 Distance2
node 4 via 4 Distance0

Dept. of IT CS506PC: SE & CN LAB


7. Implement data encryption and data decryption
#include<stdio.h>
#include<conio.h>
#include<string.h>
int p10[]={3,5,2,7,4,10,1,9,8,6},
p8[]={6,3,7,4,8,5,10,9},
p4[]={2,4,3,1};
int ip[]={2,6,3,1,4,8,5,7},
ipinv[]={4,1,3,5,7,2,8,6},
ep[]={4,1,2,3,2,3,4,1};
int s0[][4]={{1,0,3,2,},{3,2,1,0},{0,2,1,3,},{3,1,3,2}};
int s1[][4]={{0,1,2,3},{2,0,1,3},{3,0,1,0},{2,1,0,3}};
void permute(char op[],char
ip[],int p[], int n){ int i;
for(i=0;i<n;i++) op[i]=ip[p[i]-1]; op[i]='\0';
}
void circularls(char pr[],int n){ int i;
char ch=pr[0]; for(i=0;i<n-1;i++) pr[i]=pr[i+1]; pr[i]=ch;
}
void keygen(char k1[],char k2[],char key[]){ char keytemp[11];
permute(keytemp,key,p10,10;
circularls(keytemp,5);
circularls(keytemp+5,5);
permute(k1,keytemp,p8,8);
circularls(keytemp,5);
circularls(keytemp,5);
circularls(keytemp+5,5);
circularls(keytemp+5,5);
permute(k2,keytemp,p8,8);
}
void xor(char op[],char ip[]){ int i;
for(i=0;i<strlen(op)&&i<str
len(ip);i++) op[i]=(op[i]-
'0')^(ip[i]-'0')+'0';
}
void sbox(char op[],char ip[],int s[][4]) { int value;
value=s[(ip[0]-'0')*2+(ip[3]-'0')][(ip[1]-'0')*2+(ip[2]-'0')];
op[0]=value/2+'0'; op[1]=value%2+'0'; op[2]='\0';
}
void fk(char op[],char ip[],char k[])
{
char l[5],r[5],tmp[9],tmp1[9],tmp2[9]; strncpy(l,ip,4);
l[4]='\0';
strncpy(r,ip+4,4); r[4]='\0';

Dept. of IT CS506PC: SE & CN LAB


permute(tmp,r,ep,8); xor(tmp,k);
sbox(tmp1,tmp,s0); sbox(tmp2,tmp+4,s1); strcat(tmp1,tmp2); permute(tmp,tmp1,p4,4);
xor(tmp,l);
strcat(tmp,r); strcpy(op,tmp);
}
void sw(char pr[]) { char tmp[9]; strncpy(tmp,pr+4,4); strncpy(tmp+4,pr,4); tmp[8]='\0';
strcpy(pr,tmp);
}
void main()
{
char key[11],k1[9],k2[9],plain[9],cipher[9],tmp[9]; clrscr();
printf("enter 10 bit key:"); gets(key);
if(strlen(key)!=10) printf("invalid key length !!"); else
{
keygen(k1,k2,key); printf("sub key k1::"); puts(k1); printf("subkey k2::"); puts(k2);
printf("enter 8 bit plain text:"); gets(plain);
if(strlen(plain)!=8) printf("invalid length plain text !!"); permute(tmp,plain,ip,8);
fk(cipher,tmp,k1); sw(cipher); fk(tmp,cipher,k2); permute(cipher,tmp,ipinv,8);
printf("cipher teaxt is::"); puts(cipher);
/* decryption process*/ permute(tmp,cipher,ip,8); fk(plain,tmp,k2); sw(plain);
fk(tmp,plain,k1); permute(plain,tmp,ipinv,8); printf("decrypted text is::"); puts(plain);
}
getch();
}

OUTPUT:
Enter 10 bit key: 1456987203 Sub key k1::17062538
Sub keyk2::25893401
Enter 8 bit plain text: computer Cipher text is::epfnmrct
Decrypted text is::computer

Dept. of IT CS506PC: SE &CNLAB

You might also like