Monday, November 16, 2009

Ubuntu 9.10 doesn't suspend when closing the lid on batteries

In Jaunty you were used to shutting the laptop's lid and trusting it would go to sleep... Well, not any more in Karmic. I've already done it several times only to find out that the poor laptop was cooking in its bag, or just shut itself down after running out of batteries.

The problem is related to a massive refactoring of gnome-power-manager, which now uses the devicekit-power daemon instead of the recently deprecated hal. Particularly, the problem has to do with the inability of devkit to determine whether we're on AC or battery reliably.

Luckily, you can get the fix from this ppa:

sudo add-apt-repository ppa:jmartinj/dkp
sudo apt-get update
sudo apt-get upgrade

Hope it works for you!

Is Karmic hogging all your memory, too?

Looks like there are some memory leaks in the new Ubuntu 9.10 (Karmic):

I just took this snapshot of the system monitor after seeing how my swap space is half full, trying to find a culprit. It shows the processes running on my computer after 5 days uptime... I'm just capturing the top hogging processes, ie. the ones that have allocated over 100 MB of virtual memory. Ok, we all know about Firefox's soft spot for memory when you have 30 tabs opened... We also know that it's normal for Xorg to join the feast, but what are gdm-simple-slave and gdm-simple-greeter doing here, taking about as much as firefox altogether??

We also excuse evince because it's dealing with some graphics. I don't know what two metacities are good for, and last but not least, gnome-power-manager (yeah, the tiny little battery icon that also takes care of suspending, etc.) is munching on another 100 MB. WTF?

If you are a fan of the TV series LOST, you probably know that the addiction to it comes partly from the directors' mastery of solving a mistery while puzzling you with three more on each episode. I believe the Ubuntu team applied this very same concept to the bugfixing process, so that users are constantly eager for a new release.

Monday, November 9, 2009

Simyo + Alcatel X060 + Ubuntu 9.10 (Karmic Koala)

Este post es para aquellos que tengáis el módem X060 que venía con la tarifa plana de Simyo y queráis utilizarlo con Ubuntu 9.10. Los que venís de Jaunty probablemente estaríais utilizando estas instrucciones, que ahora ya no funcionan.

Los problemas son varios: en primer lugar el módem ya está soportado por el kernel y no hace falta parchear el módulo "option", así que el paquete usb-modeswitch-alcatelX060-dkms_1.0.2-4_i386.deb que utilizábamos en Jaunty ya no hace falta en Karmic y se puede desinstalar:

sudo dpkg -r usb-modeswitch-alcatelX060-dkms

Segundo: ahora los problemas tienen que ver con el paquete "modemmanager", que es el que gestiona los módems 3G. Podéis ver los detalles aquí, esperemos que el autor los solucione. Mientras tanto podéis bajaros la versión parcheada haciendo:

sudo add-apt-repository ppa:jmartinj/x060-karmic
sudo apt-get update
sudo apt-get upgrade

Por otro lado necesitamos que el paquete usb-modeswitch esté instalado:

sudo apt-get install usb-modeswitch

Si todo ha ido bien, se habrá instalado el nuevo modemmanager que corrige este asunto. Reiniciad la máquina y probad.

¡Ya me diréis si os va!

Viendo los comentarios parece que algunos tenéis problemas. Ahora que tengo un poco de tiempo puedo mirarlo, pero necesito que me mandéis un par de logs. Los que tengáis problemas haced esto:

Lo primero, desenchufad el módem. Luego abrís un terminal (Aplicaciones > Accesorios > Terminal) y ponéis:
sudo stop network-manager
sudo killall modem-manager
sudo modem-manager --debug >modem.log 2>&1

En otro terminal:
sudo NM_PPP_DEBUG=1 NetworkManager --no-daemon >nm.log 2>&1

Enchufad el módem y le dais a conectar. Lo dejáis 2 ó 3 minutos para que se conecte. Pasados esos 3 minutos le dais a CONTROL-C en los dos terminales y los cerráis.
Luego os vais a Lugares > Carpeta personal. Le dais con doble click a los dos ficheros de antes (nm.log y y se abrirán con el gedit. Copiáis todo y lo pegáis en Pero antes buscad en el modem.log la palabra "PIN" y si aparece vuestro PIN lo borráis, para que no aparezca publicado. Al final el os dará un enlace por cada fichero, pues lo ponéis en los comentarios. Cuando tenga un rato lo miro e intento averiguar el problema.

Tuesday, October 27, 2009

Grading Packet Tracer activity files from Moodle

I love Cisco's Packet Tracer. One of my favorite activities consists of building a completely operational network, then causing a random fault somewhere and leaving students with the broken-down network to figure the problem out. These kind of activities put a lot of skills to the test: you need to understand the network, know which tools to use, emit a valid diagnostic and find a proper solution that doesn't break something else. In fact, I'd only need to page my students at 3am to make it look like a real life problem :)

With Packet Tracer's "Activity Wizard", you can even automate the grading of these kind of exercises: you just create an answer network (the student's target) and an initial network (the faulty one). Packet Tracer will figure out what changed between both scenarios and grade each of the steps required to move between one another. A lot of things can be graded: setting the correct netmask, using the right cable, issuing any IOS command, etc. Students start off from 0% and get to 100% when they reach the answer network. This makes life extraordinarily easier for the teacher. Creating the initial and answer scenarios takes quite a bit, but it's definitely worth the effort.

If you use Moodle, you can propose new activities, let the students work on them, and after they're done, you just open the result PKA file to check their score. I normally grade PKAs as "completed", "incomplete" or "not handed in". Only when they're incomplete do I make some comment, usually with a hint to what's going wrong.

Now, wouldn't be great if Moodle could put the PKA score out to the gradebook automatically? That way you don't even have to download the "completed" activities. Moodle grades them for you.

Well... this is the closest I've gotten to it. The key to this solution is a .jar that comes with Packet Tracer. This .jar has a bunch of libraries that allow PT to be used as a back-end, issue commands, query the status of any device and, among other useful things, obtain the studen't score.

You need:
  1. Packet Tracer 5.2. I'm not sure if this file was in5.0 or 5.1, so just get 5.2 (it fixes quite a few bugs anyway). I tried this with the Linux version. Look for the "ptaplayer-011.01.jar" under /usr/local/PacketTracer5/extensions/ptaplayer/.
  2. A Java compiler. In Ubuntu, "apt-get install openjdk-6-jdk" or "sun-java6-jdk" will do.
Get this code and paste it in a file named "":
import apiipc.generated.system.*;

class Grade
public static void main(String args[])
throws Exception
File file;
PacketTracer packettracer;
if (args.length != 1) {
System.err.println("You need to specify a pka file to grade");
file = new File(args[0]);
packettracer = new PacketTracer("localhost", 39000, true);

ActivityFile activityfile = packettracer.getActivityFile();
Double s = activityfile.getPercentageComplete();

System.out.println((new StringBuilder()).append(s).append("\t").append(args[0]).toString());


Compile it with:
$ javac -classpath ptaplayer-011.01.jar

Now get some PKA file and try to grade it!
$ java -classpath ./ptaplayer-011.01.jar:. Grade

Yes, that "100.0" indicates the score is 100% :)

You might want to wrap the ugly java command line into a simpler script. One thing I noticed is that Packet Tracer opens a window even though it's running in "no-gui" mode. No big deal on an X desktop (the window will pop up briefly and then disappear), but it makes the whole thing totally inadequate for headless servers without X, since Packet Tracer does need X. As a workaround, you can use xvfb. Like this:

sd=$(dirname $0)
xvfb-run java -classpath "$sd"/ptaplayer-011.01.jar:"$sd" Grade "$1"
sleep 1 # Give xvfb time to die

That's about it. Put this, Grade.class and the .jar file in ~/pkagrader and just do ~/pkagrader/grade to get the score.

When you have a bunch of PKAs, just do this to grade them all:
$ for i in *; do ~/pkagrader/grade "$i"; done

A few challenges still remain...
  1. As of 1.9.5+, Moodle doesn't support downloading all the assignment files at once. You have to go one by one. Fortunately this patch will add this feature. It applies cleanly on a 1.9.5+ install. This is the jira issue about the issue.
  2. The ultimate solution would be creating a new type of activity for Moodle, something like "Packet Tracer activity" and having the grader fire up automatically after a student uploads a .pka. Anyone interested?