Posts

Showing posts from December, 2024

6

 // jTCPServer7 import java.net.*;  import java.io.*;  public class jTCPServer7  {  public static void main(String[] args) throws Exception  {  ServerSocket sersock=new ServerSocket(4000);  System.out.println("Server ready for connection");  Socket sock=sersock.accept();  System.out.println("Connection Is successful and waiting for chatting");  InputStream istream=sock.getInputStream();  BufferedReader fileRead=new BufferedReader(new InputStreamReader(istream));  String fname=fileRead.readLine();  BufferedReader ContentRead=new BufferedReader(new FileReader(fname));  OutputStream ostream=sock.getOutputStream();  PrintWriter pwrite=new PrintWriter(ostream,true);  String str;  while((str=ContentRead.readLine())!=null){  pwrite.println(str);  }  sock.close();  sersock.close();  pwrite.close();  fileRead.close();  ContentRead.close();  }  } //jTCPClient7 imp...

5

 import java.util.Scanner; import java.io.*; public class jCRC4 {     public static void main(String args[]) {     Scanner sc = new Scanner(System.in);     //Input Data Stream     System.out.print("Enter message bits: ");     String message = sc.nextLine();     System.out.print("Enter generator: ");     String generator = sc.nextLine(); int data[] = new int[message.length() + generator.length() - 1]; int divisor[] = new int[generator.length()]; for(int i=0;i<message.length();i++) data[i] = Integer.parseInt(message.charAt(i)+""); for(int i=0;i<generator.length();i++) divisor[i] = Integer.parseInt(generator.charAt(i)+""); //Calculation of CRC for(int i=0;i<message.length();i++) { if(data[i]==1)  for(int j=0;j<divisor.length;j++) data[i+j] ^= divisor[j]; //a=a^b } //Display CRC System.out.print("The checksum code is: "); for(int i=0;i<message.length();i++) data[i] = Integer.parseIn...

4

 import java.util.Scanner; import java.lang.*; public class jLB10 { public static void main(String[] args) {           int i; int a[]=new int[20]; int buck_rem=0,buck_cap=4,rate=3,sent,recv; Scanner in = new Scanner(System.in); System.out.println("Enter the number of packets"); int n = in.nextInt(); System.out.println("Enter the packets"); for(i=0;i<n;i++) a[i]= in.nextInt(); System.out.println("Clock  \t packet size \t     accept   sent    remaining"); for(i=0;i<n;i++) { if(a[i]!=0) { if(buck_rem+a[i]>buck_cap)      recv=-1; else { recv=a[i]; buck_rem+=a[i]; } } else recv=0; if(buck_rem!=0) { if(buck_rem<rate) { sent=buck_rem; buck_rem=0; } else { sent=rate; buck_rem=buck_rem-rate; } } else sent=0; if(recv==-1) ...

3

  set ns [new Simulator]  set nf [open lab3.nam w] $ns namtrace-all $nf set tf [open lab3.tr w] $ns trace-all $tf set n0 [$ns node]  set n1 [$ns node]  set n2 [$ns node]  set n3 [$ns node] $ns color 1 red $ns color 2 blue  #create LAN $ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3 #Attach Agents set tcp0 [new Agent/TCP] $ns attach-agent $n0 $tcp0  set ftp0 [new Application/FTP] $ftp0 attach-agent $tcp0 set sink3 [new Agent/TCPSink] $ns attach-agent $n3 $sink3 $ns connect $tcp0 $sink3 set tcp2 [new Agent/TCP] $ns attach-agent $n2 $tcp2  set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 set sink1 [new Agent/TCPSink] $ns attach-agent $n1 $sink1 $ns connect $tcp2 $sink1 $tcp0 set class_ 1 $tcp2 set class_ 2 ######To trace the congestion window########## set file1 [open file1.tr w] $tcp0 attach $file1 $tcp0 trace cwnd_ $tcp0 set maxcwnd_ 10 set file2 [open file2.tr w] $tcp2 attach $file2 $tcp2 trace cwnd_   proc finish ...

2

  set ns [ new Simulator ] set nf [open lab2.nam w] $ns namtrace-all $nf set tf [open lab2.tr w] $ns trace-all $tf set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] $n4 shape box $ns duplex-link $n0 $n4 1005Mb 1ms DropTail $ns duplex-link $n1 $n4 50Mb 1ms DropTail $ns duplex-link $n2 $n4 2000Mb 1ms DropTail $ns duplex-link $n3 $n4 200Mb 1ms DropTail $ns duplex-link $n4 $n5 1Mb 1ms DropTail set p1 [new Agent/Ping] $ns attach-agent $n0 $p1 $p1 set packetSize_ 50000 $p1 set interval_ 0.0001 set p2 [new Agent/Ping] $ns attach-agent $n1 $p2 set p3 [new Agent/Ping] $ns attach-agent $n2 $p3 $p3 set packetSize_ 30000 $p3 set interval_ 0.00001 set p4 [new Agent/Ping] $ns attach-agent $n3 $p4   set p5 [new Agent/Ping] $ns attach-agent $n5 $p5 $ns queue-limit $n0 $n4 5 $ns queue-limit $n2 $n4 3 $ns queue-limit $n4 $n5 2 Agent/Ping instproc recv {from rtt} { $sel...

1

  TCL Program: set ns [new Simulator] set ntrace [open prog1.tr w] $ns trace-all $ntrace set namfile [open prog1.nam w] $ns namtrace-all $namfile #Finish Procedure proc Finish {} { global ns ntrace namfile $ns flush-trace close $ntrace close $namfile exec nam prog1.nam & #show the number of packets dropped exec echo “The number of packets dropped is ” & exec grep -c “^d” prog1.tr & exit 0 } # create 3 nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] #Label the nodes $n0 label "TCP Source" $n2 label "Sink" #Set the color $ns color 1 blue #Create Links between nodes #You need to modify the bandwidth to observe the variation in packet drop $ns duplex-link $n0 $n1 1Mb 10ms DropTail $ns duplex-link $n1 $n2 0.5Mb 10ms DropTail #Make the Link Orientation $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n1 $n2 orient right #Set Queue Size #You can modify the queue length ...