CG Report NCC-2

You might also like

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

ABSTRACT

Main aim of this Mini Project is to illustrate the concepts and usage of Congestion Control in
OpenGL. In data networking and queuing theory, network congestion occurs when a link or
node is carrying so much data that its quality of service deteriorates. When more packets
were sent than could be handled by intermediate routers, the intermediate routers discarded
many packets, expecting the end points of the network to retransmit the information. When
this packet loss occurred, the end points sent extra packets that repeated the information lost,
doubling the data rate sent, exactly the opposite of what should be done during congestion.
This pushed the entire network into a 'congestion collapse' where most packets were lost and
the resultant throughput was negligible. We have used input devices like mouse and key
board to interact with program.

Page | 1
CONTENTS

Chapter no Chapter Name Page no


1 Introduction
1.1. To OpenGL 3
1.1.1 OpenGL Command Syntax 5
1.1.2 Pixel Operation 5
1.1.3 Texture Assembly 6
1.1.4 Rasterization 6
1.1.5 Immediate mode and display lists 7
1.1.6 Advantages of using OpenGL 7
1.2. To Network Congestion 8

2 System Requirements
2.1 Software Requirements
9
2.2 Hardware Requirements 9

3 Design and Implementation 10


3.1 Methodology
11
3.2 Algorithm with code 12
3.3 Interaction with program 35

4 Snapshots 36

5 Conclusion 40

6 Bibliography 40

Page | 2
Chapter 1

INTRODUCTION

1.1 OpenGL :

As a software interface for graphics hardware, OpenGL's main purpose is to render two- and
three-dimensional objects into a frame buffer. These objects are described as sequences of
vertices or pixels. OpenGL performs several processing steps on this data to convert it to
pixels to form the final desired image in the frame buffer. OpenGL Fundamentals This
section explains some of the concepts inherent in OpenGL. Primitives and Commands
OpenGL draws primitives—points, line segments, or polygons—subject to several selectable
modes. You can control modes independently of each other; that is, setting one mode doesn't
affect whether other modes are set .Primitives are specified, modes are set, and other OpenGL
operations are described by issuing commands in the form of function calls. Primitives are
defined by a group of one or more vertices. A vertex defines a point, an endpoint of a line, or
a corner of a polygon where two edges meet. Data is associated with a vertex, and each
vertex and its associated data are processed independently, in order, and in the same way. The
type of clipping depends on which primitive the group of vertices represents. Commands are
always processed in the order in which they are received, although there may be an
indeterminate delay before a command takes effect. This means that each primitive is drawn
completely before any subsequent command takes effect. It also means that state-querying
commands return data that's consistent with complete execution of all previously issued
OpenGL commands.

Most of our application will be designed to access OpenGL directly through functions in
three libraries. Functions in the main GL (or OpenGL in windows) library have names that
begin with the letters gl and are stored in a library usually referred to as GL (or OpenGL in
windows). The second is the OpenGL Utility Library(GLU). This library uses only GL
functions but contains code for creating common objects and simplifying viewing. All
functions in GLU can be created from the core GL library but application programmers prefer
not to write the code repeatedly. The GLU library is available in all OpenGL
implementations; functions in the GLU library begin with letters glu.

Page | 3
To interface with the window system and to get input from external devices into our
programs, developer needs at least one more library. For each major window system there
is a system-specific library that provides the “glu” between the window system and OpenGL.
For the X window system, this library is called GLX, for windows, it is wgl, and for the
Macintosh, it is agl. Rather than using a different library for each system, here it uses a readily
available library called the OpenGL Utility Toolkit(GLUT),which provides the minimum
functionality that should be expected in any modern windowing system.

Figure 1.1(a): Library Organization

Basic OpenGL Operation


The figure shown below gives an abstract, high-level block diagram of how OpenGL
processes data. In the diagram, commands enter from the left and proceed through what can
be thought of as a processing pipeline. Some commands specify geometric objects to be
drawn, and others control how the objects are handled during the various processing stages.
Figure . OpenGL Block Diagram As shown by the first block in the diagram, rather than
having all commands proceed immediately through the pipeline, you can choose to
accumulate some of them in a display list for processing at a later time. Rasterization
produces a series of frame buffer addresses and associated values using a two-dimensional
description of a point, line segment, or polygon. Each fragment so produced is fed into the
last stage, per-fragment operations, which performs the final operations on the data before it's
stored as pixels in the frame buffer. These operations include conditional updates to the frame
buffer based on incoming and previously stored z-value s (for z-buffering) and blending of
incoming pixel colors with stored colors, as well as masking and other logical operations on
pixel values. All elements of OpenGL state, including the contents of the texture memory and
even of the frame buffer, can be obtained by an OpenGL application.

Page | 4
Figure 1.1(b) : OpenGL Block Diagram

1.1.1 OpenGL command syntax

OpenGL commands use the prefix gl and initial capital letters for each word making up the
command name. Similarly, OpenGL defined constants begin with GL_, use all capital letters,
and use underscores to separate words (like GL_TRUE).

Some extraneous letters are appended to some command names (for example, the 3fin
glColor3f() and glVertex3f()). It's true that the Color part of the command name glColor3f() is
enough to define the command as one that sets the current color. However, more than one such
command has been defined so as to use different types of arguments. In particular, the 3 part
of the suffix indicates that three arguments are given; another version of the Color command
takes four arguments. The f part of the suffix indicates that the arguments are floating-point
numbers. Having different formats allows OpenGL to accept the user's data.

1.1.2 Pixel operation

Pixels from an array in system memory are first unpacked from one of a variety of formats into
the proper number of components. Next the data is scaled, biased, and processed by a pixel
map. The results are clamped and then either written into texture memory or sent to the
Rasterization step. If pixel data is read from the frame buffer, pixel-transfer operations(scale,

Page | 5
bias, mapping, and clamping) are performed. Then these results are packed into an appropriate
format and returned to an array in system memory. There are special pixel copy operations to
copy data in the frame buffer to other parts of the frame buffer or to the texture memory. A
single pass is made through the pixel transfer operations before the data is written to the texture
memory or back to the frame buffer.

1.1.3 Texture assembly

An OpenGL application may wish to apply texture images onto geometric objects to make
them look more realistic. Some OpenGL implementations may have special resources to
accelerate texture performance. There may be specialized, high-performance texture memory.

1.1.4 Rasterization

Rasterization is the conversion of both geometric and pixel data into fragments. Each fragment
square corresponds to a pixel in the frame buffer. Line and polygon stipples, line width, point
size, shading model, and coverage calculations to support initializing are taken into
consideration as vertices are connected into lines or the interior pixels are calculated fora filled
polygon. Color and depth values are assigned for each fragment square. Below figure shows
the block diagram of Rasterization.

Figure 1.1.4 : Block diagram showing Rasterization

Page | 6
1.1.5 Immediate mode and display lists

All data, whether it describes geometry or pixels, can be saved in a display list for current or
later use. When a display list is executed, the retained data is sent from the display list just as
if it were sent by the application in immediate mode.

Before clip coordinates can be converted to window coordinates, they are normalized by
dividing by the value of w to yield normalized device coordinates. After that, the view port
transformation applied to these normalized coordinates produces window coordinates. One can
control the viewport, which determines the area of the on-screen window that displays an
image, with glDepthRange() and glViewport().

1.1.6 Advantages of using OpenGL

• Industrystandard:Anindependentconsortium,theOpenGLArchitectureReviewBoard
,guidestheOpenGLspecification.Withbroadindustrysupport,OpenGListheonlytruly
open,vendor-neutral, multiplatform graphics standard.
• Stable: OpenGL implementations have been available for more than seven years on
awidevarietyofplatforms.Additionstothespecificationarewellcontrolled,andpropos
ed updates are announced in time for developers to adopt changes. Backward
compatibility requirements ensure that existing applications do not become
obsolete.
• Reliableandportable:AllOpenGLapplicationsproduceconsistentvisualdisplayresult
son any OpenGL API-compliant hardware, regardless of operating system or
windowing system.

• Evolving: Because of its thorough and forward-looking design, OpenGL allows


new hardware innovations to be accessible through the API via the OpenGL
extension mechanism. In this way, innovations appear in the API in a timely
fashion, letting application developers and hardware vendors incorporate new
features into the normal product release cycles.

Page | 7
1.2 Network congestion :
Network congestion control is an important area of research and development in computer
networks. With the rapid growth of network traffic and the increasing demand for high-speed
data transfer, network congestion has become a major concern for network administrators and
service providers. Congestion occurs when the demand for network resources exceeds the
available capacity, leading to a slowdown in data transfer, packet loss, and even network
failure.

To prevent congestion and maintain optimal network performance, various congestion control
strategies and algorithms have been developed. These strategies and algorithms aim to
manage network traffic and allocate resources efficiently, preventing congestion and ensuring
that data is transferred reliably and efficiently.

A network congestion control project involves implementing and testing these strategies and
algorithms in a real-world or simulated network environment. This project can involve the
development of new congestion control algorithms, the implementation and testing of
existing algorithms, or the evaluation of the effectiveness of different congestion control
strategies in specific network environments.

Overall, a network congestion control project requires a strong understanding of network


architecture, traffic management, and congestion control algorithms. It also requires expertise
in network configuration, testing, and evaluation to ensure that the congestion control
strategies and algorithms are effective in preventing congestion and maintaining optimal
network performance.

Figure 1.2 : Simple Free Network Congestion Control

Page | 8
Chapter 2

SYSTEM REQUIREMENTS
This chapter will focus on the software and hardware requirements of this mini project.

2.1 Software Requirements

➢ IDE : Code Blocks.


➢ Compiler : GNU / GCC Compiler.
➢ Graphics Library : OpenGL.

2.2 Hardware Requirements

➢ Processor : Intel Core i3 or higher.


➢ Memory : 1GB or more.
➢ Operating System : Windows / Linux / MacOS X

Page | 9
Chapter 3

DESIGN &IMPLEMENTATION
Built-in functions:

This program is implemented using various OpenGL functions which are shown below.
Various functions used in this program:

glutInit() : interaction between the windowing system and OPENGL is initiated.

glutInitDisplayMode() : used when double buffering is required and depth information is


required.

glutCreateWindow() : this opens the OPENGL window and displays the title at top of the
window.

glutInitWindowSize() : specifies the size of the window.

glutInitWindowPosition() : specifies the position of the window in screen co-ordinates.

glutKeyboardFunc() : handles normal ascii symbols.

glutSpecialFunc() : handles special keyboard keys.

glutReshapeFunc() : sets up the callback function for reshaping the window.

glutIdleFunc() : this handles the processing of the background.

glutDisplayFunc() : this handles redrawing of the window.

glutMainLoop() : this starts the main loop, it never returns.

glViewport() : used to set up the viewport.

glVertex3fv() : used to set up the points or vertices in three dimensions.

glColor3fv() : used to render color to faces.

glFlush() : used to flush the pipeline.

glutPostRedisplay() : used to trigger an automatic redrawal of the object.

glMatrixMode() : used to set up the required mode of the matrix.

Page | 10
glLoadIdentity() : used to load or initialize to the identity matrix.

glTranslatef() : used to translate or move the rotation centre from one point to another in three
dimensions.

glRotatef() : used to rotate an object through a specified rotation angle.

3.1 Methodology

The methodology for congestion control :

1. Traffic monitoring: Continuously monitor network traffic for congestion indicators.

2. Congestion detection: Analyse data to identify signs of congestion, such as increased


packet loss or delays.

3. Congestion notification: Notify relevant components or systems about congestion.

4. Congestion control algorithms: Implement appropriate algorithms to regulate data transmission


rates.

5. Traffic regulation: Adjust transmission rates to mitigate congestion, such as reducing packet counts
or adjusting window sizes.

6. Feedback loop: Continuously monitor network conditions and adapt congestion control parameters
based on feedback.

7. Congestion recovery: Employ additional mechanisms, like packet dropping or marking, to recover
from persistent congestion.

8. Testing and optimization: Evaluate and optimize congestion control methods through simulations
and performance measurements.

9. Documentation and maintenance: Document implemented strategies and regularly update to


address changing network conditions.

This methodology ensures effective congestion control, helping to maintain network performance and
prevent congestion-related issues in a small network setting.

Page | 11
3.2 Algorithm

1. Import the necessary header files: `GL/glut.h`, `windows.h`, `string.h`, `stdarg.h`, and
`stdio.h`.

2. Define function prototypes for drawing text and setting the font.

3. Declare global variables for positioning and animation.

4. Implement the `setFont` function to set the current font.

5. Implement the `drawstring` function to draw text at a given position.

6. Implement the `stroke_output` function to draw stroke text at a given position.

7. Implement the `cloud` function to draw a cloud shape using scaled and translated solid
spheres.

8. Implement the `router` function to draw a router shape using a torus.

9. Implement the `dte` function to draw a data terminal equipment shape using a wireframe
cube.

10. Implement the `line` function to draw a line loop using `glBegin(GL_LINE_LOOP)` and
`glEnd()`.

11. Implement the `line1` function to draw another line loop.

12. Implement the `rack` function to draw a rack shape using a solid cube.

13. Implement the `rack1` function to draw another rack shape.

14. Implement the `window` function to draw a window shape.

15. Implement the `top` function to draw a triangular top shape using
`glBegin(GL_TRIANGLES)` and `glEnd()`.

16. Implement the `animate` function for animation purposes.

17. Implement the `network` function to draw the entire network diagram.

18. Call the necessary OpenGL functions to set up the rendering environment.

19. Call the `network` function to draw the network diagram.

Page | 12
Program source code:
#include<GL/glut.h>
#include <windows.h>
#include<string.h>
#include<stdarg.h>
#include<stdio.h>
void *font;
void *currentfont;
static double x=0.0,x1=-3.5,x2=3.5,y1=-1.4,y2=-1.4,x3=-3.5,y3=1.3;
static double move=-60;
static bool goDown=false,goup=false,down=false,congested=false,remote=false;
void setFont(void *font)
{
currentfont=font;
}
void drawstring(float x,floaty,floatz,char *string)
{char *c;
glRasterPos3f(x,y,z);

for(c=string;*c!='\0';c++)
{ glColor3f(0.0,1.0,1.0);
glutBitmapCharacter(currentfont,*c);
}
}
void
stroke_output(GLfloat x, GLfloat y, char *format,...)
{ va_listargs;
char buffer[200], *p;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glPushMatrix();
glTranslatef(x, y,2);
glScaled(0.003, 0.005, 0.005);

Page | 13
for (p = buffer; *p; p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
}
void cloud(){
//vertical eclipse
glPushMatrix();
glTranslatef(0.0,0.0,0.0);
glScaled(1,3.5,0.1);
glColor3f(1,1,1);
glutSolidSphere(1,100,100);
glPopMatrix();
//horizotal eclipse
glPushMatrix();
glTranslatef(0.0,0.0,0.0);
glScaled(3,2.65,0.1);
glColor3f(1,1,1);
glutSolidSphere(1,100,100);
glPopMatrix();
glPushMatrix();
glScaled(3.5,1.8,0.1);
glRotatef(60,0.0f,1.0f,1.0f);
glTranslatef(0.0,0.0,0.0);
glColor3f(1,1,1);
glutSolidSphere(1,100,100);
glPopMatrix();
glPushMatrix();
glScaled(1.5,3.5,0.1);
glRotatef(50,0.0f,1.0f,1.0f);
glTranslatef(0.0,0.0,0.0);
glColor3f(1,1,1);
glutSolidSphere(1,100,100);
glPopMatrix();
}

Page | 14
void router(float x6, float y6,float z6)
{ glColor3f(0.2,0.3,1);
glPushMatrix();
glScaled(0.2,1.0,0.1);
glRotatef(91,1.0f,0.0f,0.0f);
glTranslatef(x6,y6,z6);
glutSolidTorus(0.2,1.5,100,100);
glPopMatrix();
}
void dte(float x1, float x2)
{ glPushMatrix();
glTranslatef(x1,x2,0.1);
glScaled(1,0.1,0.1);
glColor3f(1,1,1);
glRotatef(0,0.0f,1.0f,0.0f);
glutWireCube(1.5);
glPopMatrix();
}
void line()
{glPushMatrix();
glBegin(GL_LINE_LOOP);
glColor3f(1,0,0);
glVertex3f(0.1,-0.2,1);
glVertex3f(0.0,0,1);
glVertex3f(2,1.3,1);
glVertex3f(2.1,1.1,1);
glEnd();
glPopMatrix();
}
void line1()
{glPushMatrix();
glBegin(GL_LINE_LOOP);
glColor3f(1,0,0);
glVertex3f(0.2,2.5,1);

Page | 15
glVertex3f(0.1,2.3,1);
glVertex3f(2.1,1.1,1);
glVertex3f(2.3,1.2,1);
glEnd();
glPopMatrix();
}
void rack(float x1, float x2)
{glPushMatrix();
glScaled(0.35,.05,1.0);
glTranslatef(x1,x2,0.1);
glColor3f(0,0,0.3);
glutSolidCube(1.1);
glPopMatrix();
}
void rack1(float x1, float x2)
{glPushMatrix();
glScaled(1.75,.1,1.0);
glTranslatef(x1,x2,0.3);
glColor3f(0,0,1.3);
glutSolidCube(0.5);
glPopMatrix();
}
void window(float x1, float x2)
{glPushMatrix();
glScaled(0.5,.3,1.0);
glTranslatef(x1,x2,0.4);
glColor3f(0.1,0.1,0.1);
glutSolidCube(0.5);
glPopMatrix();
}
void top()
{glBegin(GL_TRIANGLES);
/* Front */
glColor3f(1.0f,1.0f,1.0f);

Page | 16
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f( 0.5f,-0.5f, 0.5f);

/* Left */
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(-0.5f,-0.5f,0.5f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(-0.5f,-0.5,-0.5f);

/* Right */
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(0.5f,-0.5f,0.5f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(0.5f,-0.5,-0.5f);

/* Back */
glColor3f(1.0f,1.0f,1.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(-0.5f,-0.5f, -0.5f);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f( 0.5f,-0.5f, -0.5f);
glEnd();
}
void animate();
void network()
{ glClearColor(0.0,0,0,0.0);

Page | 17
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
// glRotatef(ang,1.0f,1.0f,0.0f);

//Server
glPushMatrix();
glScaled(0.8,2.0,0.8);
glTranslatef(5,0.8,0.0);
glColor3f(0,1.5,1.5);
glutSolidCube(1);
glPushMatrix();
glScaled(0.5,.1,1.0);
glTranslatef(.0,3.5,0.01);
glColor3f(0.3,0.3,0.3);
glutSolidCube(1.5);
glPopMatrix();
rack1(.0,1);
rack1(.0,2);
rack1(.0,0);
rack(-1,-4);
rack(1,-4);
rack(-1,-6);
rack(1,-6);
rack(-1,-8);
rack(1,-8);
glPopMatrix();

//Home
glPushMatrix();
glScaled(0.8,1.0,0.8);
glTranslatef(4.8,-2.5,0.0);
glColor3f(1,1,0);
glutSolidCube(1);

Page | 18
glPushMatrix();
glScaled(.7,.1,1.0);
glTranslatef(0.0,4.5,0.2);
glColor3f(1.3,1.3,1.3);
glutSolidCube(1.5);
glPopMatrix();
glPushMatrix();
glScaled(0.12,.3,.75);
glTranslatef(0,-.75,0.02);
glColor3f(0.3,0.3,0.3);
glutSolidCube(1.5);
glPopMatrix();

// Top
glPushMatrix();
glTranslatef(0,.9,0);
top();
glPopMatrix();
window(-.6,-.3);
glPopMatrix();

//Office Building
glPushMatrix();
glScaled(0.8,2.0,0.8);
glTranslatef(-4.8,-1,0.0);
glColor3f(2,.5,.5);
glutSolidCube(1);
window(-.5,1.3);
window(.5,1.3);
window(-.5,0.5);
window(.5,0.5);
window(-.5,-0.3);
window(.5,-0.3);

Page | 19
window(-.5,-1.1);
window(.5,-1.1);
glPopMatrix();

// Remote User
glPushMatrix();
glTranslatef(-4.0,1.5,0.0);
glScaled(0.3,.3,.3);
glColor3f(1.3,1.3,1.3);
glutSolidCube(0.5);
glPopMatrix();

// Routers inside cloud


//router 5
router(10,10,1.15);

//router 2
router(-10,10,-1.3);

//router 1
router(-10,10,1.2);

//router 3
router(0,10,-2.5);
router(0,10,0);

//router 5
router(0,10,2.5);

//router 4
router(10.6,10,-1.2);

// Line 1
glPushMatrix();

Page | 20
glTranslatef(-2.1,0.0,0.5);
glScaled(0.1,1.8,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

// Link 2
glPushMatrix();
glTranslatef(-2,1.15,0);
line();
glPopMatrix();

// Link 3 to server
glPushMatrix();
glTranslatef(1.2,1.7,0.5);
glRotatef(57,0,0,1);
glScaled(0.15,1.7,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

// Link 4
glPushMatrix();
glTranslatef(0.85,0.4,0.5);
glRotatef(120,0,0,1);
glScaled(0.2,1.7,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

// Link 5
glPushMatrix();
glTranslatef(0,-2.6,0);
line();

Page | 21
glPopMatrix();

// Link 6
glPushMatrix();
glTranslatef(-2.2,-3.85,0);
line1();
glPopMatrix();

// Link 7(1step data transfer from ...)


glPushMatrix();
glTranslatef(-1.2,-0.85,0.5);
glRotatef(125,0,0,1);
glScaled(0.15,1.6,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

// Link 9
glPushMatrix();
glTranslatef(0.0,1.0,0.5);
glScaled(0.1,1.65,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

//R0 - R6
glPushMatrix();
glTranslatef(0.0,-1.6,0.5);
glScaled(0.1,1.65,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

//link 10 from home

Page | 22
glPushMatrix();
glTranslatef(1.05,-0.8,0.5);
glRotatef(52,0,0,1);
glScaled(0.15,1.6,0.1);
glColor3f(1,0,0);
glutWireCube(1.5);
glPopMatrix();

// Office Link to Cloud


dte(-3.0,-1.4);

// Home Link to Cloud


dte(3.0,-1.4);

// Server Link to Cloud


dte(3.0,1.1);

//Cloud Call Function


cloud();
glPushMatrix();
//glScaled(1.1,2.0,0.1);
glTranslatef(0.0,0.0,2.0);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-0.3,2.5,0.0,"CLOUD");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-2.1,-1.4,0.0,"R1");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-2.05,0.95,0.0,"R2");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(0,2,0.0,"R3");

Page | 23
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-0.1,-0.3,0.0,"R0");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(1.8,0.8,0.0,"R4");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(1.8,-1.35,0.0,"R5");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(0,-2.6,0.0,"R6");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(3,-2.1,0.0,"HACKER");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1.5,1.5,1.5);
drawstring(-3.7,-0.8,0.0,"OFFICE");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1.5,1.5,1.5);
drawstring(3,2.3,0.0,"SERVER");
glPopMatrix();

//Transtitions all together


animate();
glFlush();
glutSwapBuffers();
}
void animate(){
// Company to server Using path 1
glPushMatrix();
glTranslatef(x1,y1,0.2);
glScaled(0.1,0.1,0.1);
glColor3f(0,0,1);

Page | 24
glutSolidCube(0.5);
glPopMatrix();
if(remote){
glPushMatrix();
glTranslatef(x3,y3,0.2);
glScaled(0.1,0.1,0.1);
glColor3f(1,0,0.5);
glutSolidCube(0.5);
glPopMatrix();
}
if(congested)
{
glPushMatrix();
glTranslatef(x2,y2,0.2);
glScaled(0.1,0.1,0.1);
glColor3f(4,0,0);
glutSolidCube(0.5);
glPopMatrix();
}
}
void about()
{ glClearColor(0.5,0.5,0.5,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-4.2,2,0.0,"About Congestion Control");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
drawstring(-3.5,1.5,0.0,"* Congestion is a situation in Communication Networks in which too
many packets");
drawstring(-3.5,1,0.0," are present in a part of the subnet, performance degrades.");
drawstring(-3.5,.5,0.0,"* In data networking network congestion occurs when a link or node
");

Page | 25
drawstring(-3.5,0.0,0.0," is carrying so much data that its quality of service deteriorates.");
drawstring(-3.5,-0.5,0.0,"* Congestion control concerns controlling traffic entry into a ");
drawstring(-3.5,-1,0.0," telecommunications network, so as to avoid congestive collapse by
attempting ");
drawstring(-3.5,-1.5,0.0," to avoid oversubscription of any of the processing or link
capabilities ");
drawstring(-3.5,-2,0.0," of the intermediate nodes and networks and taking resource
reducing steps, ");
drawstring(-3.5,-2.5,0.0," such as reducing the rate of sending packets.");
drawstring(-3.5,-3,0.0,"* It should not be confused with flow control, which prevents the
sender from overwhelming the receiver.");
glFlush();
glutSwapBuffers();
}
void s()
{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
network();
}
void com_ser(){
// No congestion, take the best path
if(!congested && !remote)
{ if(x1>=-3.5 && y1==-1.4 && x1<=-2)
{ x1+=0.1;
}
if(x1>=-2 && y1>=-1.4 && x1<=2 && y1<=1.8)
{ x1+=0.1;
y1+=0.065;
}
if(x1>=2 && y1>=1 && x1<=3.8)
{ x1+=0.1;
y1=1.1;
}
}
//if Congested only from Hacker A
if(congested && x2>=2 && y2>=1 && !remote)

Page | 26
{ if(x1>=-3.5 && y1==-1.4 && x1<=-2){
x1+=0.1;
}
if(x1>=-2 && y1>=-1.4 && x1<=0 && y1<=0){
x1+=0.1;
y1+=0.07;
}
if(x1>=-0.05 && x1<=0.05 && y1<=0.05 && y1>=-0.05){
x1=0;
y1=0;
}
if(x1==0 && y1>=0 && y1<=2.6){
y1+=0.06;
}
if(x1==0 && y1>=2.5)
goDown=true;
if(goDown&& x1>=0 && x1<=2 && y1<=2.6 && y1>=1 ){
x1+=0.1;
y1-=0.06;
}
if(x1>=2 && y1>=1 && x1<=3.8){
x1+=0.1;
y1=1.1;
}
}
/ if congested only from Hacker B
if(remote && y3<=1 && !congested)
{ if(x1>=-3.5 && y1==-1.4 && x1<=-2){
x1+=0.1;
}
if(x1>=-2 && x1<=-0.2 && y1<=-1.4 && y1>=-3){
x1+=0.1;
y1-=0.08;
}

Page | 27
if(x1>=-0.3 && x1<=-0.2 && y1<=-2.7 && y1>=-3 &&goup==false){
x1=0;
y1=-3;
goup=true;
}
if(goup&& y1<=0){
x1=0.0;
y1+=0.1;
}
if(goup&& x1>=0 && y1>=0 && x1<=2 && y1<=1.8)
{ x1+=0.1;
y1+=0.055;
}
if(x1>=2 && y1>=1 && x1<=3.8)
{ x1+=0.1;
y1=1.1;
}
}
// if congested from both Hackers
if(remote && y3<=1 && congested)
{ if(x1>=-3.5 && y1==-1.4 && x1<=-2){
x1+=0.1;
}
if(x1>=-2 && x1<=-0.2 && y1<=-1.4 && y1>=-3){
x1+=0.1;
y1-=0.08;
}
if(x1>=-0.3 && x1<=-0.2 && y1<=-2.7 && y1>=-3 &&goup==false){
x1=0;
y1=-3;
goup=true;
}
if(goup&& y1<=2.6 &&goDown==false){

Page | 28
x1=0.0;
y1+=0.1;
}
if(x1==0 && y1>=2.5)
goDown=true;
if(goDown&& x1>=0 && x1<=2 && y1<=2.6 && y1>=1 ){
x1+=0.1;
y1-=0.06;
}
if(x1>=2 && y1>=1 && x1<=3.8){
x1+=0.1;
y1=1.1;
}
}
//congest the server link1, From hacker A to R
if(congested){
if(x2<=3.5 && y2==-1.4 && x2>=1.8)
{ x2-=0.1;
}
if(x2<1.8 && x2>=0 && y2<=0 && y2>=-1.4 )
{ x2-=0.1;
y2+=0.08;
}
if(x2>=-0.05 && x2<=0.051 && y2<=0.051 && y2>=-0.051){
x2=0;
y2=0;
}
if(x2>=0 && y2>=0 && x2<=2 && y2<=1.8){
x2+=0.1;
y2+=0.06;
}
}
// Congest from Hacker B to Company
if(remote)

Page | 29
{ if(x3>=-3.5 && y3==1.3 && x3<=-2)
{ x3+=0.1;
}
if(x3>=-2 && y3<=1.3 && x3<=1.5 && y3>=-1.5 && !down)
{ x3+=0.1;
y3-=0.065;
}
if(x3>=0.0 && y3<=0.0){
x3=0;y3=0;down=true;
}
if(x3<=0 && x3>=-2 && y3>=-1.4 && down)
{ x3-=0.1;
y3-=0.065;
}
}
network();
}
void doInit()
{/* Background and foreground color */
glClearColor(0.0,0.0,0.0,0);
glViewport(0,0,640,480);

/* Select the projection matrix and reset it then


setup our view perspective */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.1f,200.0f);

/* Select the modelview matrix, which we alter with rotatef() */


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

Page | 30
}

void display()
{
glClearColor(0.0,0.,0.,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(3.0,1.0,1.0);
drawstring(-1.7,3.0,0.0,"DEPARTMENT OF COMPUTER SCIENCE");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-2.0,2.5,0.0,"Computer Graphics Mini Project on CONGESTION CONTROL");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-1,2,0,"Using OPENGL");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-0.5,1.5,0,"By");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0, 1.0, 1.0);
drawstring(-2, 0.1, 0, "NAGAVENI N S (USN : 4GL20CS0015)");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0, 1.0, 1.0);
drawstring(-2, 0.5, 0, "NAVANEETH V D (USN : 4GL20CS016)");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0, 1.0, 1.0);
drawstring(-2, 0.9, 0, "RAJESH KOUNDINYA N(USN : 4GL20CS019)");
drawstring(-2,-0.5,0,"Press --> s to Start");
drawstring(-2,-1,0,"Press --> q to Quit");
GLfloatmat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloatmat_diffuse[]={0.0f,1.5f,.5f,1.0f};

Page | 31
GLfloatmat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloatmat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloatlightIntensity[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position3[]={0.0f,5.0f,5.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
}
void menu(int id)
{switch(id)
{ case 1:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutIdleFunc(s);
break;

case 2:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
goDown=false;
goup=false;
x=0.0;x1=-3.5;y1=-1.4;
x2=3.5;
y2=-1.4;
glutIdleFunc(com_ser);
break;
case 3:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
goDown=false;
down=false;

Page | 32
goup=false;
x=0.0;x1=-3.5;y1=-1.4;
x2=3.5;
y2=-1.4;
x3=-3.5,y3=1.3;
congested=true;
glutIdleFunc(com_ser);
break;

case 4:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
goDown=false;
down=false;
goup=false;
x=0.0;x1=-3.5;
x2=3.5;
y1=-1.4;
y2=-1.4;
x3=-3.5;y3=1.3;
remote=true;
glutIdleFunc(com_ser);
break;

case 5: congested=false;
goDown=false;down=false;
goup=false;
x=0.0;x1=-3.5;
x2=3.5;
y1=-1.4;
y2=-1.4;
x3=-3.5;y3=1.3;
glutIdleFunc(com_ser);
break;
case 6: remote=false;

Page | 33
down=false;
goDown=false;
goup=false;
x=0.0;x1=-3.5;
x2=3.5;
y1=-1.4;
y2=-1.4;
x3=-3.5;y3=1.3;
glutIdleFunc(com_ser);
break;
case 7:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutIdleFunc(about);
break;
case 8:exit(0);
break;
}
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void mykey(unsigned char key,intx,int y)
{ if(key=='s')
{ glutIdleFunc(s);
}
if(key=='q'||key=='Q')
{ exit(0);
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(1000,480);

Page | 34
glutInitWindowPosition(0,0);
glutCreateWindow("Local Area Network");
glutDisplayFunc(display);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
glutCreateMenu(menu);
glutAddMenuEntry("Send Some Data",2);
glutAddMenuEntry("Create Congestion From Hacker A",3);
glutAddMenuEntry("Create Congestion From Hacker B",4);
glutAddMenuEntry("Remove Congestion From Hacker A ",5);
glutAddMenuEntry("Remove Congestion From Hacker B ",6);
glutAddMenuEntry("About Project 'a/A'",7);
glutAddMenuEntry("Quit 'q'",8);
glutAttachMenu(GLUT_RIGHT_BUTTON);
doInit();
glutMainLoop();
}

3.3Interaction with program

This program includes interaction through keyboard.

• S -> Start the Project

• User Right mouse button to get menu and choose option accordingly.

• Q-> Quit

Page | 35
Chapter 4

SNAPSHOTS

Fig 4.1: Front view of program

Fig 4.1.1 : Above image shows - Options in a program

Page | 36
Fig 4.2 : Initial view before any data send

Fig 4.3 : Create congestion from Hacker A

Page | 37
Fig 4.4 : Create congestion from Hacker B

Fig 4.5 : Remove congestion from Hacker A

Page | 38
Fig 4.6 : Remove congestion from Hacker B

Fig 4.7 : “About Congestion Control” view in program

Page | 39
Chapter 5

CONCLUSION

The project “Network congestion control” demonstrates the successful implementation of OpenGL to
create a visually appealing and interactive network topology visualization. Through the utilization of
animation, descriptive labels, and data flow visualization, it effectively conveys the arrangement of
servers, routers, and links within the network. The code serves as a solid starting point for further
development and customization, allowing for additional features and enhancements to be
incorporated. By leveraging the power of OpenGL, this visualization tool has the potential to provide
valuable insights and improve understanding of complex network structures. With further refinement,
it can become a powerful tool for network administrators, researchers, and educators to analyse,
monitor, and communicate network topologies effectively.

Chapter 6

Bibliography

We have obtained information from many resources to design and implement our project
successively. We have acquired most of the knowledge from related websites. The following
are some of the resources :

1. Text books:

INTERACTIVE COMPUTER GRAPHICS A TOP-DOWN APPROACH – By Edward Angel.


COMPUTER GRAPHICS,PRINCIPLES & PRACTICES - By Foley van dam & Feiner hughes

2. Web references: http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson3.phphttp://google.com

http://opengl.org

Page | 40

You might also like