OpenDisXML

advertisement
Open-DIS and XML
DIS in Other Formats
Distributed Interactive Simulation
DIS is an IEEE standard for simulations,
primarily virtual worlds
• Binary protocol: what’s standardized is the
arrangement of bits in packets on the wire
• Mostly intended to push entities around in a
3D virtual world, so the most common
packets relate to position, orientation,
velocity, etc.
DIS: Entity State PDU
Entity State Protocol Data Unit/Packet:
• PDU header: common to all PDUs
• Entity ID: uniquely identifies an entity in the
world
• Entity Type: describes the entity, ie tank,
plane, etc.
• Position
• Orientation
• Velocity, acceleration, angular velocity, etc.
DIS
Remember, what’s standardized is the
arrangement of the bits in packets. There is
no standardized API
Typically you convert a packet into a
programming language object to work with,
modify, read field values, and send
Information Representation
Programming
Language
Object
DIS
Binary
Representation
Same information--position,
orientation, etc--but in two
different representations, one
contained in a Java or C++
object, one in a particular
arrangement of bits in a packet
Other Representations
Why not expand this to multiple representations? For
example, XML, Java Object Serialization format, SQL
database, etc.
The DIS format is mostly useful as a standard for
exchanging information with other simulations, but
the drawback is that nobody outside DoD M&S
understands the DIS format
If we had an XML representation of the data we could
use bring the standard XML tools to bear for data
transformation, data exchange, web services, etc.
This lets us exploit the information contained in DIS
simulations in other contexts
Other Representations
Programming
Language
Object
DIS
Binary
Representation
XML
Representation
Java Object
Serialization
Representation
XML
What are the advantages of an XML representation?
• THE standard for data interchange
• Useful for archiving
• Lots of tools available for transforms, SQL
interchange, etc
Disadvantages:
• Verbose
• Slow to parse
• Exact format not standardized (no single schema
agreed upon for DIS)
Creating XML
The Open-DIS package at sourceforge.net is
able to handle the process discussed here
https://sourceforge.net/projects/open-dis
It uses a package from Sun called JAXB, the
Java API for XML Binding
JAXB
The process of “data binding” often comes up with XML.
This is exactly the problem discussed earlier of
having the same information in two different formats:
XML and Java objects
You’ve got an XML document, and want to process the
information in it. Often the easiest way to do this is
to convert the XML document to Java objects,
perform the computation, then convert the Java
objects back to XML
Since this happens so often, it makes sense to have an
automated framework to do this
JAXB
<Points>
<point x=“1.0” y=“2.0”/>
<point x=“3.0” y=“4.0”/>
</Points>
You want to convert this to something like a list of the
following objects
public class Point
{
float x;
float y;
}
JAXB
JDK 1.6 includes JAXB in the standard distro.
The easiest way to use it is via “annotations”.
These look like Javadoc tags:
@XmlElement
@XmlAttribute
They are essentially metainformation that
doesn’t change the meaning of the code, but
are present so other tools can make use of
the information
Using Annotations
The Cliff Notes version:
• Have the object be Java Beans compliant
• Use @XmlElement when you want to marshal
an instance variable that is an object
• Use @XmlAttribute when you want to marshal
an instance variable that is a primitive type
• You can place the annotations immediately
before the getX() methods
Marshalling to XML
JAXBContext context =
JAXBContext.newInstance(Foo.class);
Marshaller marshaller =
context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTE
D_OUTPUT, true);
marshaller.marshal(fooInstance, new
FileOutputStream(filename));
Unmarshalling from XML
Unmarshaller unmarshaller =
context.createUnmarshaller();
PduContainer unmarshalledObject =
(PduContainer)unmarshaller.unmarshal(new
FileInputStream("somePdus.xml"));
In Open-DIS
There’s example PDU marshal and unmarshal code in
edu.nps.moves.examples.MarshalExample.java
Example XML
See example XML file
Not always what you’d write by hand, but that’s
basically OK--the work saved by using the
automated tool far outweighs this. Also, JAXB
can be tweaked in ways I haven’t gotten
around to fully exploiting yet
JAXB can also be used to generate an XML
schema for the given Java classes, or
generate Java classes from an XML schema
Efficient XML Interchange
Since XML is so cool, why not use it everywhere?
Trying to use it in a network protocol as a drop-in
replacement for the DIS standard is problematic
• XML takes a lot of space compared to a binary
representation
• It takes a lot of time to parse compared to a binary
representation
EXI is intended to address these issues. Whether it can
be used as a drop-in replacement for existing binary
protocols is an open research question
EXI
XML is text-only and human (well, programmer)
readable. If we relax this requirement we can get a
more compact and faster to parse representation of
the XML infoset
Exactly equivalent to the XML document, just in a
different representation
The intent is to expand the use of XML to domains in
which it could not otherwise be used: low bandwidth
wireless, battery-powered devices with limited CPU,
very high parsing speed requirements, etc.
EXI
Emerging World Wide Web Consortium standard
See http://www.w3.org/XML/EXI/
The format document has entered “final call”
status, which is actually the first time many
outsiders take a close look at it
EXI
Test encodings of sample DIS PDUs in XML
format has shown that they are about the
same size as the original IEEE binary PDUs
A “standard” ESPDU is 144 bytes long. EXI
encoded XML representations are ~140 bytes
long
Since EXI encodes numbers in a variable length
format, the size of PDUs can vary depending
on things like the number of significant digits
in floating point numbers
EXI
Unknowns: parse speed compared to binary
The standard XML parsing APIs only deal with
strings, while the DIS data is primarily
numeric. What is needed is a typed API for
XML, so that we can directly retrieve a
floating point number rather than converting
from a string
DIS binary is the standard, EXI…isn’t. But
potentially future networking standards can
be specified as XML documents from the start
Summary
•DIS an an IEEE standard
• Open-DIS is a free implementation of that
standard in Java and C++
• Can marshal to XML
• EXI is a more compact and faster to parse
representation of the XML infoset
Download