-
Notifications
You must be signed in to change notification settings - Fork 0
/
etx_web.py
91 lines (73 loc) · 3.46 KB
/
etx_web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
"""
This file is part of etxd: A daemon for to measure the Exptected Transmission
Count (ETX)
This class defines a tiny web server to serve requests for the node's
neighbor list. The web server is configured in etxd.py to listen on the
ethernet interface of the node. This server is used by the Testbed
Management System (TBMS) to retrieve a snapshot of the network toplogoy.
Authors: Matthias Philipp <[email protected]>,
Felix Juraschek <[email protected]>
Copyright 2008- Freie Universitaet Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin,
Computer Systems and Telematics / Distributed, embedded Systems (DES) group
(http://cst.mi.fu-berlin.de, http://www.des-testbed.net)
-------------------------------------------------------------------------------
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/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://www.des-testbed.net
"""
from syslog import *
from twisted.web import resource
import simplejson
import time
class EtxWebServer(resource.Resource):
isLeaf = True
def __init__(self, interfaces, hostname):
self.interfaces = interfaces
self.hostname = hostname
def render_GET(self, request):
"""This functions handles the GET requests by returning a list of
neighbors.
All neighbors are returned, regardless via which interface they
are reachable. For each neighbor, its MAC adress, the link
quality (ETX), and the local interface the neighbor can be
reached with is returned.
"""
# initialize dictionary to assemble all neighbors
ret_val = {
"node": self.hostname,
"time": time.time(),
"neighbors": []
}
# return neighborhood information for all interfaces
for interface in self.interfaces.values():
# discard interfaces without data
if not hasattr(interface, 'data'):
continue
# make sure the data is up to date
interface.data.remove_old_probes()
neighbors = interface.data.get_neighbors()
for neighbor, quality in neighbors.items():
mac = interface.data.get_mac(neighbor)
# ignore the item if we cannot determine the corresponding MAC
if not mac:
syslog(LOG_ERR, "Unable to determine MAC address for %s"
% neighbor)
continue
# append the neighbor to the return dictionary
ret_val["neighbors"].append({
"if_name": interface.name,
"mac_address": mac,
"quality": quality
})
return simplejson.dumps(ret_val) + "\n"