WIP: Babel Version (based on 'junk' branch)
This commit is contained in:
parent
712a41b5fc
commit
8d36fbf928
|
@ -7,7 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Vivena/babelweb2/parser"
|
"github.com/Vivena/babelweb2/state"
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,21 +31,19 @@ func (d *Daemon) babelConnect() {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
log.Infof("Connection to %v closed\n", d.Babel)
|
log.Infof("Connection to %v closed\n", d.Babel)
|
||||||
}
|
}
|
||||||
defer closeConn()
|
|
||||||
fmt.Fprintf(conn, "monitor\n")
|
fmt.Fprintf(conn, "monitor\n")
|
||||||
r := bufio.NewReader(conn)
|
s, err := state.NewBabelState(bufio.NewReader(conn), 0)
|
||||||
s := parser.NewScanner(r)
|
|
||||||
desc := parser.NewBabelDesc()
|
|
||||||
err = desc.Fill(s)
|
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
log.Warnf("Something wrong with %v:\n\tcouldn't get router id.\n", d.Babel)
|
log.Warnf("Something wrong with %v:\n\tcouldn't get router id.\n", d.Babel)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
// Don't you even dare to reconnect to this unholy node!
|
// Don't you even dare to reconnect to this unholy node!
|
||||||
log.Warnf("Oh, boy! %v is doomed:\n\t%v.\t", d.Babel, err)
|
log.Warnf("Oh, boy! %v is doomed:\n\t%v.\t", d.Babel, err)
|
||||||
|
closeConn()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
d.babelData = desc
|
d.babelData = s
|
||||||
err := d.babelDescListen(s)
|
err := s.ListenHistory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Babel listen stopped: %s", err)
|
log.Warnf("Babel listen stopped: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -54,24 +52,3 @@ func (d *Daemon) babelConnect() {
|
||||||
closeConn()
|
closeConn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) babelDescListen(s *parser.Scanner) error {
|
|
||||||
for {
|
|
||||||
upd, err := d.babelData.ParseAction(s)
|
|
||||||
if err != nil && err != io.EOF && err.Error() != "EOL" {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
//TODO maybe keep upd.action != none
|
|
||||||
if !(d.babelData.CheckUpdate(upd)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err = d.babelData.Update(upd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/FreifunkBremen/yanic/data"
|
"github.com/FreifunkBremen/yanic/data"
|
||||||
"github.com/FreifunkBremen/yanic/lib/duration"
|
"github.com/FreifunkBremen/yanic/lib/duration"
|
||||||
|
|
||||||
babelParser "github.com/Vivena/babelweb2/parser"
|
babelState "github.com/Vivena/babelweb2/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func trim(s string) string {
|
func trim(s string) string {
|
||||||
|
@ -24,7 +24,7 @@ type Daemon struct {
|
||||||
|
|
||||||
Batman []string `toml:"batman"`
|
Batman []string `toml:"batman"`
|
||||||
Babel string `toml:"babel"`
|
Babel string `toml:"babel"`
|
||||||
babelData *babelParser.BabelDesc `toml:"-"`
|
babelData *babelState.BabelState `toml:"-"`
|
||||||
|
|
||||||
dataByInterface map[string]*data.ResponseData
|
dataByInterface map[string]*data.ResponseData
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,13 @@ func (d *Daemon) updateNeighbours(iface string, resp *data.ResponseData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Neighbours.Babel = make(map[string]data.BabelNeighbours)
|
resp.Neighbours.Babel = make(map[string]data.BabelNeighbours)
|
||||||
d.babelData.Iter(func(bu parser.BabelUpdate) error {
|
d.babelData.Iter(func(t parser.Transition) error {
|
||||||
sbu := bu.ToSUpdate()
|
if t.Table != "interface" {
|
||||||
if sbu.Table != "interface" {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if sbu.EntryData["up"].(bool) {
|
if t.Data["up"].(bool) {
|
||||||
addr := sbu.EntryData["ipv6"].(string)
|
addr := t.Data["ipv6"].(string)
|
||||||
resp.Neighbours.Babel[string(sbu.Entry)] = data.BabelNeighbours{
|
resp.Neighbours.Babel[string(t.Field)] = data.BabelNeighbours{
|
||||||
Protocol: "babel",
|
Protocol: "babel",
|
||||||
LinkLocalAddress: addr,
|
LinkLocalAddress: addr,
|
||||||
Neighbours: make(map[string]data.BabelLink),
|
Neighbours: make(map[string]data.BabelLink),
|
||||||
|
@ -46,24 +45,23 @@ func (d *Daemon) updateNeighbours(iface string, resp *data.ResponseData) {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
d.babelData.Iter(func(bu parser.BabelUpdate) error {
|
d.babelData.Iter(func(t parser.Transition) error {
|
||||||
sbu := bu.ToSUpdate()
|
if t.Table != "neighbour" {
|
||||||
if sbu.Table != "neighbour" {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ifname, ok := sbu.EntryData["if"].(string)
|
ifname, ok := t.Data["if"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("neighbour without if")
|
return errors.New("neighbour without if")
|
||||||
}
|
}
|
||||||
addr := sbu.EntryData["address"].(string)
|
addr := t.Data["address"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("neighbour without address")
|
return errors.New("neighbour without address")
|
||||||
}
|
}
|
||||||
if bIfname, ok := resp.Neighbours.Babel[ifname]; ok {
|
if bIfname, ok := resp.Neighbours.Babel[ifname]; ok {
|
||||||
link := data.BabelLink{
|
link := data.BabelLink{
|
||||||
RXCost: int(sbu.EntryData["rxcost"].(uint64)),
|
RXCost: int(t.Data["rxcost"].(uint64)),
|
||||||
TXCost: int(sbu.EntryData["txcost"].(uint64)),
|
TXCost: int(t.Data["txcost"].(uint64)),
|
||||||
Cost: int(sbu.EntryData["cost"].(uint64)),
|
Cost: int(t.Data["cost"].(uint64)),
|
||||||
}
|
}
|
||||||
bIfname.Neighbours[addr] = link
|
bIfname.Neighbours[addr] = link
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (d *Daemon) updateNodeinfo(iface string, resp *data.ResponseData) {
|
||||||
resp.Nodeinfo.Software.BatmanAdv.Version = trim(string(v))
|
resp.Nodeinfo.Software.BatmanAdv.Version = trim(string(v))
|
||||||
}
|
}
|
||||||
if babel := d.babelData; babel != nil {
|
if babel := d.babelData; babel != nil {
|
||||||
resp.Nodeinfo.Software.Babeld.Version = babel.Version
|
resp.Nodeinfo.Software.Babeld.Version = babel.Version()
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Nodeinfo.Network.Mac == "" {
|
if resp.Nodeinfo.Network.Mac == "" {
|
||||||
|
@ -97,13 +97,12 @@ func (d *Daemon) updateNodeinfo(iface string, resp *data.ResponseData) {
|
||||||
meshBabel := data.NetworkInterface{}
|
meshBabel := data.NetworkInterface{}
|
||||||
resp.Nodeinfo.Network.Mesh["babel"] = &meshBabel
|
resp.Nodeinfo.Network.Mesh["babel"] = &meshBabel
|
||||||
|
|
||||||
d.babelData.Iter(func(bu babelParser.BabelUpdate) error {
|
d.babelData.Iter(func(t babelParser.Transition) error {
|
||||||
sbu := bu.ToSUpdate()
|
if t.Table != "interface" {
|
||||||
if sbu.Table != "interface" {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if sbu.EntryData["up"].(bool) {
|
if t.Data["up"].(bool) {
|
||||||
addr := sbu.EntryData["ipv6"].(string)
|
addr := t.Data["ipv6"].(string)
|
||||||
meshBabel.Interfaces.Tunnel = append(meshBabel.Interfaces.Tunnel, addr)
|
meshBabel.Interfaces.Tunnel = append(meshBabel.Interfaces.Tunnel, addr)
|
||||||
resp.Nodeinfo.Network.Addresses = append(resp.Nodeinfo.Network.Addresses, addr)
|
resp.Nodeinfo.Network.Addresses = append(resp.Nodeinfo.Network.Addresses, addr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue