0% found this document useful (0 votes)
55 views3 pages

Exp 6

This document describes a program that simulates a dumbbell network topology with left and right leaf nodes connected by a router. It sets default packet size and data rate values. It creates point-to-point links between nodes and assigns IP addresses. On/off applications are installed on the right leaf nodes to generate traffic. An animation is configured to visualize packet and protocol data and the simulation is run for 10 seconds before ending.

Uploaded by

Kartik
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)
55 views3 pages

Exp 6

This document describes a program that simulates a dumbbell network topology with left and right leaf nodes connected by a router. It sets default packet size and data rate values. It creates point-to-point links between nodes and assigns IP addresses. On/off applications are installed on the right leaf nodes to generate traffic. An animation is configured to visualize packet and protocol data and the simulation is run for 10 seconds before ending.

Uploaded by

Kartik
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/ 3

EX P E RI M E N T 6

/* -*- M o d e:C + + ; c-file-s tyl e:" g n u"; in d e n t-t a b s-m o d e: nil; -*- */
/*
* This p r o g r a m is fr e e s oft w a r e ; yo u c a n r e di s t ri b u t e it a n d /o r m o dify
* it u n d e r t h e t e r m s of t h e G N U G e n e r al P u blic Lic e n s e ve r sio n 2 a s
* p u blis h e d by t h e F r e e S oft w a r e Fo u n d a tio n;
*
* This p r o g r a m is di s t ri b u t e d in t h e h o p e t h a t it will b e u s ef ul,
* b u t WIT H O UT ANY WARRANTY; wi t h o u t e v e n t h e i m pli e d w a r r a n t y of
* M E R C HA NTABILITY o r F IT N E S S F O R A PARTICULAR P UR P O S E. S e e t h e
* G N U G e n e r al P u blic Lic e n s e fo r m o r e d e t ails.
*
* You s h o ul d h a v e r e c eiv e d a c o py of t h e G N U G e n e r al P u blic Lic e n s e
* al o n g wi t h t hi s p r o g r a m ; if n o t, w ri t e t o t h e F r e e S oft w a r e
* Fo u n d a tio n, In c., 5 9 Te m pl e Pl a c e, S ui t e 3 3 0, Bos t o n, MA 0 2 1 1 1-1 3 0 7 U SA
*
* Aut h o r: G e o r g e F. Riley < ril ey@ e c e. g a t e c h. e d u >
*/

# i n cl u d e < i o s t r e a m >

# i n cl u d e "n s 3/c o r e-m o d ul e. h"


# i n cl u d e "n s 3/ n e t w o r k-m o d ul e. h"
# i n cl u d e "n s 3/i n t e r n e t-m o d ul e. h"
# i n cl u d e "n s 3/ p oi n t-t o-p oi n t-m o d ul e. h"
# i n cl u d e "n s 3/ n e t a ni m-m o d ul e. h"
# i n cl u d e "n s 3/ a p plic a tio n s-m o d ul e. h"
# i n cl u d e "n s 3/ p oi n t-t o-p oi n t-layo u t-m o d ul e. h"

u si n g n a m e s p a c e n s 3;

in t m ai n (in t a r g c, c h a r *a r gv[])
{
Co nfig:: S e tD ef a ul t ("n s 3::O n OffAp plic a tio n::P a c k e t Siz e", Ui n t e g e rVal u e
(5 1 2));
Co nfig:: S e tD ef a ul t ("n s 3::O n OffAp plic a tio n::D a t a R a t e", S t ri n gVal u e
("5 0 0 k b/ s"));

ui n t 3 2_t nL eftL e af = 5;
ui n t 3 2_t n Ri g h tL e af = 5;
ui n t 3 2_t nL e af = 0; // If n o n-z e r o, n u m b e r of b o t h left a n d ri g h t
s t d:: s t ri n g a ni m Fil e = "d u m b b ell-a ni m a tio n.x ml" ; // N a m e of file fo r
a ni m a tio n o u t p u t

Co m m a n dLi n e c m d;
c m d .Ad dValu e ("nL eftL e af", "N u m b e r of left si d e le af n o d e s", nL eftL e af);
c m d .Ad dValu e ("nRi g h tL e af"," N u m b e r of ri g h t si d e le af n o d e s", n Ri g h tL e af);
c m d .Ad dValu e ("nL e af", "N u m b e r of left a n d ri g h t si d e le af n o d e s", nL e af);
c m d .Ad dValu e (" a ni m Fil e", "File N a m e fo r Ani m a tio n O u t p u t", a ni m Fil e);
EX P E RI M E N T 6
c m d .P a r s e (a r g c, a r g v);
if (nL e af > 0)
{
nL eftL e af = nL e af;
n Ri g h tL e af = nL e af;
}

// C r e a t e t h e p oi n t-t o-p oi n t link h el p e r s


Poi n tToPoi n t H el p e r p oi n tToPoi n tRo u t e r;
p oi n tToPoi n tR o u t er.S e tD evic eAt t ri b u t e ("D a t a R a t e", S t ri n gVal u e
("1 0 M b p s"));
p oi n tToPoi n tR o u t er.S e t C h a n n elAtt ri b u t e ("D el ay", S t ri n gValu e ("1 m s"));
Poi n tToPoi n t H el p e r p oi n tToPoi n tL e af;
p oi n tToPoi n tL e af.S e t D evic eAt t ri b u t e ("D a t a R a t e", S t ri n gVal u e ("1 0 M b p s"));
p oi n tToPoi n tL e af.S e t C h a n n elAtt ri b u t e ("D el ay", S t ri n gVal u e ("1 m s"));

Poi n tToPoi n tD u m b b ell H el p e r d (nL eftL e af, p oi n tToPoi n tL e af,


n Ri g h tL e af, p oi n tToPoi n tL e af,
p oi n tToPoi n tR o u t e r);

// In s t all S t a c k
In t e r n e t S t a c k H el p e r s t a c k;
d.I n s t allS t a c k (s t a c k);

// Assi g n IP Ad d r e s s e s
d.As si g nI pv 4A d d r e s s e s (Ipv 4A d d r e s s H el p e r ("1 0. 1. 1. 0", "2 5 5. 2 5 5. 2 5 5. 0"),
Ipv 4Ad d r e s s H el p e r ("1 0. 2. 1. 0", "2 5 5. 2 5 5. 2 5 5. 0"),
Ipv 4Ad d r e s s H el p e r ("1 0. 3. 1. 0", "2 5 5. 2 5 5. 2 5 5. 0"));

// In s t all o n/off a p p o n all ri g h t si d e n o d e s


O n OffH el p e r cli e n t H el p e r ("n s 3:: U d p S o c k e tF a c t o ry", Ad d r e s s ());
cli e n t H el p er. S e tAt t ri b u t e ("O nTi m e", S t ri n gVal u e
("n s 3:: U nifo r m R a n d o mVa ri a bl e"));
cli e n t H el p er. S e tAt t ri b u t e ("OffTi m e", S t ri n gVal u e
("n s 3:: U nifo r m R a n d o mVa ri a bl e"));
Applic a tio n C o n t ai n e r clie n tA p p s;

fo r (ui n t 3 2_t i = 0; i < d .Ri g h t C o u n t (); + + i )


{
// C r e a t e a n o n/off a p p s e n di n g p a c k e t s t o t h e s a m e le af ri g h t si d e
Ad d r e s sVal u e r e m o t eA d d r e s s (In e t S o c k e tA d d r e s s (d.G e tL eftI pv 4Ad d r e s s
(i), 1 0 0 0));
cli e n t H el p er.S e tAt t ri b u t e ("R e m o t e", r e m o t eA d d r e s s);
cli e n tA p p s.Ad d (cli e n t H el p er.I n s t all (d.G e tRi g h t (i)));
}

cli e n tAp p s. S t a r t (S e c o n d s (0. 0));


cli e n tAp p s. S t o p (S e c o n d s (1 0. 0));
EX P E RI M E N T 6
// S e t t h e b o u n di n g b ox fo r a ni m a tio n
d.Bo u n di n gBox (1, 1, 1 0 0, 1 0 0);

// C r e a t e t h e a ni m a tio n o bj e c t a n d c o nfig u r e fo r s p e cifi e d o u t p u t


Ani m a tio nI n t e rf a c e a ni m ( a ni m Fil e);
a ni m . E n a bl eP a c k e t M e t a d a t a (); // O p tio n al
a ni m . E n a bl eI pv 4L 3 P r o t o c olCo u n t e r s (S e c o n d s (0), S e c o n d s (1 0)); // O p tio n al

// S e t u p t h e a c u t al si m ul a tio n
Ipv 4Glo b alRo u ti n g H el p e r::Po p ul a t e R o u ti n gT a bl e s ();

Si m ul a t o r::R u n ();
s t d::c o u t < < "Ani m a tio n Tr a c e file c r e a t e d:" < < a ni m Fil e. c_s t r () < <
s t d:: e n dl;
Si m ul a t o r::D e s t r oy ();
r e t u r n 0;
}

You might also like