Is a proper transition to IPv6 actually impossible?

I don’t see a viable path from our current situation to a natural inevitability where IPv6 can be thought of as properly adopted: where deploying or signing up IPv6-only clients or services would be a sane and realistic thing to do.

In our current situation on the public Internet, IPv4 support is mandatory, but IPv6 is optional. Servers have to support IPv4 because without it, IPv4-only clients would not reach them. They don’t have to support IPv6 because IPv6-only clients incapable of reaching the IPv4 Internet are not a phenomenon yet. Similarly, clients have to support IPv4 (or emulate it), because without it, IPv4-only servers would be unreachable. They don’t have to support IPv6 because IPv6-only servers incapable of being reached by the IPv4 Internet are not a thing yet. These constraints are logically self-enforcing: clients will have to continue to support IPv4 because servers do and vice versa.

How do we get from this situation to one where IPv6 reachability can be taken as a given for all servers and clients on the public Internet? At the moment, the incentive to set up IPv6 isn’t there yet, apart from a warm feeling administrators may feel that they are preparing for something, we are assured, is going to come in handy in the future. The death of the IPv4 address space has been greatly exaggerated, or rather, we’ve kept it on life support by hacking in a number of workarounds such as NAT and re-allocating smaller and smaller subnets, departing from our earlier notions of class based allocation. We’re constantly warned that the gig is very much up: any moment now, the last IPv4 address will be handed out, and from then on, we’ll be thankful for having set up our IPv6 support ahead of time because we’re going to need it right away.

But are we really going to need IPv6 right away? Is it even going to be possible to use it right away, or ever, despite IPv4 address depletion?

Can we implement IPv6 support now, so that it’s “ready to go” once we need it? A lot of ISPs, software/hardware vendors and server administrators are working on this right now, despite the lack of immediate benefit, because it’s the “right thing”. DNS servers, web servers, and client ISP connections supporting IPv6 are popping up all over the place: you can even say there are lots of them. Not the whole Internet, but enough of them to represent a significant effort and expenditure. The trouble with this is, it’s never going to be complete. Only a practical 100% deployment is going to satisfy the pre-requisite for any sane ISP or service provider to provide an IPv6-only service. Let’s say 90% of servers and clients are super-responsible and do the “right thing”.  We will still have to rely on IPv4 everywhere lest people be stuck on a subset of the Internet where not quite everything is reachable. Nobody would knowingly sign up to a service that limits access to 10% of the Internet, so nobody is going to offer it, and there will be no more incentive for administrators and ISPs to continue rolling out than there already is.

Perhaps, then, will we be forced, by a “big crisis” in which the world suddenly has to scramble to implement IPv6 all-at-once in a massive panic bigger than Y2K? Let’s assume the depletion of IPv4 addresses happens, and it’s sudden. Panic stations! What do we do? The problem is, we can’t just switch to IPv6 only: that would still cut off new clients from large sections of the Internet, or cut off new servers from large numbers of clients. A big crisis is going to bring us no quicker out of the stalemate of there being no incentive to implement IPv6 until everybody else does, and any one group brute-forcing people into going IPv6-only before the rest of the Internet is ready will just be inflicting unnecessary pain. So we scramble to find other solutions. More stop-gaps. We find other IPs and we NAT huge numbers of clients or servers behind them. We’ve already started: NAT64 is a sophisticated way of giving IPv6-only services the ability to talk to the IPv4 Internet. The trouble with this is, these solutions which are intended as stop-gap solutions end up becoming the new Internet: the new way people do things. IPv6 is well and good, but we need the stop-gap solutions for the real Internet, which continues to need people to be able to talk IPv4. We end up with a situation where IPv4 addresses have depleted and we are still no closer to being able to sign up or deploy true IPv6-only clients or services, still thinking of our current situation or crazy NAT and other technologies as a temporary transitional period until people get IPv6 implemented. And a segment of the Internet still continues to ignore IPv6 because they still don’t need to.

And I’m reminded of another failed standard that everybody thought was going to be the next big thing: XHTML. Specifically, a full transition to XHTML on the public web – where we didn’t have to make it HTML-compatible and serve it as text/html – never happened, because support for it never eventuated, and support for it never eventuated because nobody stopped making it HTML-compatible because it wouldn’t have been supported. Oh, how we hoped that, for example, Microsoft would just implement it because it was a “good thing” to do. But they felt no incentive to do so, understandably enough.

In that case, smart engineers and innovators realised the mistake of trying to bootstrap everybody onto a non-backwards-compatible standard and started work on something saner – an extension to HTML that was fully backwards-compatible, requiring no “leap of faith” transitional moment. That new standard was HTML5. And the world adopted it enthusiastically, never needing to worry about adopting a new standard before the world at large could actually benefit from it.

Is IPv6 going to suffer a similar collapse? If not, why not? How is it actually going to be possible to let go of IPv4 and all IPv4-supporting transition mechanisms and reach the point where we can deploy IPv6-only hosts on the public Internet? I’m not a qualified network engineer but I do sense there may be a gap in strategy here.

Chromecast: First impressions

I got a Chromecast recently, and it’s worth writing about because I feel it’s part of an important step in how we enjoy media (television, movies, music) and will do in the future.

So, on to my observations.

My general misunderstanding of what they did

Before getting one I never properly understood how they actually worked and what they did. I did understand that videos weren’t streamed to the Chromecast via your client device, and that instead the Chromecast directly fetched the video to stream.

What I didn’t understand was that the number of things you could stream on it were endless, and limited only by the vast array of apps on the Chrome Web Store, Play Store (Android) or App Store (iOS) which chose to take advantage of it (and that anyone could develop such an app of their own).  I assumed that it was limited to a small set of high-profile apps: Netflix, YouTube, Play Movies & TV, Play Music, and probably a handful of other things Google will have deemed worthy of building into the device.

In reality, the Chromecast device itself has no “apps” built into it, well, apart from the thing that sets up its wifi connection and the thing that shows wallpapers as a sort of screensaver when it’s idle.  The “apps” all run on the client device and control it from there, whether that is your Android device, your Chrome web browser on a computer, or an iOS device, and anyone can write an app for any of those three devices that can control it.

The device can basically stream a bunch of different video or audio formats or display pictures, which it downloads from whichever server the app specifies.  The app you are using tells it what address and protocol to fetch video, audio or pictures from, and how to show it on screen.  Once you start a video streaming, you can kill the app and it’ll keep streaming on the Chromecast, but because it has no inherent controls or intelligence itself, that’s all it will do – you can’t pause, restart, or change anything unless you are still using the app and the app is still connected to it.

Issues I’ve found

Even though I wouldn’t say I’m elderly, looking down at my phone, then back up at the screen, repeatedly, strains the eyes a bit.  Once you get a video or music started, you don’t really need to do this much I guess.

Once you’ve been watching a show for a little while and you want to pause it because the baby is crying or something, it’s not a case of finding just one pause button on your remote: because it’s your Android device, it has probably gone to sleep.  So you wake up its screen first.  The app you were controlling the Chromecast with may have a pause control on the lock screen, but if so the button will be small so you actually have to focus on the screen a bit to see where the button is a press it carefully to pause.  But occasionally the app may have closed so you have to unlock your device and find the app again in your home screen or app drawer.  Sometimes the app may have even disassociated itself with the Chromecast, in which case you have completely lost control over it; the only way to stop it is to go back in to the app, re-connect with the Chromecast, choose the Chromecast device from the menu, then hope it brings up what was playing – and if not, you may even have to search for what you were watching all over again. This is obviously more an issue with the individual app than with the Chromecast model in general.  If the app that was in control of the Chromecast stayed running always, and always had lock screen controls working and visible, this would minimise some of these problems.

I started a YouTube “mix” of 50 videos and for some unknown reason the Chromecast stopped playing after only 4 videos.  Waking up my phone showed that the YouTube app was no longer running but opening it up again showed that it did still know it was connected to the Chromecast, it just wasn’t playing anything for some reason.  I don’t know what to blame this glitch on.

I watched a TV episode using the Stan app (I have free subscription to Stan) and with 2 minutes remaining it mysteriously stopped playing and again I looked at my phone to find no sign of the Stan app running.  Going back in, I found that it had disassociated itself from the Chromecast and didn’t remember where I was in the episode: sharing to Chromecast and pressing play again sent me to the start.  Again, more an issue with the individual app than the Chromecast or that model in general.

PHP: recursion causes segmentation fault

The fact that attempting recursion in PHP leaves you at the mercy of segmentation faults isn’t anything new, really (though it is new to me now).  Since 1999, bug reports to this effect have been knocked back, stating that this is the intended behaviour.

This is all due to technical limitation inside PHP, which I guess is reasonable.  PHP pushes to the stack each time you enter a new function call, which is quick and handy, but limits your recusion depth.

What annoys me is that it’s one more reason that PHP is not very good for creating portable code.  There’s no warning or PHP error before you exhaust the recursion limit, PHP just crashes (bringing down an Apache process with it if you’re using mod_php).  The “safe” depth of recursion you could do on PHP is hard to predict, and is going to vary between installations and builds.  I’ve seen posts online showing people doing experiments to try and figure out PHP’s recursion limit, but there’s too many factors at work – how PHP’s been built, whether it’s 32-bit or 64-bit, the type and quantity of variables you are passing as arguments or return values, and so on.  In some code of my own, I’ve seen php-cgi crashing after just 20 to 30 levels of recursion.  The function was passing some rather large arrays as return values.

You could argue that the same issue is going to happen in a C program, and that any decent programmer should be ready to code around this, anyway.  However, in my mind PHP should be a level of abstraction higher than this sort of detail; a programmer in such a high level scripting language should not need to worry about the underlying low-level implementation.  Ideally, PHP ought to put out a PHP error, allowing for the problem to be reported gracefully just as if you’d tried to call a non-existant function, and the PHP interpreter should end the script gracefully without crashing any processes.

The bottom line is that if you’re doing recursion in PHP, you should use your own method to limit the depth to a very conservative level, or perhaps rewrite it to use a big loop instead of recursion.  If, like me, you’re writing a recursive descent parser, if you need to make your code portable you may be better off to rewrite it to use a big loop.

Stable vs stable: what ‘stable’ means in software

I’ve come to learn that when someone refers to software as ‘stable’, there is more than one quite different thing they might mean.

A stable software release

A stable software release is so named because it is unchanging.  Its behaviour, functionality, specification or API is considered ‘final’ for that version.  Apart from security patches and bug fixes, the software will not change for as long as that version of the software is supported, usually from 1 to many years.

Software that is intended for the public to use is usually “stable”.  It is released, and following the release no new features are added apart from the odd bug fix.  To get new functionality users eventually need to upgrade to the next version.  Any problems with the software (unless they can easily be fixed with a bug fix update) are “known” problems, and the software vendor does not need to keep track of more than one variantion of these problems for any given version.

Examples of releases that are the opposite of stable include development snapshots, beta releases, and rolling releases.  A characteristic of all three of these is that they are in a frequent state of change; even their functionality and feature list can change from week to week, or day to day. You cannot depend on them to behave the same way from one week to the next.

Some people like that with non-stable releases such as development snapshots, beta releases or rolling releases, they are always getting the latest features as soon as they are written into the software.  In many cases, these releases also fix deficiencies or bugs that would otherwise remain stagnant in the stable release.  However, with no stability in the feature list or functionality, this affects the ability for documentation, other software that interfaces with the software, plugins, and more to function: a change in the software can mean these become out of date or fail to work anymore.  When you have software which needs to work well with a lot of other software, having a stable release reduces the frequency with which changes in the software will break compatibility with the other software relying on it.

Another meaning of stable

Another meaning of stable exists in common use, where people take it to mean “working reliably” or “solid”.  That is, people refer to software that runs consistently without crashing as stable.  You can see why they may use the word in this way: in real life, when something can be described as stable, it won’t fall over.  If a chair is stable enough, you can sit in it and it won’t topple or collapse.

However, confusion arises when people use this form of the word stable to refer to software that isn’t stable in the earlier sense.  For example, it’s why you see comments like “I’ve been using the beta version since February and it is very stable” or “the newer version is more stable”.  The point that these comments make is not that the software is final and unchanging, as in a stable software release, but more that the software is stable like a chair might be stable.  It seems reliable, and the user hasn’t experience any major problems.

This kind of stability won’t help developers extending the software with other software, or writing plugins or customisations for the software, since the fact that at any given time the software is running well does not make up for the fact that the software is subject to frequent changes.

Commenters or reviewers who describe beta or rolling releases of software as stable, might want to try describing them as “solid” or “reliable” instead, to save confusion with a stable release which is an unchanging release.  Or, the fact that the same term is understood in two different and sometimes conflicting ways may indicate that the term is not an ideal one in the first place.  It does, however, seem firmly entrenched in the software development world, where the meaning of a stable release is well known.

How JPEG and MPEG picture compression algorithms work

While their names sound similar apart from the first letter, JPEG and MPEG refer to the names of two unrelated organisations.  The Joint Photographic Experts Group (JPEG) created the JPEG image file format (as well as JPEG 2000, a different format), while the Moving Picture Experts Group give their backing to a large number of audio, video, container and stream formats to support the transmission of digital audio or digital video, which are grouped into generations (MPEG 1, MPEG 2, MPEG 4).  For instance, the popular MP3 audio file format is a part of MPEG 1 (MPEG 1 audio layer 3), DVDs and digital television usually use standards from MPEG 2, and the popular “MPEG 4” or “DivX” video format is standardised as part of MPEG 4 (MPEG 4 part 4).

All of the formats, including JPEG images and all types of MPEG videos, work in a very similar way, which I’ll call block based DCT image compression.  This involves chopping up the picture into blocks, 8 pixels by 8 pixels, and compressing each block separately, and using a mathematical transform called a Discrete Cosine Transformation (DCT).

Here are some of the steps involved in JPEG and MPEG image compression:

Colour space conversion and resampling

If necessary, the image is first converted into the correct colour space and resolution.  This involves separating the colour image into 3 separate images or ‘channels’: a luma channel which carries the brightness information (like a black and white image), and two chroma channels which carry the colour information.  Furthermore, the luma channel is usually given double or quadruple the resolution of the colour channels; this saves some storage space already, and works because humans are much better at seeing intricate changes in lightness than colour, which is why we prefer reading light text on dark background and vice versa, to red text on green or similar.

Separate into 8×8 blocks and perform Discrete Cosine Transform

Each channel of the image is then divided into blocks of 8 pixels by 8 pixels (64 pixels per block).  To each block, a mathematical formula called a Discrete Cosine Transform (DCT) is performed.

Before the discrete cosine transform, you have 64 values, each representing a pixel in the block.  After the transform, you have 64 values, each representing a particular frequency of any detail in that block.  It is like taking a piece of audio and constructing a spectrum analysis, where you get a frequency vs amplitude curve, except the curve is more of a surface, because it’s in two dimensions.  The very first resulting value represents a frequency of ‘zero’, ie it is the average value of all of those original 64 pixels.  The rest are co-efficients: values which you can input back into the inverse DCT function to get the original pixel values.

Storing these coefficients is no more efficient than storing the original pixel values.  In fact, due to rounding error you need greater precision in order to be able to store them than the pixel values.  How, then do we achieve any compression?  Well, for that, you need to throw away some data.

Quantisation

Quantisation is the process of reducing the precision of a number so that it is less accurate, but takes fewer digits (that is, bits) to write, or store.  It is, quite simply, dividing a number by a certain value, and throwing away the remainder.  When multiplying by that value again in an attempt to get the original number, chances are that the number is close to, but slightly different to, the number you started with.  The more you divide the number by, the greater the strength of the quantisation and hence the greater the likely loss in precision once you multiple the number again.

So, the previous compression step left us with 64 co-efficients arranged in an 8×8 matrix, representing the values of different horizontal and vertical frequencies within that 8×8 block.  Now, we apply quantisation to these coefficients, reducing their precision by dividing them by a specific number and throwing away the remainders.  When we save a JPEG image or MPEG movie we can usually set either a quality slider or quantisation factor – these just vary the number we are dividing by and hence the amount of precision we want to retain.

The JPEG and MPEG compression can also apply different amounts of quantisation to the different frequency coefficients within a single block, or different amounts per block in an image.  When this is done, it is all in an attempt to get the best looking picture, as perceived by human eyes, for a given amount of quantisation.

Encoding the coefficients

Depending on the amount of quantisation applied, some or most of the smallest coefficients will have been reduced to zero, because they were so small and insignificant to start with and during quantisation, resulted in a value less than 1 and therefore were discarded.  It’s likely that a typical block will only have a few non-zero coefficients remaining after quantisation.

The co-efficients, which were laid out in an 8×8 matrix, are now picked out in a specific order for encoding: usually a “zigzag pattern”, chosen so that the smallest co-efficients will likely be last; any zero-coefficients at the end are not encoded at all.  The remaining coefficients undergo some form of lossless coding, which minimises the bits taken by the remaining coefficients.  The type of coding chosen varies between sub-types of MPEG video, but the general idea is that each coefficient is represented using a variable number of bits, so that smaller ones take less space.

Motion

The process so-far is simplified, but basically true for still images, and for the still component (keyframes or I-frames) of MPEG video.  MPEG video encoding can also involve motion estimation, where a block can be optimised by only encoding the difference between it and a nearby area of some other frame.  Encoding is still done per-block, and the blocks still undergo DCT and quantisation, but the selection of a reference point in another frame can be somewhat complex.

Decoding the image

Decoding is a reverse of the above process: the stream is decoded to find the coefficients for each block, and these coefficients are multiplied by the same number they were previously divided by, in order to reverse the quantisation.  The quantisation process did involve some precision loss, which can be seen by this point.  Then, an inverse DCT is applied to get pixel values for the block.

Finally, if it is a colour image and the two chroma channels used a lower resolution than the luma channel, these are now up-sampled – by interpolation – to match the luma channel, and then the image can be converted into a suitable colour space for viewing, such as RGB (when displaying on a monitor).