Easter Fun


Now that we're approaching the end of the course you might be eager to see the whole thing in action. There is no better way to learn anything that when you're facing the task of building a working system. And I mean to build all of it!

Most of the time you work on a personal computer. Not the hardware or the operating system are part of what you have to build. In an extreme case you might be rebuilding the kernel of the operating system you're running.

If you like hardware and to experiment I propose you to get one Arduino board and a LAN adapter for it. I've used in the past the ones I'm referencing and I've found that seller the cheapest option at the time.

To get things running you'll need to download the software library for the LAN card plus the Arduino IDE appropriated for your computer (OS X, Linux or Windows).

Arduino is an easy-to-use low-cost "open hardware" microcontroller board around ATmega168 chip. USB bus server to both power the board and download developed code to it. Many extensions are possible and the LAN card adds a simple Microchip LAN controller to Arduino. All the source code you see is all what's available: no operating system below, no hidden strings, just the bare source of the library.

Lab#9

Click on the title.

Error checking (kind of)

If you want to know the character (for error control purposes) of a Spanish identification document, just perform the modulo 23 operation over the DNI number. Then use the next table. That's it.

0 T 12 N
1 R 13 J
2 W 14 Z
3 A 15 S
4 G 16 Q
5 M 17 V
6 Y 18 H
7 F 19 L
8 P 20 C
9 D 21 K
10 X 22 E
11 B



And if you want to get a better idea about how CRC works you can visit this old post. There is a detailed Wikipedia article too.

Chapter #5 slides

Oops, I've almost forgot to post it here. You can click on the title to get the file.

Lab#8

Just click on the title.

IPv6 survey result

It was published recently on NetworkWorld site. ISP's are not seeing a big business drive for IPv6.

Sample implementation of assignment#3

You'll need it if you're planning to do assignment#4 but you did not do #3. Source code is available here. It consists of a main class and three additional classes one for each server (peer, query and file server).

Better late than never

After some questions I've learned that I mention nowhere what the expected command-line parameters order for #3 and #4 is. Three are the parameters you need: port number, shared folder and initial peer, like this:

$ java P2P 7123 ./ 158.42.53.17:7777
| | |
port | |
folder |
initial peer

I just thought this afternoon that a test tool might come in handy for you to test your assignment #3 servers. So here you have such a tool. Please remember a full implementation of a peer was also available (as another way to test that your server works nicely).

The test program is intended to be run in the same computer as #3, so you only need to provide the port information.

$ java P2Tester 7777
>>> CONNECT OK
158.42.53.17:7777
158.42.53.17:8899
1.1.1.1:1234

P2P.class
QueryServer.class
ListManagement.class
Peers.class
FileServer.class

>>> READ FROM FILE (first ten bytes): FileServer.class
ca fe ba be 00 00 00 32 00 72
Please note the output above shows the expected behaviour where you have three sections. On the top it is the peer list, after connect ok message that tells you the three server ports are open (p, p+1 and p+2). Next you have the list of filenames (only if your code reacts this way to an empty line query, something mine does) and in the third place you have the first 10 data bytes of the filename that appears last on your file list (FileServer.class).

Please note the file is not read from the filesystem but sending a file download request to your server listening on port P+2.

Also note that peer 1.1.1.1:1234 might not appear on the peer list till you run test program twice.

Do not use an empty folder for your P2P server: share some files!!

Last assignment is out


Fourth and last assignment completes the P2P software you started building on #3. Therefore you'll need to add the #4 code to the one you wrote for #3. If you did not do third assignment but you'd like to attempt the fourth, please contact me for a reference implementation for third assignment (once #3 due time has expired).

This last assignment takes care of the user interface of the peer to peer program, that allows the user to search for files on the network of peers and to download a file from a peer. It also takes care of maintaining a "live" list of active peers (pruning it when a peer is found not responsive).

Due date is April 30th, 2009.

Assume command line information is correct.

Lab #7 available only in Spanish

Just click on the title to get the file.

IPv6 addresses problem

IPv6 is proposed as an almost unlimited source of addresses to overcome the IPv4 address shortage some people have suggested. As IPv6 addresses are 128-bit long, 2^128 (aprox 3.4 x 10^38 ) addresses are possible. This should be large enough.

To put things into perspective consider the following problem: How many IPv6 addresses could you put into each squared centimeter of the planet? (Assume the Earth is a regular sphere of 40.000 Km of perimeter).

And a second part ... compare the above number of IPv6 addresses per square centimeter to the total address space of IPv4.

Fragmentation exercise


A 4000 byte-long datagram has to be transmitted over a network whose MTU is 512 bytes. Determine the number of fragments and, for each one of them, write down the fragment offset field contents and the number of data bytes of each fragment.

Solution was presented as a spreadsheet in the class. Here you have a copy. You can export it to your favorite spreadsheet software too (to see the formulas).

Third assignment announcement


Third and forth assignments will be based on a peer-to-peer protocol invented for the occasion. The so-called "P+2" protocol has been created to be one of the simplest P2P protocols (but not any simpler). You need to read and to understand the protocol specification. Protocol was already presented in the class but if there is general call I will repeat the explanation.

This assignment covers three different servers needed to create a full implementation. Assignment's servers can be tested to work using either telnet, netcat (nc) or sock commands. Java language is mandatory for Spanish students but the rest may use the language of your choice. A working implementation of a peer is available too (just a binary version).

You can download assignment text from here. Or you can just go to the file repository (linked on the top right corner, under the new stuff title).

There is a sample peer running too. You may not need it yet for this assignment. Anyway, it is available at 158.42.53.17:7777

You are welcome to ask me for help. Please remember you have to write code by yourself. As assignments are marked individually, it is not something you can develop jointly with a classmate. If two or more assignments are copied from each other all the involved parties will fail the assignment. Due date is March 13th.

p_2

Second term starts

Chapter 4 slides are already available. For those of you joining us for the second term please note you should read the syllabus that contains important details about how the subject works.

Next week we'll start with the lab again. Lab#6 is out too.
 

Marks are out

Not all of you have sent me your own grading of your exam. The reason I was asking you to do that is not because I can save some work this way but because I want you to have a look at your own answers. Most of your marks are quite close to what I've got, at least from the set of students who sent them to me.

You can check your mark on-line. There a few more students who have never attended lectures that will appear at the end of the list of names. This marks are not final as you still have a choice to check your exam. If you want to do that, please tell me so next week in the classroom (or send me an e-mail).

You can see we have a tie on the top performers. I want to congratulate both: Rasmus and Juliusz. Keep up the good work!

Solved 1st term exam Feb 2009

Feb2009 Solved

You know what you have answered. Now you know the right answers. So please check them out, use a binary logic (an answer is either right or wrong, and it scores or not) and calculate your mark and email it to me.

My mark after the exam ...

  1. Exam will be marked from 0 to 10 (being 10 the best mark possible).
  2. Attendance is already marked as a value from 0 to 1 (expressed as a %).
  3. Assignments have been marked too (0 to 2).
First term mark (again from 0 to 10) we'll be calculated as:

1st-term = attendance + (9-assignments)*exam/10 + assignments

Same process will hold for the second term. Course mark will be obtained by averaging both terms. There is not a minimum average you need to obtain on each term, but course average needs to be equal or higher than 5 points to pass the course.

To know more about threads synchronization


Assignment#2 presented you an scenario where multiple threads handle one client each. However, given that each thread has to send a text line to each any other thread's client, a synchronization problem may happen.

If all you use to test server's code is a few telnet clients running on your computer, it is difficult you see any problem (as only one client is typing at a time). If you're interested on researching this topic further, you may use IMTester.java code. This program will throw one hundred simultaneous clients to your server, each one sending on hundred text lines and then the mandatory quit command.

You may well see errors like this "Exception in thread "Thread-85" java.util.ConcurrentModificationException" on the server program. It basically means that an object was modified while others were reading from it (not a good thing). While I was not interested on raising this topic of synchronization, some of you pointed it out, so I cannot avoid explaining a bit more.

The main problem happens because the list of clients may change while one (or more) thread is iterating through it. If the client list changes while messages are being sent to other clients it is possible that either a client is missing the message or that a message is attempted to be delivered to client who is gone.

The solution is pretty simple but not obvious, and most of you failed to provide a proper one (not that it was a requirement though). I'm including an slightly modified version of my sample implementation for you that addresses the synchronization problem. The basic idea is that looping through client list and removing a client from the list are performed exclusively.

Update: A Vector object should have been used instead of ArrayList (as Vector is Thread safe and ArrayList is not).

Assignment #2 is marked


You should have got an email answer about your work. At any rate, marks are on the usual place (assignments tab). Those with a 0 mark still can try to fix it by Thursday 15th.

If any of you is missing a mark, please let me know.



You can have a look at my implementation.