Added support for layer 3 links (fixes #38)
Signed-off-by: Steffen Pankratz <kratz00@gmx.de>
This commit is contained in:
parent
58465e6d5d
commit
3318794d0f
|
@ -48,6 +48,11 @@
|
|||
<LineSymbolizer stroke-width="3" stroke="#04ff0a" stroke-linecap="butt" clip="false" />
|
||||
</Rule>
|
||||
</Style>
|
||||
<Style name="l3_color" filter-mode="first">
|
||||
<Rule>
|
||||
<LineSymbolizer stroke-width="3" stroke="#0684c4" stroke-linecap="butt" clip="false" />
|
||||
</Rule>
|
||||
</Style>
|
||||
<Style name="shadow1">
|
||||
<Rule>
|
||||
<LineSymbolizer stroke-width="4" stroke="#333333" stroke-linecap="round" stroke-opacity="0.5" />
|
||||
|
@ -62,6 +67,14 @@
|
|||
<Parameter name="file">csv/links.csv</Parameter>
|
||||
</Datasource>
|
||||
</Layer>
|
||||
<Layer name="l3_links" srs="+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs">
|
||||
<StyleName>shadow1</StyleName>
|
||||
<StyleName>l3_color</StyleName>
|
||||
<Datasource>
|
||||
<Parameter name="type">csv</Parameter>
|
||||
<Parameter name="file">csv/l3_links.csv</Parameter>
|
||||
</Datasource>
|
||||
</Layer>
|
||||
<Layer name="routers" srs="+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs">
|
||||
<StyleName>routerpoint</StyleName>
|
||||
<Datasource>
|
||||
|
|
|
@ -42,7 +42,7 @@ def update_mapnik_csv():
|
|||
{"position": 1, "neighbours": 1}
|
||||
):
|
||||
for neighbour in router["neighbours"]:
|
||||
if "position" in neighbour:
|
||||
if "position" in neighbour and not neighbour.get("type"):
|
||||
links.append((
|
||||
router["position"]["coordinates"][0],
|
||||
router["position"]["coordinates"][1],
|
||||
|
@ -53,6 +53,25 @@ def update_mapnik_csv():
|
|||
for link in sorted(links, key=lambda l: l[4]):
|
||||
csv.write("\"LINESTRING (%f %f,%f %f)\",%i\n" % link)
|
||||
|
||||
with open(os.path.join(CONFIG["csv_dir"], "l3_links.csv"), "w") as csv:
|
||||
csv.write("WKT\n")
|
||||
for router in db.routers.find(
|
||||
{
|
||||
"position.coordinates": {"$exists": True},
|
||||
"neighbours": {"$exists": True},
|
||||
"status": "online"
|
||||
},
|
||||
{"position": 1, "neighbours": 1}
|
||||
):
|
||||
for neighbour in router["neighbours"]:
|
||||
if "position" in neighbour and neighbour.get("type") and neighbour["type"] == "l3":
|
||||
csv.write("\"LINESTRING (%f %f,%f %f)\"\n" % (
|
||||
router["position"]["coordinates"][0],
|
||||
router["position"]["coordinates"][1],
|
||||
neighbour["position"]["coordinates"][0],
|
||||
neighbour["position"]["coordinates"][1]
|
||||
))
|
||||
|
||||
with open(os.path.join(CONFIG["csv_dir"], "hood-points.csv"), "w", encoding="UTF-8") as csv:
|
||||
csv.write("lng,lat,name\n")
|
||||
for hood in db.hoods.find({"position": {"$exists": True}}):
|
||||
|
|
|
@ -377,19 +377,59 @@ def parse_nodewatcher_xml(xml):
|
|||
"quality": int(o_link_quality),
|
||||
"net_if": o_out_if,
|
||||
}
|
||||
with suppress(AssertionError, TypeError):
|
||||
neighbour_router = db.routers.find_one({"netifs.mac": neighbour["mac"]}, {"hostname": 1, "position": 1})
|
||||
neighbour["_id"] = neighbour_router["_id"]
|
||||
neighbour["hostname"] = neighbour_router["hostname"]
|
||||
assert "position" in neighbour_router
|
||||
assert "coordinates" in neighbour_router["position"]
|
||||
assert neighbour_router["position"]["coordinates"][0] != 0
|
||||
assert neighbour_router["position"]["coordinates"][1] != 0
|
||||
neighbour["position"] = neighbour_router["position"]
|
||||
set_hostname_and_pos_for_neighbour(neighbour)
|
||||
router_update["neighbours"].append(neighbour)
|
||||
|
||||
router_update["system"]["visible_neighbours"] = visible_neighbours
|
||||
l3_neighbours = get_l3_neighbours(tree)
|
||||
visible_neighbours += len(l3_neighbours)
|
||||
router_update["system"]["visible_neighbours"] = visible_neighbours
|
||||
router_update["neighbours"] += l3_neighbours
|
||||
|
||||
return router_update
|
||||
except (AssertionError, lxml.etree.XMLSyntaxError, IndexError) as e:
|
||||
raise ValueError("%s: %s" % (e.__class__.__name__, str(e)))
|
||||
|
||||
|
||||
def set_hostname_and_pos_for_neighbour(neighbour):
|
||||
with suppress(AssertionError, TypeError):
|
||||
neighbour_router = db.routers.find_one(
|
||||
{"netifs.mac": neighbour["mac"]}, {"hostname": 1, "position": 1})
|
||||
neighbour["_id"] = neighbour_router["_id"]
|
||||
neighbour["hostname"] = neighbour_router["hostname"]
|
||||
assert "position" in neighbour_router
|
||||
assert "coordinates" in neighbour_router["position"]
|
||||
assert neighbour_router["position"]["coordinates"][0] != 0
|
||||
assert neighbour_router["position"]["coordinates"][1] != 0
|
||||
neighbour["position"] = neighbour_router["position"]
|
||||
|
||||
|
||||
def get_l3_neighbours(tree):
|
||||
l3_neighbours = list()
|
||||
for neighbour in tree.xpath("/data/babel_neighbours/*"):
|
||||
v6_fe80 = neighbour.text
|
||||
out_if = neighbour.xpath("outgoing_interface/text()")[0]
|
||||
neighbour = {
|
||||
"mac": get_mac_from_v6_link_local(v6_fe80).lower(),
|
||||
"quality": -1,
|
||||
"net_if": out_if,
|
||||
"type": "l3"
|
||||
}
|
||||
set_hostname_and_pos_for_neighbour(neighbour)
|
||||
l3_neighbours.append(neighbour)
|
||||
return l3_neighbours
|
||||
|
||||
|
||||
def get_mac_from_v6_link_local(v6_fe80):
|
||||
v6_fe80_parts = v6_fe80[6:].split(':')
|
||||
mac = list()
|
||||
for v6_fe80_part in v6_fe80_parts:
|
||||
while len(v6_fe80_part) < 4:
|
||||
v6_fe80_part = '0' + v6_fe80_part
|
||||
mac.append(v6_fe80_part[:2])
|
||||
mac.append(v6_fe80_part[-2:])
|
||||
|
||||
mac[0] = '%02x' % (int(mac[0], 16) ^ 2)
|
||||
del mac[3]
|
||||
del mac[3]
|
||||
|
||||
return ':'.join(mac)
|
||||
|
|
|
@ -19,7 +19,9 @@ filters = Blueprint("filters", __name__)
|
|||
@filters.app_template_filter('neighbour_color')
|
||||
def neighbour_color(quality):
|
||||
color = "#04ff0a"
|
||||
if quality < 105:
|
||||
if quality == -1:
|
||||
color = "#0684c4"
|
||||
elif quality < 105:
|
||||
color = "#ff1e1e"
|
||||
elif quality < 130:
|
||||
color = "#ff4949"
|
||||
|
|
|
@ -121,7 +121,8 @@ map.on('click', function(pos) {
|
|||
// skip unknown neighbours
|
||||
if ('_id' in neighbour) {
|
||||
var tr_color = "#04ff0a";
|
||||
if (neighbour.quality < 105) { tr_color = "#ff1e1e"; }
|
||||
if (neighbour.quality == -1) { tr_color = "#0684c4"; }
|
||||
else if (neighbour.quality < 105) { tr_color = "#ff1e1e"; }
|
||||
else if (neighbour.quality < 130) { tr_color = "#ff4949"; }
|
||||
else if (neighbour.quality < 155) { tr_color = "#ff6a6a"; }
|
||||
else if (neighbour.quality < 180) { tr_color = "#ffac53"; }
|
||||
|
|
Loading…
Reference in New Issue