Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

20
Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

description

Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis. Introduction. One semester course (VIII) Hours per week: 2+2+1 Textbooks: Andrew S. Tanenbaum, Computer Networks James F. Kurose, Keith W. Ross, Computer Networking: A Top Down Approach Featuring the Internet. - PowerPoint PPT Presentation

Transcript of Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Page 1: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Lab assignments in Computer Networks at Faculty of Electronic

Engineering - Nis

Page 2: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Introduction

• One semester course (VIII)

• Hours per week: 2+2+1

• Textbooks:– Andrew S. Tanenbaum, Computer Networks– James F. Kurose, Keith W. Ross, Computer

Networking: A Top Down Approach Featuring the Internet

Page 3: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Main problemsof students population

Exams “dragged” fromprevious semesters

Often exams

Not interested in

Not attended classes

Prerequisite examsnot passed

Fear of new matterand programming language

Page 4: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Ways to solve the problem

• Avoid difficult exercises.• Include new and popular technologies and

programming languages.• Enable accommodation period, and new

programming language adoption, at the start.• Combine several problems in one exercise.• Purpose of exercise should be obvious, and easily

applicable.

Page 5: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Goals

• Introduction to Java application programming

• Introduction to data-link layer functions

• Introduction to Java Socket programming

• Introduction to common network utilities available on WinNT/2000 platforms

Page 6: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercises

1. Framing

2. Error Control

3. Flow Control – Stop-and-wait

4. Datagram Sockets – Stop-and-wait chatter

5. Stream Sockets – HTTP Server/Client

6. Windows NT/2000 Net Services

Page 7: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 1. – FramingTask Description

• Implement Java class (DataLinkLayer) for message framing. The class have to implement, at least two methods: –frame – for message framing, and–unframe – for message extraction

• Maximal frame size is 128 B. • Sending and receiving should be performed using

PhysicalLayer class methods:–void send (byte[] data) and –byte[] receive() metode. (class PhysicalLayer is already created and is available for download from http://gislab.elfac.ni.ac.yu/Aks/Download/PhysicalLayer.class)

Frame is delimited by starting (AAH i EBH) and ending (AAH i 7BH) bytes

Page 8: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Java Classes to Implement

• Sender – sends message to DataLink Layer

• Receiver – receives message from DataLink Layer and displays on the screen

• DataLinkLayer – main class that implements two methods:– public byte[] frame (byte[] data)– public byte[] unframe(byte[] data)

Page 9: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 1. – FramingExample

45:3E:AA:EB:AA:7B:67:93H

AA:EB:45:3E:AA AA:EB:AA AA:7B:67:93:AA:7BH

45:3E:AA:EB:AA:7B:67:93H

Framing bytesFraming bytes

Inserted bytes Inserted bytes

Page 10: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Example of Screen Layout

Original message (Sender):|69|-1|-86|-21|-86|123|-1|-109|

Framed message in communication channel (Sender’s output):|0|0|0|-86|-21|69|-1|-86|-86|-21|-86|-86|123|-1|-109|-86|123|0||0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0||0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|

Unframed message (Receiver):|69|-1|-86|-21|-86|123|-1|-109|

Page 11: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 2. – Error Control Task Description

Modify the DataLinkLayer class by adding iCheckSum method for error control. Error control should be performed by calculating Internet checksum.

Page 12: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Example of Screen Layout

Original message (Sender):|69|-1|-86|-21|-86|123|-1|-109|

Framed message in communication channel (Sender’s output):|0|0|0|-86|-21|69|-1|-86|-86|-21|-86|-86|123|-1|-109|23|14| 86|123|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0||0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|

Unframed message (Receiver):|69|-1|-86|-21|-86|123|-1|-109| -> No error

Page 13: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 3. – Flow Control Task Description

• Modify the DataLinkLayer class from exercise 2, by adding flow control capability, based on stop and wait protocol.

• For noisy channel simulation class NoisyPhysicalLayer can be used (and downloaded from: http://gislab.elfak.ni.ac.yu/Aks/Download/NoisyPhysicalLayer.class).

• The end of communicated is denoted by message KRAJ (75:82:65:7410)

Page 14: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 4. – Datagram Sockets Task Description

• Implement simple chatter application ( both client and server side ), using stop and wait protocol for flow control.

• Application could be based on sample Java program code, available on the Web.

Page 15: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Sample code

import java.io.*; import java.net.*;   class UDPClient {     public static void main(String args[]) throws Exception     {      BufferedReader inFromUser =         new BufferedReader(new InputStreamReader(System.in));         DatagramSocket clientSocket = new DatagramSocket();       InetAddress IPAddress = InetAddress.getByName("hostname");         byte[] sendData = new byte[1024];       byte[] receiveData = new byte[1024];       String sentence = inFromUser.readLine();         sendData = sentence.getBytes();       DatagramPacket sendPacket =          new DatagramPacket(sendData, sendData.length, IPAddress, 9876);       clientSocket.send(sendPacket);         DatagramPacket receivePacket =          new DatagramPacket(receiveData, receiveData.length);       clientSocket.receive(receivePacket);         String modifiedSentence =           new String(receivePacket.getData());         System.out.println("FROM SERVER:" + modifiedSentence);       clientSocket.close();      } }  

import java.io.*; import java.net.*;   class UDPServer {   public static void main(String args[]) throws Exception     {        DatagramSocket serverSocket = new DatagramSocket(9876);       byte[] receiveData = new byte[1024];       byte[] sendData  = new byte[1024];         while(true)         {           DatagramPacket receivePacket =              new DatagramPacket(receiveData, receiveData.length);             serverSocket.receive(receivePacket);           String sentence = new String(receivePacket.getData());             InetAddress IPAddress = receivePacket.getAddress();           int port = receivePacket.getPort();                         String capitalizedSentence = sentence.toUpperCase();           sendData = capitalizedSentence.getBytes();           DatagramPacket sendPacket =              new DatagramPacket(sendData, sendData.length, IPAddress,                                port);             serverSocket.send(sendPacket);         }     } }

 

Page 16: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 5. – Stream Sockets Task Description

• Implement HTTP server and/or client, based on sample Java program code, available on the Web (http://gislab.elfak.ni.ac.yu/Aks/Download/HTTPServer.java).

• The server should be able to return following codes:– 200 OK – 400 Bad Request– 404 Not Found– 505 HTTP Version Not Supported

• The client should print, at least, header of received HTTP message.

Page 17: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Validation

• Server implementation should be validated by InternetExplorer Web client

(requiring some image, for example, from the server)

• Client implementation should be validated by visiting some real Web sites.

Page 18: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Simple Web server(less then 40 lines of code)

import java.io.*; import java.net.*; import java.util.*;

class WebServer{     public static void main(String argv[]) throws

Exception  {           String requestMessageLine;

          String fileName;           ServerSocket listenSocket = new

ServerSocket(6789);           Socket connectionSocket = listenSocket.accept();

          BufferedReader inFromClient =             new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));           DataOutputStream outToClient =             new DataOutputStream(connectionSocket.getOutputStream());

          requestMessageLine = inFromClient.readLine();           StringTokenizer tokenizedLine =

            new StringTokenizer(requestMessageLine);

                      if (tokenizedLine.nextToken().equals("GET")){           fileName = tokenizedLine.nextToken();           if (fileName.startsWith("/") == true )

                         fileName  = fileName.substring(1);

                    

import java.io.*;   File file = new File(fileName);           int numOfBytes = (int) file.length();

          FileInputStream inFile  = new FileInputStream (fileName);

                      byte[] fileInBytes = new byte[numOfBytes];

          inFile.read(fileInBytes);

          outToClient.writeBytes("HTTP/1.0 200 Document Follows\r\n");

          if (fileName.endsWith(".jpg"))                   outToClient.writeBytes("Content-Type: image/jpeg\r\n");           if (fileName.endsWith(".gif"))                   outToClient.writeBytes("Content-Type: image/gif\r\n");

          outToClient.writeBytes("Content-Length: " + numOfBytes + "\r\n");           outToClient.writeBytes("\r\n");

          outToClient.write(fileInBytes, 0, numOfBytes);

          connectionSocket.close();                      }

     else System.out.println("Bad Request Message");        } }

Page 19: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Exercise 6. – Command Promt WinNT/2000 Net Utilities

Introduction to real TCP/IP protocols using the following services:

•Arp•IPConfig•Netstat•Ping•Route•Tracert

Page 20: Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis

Conclusion

• Computer Networks is a very dynamic topic, so this is only the current “state of art”.

• Laboratory exercise should be under constant changing, following the students needs and capabilities, on one side, and main streams and new technologies, on the other.