diff --git a/config/inventory b/config/inventory index 943713f70df88b1af5acbfe4f256a47367af8bd6..9075217905a0fee205875fceb0fa3d75cf9f0bb5 100644 --- a/config/inventory +++ b/config/inventory @@ -11,8 +11,8 @@ ss2 ; s4 ansible_host=192.168.1.100 [ss2] -# s5 ansible_host=192.168.1.248 -s6 ansible_host=192.168.1.246 +; s5 ansible_host=192.168.1.248 +s6 ansible_host=192.168.1.244 # rp4 ansible_host=192.168.1.248 diff --git a/config/test.yml b/config/test.yml index b87e50c943c6a1fd41070a99e6efcf693511a607..09be7d712e1e343e1833ba33ebf2c5bc3594c493 100644 --- a/config/test.yml +++ b/config/test.yml @@ -1,6 +1,10 @@ -- hosts: s5 +- hosts: all become: yes tasks: - - debug: - msg: "{{ansible_user_id}}" + - name: transfer location finder + copy: + src: ../files/positionGetter.sh + dest: "/home/{{ansible_ssh_user}}/positionGetter.sh" + mode: 0755 + diff --git a/docs/PLAYBOOKS.md b/docs/PLAYBOOKS.md index 51583206fbcb56ff68956e64609c35ac4eabf10a..779b388c9a11f71edbfd56fa96e5ef0059544648 100644 --- a/docs/PLAYBOOKS.md +++ b/docs/PLAYBOOKS.md @@ -56,6 +56,7 @@ Multiple configuration scripts, here called microstasks, have been put into a si The playbook `start_sens_sniffer.yml` asks parameters to run mitik-sens : - The folder of mitik-sens on the nodes. Defaults to `/home/tribe/mitik-sens-mod/` - hour and minute at which to start the experiment. Defaults to current time +15m +- The format of the name of the output pcap file. Defaults to mitik_experiment-%post, with %post being replaced at mitik-sens level - Timeout after which to stop the experiment in seconds. Defaults to 3600 (1h) - The interfaces on which to run the experiment, separated by commas (e.g. `wifi5,wifi6`). Defaults to `wifi5`. Order matters. - The channels on which to start the interface, separated by commas. (e.g. `6,11`). Defaults to `1`. Order matters. @@ -64,8 +65,9 @@ Multiple configuration scripts, here called microstasks, have been put into a si - The hashing function. Defaults to SHA256, can be MD5 and None - The fields to anonymize. All MACs and ssids is 15; not ssid is 14; nothing is 0. Defaults to 15 -Then it checks if the length of interfaces and channels is the same. -If they are, we set up a crontab to run the sniffer when planned. +Then it translates the csv interfaces and channels into lists, and finds out the prefix to use for the gps file. It is {{ _pcap_name | replace('%post', '') }}-location-YYYYMMDD-ddmmss.gps +it checks if the length of interfaces and channels is the same. +If they are, we set up a crontab to run the sniffer when planned, and a crontab for the location of the device. **`stop_sens_sniffer.yml`** This playbook interrupts any running `sniffer.py`, and cancels planned crontabs. diff --git a/files/positionGetter.sh b/files/positionGetter.sh index cc58e97d119675f9d534ced4def67a4a823e3b87..cd7ee4f545b6d32c1799ecec1a46cb6d8f53b32f 100755 --- a/files/positionGetter.sh +++ b/files/positionGetter.sh @@ -1,30 +1,45 @@ #!/bin/bash +# script.sh 900 30 "~/mitik-sens-mod/" "experiment-identifier" # run with arg 1 the sleep TO, and $2 the waiting time before doing things if [ $2 ]; then sleep $2 fi -rm ~/locations.log +# files in /temp will get deleted on reboot +gpsLocations=$(mktemp /tmp/locations-XXXXXX.gps) -while echo $(pgrep -a "sniffer.py" >/dev/null; echo $?); do +gpsPresenceTest=$(mktemp /tmp/test-XXXXXX.gps) +timeout 1s sudo gpiomon 4 15 > $gpsPresenceTest +if [ $(cat $gpsPresenceTest | wc -l) -eq 0 ]; then +echo "no gps found !" +exit 1 +fi -data=$(gpspipe --nmea -n 10 | awk -F, '$1 == "$GPGGA"' | awk -F, '{print $3, $5, $10}') -# $GPGGA,124226.00,4842.8648,N,00212.3549,E,1,07,1.30,160.28,M,46.512,M,,*63 -# │ Latitude: 48.71441340 N │ -# │ Longitude: 2.20591520 E │ -# │ Alt (HAE, MSL): 206.490, 160.283 m +while echo $(pgrep -a "sniffer.py" >/dev/null; echo $?); do -echo $data >> ~/locations.log + data=$(gpspipe --nmea -n 10 | awk -F, '$1 == "$GPGGA"' | awk -F, '{print $3, $5, $10}') + # $GPGGA,124226.00,4842.8648,N,00212.3549,E,1,07,1.30,160.28,M,46.512,M,,*63 + # │ Latitude: 48.71441340 N │ + # │ Longitude: 2.20591520 E │ + # │ Alt (HAE, MSL): 206.490, 160.283 m -if [ $1 ]; then -sleep $1 -else -sleep 900 #15m -fi + echo $data >> $gpsLocations + if [ $1 ]; then + sleep $1 + else + sleep 900 #15m + fi done -if [ $(ls ~/locations.log; echo $?) ]; do -# faut moyenner toutes les potitions imo -done \ No newline at end of file +awk -F',' ' +{ + lat += $1; + lon += $2; + alt += $3; +} +END { + print lat/NR/100,lon/NR/100,alt/NR; +}' $gpsLocations > $3"/location-"$4".log" +# will write eg as ~/mitik-sens-mod/location-MM-DD-HH-MM-wifiX-chan6.log diff --git a/playbooks/data_transfer.yml b/playbooks/data_transfer.yml index 97db4b01893661fe8e8d62f6d2e14942dc308204..541a802f448376aeae4265df261a965df9a2f6f5 100644 --- a/playbooks/data_transfer.yml +++ b/playbooks/data_transfer.yml @@ -5,9 +5,9 @@ - name: find files to copy find: - paths: "~/termporary-transfer-sniffer/hopping-time-tests/" # top folder to search from/in - recurse: yes # yes|no recursive file search ? - patterns: "*.pcap" # what your target files look like + paths: "~/mitik-sens-mod/" # top folder to search from/in + recurse: no # yes|no recursive file search ? + patterns: "*.pcap, *.gps" # what your target files look like register: files_to_copy - name: Copy files diff --git a/playbooks/microstask_GPS_setup.yml b/playbooks/microstask_GPS_setup.yml index c52726092fdda7b8669d26dda39d138a7395edfd..9a3ce1e8433da5b0e0aba0e56a934f63bb549b47 100644 --- a/playbooks/microstask_GPS_setup.yml +++ b/playbooks/microstask_GPS_setup.yml @@ -1,5 +1,4 @@ - hosts: sniffers - user: tribe become: yes become_user: root tasks: @@ -76,3 +75,11 @@ src: ../files/chrony.conf dest: /etc/chrony/chrony.conf + - name: transfer location finder + become: y + copy: + src: ../files/positionGetter.sh + dest: "/home/{{ansible_ssh_user}}/positionGetter.sh" + mode: 0755 + + diff --git a/playbooks/start_sens_sniffer.yml b/playbooks/start_sens_sniffer.yml index d798eb03ff28e89566f3f84f19dcfa05cc8237f0..2d538da6298f78edeb500d4435c6be51f86b70f3 100644 --- a/playbooks/start_sens_sniffer.yml +++ b/playbooks/start_sens_sniffer.yml @@ -26,6 +26,11 @@ default: "{{ lookup('pipe', 'date -d \"+15 minutes\" +%M') }}" private: no + - name: _pcap_name + prompt: "Name of the PCAP file. %post will get replaced by a bunch of context info (date and params) and .pcap" + default: "mitik_experiment-%post" + private: no + - name: _timeout prompt: Please specify the runtime duration in sec default: 3600 @@ -62,11 +67,17 @@ default: 15 private: no + + - name: _gps_poll_timeout + prompt: time in seconds between each location polling + default: 900 + private: no tasks: - set_fact: _interfaces: "{{ _interfaces_csv.split(',') }}" _channels: "{{ _channels_csv.split(',') }}" + _location_prefix: "{{_pcap_name | replace('%post', '')}}" delegate_to: 127.0.0.1 run_once: True @@ -78,12 +89,21 @@ - - name: start sens-sniffer + + + - name: setup future start of sens-sniffer cron: name: "ansible_sens_sniffer {{ _hour }} {{ _minute }} {{ item }}" minute: "{{ _minute }}" hour: "{{ _hour }}" - job: "cd {{_workdir}}; sudo python ./sniffer.py -s {{_timeout}} -i {{item}} -c {{_channels[my_idx]}} -j {{_channel_hopping}} -sf {{_filter}} -p {{_hash_pattern}} -e {{_hash_function}}" + job: "cd {{_workdir}}; sudo python ./sniffer.py -s {{_timeout}} -i {{item}} -c {{_channels[my_idx]}} -j {{_channel_hopping}} -sf {{_filter}} -p {{_hash_pattern}} -e {{_hash_function}}" -w "{{_pcap_name}}" loop: "{{_interfaces}}" loop_control: index_var: my_idx + + - name: setup future start of location querier + cron: + name: "ansible_sens_gps {{ _hour }} {{ _minute }}" + minute: "{{ _minute }}" + hour: "{{ _hour }}" + job: "/home/{{ansible_ssh_user}}/positionGetter.sh {{_gps_poll_timeout}} 10 '{{_workdir}}' '{{_location_prefix}}-location$(date +%Y%m%d_%H%M%S).gps'" diff --git a/playbooks/stop_sens_sniffer.yml b/playbooks/stop_sens_sniffer.yml index d47978dd476ab5d9e7752e7888cbd966e57a2bbf..68dea7aac0cb9c50af07573382cecd99ecc4bbb2 100644 --- a/playbooks/stop_sens_sniffer.yml +++ b/playbooks/stop_sens_sniffer.yml @@ -3,7 +3,7 @@ tasks: - name: List active snifing crontabs tags: device-setup config nodes - shell: "crontab -l | grep ansible_sens_sniffer | sed 's/#Ansible: //g'" + shell: "crontab -l | grep ansible_sens_ | sed 's/#Ansible: //g'" register: crontabs