gluon-status-page: rework package to not depend on batman, introduce babel mesh protocol, move neighbors-batadv from statuspage-api to gluon-mesh-batmand-adv

This commit is contained in:
Christof Schulze 2017-12-29 23:00:43 +01:00
parent 4911da56e1
commit f213485917
11 changed files with 107 additions and 79 deletions

View File

@ -13,7 +13,7 @@ define Package/gluon-mesh-batman-adv/common
SECTION:=gluon
CATEGORY:=Gluon
PROVIDES:=gluon-mesh-batman-adv
DEPENDS:=+gluon-core +libgluonutil +gluon-client-bridge +gluon-ebtables +firewall +libiwinfo +kmod-dummy +libnl-tiny +libbatadv
DEPENDS:=+gluon-core +libgluonutil +gluon-client-bridge +gluon-ebtables +firewall +libiwinfo +kmod-dummy +libnl-tiny +libbatadv +libjson-c
endef
define Package/gluon-mesh-batman-adv-14
@ -43,6 +43,8 @@ define Package/gluon-mesh-batman-adv/common/install
$(CP) ./files/* $(1)/
$(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/
$(INSTALL_DIR) $(1)/lib/gluon/respondd
$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
$(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-batadv $(1)/lib/gluon/status-page/providers/
$(CP) $(PKG_BUILD_DIR)/respondd.so $(1)/lib/gluon/respondd/mesh-batman-adv.so
$(INSTALL_DIR) $(1)/lib/gluon/mesh-batman-adv

View File

@ -1,4 +1,4 @@
all: respondd.so
all: neighbours-batadv respondd.so
CFLAGS += -Wall
@ -9,6 +9,17 @@ ifeq ($(origin PKG_CONFIG), undefined)
endif
endif
ifeq ($(origin LIBJSONC_CFLAGS) $(origin LIBJSONC_LDLIBS), undefined undefined)
LIBJSONC_NAME ?= json-c
ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBJSONC_NAME) 2>/dev/null),)
$(error No $(LIBJSONC_NAME) development libraries found!)
endif
LIBJSONC_CFLAGS += $(shell $(PkG_CONFIG) --cflags $(LIBJSONC_NAME))
LIBJSONC_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBJSONC_NAME))
endif
CFLAGS += $(LIBJSONC_CFLAGS)
LDLIBS += $(LIBJSONC_LDLIBS)
ifeq ($(origin LIBNL_CFLAGS) $(origin LIBNL_LDLIBS), undefined undefined)
LIBNL_NAME ?= libnl-tiny
ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_NAME) 2>/dev/null),)
@ -33,3 +44,7 @@ LDLIBS += $(LIBBATADV_LDLIBS)
respondd.so: respondd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil -liwinfo -luci
neighbours-batadv: neighbours-batadv.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -D_GNU_SOURCE -o $@ $^ $(LDLIBS)

View File

@ -29,7 +29,6 @@ endef
define Package/gluon-status-page-api/install
$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
$(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-batadv $(1)/lib/gluon/status-page/providers/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/stations $(1)/lib/gluon/status-page/providers/
$(INSTALL_DIR) $(1)/lib/gluon/respondd

View File

@ -8,6 +8,6 @@ badrequest() {
echo 'Access-Control-Allow-Origin: *'
batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest
ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device"| grep -qxF "$QUERY_STRING" || badrequest
exec /usr/bin/gluon-neighbour-info -s neighbour -i "$QUERY_STRING" -d ff02::2:1001 -p 1001 -r nodeinfo

View File

@ -8,7 +8,7 @@ badrequest() {
echo 'Access-Control-Allow-Origin: *'
batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest
ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device"| grep -qxF "$QUERY_STRING" || badrequest
CMD="exec /lib/gluon/status-page/providers/stations '$QUERY_STRING'"

View File

@ -29,10 +29,7 @@ ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined
LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME))
endif
all: neighbours-batadv stations respondd.so
neighbours-batadv: neighbours-batadv.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LIBNL_CFLAGS) $(LIBBATADV_CFLAGS) $(LDFLAGS) $(LDFLAGS_JSONC) $(LIBNL_LDLIBS) $(LIBBATADV_LDLIBS) -Wall -o $@ $^ $(LDLIBS)
all: stations respondd.so
stations: stations.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDFLAGS_JSONC) -Wall -o $@ $^ $(LDLIBS) -liwinfo

View File

@ -77,13 +77,17 @@ function (Helper, SignalGraph, Signal) {
tdSignal.textContent = signal
tdInactive.textContent = Math.round(inactive / 1000) + " s"
}
if (d.routingMetrics.protocol == "batadv") {
tdTQ.textContent = "TQ: " + Math.round(d.routingMetrics.tq / 2.55) + " %"
}
else if (d.routingMetrics.protocol == "babel") {
tdTQ.textContent = "Cost: " + Math.round(d.routingMetrics.cost / 653.53) + " %"
}
else {
tdTQ.textContent = "?PROTO? (" + d.routingMetrics.protocol + ")"
}
if ("batadv" in d)
tdTQ.textContent = Math.round(d.batadv.tq / 2.55) + " %"
else
tdTQ.textContent = ""
if (infoSet)
if (infoSet)
return
if ("nodeInfo" in d) {
@ -111,8 +115,9 @@ function (Helper, SignalGraph, Signal) {
} catch (e) {
tdDistance.textContent = ""
}
} else
} else {
hostname.textContent = d.id
}
}
}
@ -136,7 +141,7 @@ function (Helper, SignalGraph, Signal) {
tr.appendChild(th)
th = document.createElement("th")
th.textContent = "TQ"
th.textContent = "Metrik"
tr.appendChild(th)
th = document.createElement("th")

View File

@ -1,48 +1,48 @@
"use strict"
define([ "bacon"
, "lib/helper"
, "lib/streams"
], function(Bacon, Helper, Streams) {
, "lib/helper"
, "lib/streams"
], function(Bacon, Helper, Streams) {
return function (mgmtBus, nodesBus, ip) {
function nodeQuerier() {
var asked = {}
var timeout = 6000
return function (ifname) {
var now = new Date().getTime()
return function (ifname) {
var now = new Date().getTime()
if (ifname in asked && now - asked[ifname] < timeout)
return Bacon.never()
if (ifname in asked && now - asked[ifname] < timeout)
return Bacon.never()
asked[ifname] = now
return Streams.nodeInfo(ip, ifname).map(function (d) {
return { "ifname": ifname
, "nodeInfo": d
}
})
}
asked[ifname] = now
return Streams.nodeInfo(ip, ifname).map(function (d) {
return { "ifname": ifname
, "nodeInfo": d
}
})
}
}
var querierAsk = new Bacon.Bus()
var querier = querierAsk.flatMap(nodeQuerier())
querier.map(".nodeInfo").onValue(mgmtBus, "pushEvent", "nodeinfo")
var querier = querierAsk.flatMap(nodeQuerier())
querier.map(".nodeInfo").onValue(mgmtBus, "pushEvent", "nodeinfo")
function wrapIfname(ifname, d) {
return [ifname, d]
}
function wrapIfname(ifname, d) {
return [ifname, d]
}
function extractIfname(d) {
var r = {}
for (var station in d) {
var ifname = d[station].ifname
delete d[station].ifname
var ifname = d[station].ifname
delete d[station].ifname
if (!(ifname in r))
r[ifname] = {}
if (!(ifname in r))
r[ifname] = {}
r[ifname][station] = d[station]
r[ifname][station] = d[station]
}
return r
@ -54,74 +54,75 @@ define([ "bacon"
function magic(interfaces) {
var ifnames = Object.keys(interfaces)
ifnames.forEach(querierAsk.push)
ifnames.forEach(querierAsk.push)
var wifiStream = Bacon.fromArray(ifnames)
.flatMap(stationsStream)
.scan({}, function (a, b) {
a[b[0]] = b[1]
return a
})
var wifiStream = Bacon.fromArray(ifnames)
.flatMap(stationsStream)
.scan({}, function (a, b) {
a[b[0]] = b[1]
return a
})
var batadvStream = new Streams.Batadv(ip).toProperty({})
var babelStream = new Streams.Babel(ip).toProperty({})
return Bacon.combineWith(combine, wifiStream
, batadvStream.map(extractIfname)
, nodesBus.map(".macs")
)
return Bacon.combineWith(combine, wifiStream
, Bacon.combineWith(Object.assign, batadvStream, babelStream).map(extractIfname)
, nodesBus.map(".macs")
)
}
function combine(wifi, batadv, macs) {
var interfaces = combineWithIfnames(wifi, batadv)
function combine(wifi, routingMetrics, macs) {
var interfaces = combineWithIfnames(wifi, routingMetrics)
for (var ifname in interfaces) {
var stations = interfaces[ifname]
for (var station in stations) {
stations[station].id = station
for (var ifname in interfaces) {
var stations = interfaces[ifname]
for (var station in stations) {
stations[station].id = station
if (station in macs)
stations[station].nodeInfo = macs[station]
else
querierAsk.push(ifname)
}
}
if (station in macs)
stations[station].nodeInfo = macs[station]
else
querierAsk.push(ifname)
}
}
return interfaces
}
function combineWithIfnames(wifi, batadv) {
var ifnames = Object.keys(wifi).concat(Object.keys(batadv))
function combineWithIfnames(wifi, routingMetrics) {
var ifnames = Object.keys(wifi).concat(Object.keys(routingMetrics))
// remove duplicates
ifnames.filter(function(e, i) {
return ifnames.indexOf(e) === i
})
// remove duplicates
ifnames.filter(function(e, i) {
return ifnames.indexOf(e) === i
})
var out = {}
ifnames.forEach(function (ifname) {
out[ifname] = combineWifiBatadv(wifi[ifname], batadv[ifname])
out[ifname] = combineWifiRoutingMetrics(wifi[ifname], routingMetrics[ifname])
})
return out
}
function combineWifiBatadv(wifi, batadv) {
function combineWifiRoutingMetrics(wifi, routingMetrics) {
var station
var out = {}
var out = {}
for (station in batadv) {
for (station in routingMetrics) {
if (!(station in out))
out[station] = {}
out[station].batadv = batadv[station]
out[station].routingMetrics = routingMetrics[station]
}
for (station in wifi) {
if (!(station in out))
out[station] = {}
if (!(station in out))
out[station] = {}
out[station].wifi = wifi[station]
out[station].wifi = wifi[station]
}
return out

View File

@ -1,4 +1,7 @@
"use strict"
define(["bacon", "lib/helper"], function(Bacon, Helper) {
function nodeInfo(ip, ifname) {
return Bacon.fromBinder(function (sink) {
@ -42,6 +45,11 @@ define(["bacon", "lib/helper"], function(Bacon, Helper) {
return tearDown
})
}
function babel(ip) {
var url = Helper.buildUrl(ip, "dyn/neighbours-babel")
return simpleStream(url)
}
function batadv(ip) {
var url = Helper.buildUrl(ip, "dyn/neighbours-batadv")
@ -59,8 +67,9 @@ define(["bacon", "lib/helper"], function(Bacon, Helper) {
}
return { nodeInfo: nodeInfo
, Batadv: batadv
, Stations: stations
, Batadv: batadv
, Babel: babel
, Statistics: statistics
}
})