A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES...

17
A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute [email protected]

Transcript of A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES...

Page 1: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

A Javascript Implementation of the Binary DIS Protocol

Don McGregor, Don Brutzman, Curt Blais,

MOVES Institute

[email protected]

Page 2: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

2

Javascript & Web Networking

• Javascript? That’s just a toy language, right?

• Not any more. Simulation applications can be written in Javascript, and there are significant advantages to doing so

• New Javascript networking standards (Websockets, WebRTC) allow low latency, high (ish) performance directly into the web page

Page 3: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

3

Web Networking

Web Server

Content: Javascript,3D, images, graphing,Maps, mash-ups

Websocket(Javascript TCP socket)

WebRTC (Javascript UDP)

Web Page:Internet Explorer

Web Page:Firefox Mobile

Page 4: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

4

Web Networking

• Websockets allow low latency TCP sockets between web page pages and servers in Javascript—no polling, not wrapped in HTTP

• WebRTC can allow low latency UDP Javascript messages directly between web pages

• Performance is not bad--~5K messages per second to desktop clients for websockets

• It’s all unicast—no broadcast or multicast, with all that implies

Page 5: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

5

Why Do It?

• Compelling economic & system management advantages for web-based simulation– Distribute all applications from a central web server,

where it can be easily upgraded– Cross-platform, including mobile– Moves at web speed—can mash up with maps,

graphics, WebGL, Twitter, IM, …– Scale out on cloud, low barrier to entry. Cloud-side

compute resources are effectively infinite– How many desktop apps do you use today, vs how

many web based applications? That’s because the economics are that compelling

Page 6: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

6

What Message Format?

6

These are the pipes;What format should wesend state information such asposition and orientation?

Page 7: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

7

Message Format: JSON

• One option is to send messages in JSON format• This is the approach taken by WebLVC• But this requires you to specify the format of the JSON• Lots of standards meetings

Page 8: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

8

Message Format: DIS

• Classical Javascript wasn’t very good at handling binary

• More modern Javascript can use “ArrayBuffers” to manipulate binary data

• Support is good (~80% of current browsers in the wild, will only get better as old browsers are upgraded). See http://caniuse.com

• So why not use this to implement classic IEEE-1278.1?

Page 9: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

9

DIS in Javascript

• Strong standards support, lots of gateway support for HLA, TENA, AIS, other protocols to DIS

• It’s already standardized• DIS can be verbose and carries redundant

information compared to HLA RPR-FOM, which is what WebLVC is based on

• Protocol issues such as heartbeat

Page 10: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

10

Using Javascript DIS// Receive and decode a messageNetworkSingleton.prototype.onMessage = function(evt) { // convert from binary to javascript object var pduFactory = new dis.PduFactory(); var pdu = pduFactory.createPdu(evt.data); switch(pdu.pduType) { case 1: …..

// Convert to local (or lat/lon/alt) coordinatesvar localCoordinates = rangeCoordinates.ECEFtoENU(espdu.entityLocation.x, espdu.entityLocation.y, espdu.entityLocation.z);

// Encode DISvar dataBuffer = new ArrayBuffer(1500);var os = new dis.OutputStream(dataBuffer);espdu.encodeToBinaryDIS(os);var trimmedData = dataBuffer.slice(0, os.currentPosition);websocketConnection.send(trimmedData);

Page 11: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

11

Performance Compared to JSON

• Binary DIS vs JSON-encoded DIS, longer bars better• Yellow JSON DIS, red binary DIS

Page 12: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

12

Performance Notes• See http://jsperf.com/javascript-dis-native-vs-json/2, benchmark your

own browser, or create new benchmarks• Both JSON and binary formats can be workable; depending on

Javascript engine they can even be about the same• Browsers and Javascript engines matter a lot! JSON can be as fast as

binary on some browsers and Javascript engines (IE 11, for example) • JSON can be faster on IE 11 than binary on Firefox• I suspect in the long term results will converge towards the current

Safari benchmarks as Javascript engines improve• OK performance on mobile—and it works on mobile!• OK for a few thousand messages per second into the web page

(depending on lots of stuff) which puts about a 10% load on desktop CPU

• In general, the simulation implementation is more likely to be an issue than the networking overhead, particularly with 3D.

Page 13: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

13

Binary Javascript DIS Vs WebLVC• WebLVC JSON update messages have less state information and can

be parsed somewhat faster, but it’s in the same ballpark• WebLVC can also avoid DIS heartbeats• http://jsperf.com/javascript-dis/13

Page 14: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

14

Google Maps Example

• Application on server side listens for traditional native UDP DIS on the local ethernet network. In this case, AIS (real time commercial ship locations) is being translated into DIS by JBUS

• Web page receives forwarded DIS messages via websockets, decodes, does coordinate conversion to lat/lon, displays icon on map. Also sends DIS updates based on web browser geolocation

• Uses Google Maps Javascript API to implement a real-time mapping application. Works on modern browsers and mobile, including IOS and Android

Page 15: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

15

Google Maps + DIS in Browser

Page 16: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

16

Availability

• Free, BSD non-viral license• https://svn.code.sf.net/p/open-dis/code/ open-dis-code/

– Includes server side code (to convert native UDP to websocket transport) and client code in languages/javascript directory

• NodeJS is a scalable server-side Javascript framework popular in Silicon Valley (used at linkedin, twitter, ebay, etc.)– NodeJS DIS javascript module available at

https://www.npmjs.org/package/open-dis

Page 17: A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute mcgredo@nps.edu.

17

Future Work

• Open Street Map vs Google Maps to avoid proprietary vendor dependencies, requirement to have a Google Maps server inside classified areas

• Server side architecture for scalability: how much to put on client vs server? How to limit traffic to the client? Inherent unicast problems as the number of clients increase?

• Node.js transport gateways on the server side?• Integration with voice, video in web browsers and DIS

intercom PDUs• Integrate with <your favorite web-based application>