FUDCon Pune: My talk on ‘Linux Virtualization’

My second talk at FUDCon Pune was on Virtualization (slides) on day 2.  While I had registered the talk well in advance, I wasn’t quite sure what really to talk about: should I talk about the basics of virtualization?  Should I talk about what’s latest (coming up in Fedora 16)?  Should I talk about how KVM works in detail?  My first talk on git had gone well, and as expected for this FUDCon, majority of the participants were students.  Expecting a similar student-heavy audience for the 2nd talk as well, I decided on discussing the basics of the Linux Virt Stack.  Kashyap had a session lined up after me on libvirt, so I thought I could give an overview of virt-manager, libvirt, QEMU and Linux (KVM).

And since my registered talk title was ‘Latest in Linux Virtualization’, I did leave a few slides on upcoming enhancements in Fedora 16 (mostly concentrating on the QEMU side of things) at the end of the slide deck, to cover those things if I had time left.

As with the previous git talk, I didn’t get around to making the slides and deciding on the flow of the talk till the night before the day of the talk, and that left me with much less sleep than normal.  The video for the talk is available online; I haven’t seen it myself, but if you do, you’ll find I was almost sleep-talking through the session.

To make it interactive as well as keep me awake, I asked the audience to stop me and ask questions any time during the talk.  What was funny about that was the talk was also being live streamed, and the audio signal for the live streaming was carried via one mic and the audio stream for the audience as well as the recorded talk was on a different mic.  So even though the audience questions were taken on the audience mic, I had to repeat the questions for the people who were catching the talk live.

I got some feedback later from a few people — I missed to introduce myself, and I should have put some performance graphs in the slides, as almost all users would be interested in KVM performance vs other hypervisors.  Both good points.  The performance slides I hadn’t thought about earlier, I’ll try to incorporate some such graphs in future presentations.  Interestingly, I hadn’t also thought of introducing myself.  Previously, I was used to someone else introducing me and then me picking up from there.  At the FUDCon, we (the organisers) missed on getting speaker bios, and didn’t have volunteers introduce each speaker before their sessions.  So no matter which way I look at it, I take the blame as speaker and organiser for not having done this.

There was some time before my session to start and there were a few people in the auditorium (the room where the talk was to be held), so Kashyap thought of playing some Fedora / FOSS / Red Hat videos.  (People generally like the Truth Happens video, and that one was played as well.)  These, and many more are available on the Red Hat Videos channel on YouTube. There was also some time between my session and Kashyap’s (to allow for people to move around, take a break, etc.), so we played the F16 release video that Jared gave us.

Overall, I think the talk went quite well (though I may have just dreamed that).  I tried to stay awake for Kashyap’s session on libvirt to answer any questions directed my way; I know I did answer a couple of them, so I must have managed to stay up.

Gearing Up for FUDCon Pune 2011: Day -2

We’re in the final stages now, and things are mostly in place:

  • Website: http://fudcon.in working fine
  • People have started arriving, cabs booked for all coming via Mumbai
    • A couple of them missed their flights, but they’re on their way with a new schedule
  • Posters, booklet, banners printed
  • Budget is under control
  • Videographing set up (but will only be available for one room)
  • Hotel and Guest House rooms ready for speakers coming in
  • Lunch and FUDPub menus finalised

And we have an overwhelming response for the conference:

  • About 50 speakers
  • About 60 sessions (talks, demos, workshops, hackfests)
  • Almost 500 registered attendees
  • About 40 volunteers from COEP

Looks like this FUDCon is set to be the biggest in terms of attendance. We’ve had to propose a draft schedule to avoid confusion with such a huge crowd. The schedule’s put up at  http://fudcon.in/program/fudcon_schedule.

What’s left?

  • Adding power extension boards for classrooms and auditorium — scheduled for tomorrow afternoon
  • Checking wifi access at venue.  We have rented a few routers to boost their signals if needed (we think they’ll be needed)
  • Setting up banners around the campus — tomorrow, after classes

Hmm, amidst all this, I have to find time to ready my slides and prepre for my talks. /me runs to get it done.

KVM Forum 2011

This year’s KVM Forum, like last year’s, was co-located with LinuxCon NA.  Vancouver city played the host this year.

The interest in KVM has been rising over the years; from the first Forum in 2008, when we were just about 30 developers in a single room presenting work done and chatting about directions to take (the virtio design was hashed out during this conference), this year there were about 150 attendees, discussing optimising KVM instances and tracing the guests.  That’s a really big leap in three years.

Due to lots and lots of good talk submissions, not all of which could be rejected, the talk slots were reduced to 30 minutes per talk and there were parallel tracks in the afternoon sessions.  This allowed for more talks, but small Q&A sessions, and obviously, having to miss out on some talks due to another talk happening at the same time. All the talks have been video-recorded, though, and they should appear soon on the Forum page.

Some brief notes on the talks I attended:

Avi’s keynote started off the Forum. One of the main points was the lack of marketing in KVM, and how the formation of the Open Virtualization Alliance to bridge the gap.  He also talked about an ARM port finally getting some development (on his 2008 prediction of an ARM port coming soon not materialising, he said in his 2010 keynote: “this is a case of reality not catching up with predictions”).

Paul Mackerras then talked about KVM on the POWER7 processor, another processor to get virt extensions. He talked of replacing pHype with KVM and the challenges to run custom firmware and Linux directly on the machines, as opposed to the default firmware which can only run pHype.

Alex Williamson talked about VFIO-based PCI device assignment.  The current device assignment code makes the kvm.ko module a device driver for the device to be assigned to the guest (I’m to blame for that, I wrote that code). The idea with VFIO is to move the complexity of device assignment into userspace.  VFIO is a device driver which exposes devices in /dev/vfio*, via which the device can be configured and controlled.  This is a much more cleaner and secure way of doing device assignment.

Kevin Wolf talked on the current state of block file formats, and the next-gen block file format.  He criticised the NIH syndrome of people developing new formats in isolation instead of enhancing the current ones.  He’s working on collecting the best ideas from QED and FVD, the newest formats, and putting them into QCOW3 while retaining the features from QCOW2, which the other formats dropped.

Stefan Hajnoczi and Paolo Bonzini then talked of a new virtio-scsi transport, Stefan is working on the new in-kernel SCSI target and using vhost to accelerate communication.  Paolo has already written the virtio-scsi spec.

Asias He presented the Native Linux KVM tool. My reaction on the presentation was that they started out as a toy project to run Linux guests, but their planned feature set sounds like they are going to replicate qemu.  That’s not a bad thing, though, KVM (the kernel module) was designed to be able to drive multiple userspace hypervisors, and this is the first one that’s making some news.

That ended the first day’s morning session.  The afternoon session had parallel tracks, I attended the following:

Andrea Arcangeli’s talk on the future of Memory Management in KVM had quite a lot of TODO items.  He particularly talked on NUMA management and his ongoing work on it. Current NUMA policies are static; he wants to make them dynamic, with the guest moving to the node where RAM is allocated, and vice-versa.

Rik van Riel then talked about some more MM work: free page hinting, which can improve the memory utilisation both in the host and guest, and automatic memory resizing.  There might be some drawbacks to this as free page hinting may not consider THP and end up breaking huge pages.

Next was “experiences porting KVM to SmartOS“, a lively and animated talk by Bryan Cantrill. This talked about porting the kvm module and qemu-kvm to Illumos, a Solaris clone.  They primarily want the benefits of ZFS, DTrace, Zones and KVM. No matter how much interesting it sounds, the question on licensing was addressed vaguely (if at all) during the talk.  In a private chat later, Bryan mentioned there’s no violation at all.  There’s some talk at lwn.net on licensing as well.

Michael Tsirkin talked on new virtio networking features. Main was the event indexing feature which reduces the exit interrupts to host if there are pending exits and a new buffer is queued in the vring.  Sort of like NAPI for virtio. He also talked about zero-copy TX and filtering, and the security pitfalls of doing so.

Ryan Harper then talked of IO throttling in QEMU, a feature that uses cgroups to ensure guests don’t go over their allocated quota of IO activity.

A couple of lightning talks were held, where Dan Magenheimer talked of Transcendent memory, and how that can help with the work that Rik is doing.

A few BOF sessions were lined up, people gathered in groups to discuss.  I caught hold of Hans de Goede, Alon Levy, Anthony Liguori and Gerd Hoffmann to discuss the state of chardevs in QEMU.  Hans had initiated a discussion just prior to the Forum on the non-upstream RHEL and Fedora patches that we carry for chardev flow control.  Anthony mentioned some races in the existing implementation and came up with his own.  He promised to merge the cleanup patchset soon and float the flow control patches to the mailing list.

My other topic, on guest – host communication, got fizzled out, partly due to my jet lag not allowing me to concentrate much, and the other interesting topic, moving qemu away from C.  I used that time to talk with other people.

That ended day 1 of talks. All the attendees then headed out to a pub nearby to exchange stories over beer.

The second day started with Anthony Liguori presenting the keynote on QEMU development. He mentioned how the project has been doing very well with sub-maintainers doing pull requests. A lot of patches have been committed since the last year. Things indeed have improved since the last year, when many people were complaining of patches bit-rotting on the mailing list for ages.

Avi then took stage again to talk of performance monitoring in KVM guests. He talked of providing a Performance Monitoring Unit to the guest via several ways: pass-through, emulating a virtual PMU and emulating a real-life PMU. He also talked of some new PMU features which are not model-specific which can be safely exposed to all guests.

Alex Graf then presented on AHCI.  This was a very cool presentation with nice animation effects (too sad it used non-free software to do that — I don’t know if free software can match those effects, though). He showed how AHCI performed much better than the default IDE storage type.  Performance is half-way between virtio-blk and IDE, but since most OSes support AHCI out of the box (notable exception being Windows XP), he made a case for making AHCI the default.  There is some work to be done before we can do that, though.

Anthony Liguori next talked about QAPI and QOM, the QEMU Object Model.  These refactorings will make QEMU machines much easier to generate, and present a much saner interface to higher-level management tools like libvirt.  The plan is to get as much work done for the impending 1.0 release.  It was refreshing to hear Anthony not talk of replacing code in one big patch (or one big series), and rather work in incremental steps in-tree.  His last year’s main point of developing code in separate trees and doing merges had not gone down well with many developers.

Markus Armbruster then talked on qdev, on where we are, what’s left, and what are the major pain points.  qdev conversion still remains one of the TODO items from last year, and the more it gets delayed, the more everything else gets delayed in QEMU (including QOM conversion, which could be an incremental step from qdev).

Alon Levy then presented on SPICE, the current status as well as the future. The SPICE protocol is an alternative to VNC with a much better focus on high-latency links and more than just video over network.

Gerd Hoffmann described his work on the USB subsystem. QEMU could go from the last project to support USB 2 to the first one to support USB 3. He also highlighted the work done on bringing down the CPU usage with USB tablet devices to minimal, a common complaint that was heard from users.

That ended the first session; the talks I attended in the parallel tracks were:

KVM Graphics Device Assignment by Allen Kay. We had worked together on PCI device assignment a few years back, and now Allen Kay talked of some roadblocks and ideas in implementing graphics device assignment and experiences from doing so in Xen.

Live block copy in QEMU is being worked on by a few people, Marcelo Tosatti presented the work done so far and the direction in the future. He talked of how the two seemingly independent features of live block copy and snapshot merges can share code.

Joerg Roedel then talked of AMD IOMMU v2 support in KVM: the new feature set makes it possible to not pin all the guest memory pages on the host.  This alone is a very important feature for the future of device assignment.

Next up was Juan Quintela’s session on Live Migration.  It was an entertaining ride on the challenges faced and the new directions to take.  One of them was post-copy migration, where the guest memory is faulted over the network after the guest is running on the destination host, since the amount of guest RAM has been increasing over time.

I missed out on the next two sesions, talking to people.

I rejoined for postcopy live migration by Takahiro Hirofuchi. As promising as it may sound, Anthony wanted to ensure we have eked out maximum performance from the current pre-copy implementation and then look at post-copy.  He also asked for benchmarking results for post-copy migration.  An interesting case here may be to guess the working set of a guest, perform a pre-copy using this set of pages, and then switch to post-copy.  The guessing of working set could be done via a guest agent or using MMU notifiers in the host.

That ended a very very long two days of the KVM Forum. We Red Hat folks had a dinner hosted by CTO Brian Stevens, so we headed out to the nearby brewery and enjoyed the fresh lager there.

KVM Forum 2011

The KVM Forum for this year is happening in Vancouver, Canada:

http://www.linux-kvm.org/page/KVM_Forum_2011

The schedule’s jam-packed; this is the first time we’re going to have parallel tracks (which sucks, since one can’t attend all the talks).

There has always been interest from developers in KVM, being the nice, clean, modular solution that it is. But now that it’s been dominating the SPECVirt results, businesses are looking at it as well, so there are a few end-user talks on the schedule this time, which is nice to see.

I’m going to be running a BoF session on guest agents and guest-host communication protocols.

I’m looking forward to meet the team.  I’m not staying back for the co-located LinuxCon Vancouver (though KVM Forum participants get a free entry; so you could register for KVM Forum instead of registering for LinuxCon if you haven’t done so yet).

.

FUDCon India Planning: Weekly Meetings

If you want to keep track of how FUDCon India planning is shaping up, or want to lend a helping hand in deciding how it shapes up, there are two weekly meetings you should be aware of:

  1. The IRC meeting on #fudcon-planning on irc.freenode.net every Friday at 1300 UTC / 1830 IST.
  2. The weekly face-to-face meeting at the Red Hat office in Pune, India.  This happens every Tuesday at 1500 IST.  If you can’t attend these and if some other day works for you, drop us an email at the India list.

The preparations for the FUDCon are well under way, watch the India list for minute-by-minute details.

FUDCon APAC 2011: Pune, Nov 4-6

Jared Smith, the Fedora Project Leader, has announced the Pune bid has won for the APAC FUDCon for 2011.

https://fedoraproject.org/wiki/FUDCon:India_2011

If you’re planning to attend, there’s information on travel and costs on the bid page above.  A few community volunteers who will speak at the event can be sponsored, subject to budget restrictions.

Make sure to get your proposed talks or hackfests listed on the link above.  We already have a healthy list of topics; I’m eagerly looking forward to the event.

For people local to Pune, you can help organising the event. Please contact Rahul Sundaram, the event owner, or send an email to the fedora-india mailing list for details.

Maximum LCD Brightness Lower Than Before?

If you’re trying out a kernel newer than 2.6.38-rc6 and find your LCD brightness doesn’t go up to its maximum, here’s some help:  boot into an older kernel, set the brightness to maximum, then reboot into the newer kernel, and now you’ll get the max. brightness that you’re used to.

The git commit by Indan Zupancic explains why this happens:


drm/i915: Do not handle backlight combination mode specially

The current code does not follow Intel documentation: It misses some things and does other, undocumented things. This causes wrong backlight values in certain conditions. Instead of adding tricky code handling badly documented and rare corner cases, don’t handle combination mode specially at all. This way PCI_LBPC is never touched and weird things shouldn’t happen.

If combination mode is enabled, then the only downside is that changing the brightness has a greater granularity (the LBPC value), but LBPC is at most 254 and the maximum is in the thousands, so this is no real functional loss.

A potential problem with not handling combined mode is that a brightness of max * PCI_LBPC is not bright enough. However, this is very unlikely because from the documentation LBPC seems to act as a scaling factor and doesn’t look like it’s supposed to be changed after boot. The value at boot should always result in a bright enough screen.

IMPORTANT: However, although usually the above is true, it may not be when people ran an older (2.6.37) kernel which messed up the LBPC register, and they are unlucky enough to have a BIOS that saves and restores the LBPC value. Then a good kernel may seem to not work: Max brightness isn’t bright enough. If this happens people should boot back into the old kernel, set brightness to the maximum, and then reboot. After that everything should be fine.

For more information see the below links. This fixes bugs:

  http://bugzilla.kernel.org/show_bug.cgi?id=23472 
  http://bugzilla.kernel.org/show_bug.cgi?id=25072

Fedora Miniconf and foss.in/2010

A very delayed post on the Fedora Miniconf and foss.in/2010.

foss.in/2010 was held on the 15th, 16th and 17th of this month in Bengaluru. I could confirm my attendance very late, so I missed out on the CfP and a chance at speaking in the main conference, but I could manage to get a speaking slot in the Fedora miniconf. Thanks to Rahul for accomodating me at a short notice.

One of the main things I was looking forward to was meeting my team-mate Juan Quintela. Though we met recently at the KVM Forum 2010, I was going to use this opportunity to catch him and discuss some of the things I’m working on that overlap with his domain, virtual machine live migration, and get things going.

The other thing was to get to know more people — Fedora users and developers from India who I’ve spoken with on the irc channel but not met, other developers and users of free software from around the world. Add to that a few people who I’ve worked with and not met and also people whose software I use daily and who I want to thank for working on what they do.  It was also nice meeting the old known faces from the IBM LTC in Bengaluru — Balbir Singh, Kamalesh Babulal, Vaidy, Aneesh K. V., et al.

It’s always a certainty that there will be users of virtualization (particularly kvm) stack and it’s nice to get a feel of how many people are using kvm, in what ways, how well it works for them, and so on. That’s always a motivation.

The Fedora miniconf was on the 16th. The schedules for talks for miniconfs aren’t published by the foss.in people, so it was left to us to do our advertising and crowd-pulling. Rahul had listed the speakers and the talks on the Fedora foss.in/2010 wiki page. I went ahead and took out a few print-outs for the talks and assigned time slots for each talk depending on the suggested length given by the speakers for their talks as well as the slot allotted to the Fedora Project for the miniconf. The print-outs of the schedules were meant to be pasted around the venue to attract attention to the remotest section that was to host the miniconf, Hall C. However, we just ended up keeping the printouts as handouts at the Fedora stall that we set up. The Fedora stall was quite a crowd-puller. And since it was set up on the second day, we didn’t have to compete with the other stalls since they had their share of attendance on the first day.

The other members of the Fedora crowd, Rahul, Saleem, Arun, Shreyank, Aditya, Suchakra, Siddhesh, Neependra, … have written about the Fedora stall and their experiences earlier (and linked to from the Fedora foss.in/2010 page).

The Fedora miniconf was a great success, going by the attendance and the participation we had. My talk was the first, and I could see we had a full house. I think my talk went quite well. It could have been a little disappointing for people who expected demos, but I wanted to aim this talk towards people who had a general sense of using and deploying Fedora virt as well as Fedora on the cloud and also at people who would go and do stuff themselves rather than being given everything on a silver platter. This does resonate also with the foss.in philosophy of recent years of being a contributor-oriented conference rather than a user-originted one, so I didn’t mind doing that. Gauging by the response I got after the talk, I believe I was right in doing that. (I even got one email mentioning it was a great talk by the CEO of a company).

The other talks from the Fedora miniconf were engaging, I learnt quite a bit from what the others are up to. Arun’s talk on packaging emacs extensions was entertaining. He connects with the audience, I liked that about him.

Aditya’s talk on Fedora Summer Coding was a good call to students to participate in the free software world via Fedora’s internship programme. He narrated his own experience as a Fedora Project intern, which touches the right chords of the intended audience. I think doing more such talks will get him over the jitters of presenting to a big crowd.

Suchakra’s doing good work on accessing an embedded Linux box via a console inside a browser tab — it’s a very interesting project.

Neependra’s talk was a good walk-through of using tracing commands to see what really happens in the kernel when a userspace program runs. He walked through the ‘mkdir’ command and showed the call trace. This was a good demo. He spoke about the various situations in which tracing tools could be used, not just for debugging, and that should have set people’s thoughts in motion as to how they could get more information on how the system behaves instead of just using a system.

Shreyank’s talk on creating a web tool for managing student projects and the Fedora Summer of Code was interesting as well. It was nice to see the way an actual student project was designed and developed and how it’s going to make future students’ and mentors’ lives easier. This talk should have served as a good introduction to the flow and process students have to go through in applying, starting, reviewing and completing their project.

Apart from the Fedora miniconf, I attended a few sessions in the main conf. James Morris’s keynote on the history of the security subsytem in the Linux kernel was very informative. Rahul’s keynote on the ‘Failures of Fedora‘ was totally packed with anecdotes and analyses of the decisions taken by the Fedora project and their impact on the users and developers. Fedora (earlier Red Hat Linux) is one of the oldest distributions around, and any insights into the functioning and data as to what works and what does not is a great source of information to look for building engaging communities of users and contributors.

Lennart‘s two talks on systemd and the state of surround sound on Linux were not very new to me. However, there were a few bits in there that provided some food for thought.

Juan‘s talk on live migration was packed full of experiences in getting qemu to a state where migration works fairly well. He also spoke about all the work that’s left to do. It was totally technical and I think the people who were misguided by it being labelled as a ‘sysadmin’ talk or by the title (expecting to migrate from an older physical machine to a newer physical machine w/o downtime) quickly left the hall. Whoever stayed back were either people who work on QEMU/KVM (esp. the folks from the IBM LTC) or people too polite to walk out.

Dimitris Glezos‘s talk on building large-scale web applications was a very informative one for me. I’ve never done web programming (except for html, css and a bit of php ages ago), and this was a good intro for me to understand what various web development frameworks there are, their pros and cons, the way to deploy them, the way to structure them, etc. It was evident he took a lot of effort to prepare the slides and the talk, it was totally worth it.

Danese Cooper‘s keynote on the Wikimedia Foundation was an equally informative talk. She spoke on a wide range of topics, including the team that makes up Wikimedia, their servers and datacentres, their load balancing strategy, their backup systems, their editing process, their localisation efforts, their search for a new mirror site in the APAC region, etc. I was interested in one aspect, machine-readable wikipedia content, to which they had a satisfactory answer: they’re migrating to semantic web content and would look at a machine-readable API once they’re done adding semantics to their content.

The other time was spent at the Fedora booth and talking to Juan and the other friends.

The foss.in team announced this would be the last foss.in, so thanks to them for hanging around so long. To fill the void, we’re going to have to step up and organise a platform for like-minded people from the free/open source software community around here. I’ve been part of organising some events earlier in different capacities, and I’m looking forward to being part of an effort that provides such a platform. There’s a FUDCon being planned for next year in Pune, I’ll be involved in it, and will take things along from there.

Auto-login to web proxies using NetworkManager

My ISP uses a web proxy that one has to log into to access the Internet. This logging in is a manual, repetitive process, which is easily automatable. So I embarked on a few hour-long project to get to the proxy, supply login credentials and configure NetworkManager to auto-login via running the script each time a connection goes up.

It’s not just ISPs — hotel wifi networks, airport wifis, all use such web-based proxies that one has to login to first before the ‘net becomes accessible. So the steps I followed can be easily followed by others to add support for auto-logging into such web proxies.

I’ll get to the details in a bit, but I’ll first point to the code (licensed under the GPL, v2). It’s written in Python, a language that’s relatively new for me. I’ve written a couple of small programs earlier, but those were just enough to remind me of the syntax; I had to frequently look up the Python docs to get a lot of the details, like interacting with http servers, cookie management, config file management and so on. My C-style writing of the Python script might be evident: it should be possible for someone with more experience in Python to shorten or optimise the script.

My ISP, Tikona Digital Networks, uses a somewhat roundabout way to bring up the login page: for any URL accessed before the proxy login, it first displays an http page that has a redirect URL and a ‘Please wait while login page is loaded’ message. The page to be redirected to is then loaded. This page shows another ‘Please wait’ message, sets a cookie and does a POST action to the real login page after a 5-second timeout. The real login page asks for the username and password. After providing that info, one has to click on the Login button, which translates to a javascript-based POST request, and if the username/password provided match the ones in their database, we’re authenticated to the web proxy. The web proxy doesn’t interfere with any further ‘net access.

Now that I’ve gone through the rough overview of the approach to take, I’ll detail the steps I took to get this script ready:

Step 1: Follow the redirect URL

Open a browser, type in some URL — say ‘www.google.com’. This always resulted in a page that asked me to wait while it went to the login page.

OK, so time for a short python script to check what’s happening:

import urllib

f = urllib.urlopen("http://www.google.com")s = f.read()f.close()

print s

This snippet accesses the google.com website and dumps on the screen the result of the http request.

Here’s the dump that I get before the login.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Please wait while the login page is loaded...</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"/><META HTTP-EQUIV="EXPIRES" CONTENT="-1"/><META HTTP-EQUIV="Refresh" CONTENT="2;URL=https://login.tikona.in/userportal/?requesturi=http%3a%2f%2fgoogle%2ecom%2f&ip=113%2e193%2e150%2e95&nas=tikonapune&requestip=google%2ecom&sc=5a54aa1fd2de7a9c2b92a865de55b943"></head><body><p align="center">Please wait...<p>Please wait while the login page is loaded...<!---<msc><login_url><![CDATA[https://login.tikona.in/userportal/NSCLOGIN.do?requesturi=http%3a%2f%2fgoogle%2ecom%2f&ip=113%2e193%2e150%2e95&mac=00%3a16%3a01%3a8e%3a06%3a92&nas=tikonapune&requestip=google%2ecom&sc=5a54aa1fd2de7a9c2b92a865de55b943]]></login_url><logout_url><![CDATA[https://login.tikona.in/userportal/NSCLOGOUT.do?requesturi=http%3a%2f%2fgoogle%2ecom%2f&ip=113%2e193%2e150%2e95&mac=00%3a16%3a01%3a8e%3a06%3a92&nas=tikonapune&requestip=google%2ecom&sc=5a54aa1fd2de7a9c2b92a865de55b943]]></logout_url><status_url><![CDATA[https://login.tikona.in/userportal/NSCSTATUS.do?requesturi=http%3a%2f%2fgoogle%2ecom%2f&ip=113%2e193%2e150%2e95&mac=00%3a16%3a01%3a8e%3a06%3a92&nas=tikonapune&requestip=google%2ecom&sc=5a54aa1fd2de7a9c2b92a865de55b943]]></status_url><update_url><![CDATA[https://login.tikona.in/userportal/NSCUPDATE.do?requesturi=http%3a%2f%2fgoogle%2ecom%2f&ip=113%2e193%2e150%2e95&mac=00%3a16%3a01%3a8e%3a06%3a92&nas=tikonapune&requestip=google%2ecom&sc=5a54aa1fd2de7a9c2b92a865de55b943]]></update_url><content_url><![CDATA[https://login.tikona.in/userportal/NSCCONTENT.do?requesturi=http%3a%2f%2fgoogle%2ecom%2f&ip=113%2e193%2e150%2e95&mac=00%3a16%3a01%3a8e%3a06%3a92&nas=tikonapune&requestip=google%2ecom&sc=5a54aa1fd2de7a9c2b92a865de55b943]]></content_url></msc>-->

</body></html>

This shows there’s a redirect that’ll happen after the timeout (the META HTTP-EQUIV=”Refresh” line). The redirect is to the link shown.

Step 2: Get the redirect link

So now our task is to get the link from the http-equiv header and open that later. Using regular expressions, we can remove the text around the link and just obtain the link:

refresh_url_pattern = "HTTP-EQUIV="Refresh" CONTENT="2;URL=(.*)">"refresh_url = search(refresh_url_pattern, s)

The URL to access is then available in refresh_url.group(1). group(1) contains the matched string in parentheses above in the pattern searched.

Now open the page obtained in the refresh URL:

f = urllib.urlopen(refresh_url.group(1))s = f.read()

s now contains:

<html><head><title>Powered by Inventum</title><SCRIPT>function moveToLogin() {setTimeout("loadForm()",500);}function loadForm(){document.forms[0].action="login.do?requesturi=http%3A%2F%2Fgoogle.com%2F&act=null";document.forms[0].method="post";document.forms[0].submit();}</SCRIPT> </head><body onload="moveToLogin();"><FORM>Loading the login page...</FORM></body></html>

Step 3: Get the base URL, open login page

So this page does an HTTP POST request. The URL of the new page being loaded is relative to the current one, so we have to extract the base URL from the previous redirect URL obtained.

base_url_pattern = "(http.*/)(?.*)$"base_url = search(base_url_pattern, refresh_url.group(0))

The baseurl is then available via base_url.group(1). This regular expression pattern isolates the text before the first ‘?’, as is found in the refresh URL above.

So now we have to load the page login.do which is at address ‘https://login.tikona.in‘ and which is to be passed the parameters ‘?requesturi=http%3A%2F%2Fgoogle.com%2F&act=null‘. This calls for another regular expression by which we can isolate the ‘login.do…‘ part from the ‘action’ part of the POST request above.

load_form_pattern = ".*action="(.*)";"load_form_id = search(load_form_pattern, s)load_form_url = base_url.group(1) + load_form_id.group(1)

load_form_url is now the URL we need to access to get to the login page:

f = urllib.urlopen(load_form_url)s = f.read()

This should get our login page.

But it’s not. After spending some time checking and double-checking what’s happening I couldn’t see anything going wrong. There was just one more thing to try: cookies. I disabled cookies in firefox and tried accessing the page. Voila, no login page.

Step 4: Enable cookie handling

So we now have to enable cookies in our python script to be able to enter login information. The urllib2 and cookielib libraries do that for us, so a slight re-write of the code gets us to this:

import urllib, urllib2, cookielib, ConfigParser, osfrom re import search

cj = cookielib.CookieJar()opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

f = opener.open("http://google.com")s = f.read()

All other open calls (urllib.urlopen) are now replaced by opener.open. This way cookies are handled for the session and the login page appears after accessing the load_form_url:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Tikona Digital Networks</title><link rel="stylesheet" type="text/css" href="/userportal/pages/css/style.css" /><script language="JavaScript" src="/userportal/pages/js/cookie.js"></script><script language="JavaScript" src="/userportal/pages/js/common.js"></script>

</head>

<body><form name="form1"><div id="wrap"><div class="background_login"><div class="logo_header"><div class="logoimg"><img src="/userportal/pages/images/logo.jpg" alt="Tikona Digital Networks" /></div><div class="sitelink"><a href="http://www.tikona.in" target="_blank">www.tikona.in</a></div>

</div><div class="clear"></div><div class="login_box"><div id="right_curved_block"><div class="blue_head"><div class="blue_head_right"><div class="blue_head_left">&nbsp;</div><div class="hdng">Login</div></div></div>

<div class="clear"></div><div class="block_content"><div class="form"><table height="100%" border="0" cellpadding="0" cellspacing="0">

<tr>

<td width="126"><label>Service Type</label></td><td width="200" align="left" valign="middle"><select name="type"><option value="1">Check Account Details</option>

<option value="2" selected="selected">Internet Access</option></select></td>

</tr><tr><td width="126"><label>User Name</label></td><td width="200" align="left" valign="middle"><input type="text" name="username" value="" class="logintext">

</td></tr><tr><td width="126"><label>Password</label></td><td width="200" align="left" valign="middle"><input type="password" name="password" value="" class="loginpassword"></td></tr><tr><td width="126"><label>Remember me</label></td>

<td width="200" align="left" valign="middle"><div style=" width:30%; float:left;"><input name="remeberme" id="rememberme" type="checkbox" class="checkbox"/></div><div style=" width:70%; float:right;"><a href="javascript:savesettings()"><img src="/userportal/pages/images/login.gif" alt="" width="117" height="30" hspace="0" vspace="0" border="0" align="right" /></a></div></td></tr></table></div></div><div class="clear"> </div><div class="white_bottom"></div></div></div>

<div class="tips_box"><div class="v_box"><div id="tips_block"><div class="white_head_v"><div class="blue_head_right"><div class="white_head_left_v">&nbsp;</div><div class="wbs_version">&nbsp;</div></div></div><div class="clear"></div><div class="block_content"><div class="scrol"><h1>Importance of Billing Account Number</h1><br />

<font size="2"><ul><li>Billing Account Number (BAN) is a 9 digit unique identification number of your Tikona Wi-Bro service billaccount. It is mentioned below your name and address in the bill.</li><li>Bill payments done through cheque or demand draft should mandatorily have BAN mentioned on them. <br /><span style="color:#558ed5">Example:</span> Cheque or demand draft should be drawn in the name of &lsquo;Tikona Digital Networks Pvt. Ltd. a/c xxx xxx xxx&rsquo;. Here &lsquo;xxx xxx xxx&rsquo; denotes your BAN.</li><li>If the BAN is not mentioned or incorrectly mentioned on the cheque or demand draft, the bill amount does not get credited against your Tikona Wi-Bro service account.</li><li>In case you have paid bill through cheque or demand draft without mentioning BAN on it and the amount is not credited to your Tikona billing account, then please contact TikonaCare at 1800 20 94276. Kindly furnish your cheque number, service ID, BAN and bank statement for payment verification.</li></ul>    </font><br /></div></div><div class="clear"> </div><div class="white_bottom">&nbsp;</div></div></div>

</div><div style="padding:110px 0 0 0; float:left; width:100%;"><div class="helpline">Tikona Care: 1800 20 94276  | <a href="mailto:customercare@tikona.in">customercare@tikona.in</a></div></div>

<div class="footer_line">&nbsp;</div><div class="footer_blueline"></div>

<div class="footer">Copyright &copy; 2009. Tikona Digital Networks. All right Reserved.</div></div></div><input type="hidden" name="act" value="null"></form></body></html>

Step 5: Login

OK, this page doesn’t say what exactly to do after the username/password is entered. There’s no POST action. Instead, what they do is call the saveettings() function on clicking of the login.gif image. saveettings() is in the cookie.js file:

function savesettings(){

if (document.forms[0].rememberme.checked){ createCookie('nasusername',document.forms[0].username.value,2);createCookie('type',document.forms[0].type.value,2);createCookie('nasrememberme',1,2);

}else{eraseCookie('nasusername');eraseCookie('type');eraseCookie('nasrememberme');}document.forms[0].action = "newlogin.do?phone=0";document.forms[0].method = "post";document.forms[0].submit();return true;      }

OK, so the page ‘newlogin.do’ is to be opened as a response to the clicking of the login button. And the username and password info has to be passed along, of course.

We already have the base url for the login page that we just used. Now we have to combine the base url with the ‘newlogin.do’ page instead of the ‘login.do’ page that we accessed earlier:

login_form_id = "newlogin.do?phone=0"type = "2"

login_form_url = base_url.group(1) + login_form_id

login_data = urllib.urlencode({'username': username, 'password': password,'type': type})

f = opener.open(login_form_url, login_data)

… and success! This is enough to get the login done. I added config file handling to the final code so that the username/password are stored in a config file. The final code also ensures that we’re on a Tikona network before proceeding with the steps of logging in (by checking if the redirect URL is obtained in Step 1). See the latest code here.

Step 6: Auto-login on successful connection

Just one last step remains: a NetworkManager dispatcher script that will invoke this login program each time a network becomes ready:

#!/bin/sh

if [ "$2" = "up" ]; then/home/amit/bin/tikona-auto-login || :fi

Put this in /etc/NetworkManager/dispatcher.d with the appropriate permissions (744) and we’re good to go!

Next steps:
The project surely isn’t complete: a lot of support has to be added to NetworkManager itself to present a good UI to enable/disable these dispatcher scripts and also to prompt for a username/password instead of storing in a config file. This and several other TODO items are listed in the README file. If you plan on adding new networks that can be auto-logged in to, it’s easy to follow these steps or feel free to email me for guidance.