contiki-os/contiki — pull request #628 by ejoerns (2014-04-10 00:25:53+00:00)
Title: [Cooja] Rewrote Coojas mote memory management

During working with Cooja and trying to simulate, analyze and debug different types of motes (including mspsims, avrora, native) I ran into several problems with mote memory handling.

A simple example is the `IPAddress` interface which reads ip data from memory. It assumes a padding of 8 bit after the 8 bit `isused` flag. This is true for 16 bit mspsim but if I use an 8 bit AVR mote there is no padding byte and thus the `IPAddress` interface shows invalid data.

When I tried to write an ipv6 neighbor/route table visualizer I ended up in frustration. This and because of many comments I found in the code that say something like "we could do some boundary checks here" I started rewriting, simplifying and extending the mote memory access capabilities of Cooja.

Well, here is the result of my work. I know It's a lot of code for a single commit but i was not able to split it up in multiple commits that make sense on their own.

Note that if this becomes merged there is also an advanced `VariableWatcher` plugin, an extended Avrora integration, and some more waiting ;)

Below I added the original commit message as its markdown is easier to read than in the code window:

---
This provides a more generic and easy way of handling memory access to
motes with different kinds of memory layouts, including different word sizes,
different endianess and different data type sizes. It supports reading
and writing both simple and struct data including several boundary checks.

The base class `Memory` provides a simple memory interface based on
addresses. It supports read and write operations both for different data
types including fixed-width data types and pointers.

The subclass `VarMemory` adds support for accessing memory based on
symbol (variable) names.

Every mote implementaiton has to provide an instance of `MemoryLayout`
to announce its word size, endianess, etc and an implementation of the
`MemoryInterface` interface to provide a minimum set of mote memory
segment readout and manipulation capabilities.

The two classes `MoteMemory` and `SectionMoteMemory` are a glue between
`VarMemory` and the motes `MemoryLayout` and `MemoryInterface`.
In contrast to `MoteMemory` which represents a whole memory, the
`SectionMoteMemory` represents a memory with different independent
sections.
All read and write operations include boundary checks to warn if invalid
memory regions are accessed.

For reading and writing both simple and complex data structures such as
structs the base class `MemoryBuffer` (uses ByteBuffer internally) can
be used which also handles padding.