├── BellmanFord.java ├── Client.java ├── Crc.java ├── LICENSE ├── Leaky.java ├── OUTPUT ├── 3-XGRAPH - 1.JPG ├── 3-XGRAPH - 2.JPG ├── 3-XGRAPH - 3.JPG ├── OUTPUT1.JPG ├── OUTPUT10.jpg ├── OUTPUT11.jpg ├── OUTPUT12.jpg ├── OUTPUT2.JPG ├── OUTPUT3.JPG ├── OUTPUT4.JPG ├── OUTPUT5.JPG ├── OUTPUT6.jpg ├── OUTPUT7.jpg ├── OUTPUT8.jpg ├── OUTPUT9.jpg ├── STEPS1.JPG ├── STEPS2.JPG ├── STEPS3.jpg ├── STEPS4.JPG └── STEPS5.JPG ├── README.md ├── RSA.java ├── Server.java ├── UDPClient.java ├── UDPServer.java ├── cn1.AWK ├── cn1.tcl ├── cn2.AWK ├── cn2.tcl ├── cn3.AWK ├── cn3.tcl ├── cn4.AWK ├── cn4.tcl ├── cn5.AWK ├── cn5.tcl ├── cn6.tcl └── file.txt /BellmanFord.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BellmanFord 4 | { 5 | int d[],noofvertices; 6 | public BellmanFord(int noofvertices) 7 | { 8 | this.noofvertices = noofvertices; 9 | d = new int[noofvertices + 1]; 10 | } 11 | 12 | public static void main(String[] args) 13 | { 14 | int noofvertices,source; 15 | Scanner s = new Scanner(System.in); 16 | System.out.println("Enter the number of vertices:"); 17 | noofvertices = s.nextInt(); 18 | 19 | int a[][] = new int[noofvertices + 1][noofvertices + 1]; 20 | System.out.println("Enter the adjacency matrix:"); 21 | for(int sn = 1; sn <= noofvertices; sn++) { 22 | for(int dn = 1; dn <= noofvertices; dn++) { 23 | a[sn][dn] = s.nextInt(); 24 | if(sn == dn) { 25 | a[sn][dn] = 0; 26 | continue; 27 | } 28 | if(a[sn][dn] == 0) 29 | a[sn][dn] = 999; 30 | } 31 | } 32 | 33 | System.out.println("Enter src vertex:"); 34 | source = s.nextInt(); 35 | BellmanFord b = new BellmanFord(noofvertices); 36 | b.bellmanFordeval(source,a); 37 | } 38 | 39 | private void bellmanFordeval(int source, int[][] a) 40 | { 41 | for(int node = 1; node <= noofvertices; node++) 42 | d[node] = 999; 43 | d[source] = 0; 44 | 45 | for(int node = 1; node <= noofvertices-1; node++) 46 | for(int sn=1; sn <= noofvertices; sn++) 47 | for(int dn = 1;dn <= noofvertices; dn++) 48 | if(a[sn][dn] != 999) 49 | if(d[dn] > d[sn]+a[sn][dn]) 50 | d[dn] = d[sn]+a[sn][dn]; 51 | 52 | for(int sn = 1; sn <= noofvertices; sn++) 53 | for(int dn = 1; dn <= noofvertices; dn++) 54 | if(d[dn] > d[sn]+a[sn][dn]) 55 | System.out.println("-ve cycle"); 56 | 57 | for(int vertex = 1; vertex <= noofvertices; vertex++) 58 | System.out.println( source+" to "+ vertex +" is "+ d[vertex] ); 59 | } 60 | } -------------------------------------------------------------------------------- /Client.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | import java.util.Scanner; 4 | 5 | public class Client 6 | { 7 | public static void main(String[] args) throws Exception 8 | { 9 | Scanner s=new Scanner(System.in); 10 | System.out.println("Enter file name:"); 11 | String fname=s.next(); 12 | Socket socket=new Socket("127.0.0.1",4000); 13 | 14 | OutputStream osStream=socket.getOutputStream(); 15 | PrintWriter pwWriter=new PrintWriter(osStream,true); 16 | pwWriter.println(fname); 17 | 18 | InputStream inStream=socket.getInputStream(); 19 | Scanner sin=new Scanner(inStream); 20 | while(sin.hasNext()) 21 | System.out.println(sin.next()); 22 | } 23 | } -------------------------------------------------------------------------------- /Crc.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Crc { 3 | 4 | static int n,m,msb,i,j,k,g[],d[],z[],r[]; 5 | public static void main(String[] args) 6 | { 7 | Scanner s=new Scanner(System.in); 8 | 9 | System.out.println("Enter no. of databits:"); 10 | n=s.nextInt(); 11 | 12 | System.out.println("Enter no. of generator bits:"); 13 | m=s.nextInt(); 14 | 15 | d=new int[m+n]; 16 | g=new int[n]; 17 | 18 | System.out.println("Enter databits:"); 19 | for(i=0;i 0 && e.compareTo(phi) < 0) 20 | e.add(BigInteger.ONE); 21 | d = e.modInverse(phi); 22 | } 23 | 24 | public RSA(BigInteger e, BigInteger d, BigInteger N) 25 | { 26 | this.e = e; 27 | this.d = d; 28 | this.N = N; 29 | } 30 | 31 | public static void main(String[] args) throws IOException 32 | { 33 | RSA rsa = new RSA(); 34 | DataInputStream in = new DataInputStream(System.in); 35 | String teststring; 36 | System.out.println("Enter the plain text:"); 37 | teststring = in.readLine(); 38 | System.out.println("Encrypting String: " + teststring+" "); 39 | System.out.println("String in Bytes: " + bytesToString(teststring.getBytes())); 40 | 41 | byte[] encrypted = rsa.encrypt(teststring.getBytes()); 42 | 43 | byte[] decrypted = rsa.decrypt(encrypted); 44 | System.out.println("Decrypting Bytes: " + bytesToString(decrypted)); 45 | System.out.println("Decrypted String: " + new String(decrypted)); 46 | } 47 | 48 | private static String bytesToString(byte[] encrypted) 49 | { 50 | String test = ""; 51 | for(byte b : encrypted) 52 | test += Byte.toString(b); 53 | return test; 54 | } 55 | 56 | public byte[] encrypt(byte[] message) 57 | { 58 | return (new BigInteger(message)).modPow(e, N).toByteArray(); 59 | } 60 | 61 | public byte[] decrypt(byte[] message) 62 | { 63 | return (new BigInteger(message)).modPow(d, N).toByteArray(); 64 | } 65 | } -------------------------------------------------------------------------------- /Server.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | import java.util.Scanner; 4 | 5 | public class Server 6 | { 7 | public static void main(String[] args) throws Exception 8 | { 9 | System.out.println("Server ready for communication"); 10 | ServerSocket serverSocket=new ServerSocket(4000); 11 | Socket socket=serverSocket.accept(); 12 | 13 | InputStream iStream=socket.getInputStream(); 14 | Scanner sin=new Scanner(iStream); 15 | String fname=sin.next(); 16 | 17 | OutputStream oStream=socket.getOutputStream(); 18 | PrintWriter pWriter=new PrintWriter(oStream,true); 19 | File file=new File(fname); 20 | Scanner fin=new Scanner(file); 21 | while(fin.hasNext()) 22 | pWriter.println(fin.next()); 23 | System.out.println("Connection is successful and file contents are displayed in the client window"); 24 | } 25 | } -------------------------------------------------------------------------------- /UDPClient.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | 3 | public class UDPClient { 4 | public static void main(String[] args) throws Exception{ 5 | DatagramSocket socket=new DatagramSocket(4000); 6 | byte data[]=new byte[1000]; 7 | 8 | while(true) { 9 | DatagramPacket request=new DatagramPacket(data, data.length); 10 | socket.receive(request); 11 | String str=new String(request.getData()); 12 | System.out.println(str); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /UDPServer.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.util.Scanner; 3 | 4 | public class UDPServer { 5 | public static void main(String[] args) throws Exception{ 6 | Scanner in = new Scanner(System.in); 7 | DatagramSocket socket=new DatagramSocket(); 8 | String msg=in.nextLine(); 9 | 10 | byte code[]=msg.getBytes(); 11 | InetAddress iAddress=InetAddress.getByName("127.0.0.1"); 12 | DatagramPacket request=new DatagramPacket(code,code.length,iAddress,4000); 13 | socket.send(request); 14 | } 15 | } -------------------------------------------------------------------------------- /cn1.AWK: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | count=0; 3 | total=0; 4 | } 5 | { 6 | event=$1; 7 | if(event=="d") { 8 | count++; 9 | } 10 | } 11 | END { 12 | printf("No of packets dropped : %d\n",count); 13 | } -------------------------------------------------------------------------------- /cn1.tcl: -------------------------------------------------------------------------------- 1 | # Simulation parameters setup 2 | set val(stop) 6.0 ; # stopping time of the simulation 3 | 4 | # Initialization 5 | #Create a ns simulator 6 | set ns [new Simulator] 7 | 8 | #Open the NS trace file 9 | set tracefile [open 1.tr w] 10 | $ns trace-all $tracefile 11 | 12 | #Open the NAM trace file 13 | set namfile [open 1.nam w] 14 | $ns namtrace-all $namfile 15 | 16 | # Nodes Definition 17 | #Create 3 nodes 18 | set n1 [$ns node] 19 | set n2 [$ns node] 20 | set n3 [$ns node] 21 | 22 | # Links Definition 23 | #Createlinks between nodes 24 | $ns duplex-link $n1 $n2 1000Kb 60ms DropTail 25 | $ns queue-limit $n1 $n2 14 26 | $ns duplex-link $n2 $n3 500Kb 60ms DropTail 27 | $ns queue-limit $n2 $n3 4 28 | $ns duplex-link-op $n1 $n2 queuePos 0.5 29 | $ns duplex-link-op $n2 $n3 queuePos 0.2 30 | 31 | # Agents Definition 32 | #Setup a TCP connection 33 | set tcp0 [new Agent/TCP] 34 | $ns attach-agent $n1 $tcp0 35 | set sink1 [new Agent/TCPSink] 36 | $ns attach-agent $n3 $sink1 37 | $ns connect $tcp0 $sink1 38 | $tcp0 set packetSize_ 1500 39 | 40 | # Applications Definition 41 | #Setup a FTP Application over TCP connection 42 | set ftp0 [new Application/FTP] 43 | $ftp0 attach-agent $tcp0 44 | $ns at 0.2 "$ftp0 start" 45 | $ns at 5.0 "$ftp0 stop" 46 | 47 | # Termination 48 | #Define a 'finish' procedure 49 | proc finish {} { 50 | global ns tracefile namfile 51 | $ns flush-trace 52 | close $tracefile 53 | close $namfile 54 | exec nam 1.nam & 55 | exit 0 56 | } 57 | 58 | $ns at $val(stop) "$ns nam-end-wireless $val(stop)" 59 | $ns at $val(stop) "finish" 60 | $ns at $val(stop) "puts \"done\" ; $ns halt" 61 | $ns run 62 | -------------------------------------------------------------------------------- /cn2.AWK: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | count=0; 3 | } 4 | { 5 | event=$1; 6 | if(event=="d") { 7 | count++; 8 | } 9 | } 10 | END { 11 | printf("No of packets dropped : %d\n",count); 12 | } -------------------------------------------------------------------------------- /cn2.tcl: -------------------------------------------------------------------------------- 1 | set val(stop) 10.0 ; # time of simulation end 2 | 3 | #Create a ns simulator 4 | set ns [new Simulator] 5 | 6 | #Open the NS trace file 7 | set tracefile [open 3.tr w] 8 | $ns trace-all $tracefile 9 | 10 | #Open the NAM trace file 11 | set namfile [open 3.nam w] 12 | $ns namtrace-all $namfile 13 | 14 | #Create 7 nodes 15 | set n0 [$ns node] 16 | set n1 [$ns node] 17 | set n2 [$ns node] 18 | set n3 [$ns node] 19 | set n4 [$ns node] 20 | set n5 [$ns node] 21 | set n6 [$ns node] 22 | 23 | #Create links between nodes 24 | $ns duplex-link $n0 $n1 1Mb 50ms DropTail 25 | $ns queue-limit $n0 $n1 50 26 | $ns duplex-link $n0 $n3 1Mb 50ms DropTail 27 | $ns queue-limit $n0 $n3 50 28 | $ns duplex-link $n0 $n4 1Mb 50ms DropTail 29 | $ns queue-limit $n0 $n4 50 30 | $ns duplex-link $n0 $n5 1Mb 50ms DropTail 31 | $ns queue-limit $n0 $n5 2 32 | $ns duplex-link $n0 $n2 1Mb 50ms DropTail 33 | $ns queue-limit $n0 $n2 2 34 | $ns duplex-link $n0 $n6 1Mb 50ms DropTail 35 | $ns queue-limit $n0 $n6 1 36 | 37 | #Give node position (for NAM) 38 | $ns duplex-link-op $n0 $n1 orient right-up 39 | $ns duplex-link-op $n0 $n2 orient right 40 | $ns duplex-link-op $n0 $n3 orient right-down 41 | $ns duplex-link-op $n0 $n4 orient left-down 42 | $ns duplex-link-op $n0 $n5 orient left 43 | $ns duplex-link-op $n0 $n6 orient left-up 44 | 45 | Agent/Ping instproc recv {from rtt} { 46 | $self instvar node_ 47 | puts "node [$node_ id] received ping answer from $from with round-trip-time $rtt ms." 48 | } 49 | 50 | set p1 [new Agent/Ping] 51 | set p2 [new Agent/Ping] 52 | set p3 [new Agent/Ping] 53 | set p4 [new Agent/Ping] 54 | set p5 [new Agent/Ping] 55 | set p6 [new Agent/Ping] 56 | 57 | $ns attach-agent $n1 $p1 58 | $ns attach-agent $n2 $p2 59 | $ns attach-agent $n3 $p3 60 | $ns attach-agent $n4 $p4 61 | $ns attach-agent $n5 $p5 62 | $ns attach-agent $n6 $p6 63 | 64 | $ns connect $p1 $p4 65 | $ns connect $p2 $p5 66 | $ns connect $p3 $p6 67 | 68 | $ns at 0.2 "$p1 send" 69 | $ns at 0.4 "$p2 send" 70 | $ns at 0.6 "$p3 send" 71 | $ns at 1.0 "$p4 send" 72 | $ns at 1.2 "$p5 send" 73 | $ns at 1.4 "$p6 send" 74 | 75 | proc finish {} { 76 | global ns tracefile namfile 77 | $ns flush-trace 78 | close $tracefile 79 | close $namfile 80 | exec nam 3.nam & 81 | exit 0 82 | } 83 | 84 | $ns at $val(stop) "$ns nam-end-wireless $val(stop)" 85 | $ns at $val(stop) "finish" 86 | $ns at $val(stop) "puts \"done\" ; $ns halt" 87 | $ns run 88 | 89 | -------------------------------------------------------------------------------- /cn3.AWK: -------------------------------------------------------------------------------- 1 | BEGIN{} 2 | { 3 | if($6=="cwnd_") 4 | { printf("%f\t%f\n",$1,$7); } 5 | } 6 | END{} -------------------------------------------------------------------------------- /cn3.tcl: -------------------------------------------------------------------------------- 1 | # Simulation parameters setup 2 | set val(stop) 10.0 ;# time of simulation end 3 | 4 | # Initialization 5 | #Create a ns simulator 6 | set ns [new Simulator] 7 | 8 | #Open the NS trace file 9 | set tracefile [open 5.tr w] 10 | $ns trace-all $tracefile 11 | 12 | #Open the NAM trace file 13 | set namfile [open 5.nam w] 14 | $ns namtrace-all $namfile 15 | $ns color 1 Blue 16 | $ns color 2 Red 17 | 18 | # Nodes Definition 19 | #Create 9 nodes 20 | set n0 [$ns node] 21 | set n1 [$ns node] 22 | set n2 [$ns node] 23 | set n3 [$ns node] 24 | set n4 [$ns node] 25 | set n5 [$ns node] 26 | set n6 [$ns node] 27 | set n7 [$ns node] 28 | set n8 [$ns node] 29 | 30 | # Create LAN 31 | $ns make-lan "$n3 $n4 $n5 $n6 $n7 $n8" 512Kb 50ms LL Queue/DropTail 32 | 33 | # Links Definition 34 | #Createlinks between nodes 35 | $ns duplex-link $n1 $n0 2.0Mb 50ms DropTail 36 | $ns queue-limit $n1 $n0 50 37 | $ns duplex-link $n2 $n0 2.0Mb 50ms DropTail 38 | $ns queue-limit $n2 $n0 50 39 | $ns duplex-link $n0 $n3 1.0Mb 50ms DropTail 40 | $ns queue-limit $n0 $n3 7 41 | #Give node position (for NAM) 42 | $ns duplex-link-op $n1 $n0 orient right-down 43 | $ns duplex-link-op $n2 $n0 orient right-up 44 | $ns duplex-link-op $n0 $n3 orient right 45 | 46 | # Agents Definition 47 | #Setup a TCP/Reno connection 48 | set tcp0 [new Agent/TCP/Reno] 49 | $ns attach-agent $n1 $tcp0 50 | set sink1 [new Agent/TCPSink] 51 | $ns attach-agent $n7 $sink1 52 | $ns connect $tcp0 $sink1 53 | $tcp0 set packetSize_ 1500 54 | $tcp0 set class_ 1 55 | set tfile1 [open cwnd1.tr w] 56 | $tcp0 attach $tfile1 57 | $tcp0 trace cwnd_ 58 | 59 | #Setup a TCP/Vegas connection 60 | set tcp5 [new Agent/TCP/Vegas] 61 | $ns attach-agent $n2 $tcp5 62 | set sink6 [new Agent/TCPSink] 63 | $ns attach-agent $n8 $sink6 64 | $ns connect $tcp5 $sink6 65 | $tcp5 set packetSize_ 1500 66 | $tcp5 set class_ 2 67 | set tfile2 [open cwnd2.tr w] 68 | $tcp5 attach $tfile2 69 | $tcp5 trace cwnd_ 70 | 71 | # Applications Definition 72 | #Setup a FTP Application over TCP/Reno connection 73 | set ftp0 [new Application/FTP] 74 | $ftp0 attach-agent $tcp0 75 | $ns at 0.3 "$ftp0 start" 76 | $ns at 8.0 "$ftp0 stop" 77 | 78 | #Setup a FTP Application over TCP/Vegas connection 79 | set ftp4 [new Application/FTP] 80 | $ftp4 attach-agent $tcp5 81 | $ns at 0.3 "$ftp4 start" 82 | $ns at 8.0 "$ftp4 stop" 83 | 84 | # Termination 85 | #Define a 'finish' procedure 86 | proc finish {} { 87 | global ns tracefile namfile 88 | $ns flush-trace 89 | close $tracefile 90 | close $namfile 91 | exec nam 5.nam & 92 | exit 0 93 | } 94 | 95 | $ns at $val(stop) "$ns nam-end-wireless $val(stop)" 96 | $ns at $val(stop) "finish" 97 | $ns at $val(stop) "puts \"done\" ; $ns halt" 98 | $ns run 99 | 100 | -------------------------------------------------------------------------------- /cn4.AWK: -------------------------------------------------------------------------------- 1 | BEGIN{ 2 | count=0; 3 | total=0; 4 | } 5 | { 6 | event =$1; 7 | if(event=="D") { 8 | count++; 9 | } 10 | } 11 | END{ 12 | printf("No of packets dropped : %d\n",count); 13 | } -------------------------------------------------------------------------------- /cn4.tcl: -------------------------------------------------------------------------------- 1 | # Simulation parameters setup 2 | set val(chan) Channel/WirelessChannel ;# channel type 3 | set val(prop) Propagation/TwoRayGround ;# radio-propagation model 4 | set val(netif) Phy/WirelessPhy ;# network interface type 5 | set val(mac) Mac/802_11 ;# MAC type 6 | set val(ifq) Queue/DropTail/PriQueue ;# interface queue type 7 | set val(ll) LL ;# link layer type 8 | set val(ant) Antenna/OmniAntenna ;# antenna model 9 | set val(ifqlen) 50 ;# max packet in ifq 10 | set val(nn) 2 ;# number of mobilenodes 11 | set val(rp) DSDV ;# routing protocol 12 | set val(x) 700 ;# X dimension of topography 13 | set val(y) 444 ;# Y dimension of topography 14 | set val(stop) 10.0 ;# time of simulation end 15 | 16 | # Initialization 17 | #Create a ns simulator 18 | set ns [new Simulator] 19 | 20 | #Setup topography object 21 | set topo [new Topography] 22 | $topo load_flatgrid $val(x) $val(y) 23 | create-god $val(nn) 24 | 25 | #Open the NS trace file 26 | set tracefile [open out.tr w] 27 | $ns trace-all $tracefile 28 | 29 | #Open the NAM trace file 30 | set namfile [open out.nam w] 31 | $ns namtrace-all $namfile 32 | $ns namtrace-all-wireless $namfile $val(x) $val(y) 33 | set chan [new $val(chan)];#Create wireless channel 34 | 35 | # Mobile node parameter setup 36 | $ns node-config -adhocRouting $val(rp) \ 37 | -llType $val(ll) \ 38 | -macType $val(mac) \ 39 | -ifqType $val(ifq) \ 40 | -ifqLen $val(ifqlen) \ 41 | -antType $val(ant) \ 42 | -propType $val(prop) \ 43 | -phyType $val(netif) \ 44 | -channel $chan \ 45 | -topoInstance $topo \ 46 | -agentTrace ON \ 47 | -routerTrace ON \ 48 | -macTrace ON \ 49 | -movementTrace ON 50 | 51 | # Nodes Definition 52 | #Create 2 nodes 53 | set n0 [$ns node] 54 | $n0 set X_ 268 55 | $n0 set Y_ 339 56 | $n0 set Z_ 0.0 57 | $ns initial_node_pos $n0 20 58 | set n1 [$ns node] 59 | $n1 set X_ 428 60 | $n1 set Y_ 344 61 | $n1 set Z_ 0.0 62 | $ns initial_node_pos $n1 20 63 | 64 | # Generate movement 65 | $ns at .1 " $n0 setdest 600 344 100 " 66 | $ns at .1 " $n1 setdest 300 339 100 " 67 | 68 | # Agents Definition 69 | #Setup a TCP connection 70 | set tcp0 [new Agent/TCP] 71 | $ns attach-agent $n0 $tcp0 72 | set sink1 [new Agent/TCPSink] 73 | $ns attach-agent $n1 $sink1 74 | $ns connect $tcp0 $sink1 75 | $tcp0 set packetSize_ 1500 76 | 77 | # Applications Definition 78 | #Setup a FTP Application over TCP connection 79 | set ftp0 [new Application/FTP] 80 | $ftp0 attach-agent $tcp0 81 | $ns at 1.0 "$ftp0 start" 82 | $ns at 5.0 "$ftp0 stop" 83 | 84 | #Define a 'finish' procedure 85 | proc finish {} { 86 | global ns tracefile namfile 87 | $ns flush-trace 88 | close $tracefile 89 | close $namfile 90 | exec nam out.nam & 91 | exit 0 92 | } 93 | 94 | for {set i 0} {$i < $val(nn) } { incr i } { 95 | $ns at $val(stop) "\$n$i reset" 96 | } 97 | 98 | $ns at $val(stop) "$ns nam-end-wireless $val(stop)" 99 | $ns at $val(stop) "finish" 100 | $ns at $val(stop) "puts \"done\" ; $ns halt" 101 | $ns run 102 | -------------------------------------------------------------------------------- /cn5.AWK: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | count=0; 3 | total=0; 4 | } 5 | { 6 | event=$1; 7 | if(event=="D") { 8 | count++; 9 | } 10 | } 11 | END { 12 | printf("No of packets dropped : %d\n",count); 13 | } -------------------------------------------------------------------------------- /cn5.tcl: -------------------------------------------------------------------------------- 1 | # Simulation parameters setup 2 | set val(chan) Channel/WirelessChannel ;# channel type 3 | set val(prop) Propagation/TwoRayGround ;# radio-propagation model 4 | set val(netif) Phy/WirelessPhy ;# network interface type 5 | set val(mac) Mac/802_11 ;# MAC type 6 | set val(ifq) Queue/DropTail/PriQueue ;# interface queue type 7 | set val(ll) LL ;# link layer type 8 | set val(ant) Antenna/OmniAntenna ;# antenna model 9 | set val(ifqlen) 50 ;# max packet in ifq 10 | set val(nn) 7 ;# number of mobilenodes 11 | set val(rp) AODV ;# routing protocol 12 | set val(x) 1151 ;# X dimension of topography 13 | set val(y) 900 ;# Y dimension of topography 14 | set val(stop) 10.0 ;# time of simulation end 15 | 16 | # Initialization 17 | #Create a ns simulator 18 | set ns [new Simulator] 19 | 20 | #Setup topography object 21 | set topo [new Topography] 22 | $topo load_flatgrid $val(x) $val(y) 23 | create-god $val(nn) 24 | 25 | #Open the NS trace file 26 | set tracefile [open out.tr w] 27 | $ns trace-all $tracefile 28 | 29 | #Open the NAM trace file 30 | set namfile [open out.nam w] 31 | $ns namtrace-all $namfile 32 | $ns namtrace-all-wireless $namfile $val(x) $val(y) 33 | set chan [new $val(chan)];#Create wireless channel 34 | 35 | # Mobile node parameter setup 36 | $ns node-config -adhocRouting $val(rp) \ 37 | -llType $val(ll) \ 38 | -macType $val(mac) \ 39 | -ifqType $val(ifq) \ 40 | -ifqLen $val(ifqlen) \ 41 | -antType $val(ant) \ 42 | -propType $val(prop) \ 43 | -phyType $val(netif) \ 44 | -channel $chan \ 45 | -topoInstance $topo \ 46 | -agentTrace ON \ 47 | -routerTrace ON \ 48 | -macTrace ON \ 49 | -movementTrace ON 50 | 51 | # Nodes Definition 52 | #Create 7 nodes 53 | set n0 [$ns node] 54 | $n0 set X_ 338 55 | $n0 set Y_ 305 56 | $n0 set Z_ 0.0 57 | $ns initial_node_pos $n0 20 58 | 59 | set n1 [$ns node] 60 | $n1 set X_ 527 61 | $n1 set Y_ 300 62 | $n1 set Z_ 0.0 63 | $ns initial_node_pos $n1 20 64 | 65 | set n2 [$ns node] 66 | $n2 set X_ 672 67 | $n2 set Y_ 305 68 | $n2 set Z_ 0.0 69 | $ns initial_node_pos $n2 20 70 | 71 | set n3 [$ns node] 72 | $n3 set X_ 867 73 | $n3 set Y_ 304 74 | $n3 set Z_ 0.0 75 | $ns initial_node_pos $n3 20 76 | 77 | set n4 [$ns node] 78 | $n4 set X_ 1051 79 | $n4 set Y_ 302 80 | $n4 set Z_ 0.0 81 | $ns initial_node_pos $n4 20 82 | 83 | set n5 [$ns node] 84 | $n5 set X_ 292 85 | $n5 set Y_ 438 86 | $n5 set Z_ 0.0 87 | $ns initial_node_pos $n5 20 88 | 89 | set n6 [$ns node] 90 | $n6 set X_ 349 91 | $n6 set Y_ 58 92 | $n6 set Z_ 0.0 93 | $ns initial_node_pos $n6 20 94 | 95 | # Generate movement 96 | $ns at 1 " $n6 setdest 890 58 75 " 97 | 98 | # Agents Definition 99 | #Setup a TCP connection 100 | set tcp0 [new Agent/TCP] 101 | $ns attach-agent $n5 $tcp0 102 | set sink1 [new Agent/TCPSink] 103 | $ns attach-agent $n6 $sink1 104 | $ns connect $tcp0 $sink1 105 | $tcp0 set packetSize_ 1500 106 | 107 | # Applications Definition 108 | #Setup a FTP Application over TCP connection 109 | set ftp0 [new Application/FTP] 110 | $ftp0 attach-agent $tcp0 111 | $ns at 1.0 "$ftp0 start" 112 | $ns at 10.0 "$ftp0 stop" 113 | 114 | # Termination 115 | #Define a 'finish' procedure 116 | proc finish {} { 117 | global ns tracefile namfile 118 | $ns flush-trace 119 | close $tracefile 120 | close $namfile 121 | exec nam out.nam & 122 | exit 0 123 | } 124 | 125 | for {set i 0} {$i < $val(nn) } { incr i } { 126 | $ns at $val(stop) "\$n$i reset" 127 | } 128 | 129 | $ns at $val(stop) "$ns nam-end-wireless $val(stop)" 130 | $ns at $val(stop) "finish" 131 | $ns at $val(stop) "puts \"done\" ; $ns halt" 132 | $ns run 133 | -------------------------------------------------------------------------------- /cn6.tcl: -------------------------------------------------------------------------------- 1 | set opt(title) zero ; 2 | set opt(stop) 100 ; 3 | set opt(ecn) 0 ; 4 | set opt(type) umts ; 5 | set opt(secondDelay) 55 ; 6 | set opt(minth) 30 ; 7 | set opt(maxth) 0 ; 8 | set opt(adaptive) 1 ; 9 | 0 for plain RED 10 | set opt(flows) 0 ; 11 | set opt(window) 30 ; 12 | set opt(web) 2 ; 13 | set opt(quiet) 0 ; 14 | set opt(wrap) 100 ; 15 | set opt(srcTrace) is ; 16 | set opt(dstTrace) bs2 ; 17 | set opt(umtsbuf) 10 ; 18 | set bwDL(umts) 384000 19 | set bwUL(umts) 64000 20 | set propDL(umts) .150 21 | set propUL(umts) .150 22 | set buf(umts) 20 23 | 24 | set ns [new Simulator] 25 | set tf [open out.tr w] 26 | $ns trace-all $tf 27 | set nodes(is) [$ns node] 28 | set nodes(ms) [$ns node] 29 | set nodes(bs1) [$ns node] 30 | set nodes(bs2) [$ns node] 31 | set nodes(lp) [$ns node] 32 | proc cell_topo {} { 33 | global ns nodes 34 | $ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10ms DropTail 35 | $ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED 36 | $ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED 37 | $ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50ms DropTail 38 | puts "Cell Topology"} 39 | proc set_link_params {t} { 40 | global ns nodes bwUL bwDL propUL propDL buf 41 | $ns bandwidth $nodes(bs1) $nodes(ms) $bwDL($t) simplex 42 | $ns bandwidth $nodes(ms) $nodes(bs1) $bwUL($t) 43 | simplex $ns delay $nodes(bs1) $nodes(ms) $propDL($t) 44 | simplex $ns delay $nodes(ms) $nodes(bs1) $propDL($t) 45 | simplex $ns queue-limit $nodes(bs1) $nodes(ms) $buf($t) 46 | $ns queue-limit $nodes(ms) $nodes(bs1) $buf($t) 47 | $ns bandwidth $nodes(bs2) $nodes(ms) $bwDL($t) 48 | simplex $ns bandwidth $nodes(ms) $nodes(bs2) $bwUL($t) 49 | simplex $ns delay $nodes(bs2) $nodes(ms) $propDL($t) 50 | simplex $ns delay $nodes(ms) $nodes(bs2) $propDL($t) 51 | simplex $ns queue-limit $nodes(bs2) $nodes(ms) $buf($t) 52 | $ns queue-limit $nodes(ms) $nodes(bs2) $buf($t) 53 | } 54 | Queue/RED set summarystats_ true 55 | Queue/DropTail set summarystats_ true 56 | Queue/RED set adaptive_ $opt(adaptive) 57 | Queue/RED set q_weight_ 0.0 58 | Queue/RED set thresh_ $opt(minth) 59 | Queue/RED set maxthresh_ $opt(maxth) 60 | Queue/DropTail set shrink_drops_ true 61 | Agent/TCP set ecn_ $opt(ecn) Agent/TCP 62 | set window_ $opt(window) DelayLink set 63 | avoidReordering_ true 64 | source web.tcl 65 | switch $opt(type) { 66 | umts {cell_topo} 67 | } 68 | set_link_params $opt(type) 69 | $ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer] 70 | $ns insert-delayer $nodes(bs1) $nodes(ms) [new Delayer] 71 | $ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer] 72 | $ns insert-delayer $nodes(bs2) $nodes(ms) [new Delayer] 73 | if {$opt(flows) == 0} { 74 | set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0] 75 | set ftp1 [[set tcp1] attach-app FTP] 76 | $ns at 0.8 "[set ftp1] start" } if {$opt(flows) > 0} { 77 | set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0] 78 | set ftp1 [[set tcp1] attach-app FTP] $tcp1 79 | set window_ 100 80 | $ns at 0.0 "[set ftp1] start" 81 | $ns at 3.5 "[set ftp1] stop" 82 | set tcp2 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0] 83 | set ftp2 [[set tcp2] attach-app FTP] 84 | $tcp2 set window_ 3 85 | $ns at 1.0 "[set ftp2] start" 86 | $ns at 8.0 "[set ftp2] stop" } 87 | proc stop {} { global nodes opt nf 88 | set wrap $opt(wrap) 89 | set sid [$nodes($opt(srcTrace)) id] 90 | set did [$nodes($opt(dstTrace)) id] 91 | if {$opt(srcTrace) == "is"} { set a "-a out.tr" } else { set a "out.tr" } 92 | set GETRC "../../../bin/getrc" 93 | set RAW2XG "../../../bin/raw2xg" 94 | exec $GETRC -s $sid -d $did -f 0 out.tr | \ 95 | $RAW2XG -s 0.01 -m $wrap -r > plot.xgr 96 | exec $GETRC -s $did -d $sid -f 0 out.tr | \ 97 | $RAW2XG -a -s 0.01 -m $wrap >> plot.xgr 98 | exec $GETRC -s $sid -d $did -f 1 out.tr | \ 99 | $RAW2XG -s 0.01 -m $wrap -r >> plot.xgr 100 | exec $GETRC -s $did -d $sid -f 1 out.tr | \ 101 | $RAW2XG -s 0.01 -m $wrap -a >> plot.xgr 102 | exec ./xg2gp.awk plot.xgr if {!$opt(quiet)} { 103 | exec xgraph -bb -tk -nl -m -x time -y packets plot.xgr & 104 | } 105 | exit 0 106 | } 107 | $ns at $opt(stop) "stop" 108 | $ns run -------------------------------------------------------------------------------- /file.txt: -------------------------------------------------------------------------------- 1 | hello This is Abhishek --------------------------------------------------------------------------------