Nothing Special   »   [go: up one dir, main page]

Network Lab Output - 120819

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

Experiment 1

Step 1: Install Ubuntu (Using DVD or USB Drive)

Step 2: Allocate Drive Space


Step 3: Begin the Installation

Step 4: Select your Location


Step 5: Select Preferred keyboard layout

Step 6: Enter your Login and Password Details


Step 7: Learn More about Ubuntu while it is installing

That’s it! Installation is complete. Now restart your computer.


Experiment 2
1) ifconfig
2) ip

3) traceroute

4) tracepath
5) ping
6) netstat

7) ss
8) dig

9) nslookup

11) arp

12) whois
13) host

14) curl
Experiment 4

#Create a simulator object


set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
$ns color 3 green
#Open the NAM trace file
set nf [open usp.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam usp.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#Create links between the nodes


$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)


$ns duplex-link-op $n2 $n3 queuePos 0.5
#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 3
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#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 TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n2 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
#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
#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Print CBR packet size and interval
puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"
#Run the simulation
$ns run
Experiment 7
Experiment 5
Experiment 8

UDPServerEx.java

import java.net.*;
class UDPServerEx {
public static DatagramSocket mySocket;
public static byte myBuffer[] = new byte[2000];

public static void serverMethod() throws Exception


{
int position = 0;
while (true) {
int charData = System.in.read();
switch (charData) {
case -1:
System.out.println( "The execution of " + "the server has been
terminated");
return;
case '\r':
break;
case '\n':
mySocket.send(new DatagramPacket( myBuffer, position,
InetAddress.getLocalHost(),777));
position = 0;
break;
default:
myBuffer[position++] = (byte)charData;
}
}
}
public static void main(String args[]) throws Exception
{
System.out.println("Please enter some text here");
mySocket = new DatagramSocket(888);
serverMethod();
}
}
UDPClient.java

import java.net.*;
class UDPClient {

public static DatagramSocket mySocket;


public static byte myBuffer[] = new byte[2000];

public static void clientMethod() throws Exception


{
while (true) {
DatagramPacket dataPacket = new DatagramPacket(myBuffer,
myBuffer.length);
mySocket.receive(dataPacket);
System.out.println("Message Recieved :");
System.out.println( new String( dataPacket.getData(), 0,
dataPacket.getLength()));
}
}
public static void main(String args[]) throws Exception
{
System.out.println("You need to press CTRL+C" + " in order to quit.");
mySocket = new DatagramSocket(777);
clientMethod();
}
}
Experiment 9
Client Side Program:

import java.io.*;
import java.net.*;
class GFG {
// driver function
public static void main(String[] args)
{
try {
// Create socket object by passing id address
// and port number establish connection
Socket socket = new Socket("localhost", 1346);
System.out.println( "Connected Successfully.....");
// Buffer reader to get all the input stream
InputStreamReader r = new InputStreamReader(System.in)
BufferedReader bs = new BufferedReader( r );
System.out.println("Response from Server.....");
// Print response from server
System.out.println("Client Side : "+ bs.readLine());
// Close the connection
socket.close();
}
catch (UnknownHostException e) {
// Catch block for IP errors
System.out.println("IP not found for" + e);
}
catch (IOException e) {
// Catch block for data stream errors
System.out.println("Not found data for socket"+ e);
}
}
}

Server Side Program:

import java.io.*;
import java.net.*;
class GFG {
public static void main(String[] args)
{
try {
// establish connection
ServerSocket serversocket = new ServerSocket(1346);
System.out.println("waiting for request....");
// Socket object to accept all the connections
Socket socket = serversocket.accept();
System.out.println("Request Accepted...");
// Printstream to print all the data
PrintStream ps = new PrintStream(socket.getOutputStream());
BufferedReader br = new BufferedReader( new
InputStreamReader(System.in));
System.out.println( "Input the data at the server...");
// Printing bufferedreader data
ps.print(br.readLine());
socket.close();
serversocket.close();
}
catch (IOException e) {
// Catch block for data stream errors
System.out.println("Not found data for socket" + e);
}
}
}

You might also like