Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding first version of WiFi results #76

Merged
merged 3 commits into from
May 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ripe/atlas/sagan/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def get(cls, data, **kwargs):
elif kind == "ntp":
from .ntp import NtpResult
return NtpResult(raw_data, **kwargs)
elif kind == "wifi":
from .wifi import WiFiResult
return WiFiResult(raw_data, **kwargs)

raise ResultParseError("Unknown type value was found in the JSON input")

Expand Down
55 changes: 55 additions & 0 deletions ripe/atlas/sagan/wifi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .base import Result, ParsingDict


class WPASupplicant(ParsingDict):

def __init__(self, data, **kwargs):

ParsingDict.__init__(self, **kwargs)

self.address = data.get("address")
self.bssid = data.get("bssid")
self.connect_time = data.get("connect-time")
self.group_cipher = data.get("group_cipher")
self.wpa_supplicant_id = data.get("id")
self.ip_address = data.get("ip_address")
self.key_management = data.get("key_mgmt")
self.mode = data.get("mode")
self.pairwise_cipher = data.get("pairwise_cipher")
self.ssid = data.get("ssid")
self.wpa_state = data.get("wpa_state")


class WiFiResult(Result):
"""
WiFi measurement result class
"""

def __init__(self, data, **kwargs):

Result.__init__(self, data, **kwargs)

self.bundle = self.ensure("bundle", int)
self.group_id = self.ensure("group_id", int)
self.wpa_supplicant = WPASupplicant(
data["wpa_supplicant"], **kwargs
)

__all__ = (
"WiFiResult",
)
2 changes: 1 addition & 1 deletion tests/dns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 RIPE NCC
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 RIPE NCC
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/ntp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 RIPE NCC
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/ping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 RIPE NCC
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/ssl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 RIPE NCC
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/traceroute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 RIPE NCC
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
97 changes: 97 additions & 0 deletions tests/wifi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from ripe.atlas.sagan import Result
from ripe.atlas.sagan.wifi import WiFiResult


def test_wifi():
raw_data = {
"bundle": 1463495978,
"from": "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0",
"fw": "4733",
"group_id": 1021275,
"msm_id": 1021275,
"msm_name": "WiFi",
"prb_id": 105,
"timestamp": 1463495978,
"type": "wifi",
"wpa_supplicant": {
"address": "ea:de:27:69:e6:f0",
"bssid": "08:ea:44:3b:6d:14",
"connect-time": "2",
"group_cipher": "CCMP",
"id": "0",
"ip_address": "193.0.10.126",
"key_management": "WPA2-PSK",
"mode": "station",
"pairwise_cipher": "CCMP",
"ssid": "guestnet",
"wpa_state": "COMPLETED"
}
}

result = Result.get(raw_data)
assert(isinstance(result, WiFiResult))
assert(result.bundle == 1463495978)
assert(result.origin == "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0")
assert(result.firmware == 4733)
assert(result.group_id == 1021275)
assert(result.wpa_supplicant.address == "ea:de:27:69:e6:f0")
assert(result.wpa_supplicant.bssid == "08:ea:44:3b:6d:14")
assert(result.wpa_supplicant.connect_time == "2")
assert(result.wpa_supplicant.group_cipher == "CCMP")
assert(result.wpa_supplicant.wpa_supplicant_id == "0")
assert(result.wpa_supplicant.ip_address == "193.0.10.126")
assert(result.wpa_supplicant.key_management == "WPA2-PSK")
assert(result.wpa_supplicant.mode == "station")
assert(result.wpa_supplicant.pairwise_cipher == "CCMP")
assert(result.wpa_supplicant.ssid == "guestnet")
assert(result.wpa_supplicant.wpa_state == "COMPLETED")


def test_wifi_error():
raw_data = {
"bundle": 1463493022,
"error": "wpa timeout",
"from": "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0",
"fw": "4733",
"group_id": 1021275,
"msm_id": 1021275,
"msm_name": "WiFi",
"prb_id": 105,
"timestamp": 1463493023,
"type": "wifi",
"wpa_supplicant": {"connect-time": "11"}
}

result = Result.get(raw_data)
assert(isinstance(result, WiFiResult))
assert(result.bundle == 1463493022)
assert(result.origin == "2001:67c:2e8:ffe1:eade:27ff:fe69:e6f0")
assert(result.firmware == 4733)
assert(result.group_id == 1021275)
assert(result.created_timestamp == 1463493023)
assert(result.wpa_supplicant.address is None)
assert(result.wpa_supplicant.bssid is None)
assert(result.wpa_supplicant.connect_time == "11")
assert(result.wpa_supplicant.group_cipher is None)
assert(result.wpa_supplicant.wpa_supplicant_id is None)
assert(result.wpa_supplicant.ip_address is None)
assert(result.wpa_supplicant.key_management is None)
assert(result.wpa_supplicant.mode is None)
assert(result.wpa_supplicant.pairwise_cipher is None)
assert(result.wpa_supplicant.ssid is None)
assert(result.wpa_supplicant.wpa_state is None)