Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis
Introduction One semester course (VIII) Hours per week: Textbooks: –Andrew S. Tanenbaum, Computer Networks –James F. Kurose, Keith W. Ross, Computer Networking: A Top Down Approach Featuring the Internet
Main problems of students population Exams “dragged” from previous semesters Often exams Not interested in Not attended classes Prerequisite exams not passed Fear of new matter and programming language
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.
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
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
Exercise 1. – Framing Task 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 ) Frame is delimited by starting (AA H i EB H ) and ending (AA H i 7B H ) bytes
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)
Exercise 1. – Framing Example 45:3E:AA:EB:AA:7B:67:93 H AA:EB:45:3E:AA AA:EB:AA AA:7B:67:93:AA:7B H 45:3E:AA:EB:AA:7B:67:93 H Framing bytes Inserted bytes
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| Unframed message (Receiver): |69|-1|-86|-21|-86|123|-1|-109|
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.
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
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: ). The end of communicated is denoted by message KRAJ (75:82:65:74 10 )
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.
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); } } }
Exercise 5. – Stream Sockets Task Description Implement HTTP server and/or client, based on sample Java program code, available on the Web ( ). 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.
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.
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.getInputS tream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputS tream()); 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/ Document Follows\r\n"); if (fileName.endsWith(".jpg")) outToClient.writeBytes("Co ntent-Type: image/jpeg\r\n"); if (fileName.endsWith(".gif")) outToClient.writeBytes("Co ntent-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"); } }
Exercise 6. – Command Promt WinNT/2000 Net Utilities Introduction to real TCP/IP protocols using the following services: Arp IPConfig Netstat Ping Route Tracert
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.