Howto:Record, analyze and replay multiplayer flights with network tools: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
You can '''record, analyze and replay flights with network tools''' by recording and working on UDP packets sent through the [[multiplayer protocol]] between your computer and a [[Howto:Multiplayer|multiplayer]] server.


==intro==
This article will cover some uses in multiplayer problems diagnostics and a way to record (and replay) a multiplayer session.


This page will talk about the usage of networks tools, applied to FlightGear, by working on the udp packets sent by mp.<br>
The truth is I never found what I needed in FlightGear itself, but just a little work with some network tools made my day.
It will cover some use in mp problems diagnostics, and a way to record (and replay) a mp session.<br>
The truth is I never found what i needed in FG itself, but just a few work with some networks tools made my day
.<br>
I agree this isn't easy to use, need some time to master the tools, and root access to the network interface (so take care ;) ), but it works, as can be seen in [http://www.youtube.com/watch?v=kGHRDrc_n98 this video!]<br>
Some exemples of utilisation:
* debriefing/training of formation flight: your aerobatic formation can review the flight, and find who broke the diamond figure in the top of the loop :) You can even flight again with the recorded mp flight to improve your skills.
* make a film by recording the planes one by one, without any internet connection.
* having some "mp action files" available, eg to replay them in a FG démo, or if you don't have internet but want some other planes than the silly ai models.
* save a meeting, and do video capture after the event, this way you can make multiple video takes, and do a nice editing.
* udp traffic analysis, to see the effect of internet transmission on other mp pilot's packets (loss/jitter)


==tools==
I agree this is not easy to use, need some time to master the tools, and root access to the network interface (so take care ;) ), but it works, as can be seen in [http://www.youtube.com/watch?v=kGHRDrc_n98 this video!]


* Wireshark: a network flux sniffer/analyser, available for all plateformes, we will use it to record the FG udp traffic.
== Some examples of utilization ==
* tcpreplay: a suit of programmes, available on mac and linux, and maybe on windows by using Cygwin. Will be used to change some udp packets properties, and to send back the traffic to an other FG session.
* Debriefing/training of formation flight: Your aerobatic formation can review the flight, and find who broke the diamond figure in the top of the loop :) You can even fly again with the recorded multiplayer flight to improve your skills.
* Make a film by recording the planes one by one, without any Internet connection.
* Having some "multiplayer action files" available, for example to replay them in a FlightGear demo, or if you do not have internet but want some other planes than the silly AI models.
* Save a multiplayer event and do video capture after the event. This way you can make multiple video takes and do a nice editing.
* UDP traffic analysis, to see the effect of internet transmission on other multiplayer pilot's packets (loss/jitter)


==capture FG network traffic==
== Network tools ==
* Wireshark: A network traffic sniffer/analyzer available for all platforms. We will use it to record the FlightGear UDP traffic.
* tcpreplay: A suit of programs available on Mac and Linux, and maybe on Windows by using Cygwin. It will be used to change some UDP packet properties and to send back the traffic to another FlightGear session.


Assuming we are connected to a mpserver, and that the server and your FG session receive on udp port 5000, we can record all the udp packets going to a port 5000.
== Captureing FlightGear network traffic ==
This way we will record our outgoing packets, and the ingoing packets from the other mp pilots.<br>
Assuming we are connected to a [[Howto:Multiplayer#Servers|multiplayer server]] and that the server and your FlightGear session receive on UDP port 5000, we can record all the UDP packets going to a port 5000.


we start Wireshark, then select the network interface used, and finally set a filter and apply it, eg:
This way we will record our outgoing packets and the ingoing packets from the other multiplayer pilots.
udp.dstport == 5000 && !(icmp.type)


finally, we stop the capture and save the file as a .cap.
We start Wireshark, then select the network interface used, and finally set a filter and apply it, for example:
UDP.dstport == 5000 && !(icmp.type)


What do we have now?<br>
Finally, we stop the capture and save the file as a <code>.cap</code> file.
We have the flight recorded at the network level!


With only wireshark, we can now extract only some pilot(s), keep only a time interval of traffic, or see some traffic properties.<br>
What do we have now? We have the flight recorded at the network level!
With the help of tcpreplay/tcprewrite, we can sent the mp traffic back to a running FG session.


==pilot individual file==
With wireshark we can now extract some pilot(s), use a certain time interval of traffic, or see certain traffic properties.


In Wireshark, it is possible to extract each pilot flight individually, the filter to use looks like:
With the help of tcpreplay/tcprewrite, we can send the multiplayer traffic back to a running FlightGear session.
 
== Extracting files for individual pilots ==
In Wireshark it is possible to extract each pilot flight individually. Using the filter looks like:


  frame contains "callsign"
  frame contains "callsign"
Line 45: Line 43:
  !frame contains "callsign"
  !frame contains "callsign"


This way you can have each pilot's flight separated. If needed you can merge again 2 or more pilots in a file, if you for example you have recorded a diamond formation and you want to practice the left wingman position. Either you remove the existing one for the <code>.cap</code> file, or you merge the 3 others again, after having done individual <code>.cap</code> files.


This way you can have each pilot flight separated, and if needed, you can merge again 2 or more pilots in a file, eg you have recorded a diamond formation, and you want to practice the left wingman position, either you remove the existing one for the .cap, or you merge the 3 others again, after having done individual .cap.<br>
Wireshark come with mergecap to merge multiple <code>.cap</code> files. Taking care the chronological order is respected. The provided editcap can be used too if you need to add a time offset to a plane to address recorded latency issues.
 
Wireshark come with mergecap, to merge multiple .cap file, and taking care the chronological order is respected.<br>
The provided editcap can be used too, if you need to add a time offset to a plane, to address latency recorded issue.
 
It's sometimes difficult to have lot of matching shedules, when you are training in an aerobatic team, and we have here a good way to train with other mp pilots without being connected. You can even practice by file exchange, the leader make a flight, send the .cap to the second, wich add his flight, then pass to the 3 etc...
 
==udp packets loss/jitter==
 
Here's a wireshark analyse, showing the mp packet rate for different mp pilots, from a recorded mp session.<br>
[[File:Wireshark mp rate analyse.png|600px|received mp packet rate]]
* the black curve got a nice 10 packets/s, our internet link was good, maybe connected to the same mp server.
* red and pink were pretty choatic, their packets are often lost, and i guess they are jittery in FG. they were probably connected to an other mp server.
* blue and green show less than 1 packet/s, this can be explained by some misconnexion between servers, by default the mp server send at 1fps to the other mp server, just to "inform" them wich planes they host, and they start relaying all the packets once other mp server send them plane in vicinity. In this case probably our server didn't relay to their, and we only got the "lazy relay" from their server.
 
==replay the flight to our FG session==


Ok, we have a recorded flight saved as .cap file, and we want to see it again in FG. That's where the tricky parts start :)
It is sometimes difficult to have lot of matching schedules when you are training in an aerobatic team, and we have here a good way to train with other mp pilots without being connected. You can even practice by file exchange: The leader make a flight, send the <code>.cap</code> file to the second pilot which add his flight, then pass to the third pilot etc.


===tcpreplay limitation===
== Analyzing UDP packets loss/jitter ==
[[File:Wireshark mp rate analyse.png|600px|thumb|Received Multiplayer packet rate]]
Here is a wireshark analysis showing the multiplayer packet rate for different multiplayer pilots from a recorded multiplayer session.
* The black curve got a nice 10 packets/s, our internet link was good and is maybe connected to the same multiplayer server.
* The red and pink were pretty chaotic. Their packets are often lost and I guess they are jittery in FlightGear. They were probably connected to an other multiplayer server.
* The blue and green show less than 1 packet/s, this can be explained by some connection losses between servers. By default the multiplayer server send at 1 packet/s to the other multiplayer server just to "inform" them which planes they host, and start relaying all the packets only once other multiplayer server send them planes in vicinity. In this case our multiplayer server probably did not relay to their server, and we only got the "lazy relay" from their server.{{-}}


To make things short, tcpreplay can not send directly to fg, if we are on the same computer.<br>
== Replay the flight to our FlightGear session ==
Until now I use a other PC to send the traffic back to my FG PC, if you find an other way, tell me :) .From the tcpreplay FAQ, it could work if tcpreplay run in a virtualised machine, but i didn't gave it a go.
Ok, we have a recorded flight saved as <code>.cap</code> file and want to see it again in FlightGear. That's where the tricky parts start. :)


===tcprewrite magic===
=== Limitations of tcpreplay ===
To make things short, tcpreplay can not send directly to FlightGear if we are on the same computer.


Next is that the udp packets, to come back to our PC, need some editing in the udp packets:
Until now I either use an other PC to send traffic back to my FlightGear PC, or i send to the internet box's external IP address, with a redirection to my pc for the port used in its firewall.
* the mac address of the sender must match the mac of the PC sending the recorded flight.
* the destination mac address must match the receiving PC, or depending the case the router's mac address.
* the destination and sender IP address must match the IPaddress of the 2 PC involved.


We make the change in one go with tcprewrite, here's a practical exemple:
According to the tcpreplay FAQ, it could work if tcpreplay runs in a virtualized machine, but I did not give it a go.


we have:
=== tcprewrite magic ===
* the computer running FG, mac address 00:11:22:33:44:55, ip address 192.168.1.12 .
Next is that the UDP packets. To come back to our PC, we need some editing in the UDP packets:
* the computer we will use to send the recorded packets: mac address 99:88:77:66:55:44, ip address 192.168.1.17
* The MAC address of the sender must match the MAC of the PC sending the recorded flight.
* The destination MAC address must match the receiving PC, or depending the case the MAC address of the router.
* The destination and sender IP address must match the IP address of the 2 PC involved.


It's up to you to find your mac and ip address, you can use wireshark on some network traffic between the 2, or ifconfig on linux etc...<br>
We make the change in one go with tcprewrite, here's a practical example. We have:
here's the "magic" line:
* The computer running FlightGear, MAC address 00:11:22:33:44:55, IP address 192.168.1.12 .
* The computer we will use to send the recorded packets: MAC address 99:88:77:66:55:44, IP address 192.168.1.17


It is up to you to find your MAC and IP address. You can use wireshark on some network traffic between the two, or ifconfig on Linux etc. Here is the "magic" line,
  tcprewrite -C --enet-smac=99:88:77:66:55:44 --enet-dmac=00:11:22:33:44:55  
  tcprewrite -C --enet-smac=99:88:77:66:55:44 --enet-dmac=00:11:22:33:44:55  
  -S 0.0.0.0/0:192.168.1.17 -D 0.0.0.0/0:192.168.1.12 -i recorded.cap -o readytosend.cap
  -S 0.0.0.0/0:192.168.1.17 -D 0.0.0.0/0:192.168.1.12 -i recorded.cap -o readytosend.cap


where:
where:
 
* -C force a checksum recalculation. If not the packets are not valid and are not sent.
* -C force a checksum recalculation, if not the packets are not valid and are not sent
* --enet-smac gives the mac address of the sender
* --enet-smac give the mac address of the sender
* --enet-dmac same with the receiver
* --enet-dmac same with the receiver
* -S change source ip address
* -S changes source IP address
* -D the same for destination
* -D does the same for destination
* -i input file (the previously recorded flight)
* -i input file (the previously recorded flight)
* -o output file
* -o output file


tcprewrite don't need to be root to be used, but using tcpreplay to see again the recorded traffic need a root access to use the network interface.<br>
tcprewrite do not need to be root to be used, but using tcpreplay to see the recorded traffic again need root access to use the network interface.
Now we start FG, with mp protocol enabled by sending to a server (can be a mpserver, or the address of a valid local host on your network, eg 192.168.0.17). Finally we start replaying the flight, on the dedicaced PC:
 
Now we start FlightGear with Multiplayer enabled by sending to a server (it can be a MPserver or the address of a valid local host on your network, for example 192.168.0.17).
 
Finally we start replaying the flight, on the dedicaced PC:
  tcpreplay -i eth0 readytosend.cap
  tcpreplay -i eth0 readytosend.cap


be sure to use the correct name for the network interface, ifconfig/ipconfig is your friend here!
Be sure to use the correct name for the network interface. ifconfig/ipconfig is your friend here!
 
Tcpreplay works fine this way if we don't need a very good time flow sync, as it end being late, dépending on the cpu usage mostly. I didn't notice this issue at first, but this became evident using lag statistics available recently in next, so to keep a good sync between tcpreplay and flightgear, using a core affinity, setting a priority higher and preferably on a not overloaded PC/CPU core makes things better, so we got something like that on linux:
 
taskset 02 nice -n -15 tcpreplay -x 1.000065  -K -i enp0s10  /rab/refuel/test.pcapng
 
The "-x" option (time acceleration) ensure a good time sync over the replay (find yourself the best value for your config :) ), i just need to adjust the time offset for the mp clock, to have replayed planes in sync with my session, considered as "real time" buddys.
 
=== Give it a try ===
[[File:Fighters mont aiguille.jpg|thumb|The "mont aiguille", in the French Vercors Massif.]]
if you don't have time to make a record yourself, you can use this [http://janodesbois.free.fr/flightgear/cap_files/vercors_test.cap.bz2 flight in the French Vercors Massif] (3.4M). Start at LFLU, runway 01 with the [[UFO]] or in a plane capable of more than 400 kts, and follow the leading [[McDonnell F-4 Phantom II|F-4N]] in a Vercors Massif trip, followed by a [[English Electric Lightning|Lightning]], a [[General Dynamics F-16 Fighting Falcon|F-16]] and a [[Grumman F-14 Tomcat|F-14B]]. It is better with a detailed scenery like "La France d'el maxo".
 
Just decompress it, and use tcprewrite to match your config.{{-}}
 
== Related content ==
=== Wiki articles ===
* [[Generic protocol]] - ''A flexible way to log properties locally.''
* [[Interfacing FlightGear]] - ''Various ways to interface FlightGear.''
* [[JSBSim Logging]] - ''Logging JSBSim internal properties locally.''
* [[Logging properties]] - ''The simplest way to log properties locally.''


===give it a try===
== External links ==
* {{cite web
| url = https://www.wireshark.org
| title = wireshark.org
}}


[[File:Fighters mont aiguille.jpg|thumb|the "mont aiguille", Vercors (french alpes)]]
[[Category:Development]]
if you don't have time to make a record yourself, you can use this [http://janodesbois.free.fr/flightgear/cap_files/vercors_test.cap.bz2 flight in french vercors] (3.4M). start at LFLU, runway 01 with the ufo or a plane in the 400+ kts, and follow the leader F-4N in a vercors trip, followed by a lightning, a f16 and a f-14b. It's better with a detailled scenery like "la france d'el maxo".<br>
[[Category:Multiplayer]]
Just decompress it, and use tcprewrite to match your config.

Revision as of 19:05, 25 March 2020

You can record, analyze and replay flights with network tools by recording and working on UDP packets sent through the multiplayer protocol between your computer and a multiplayer server.

This article will cover some uses in multiplayer problems diagnostics and a way to record (and replay) a multiplayer session.

The truth is I never found what I needed in FlightGear itself, but just a little work with some network tools made my day.

I agree this is not easy to use, need some time to master the tools, and root access to the network interface (so take care ;) ), but it works, as can be seen in this video!

Some examples of utilization

  • Debriefing/training of formation flight: Your aerobatic formation can review the flight, and find who broke the diamond figure in the top of the loop :) You can even fly again with the recorded multiplayer flight to improve your skills.
  • Make a film by recording the planes one by one, without any Internet connection.
  • Having some "multiplayer action files" available, for example to replay them in a FlightGear demo, or if you do not have internet but want some other planes than the silly AI models.
  • Save a multiplayer event and do video capture after the event. This way you can make multiple video takes and do a nice editing.
  • UDP traffic analysis, to see the effect of internet transmission on other multiplayer pilot's packets (loss/jitter)

Network tools

  • Wireshark: A network traffic sniffer/analyzer available for all platforms. We will use it to record the FlightGear UDP traffic.
  • tcpreplay: A suit of programs available on Mac and Linux, and maybe on Windows by using Cygwin. It will be used to change some UDP packet properties and to send back the traffic to another FlightGear session.

Captureing FlightGear network traffic

Assuming we are connected to a multiplayer server and that the server and your FlightGear session receive on UDP port 5000, we can record all the UDP packets going to a port 5000.

This way we will record our outgoing packets and the ingoing packets from the other multiplayer pilots.

We start Wireshark, then select the network interface used, and finally set a filter and apply it, for example:

UDP.dstport == 5000 && !(icmp.type)

Finally, we stop the capture and save the file as a .cap file.

What do we have now? We have the flight recorded at the network level!

With wireshark we can now extract some pilot(s), use a certain time interval of traffic, or see certain traffic properties.

With the help of tcpreplay/tcprewrite, we can send the multiplayer traffic back to a running FlightGear session.

Extracting files for individual pilots

In Wireshark it is possible to extract each pilot flight individually. Using the filter looks like:

frame contains "callsign"

and to exclude a pilot:

!frame contains "callsign"

This way you can have each pilot's flight separated. If needed you can merge again 2 or more pilots in a file, if you for example you have recorded a diamond formation and you want to practice the left wingman position. Either you remove the existing one for the .cap file, or you merge the 3 others again, after having done individual .cap files.

Wireshark come with mergecap to merge multiple .cap files. Taking care the chronological order is respected. The provided editcap can be used too if you need to add a time offset to a plane to address recorded latency issues.

It is sometimes difficult to have lot of matching schedules when you are training in an aerobatic team, and we have here a good way to train with other mp pilots without being connected. You can even practice by file exchange: The leader make a flight, send the .cap file to the second pilot which add his flight, then pass to the third pilot etc.

Analyzing UDP packets loss/jitter

Received Multiplayer packet rate

Here is a wireshark analysis showing the multiplayer packet rate for different multiplayer pilots from a recorded multiplayer session.

  • The black curve got a nice 10 packets/s, our internet link was good and is maybe connected to the same multiplayer server.
  • The red and pink were pretty chaotic. Their packets are often lost and I guess they are jittery in FlightGear. They were probably connected to an other multiplayer server.
  • The blue and green show less than 1 packet/s, this can be explained by some connection losses between servers. By default the multiplayer server send at 1 packet/s to the other multiplayer server just to "inform" them which planes they host, and start relaying all the packets only once other multiplayer server send them planes in vicinity. In this case our multiplayer server probably did not relay to their server, and we only got the "lazy relay" from their server.

Replay the flight to our FlightGear session

Ok, we have a recorded flight saved as .cap file and want to see it again in FlightGear. That's where the tricky parts start. :)

Limitations of tcpreplay

To make things short, tcpreplay can not send directly to FlightGear if we are on the same computer.

Until now I either use an other PC to send traffic back to my FlightGear PC, or i send to the internet box's external IP address, with a redirection to my pc for the port used in its firewall.

According to the tcpreplay FAQ, it could work if tcpreplay runs in a virtualized machine, but I did not give it a go.

tcprewrite magic

Next is that the UDP packets. To come back to our PC, we need some editing in the UDP packets:

  • The MAC address of the sender must match the MAC of the PC sending the recorded flight.
  • The destination MAC address must match the receiving PC, or depending the case the MAC address of the router.
  • The destination and sender IP address must match the IP address of the 2 PC involved.

We make the change in one go with tcprewrite, here's a practical example. We have:

  • The computer running FlightGear, MAC address 00:11:22:33:44:55, IP address 192.168.1.12 .
  • The computer we will use to send the recorded packets: MAC address 99:88:77:66:55:44, IP address 192.168.1.17

It is up to you to find your MAC and IP address. You can use wireshark on some network traffic between the two, or ifconfig on Linux etc. Here is the "magic" line,

tcprewrite -C --enet-smac=99:88:77:66:55:44 --enet-dmac=00:11:22:33:44:55 
-S 0.0.0.0/0:192.168.1.17 -D 0.0.0.0/0:192.168.1.12 -i recorded.cap -o readytosend.cap

where:

  • -C force a checksum recalculation. If not the packets are not valid and are not sent.
  • --enet-smac gives the mac address of the sender
  • --enet-dmac same with the receiver
  • -S changes source IP address
  • -D does the same for destination
  • -i input file (the previously recorded flight)
  • -o output file

tcprewrite do not need to be root to be used, but using tcpreplay to see the recorded traffic again need root access to use the network interface.

Now we start FlightGear with Multiplayer enabled by sending to a server (it can be a MPserver or the address of a valid local host on your network, for example 192.168.0.17).

Finally we start replaying the flight, on the dedicaced PC:

tcpreplay -i eth0 readytosend.cap

Be sure to use the correct name for the network interface. ifconfig/ipconfig is your friend here!

Tcpreplay works fine this way if we don't need a very good time flow sync, as it end being late, dépending on the cpu usage mostly. I didn't notice this issue at first, but this became evident using lag statistics available recently in next, so to keep a good sync between tcpreplay and flightgear, using a core affinity, setting a priority higher and preferably on a not overloaded PC/CPU core makes things better, so we got something like that on linux:

taskset 02 nice -n -15 tcpreplay -x 1.000065  -K -i enp0s10  /rab/refuel/test.pcapng

The "-x" option (time acceleration) ensure a good time sync over the replay (find yourself the best value for your config :) ), i just need to adjust the time offset for the mp clock, to have replayed planes in sync with my session, considered as "real time" buddys.

Give it a try

The "mont aiguille", in the French Vercors Massif.

if you don't have time to make a record yourself, you can use this flight in the French Vercors Massif (3.4M). Start at LFLU, runway 01 with the UFO or in a plane capable of more than 400 kts, and follow the leading F-4N in a Vercors Massif trip, followed by a Lightning, a F-16 and a F-14B. It is better with a detailed scenery like "La France d'el maxo".

Just decompress it, and use tcprewrite to match your config.

Related content

Wiki articles

External links