Total Pageviews
Wednesday, February 14, 2024
QUEUE TYPE
DIFFERENT COLOR NODE
LARGE TOPOLOGY
|
|
TOPOLOGY
|
The following piece of Tcl code creates three duplex links between the nodes.
|
You can save and start the script now. You might notice that the topology looks a bit awkward in nam. You can hit the 're-layout' button to make it look better, but it would be nice to have some more control over the layout. Add the next three lines to your Tcl script and start it again.
|
You will probably understand what this code does when you look at the topology in the nam window now. It should look like the picture below.
DUPLEX LINK
$ns duplex-link node1 node2 bandwidth delay queue-type
|
A new node object is created with the command '$ns node'. The above code creates two nodes and assigns them to the handles 'n0' and 'n1'.
The next line connects the two nodes.
|
This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the bandwidth 1Megabit, a delay of 10ms and a DropTail queue.
NODE CREATION
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns color 1 blue: is to set color of the packets for a flow specified by the flow id (fid).
$n3 shape "square"
$n3 color "black"
$n0 shape "square"
$n0 color "blue"
UDP
#Setup a UDP connection
set udp [new Agent/UDP]$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
TCP
1. #Setup a TCP connection(ftp)
set tcp [new Agent/TCP]$tcp set class_ 3
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
Introduction to ns2
1.Network protocol stack written in C++
2.Tcl (Tool Command Language) used for
specifying scenarios and events.
3. Simulates both wired and wireless networks.
4.Ns, the simulator itself
5.Nam, the network animator--Nam editor: GUI interface to generate ns scripts
NAM (NETWORK ANIMATOR)
-> PROVIDES A VISUAL INTERPRETATION OF THE NETWORK CREATED
-> CONTROLS PLAY,FAST FORWARD,REWIND,PAUSE
X-GRAPH
->INTERACTIVE PLOTTING,GRAPHING ANIMATED AND DERIVATIVES
->SIZE 800x400
Tuesday, February 13, 2024
21. WAP to implement Symmetric Matrix using one-dimensional array.
21. WAP to implement Symmetric Matrix using one-dimensional array.
PROGRAME CODE
#include<stdio.h>
#include<iostream>
using namespace std;
class symmetric{
int
arr[50][50],row,col,arr1[50][50],arr2[100];
public:
symmetric(){
row=0;
col=0;
}
void
getdata(){
cout<<"ENTER
THE VALUE OF THE ROW ......."<<endl;
cin>>row;
cout<<"ENTER
THE VALUE OF THE COLOM ......."<<endl;
cin>>col;
cout<<"ENTER
THE ELEMENTS OF THE MATRIX ......."<<endl;
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++)
cin>>arr[i][j];
}
if(check())
cout<<"THE
MATRIX IS A SYMMETRIC MATRIX ....."<<endl;
else
cout<<"THE
MATRIX IS A ASYMMETRIC MATRIX....."<<endl;
}
int
check(){
int
m=0,n=0,r=0,q=0;
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++)
arr1[j][i]=arr[i][j];
}
for(int
k=0;k<row;k++){
for(int
l=0;l<col;l++){
if(arr[k][l]!=arr1[k][l])
return
0;
}
}
return
1;
}
void
dispaly(){
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++)
cout<<arr[i][j]<<" ";
cout<<endl;
}
}
void
present_sym(){
int
k=0;
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++){
arr2[k]=arr[i][j];
k++;
}
}
cout<<"THE
SYMMETRIC ELEMENTS ARE ->"<<endl;
for(int
p=0;p<(row*col);p++)
cout<<arr2[p]<<" ";
cout<<endl;
}
};
int main(){
symmetric
ob;
int
opt=0;
do{
cout<<"\nPRESS
0 TO EXIT ........"<<endl;
cout<<"PRESS
1 TO ENTER DATA ......."<<endl;
cout<<"PRESS
2 TO DISPLAY MATRIX ....."<<endl;
cout<<"PRESS
3 TO DISPLAY ALL SYMMETRIC ELEMENTS ......"<<endl;
cin>>opt;
switch(opt){
case
0:
break;
case
1:
ob.getdata();
break;
case
2:
ob.dispaly();
break;
case
3:
ob.present_sym();
break;
default:
cout<<"ERROR
CHOICE ........."<<endl;
}
}while(opt!=0);
return
0;
}
20. WAP to implement Upper Triangular Matrix using one-dimensional array.
20. WAP to implement Upper Triangular Matrix using one-dimensional array.
PROGRAME CODE
#include<stdio.h>
#include<iostream>
using namespace std;
class utm{
int
arr[50][50],row,col,arr1[100];
public:
utm(){
row=0;
col=0;
}
void
getdata(){
cout<<"ENTER
THE VALUE OF THE ROW ......"<<endl;
cin>>row;
cout<<"ENTER
THE VALUE OF THE COLOM ....."<<endl;
cin>>col;
cout<<"ENTER
THE MATRIX ELEMENTS ........"<<endl;
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++)
cin>>arr[i][j];
}
if(check())
cout<<"THE
MATRIX IS A UPPER TRIANGULAR MATRIX ....."<<endl;
else
cout<<"THE
MATRIX IS NOT A UPPER TRIANGULAR MATRIX ......"<<endl;
}
int
check(){
int
flag1=0,flag2=0;
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++){
if(i<=j&&arr[i][j]==0)
flag1++;
if(i>j&&arr[i][j]!=0)
flag2++;
}
}
if(flag1!=0||flag2!=0)
return
0;
else
return
1;
}
void
utm1(){
int
k=0,k2=0;
int
k1=row;
while(row>0){
k=k+row;
row--;
}
row=k1;
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++){
if(arr[i][j]!=0){
arr1[k2]=arr[i][j];
k2++;
}
}
}
cout<<"THE
UPPER TRI-DIAGONAL ELEMENTS ARE -> "<<endl;
for(int
p=0;p<k;p++)
cout<<arr1[p]<<"
";
cout<<endl;
}
void
display(){
for(int
i=0;i<row;i++){
for(int
j=0;j<col;j++)
cout<<arr[i][j]<<" ";
cout<<endl;
}
}
};
int main(){
int opt=0;
utm
ob;
do{
cout<<"\nPRESS
0 TO EXIT ........."<<endl;
cout<<"PRESS
1 TO ENTER MATRIX ........"<<endl;
cout<<"PRESS
2 TO DISPLAY MATRIX ......"<<endl;
cout<<"PRESS
3 TO DISPLAY UPPER TRIANGULAR ELEMENTS ......."<<endl;
cin>>opt;
switch(opt){
case
0:
break;
case
1:
ob.getdata();
break;
case
2:
ob.display();
break;
case
3:
ob.utm1();
break;
default:
cout<<"ERROR
CHOICE............."<<endl;
}
}while(opt!=0);
return
0;
}