Skip to content

Commit

Permalink
Merge 615de4d into 9d3eb12
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Jan 22, 2018
2 parents 9d3eb12 + 615de4d commit e5bb275
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 147 deletions.
2 changes: 1 addition & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestReadConfig(t *testing.T) {
assert.NotNil(config)

assert.True(config.Respondd.Enable)
assert.Equal([]string{"br-ffhb"}, config.Respondd.Interfaces)
assert.Equal("br-ffhb", config.Respondd.Interfaces[0].InterfaceName)
assert.Equal(time.Minute, config.Respondd.CollectInterval.Duration)
assert.Equal(time.Hour*24*7, config.Nodes.PruneAfter.Duration)
assert.Equal(time.Hour*24*7, config.Database.DeleteAfter.Duration)
Expand Down
29 changes: 23 additions & 6 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,45 @@ package cmd
import (
"log"
"net"
"strings"
"time"

"github.com/FreifunkBremen/yanic/respond"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/spf13/cobra"
)

var wait int
var (
wait int
port int
ipAddress string
)

// queryCmd represents the query command
var queryCmd = &cobra.Command{
Use: "query <interface> <destination>",
Use: "query <interfaces> <destination>",
Short: "Sends a query on the interface to the destination and waits for a response",
Example: `yanic query wlan0 "fe80::eade:27ff:dead:beef"`,
Example: `yanic query "eth0,wlan0" "fe80::eade:27ff:dead:beef"`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
iface := args[0]
ifaces := strings.Split(args[0], ",")
dstAddress := net.ParseIP(args[1])

log.Printf("Sending request address=%s iface=%s", dstAddress, iface)
log.Printf("Sending request address=%s ifaces=%s", dstAddress, ifaces)

var ifacesConfigs []respond.InterfaceConfig
for _, iface := range ifaces {
ifaceConfig := respond.InterfaceConfig{
InterfaceName: iface,
Port: port,
IPAddress: ipAddress,
}
ifacesConfigs = append(ifacesConfigs, ifaceConfig)
}

nodes := runtime.NewNodes(&runtime.NodesConfig{})

collector := respond.NewCollector(nil, nodes, []string{}, []string{iface}, 0)
collector := respond.NewCollector(nil, nodes, []string{}, ifacesConfigs)
defer collector.Close()
collector.SendPacket(dstAddress)

Expand All @@ -41,4 +56,6 @@ var queryCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(queryCmd)
queryCmd.Flags().IntVar(&wait, "wait", 1, "Seconds to wait for a response")
queryCmd.Flags().IntVar(&port, "port", 0, "define a port to listen (if not set or set to 0 the kernel will use a random free port at its own)")
queryCmd.Flags().StringVar(&ipAddress, "ip", "", "ip address which is used for sending (optional - without definition used the link-local address)")
}
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var serveCmd = &cobra.Command{
time.Sleep(delay)
}

collector = respond.NewCollector(allDatabase.Conn, nodes, config.Respondd.Sites, config.Respondd.Interfaces, config.Respondd.Port)
collector = respond.NewCollector(allDatabase.Conn, nodes, config.Respondd.Sites, config.Respondd.Interfaces)
collector.Start(config.Respondd.CollectInterval.Duration)
defer collector.Close()
}
Expand Down
13 changes: 11 additions & 2 deletions config_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ enable = true
synchronize = "1m"
# how often request per multicast
collect_interval = "1m"
# interface that has an IP in your mesh network
interfaces = ["br-ffhb"]
# list of sites to save stats for (empty for global only)
sites = []

# interface that has an IP in your mesh network
[[respondd.interfaces]]
# name of interface on which this collector is running
ifname = "br-ffhb"
# ip address which is used for sending
# (optional - without definition used a address of ifname)
ip_address = "fd2f:5119:f2d::5"
# multicast address to destination of respondd
# (optional - without definition used batman default ff02::2:1001)
multicast_address = "ff05::2:1001"
# define a port to listen
# if not set or set to 0 the kernel will use a random free port at its own
#port = 10001
Expand Down
17 changes: 17 additions & 0 deletions data/neighbours.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package data
// Neighbours struct
type Neighbours struct {
Batadv map[string]BatadvNeighbours `json:"batadv"`
Babel map[string]BabelNeighbours `json:"babel"`
LLDP map[string]LLDPNeighbours `json:"lldp"`
//WifiNeighbours map[string]WifiNeighbours `json:"wifi"`
NodeID string `json:"node_id"`
Expand All @@ -27,11 +28,27 @@ type LLDPLink struct {
Description string `json:"descr"`
}

// BabelLink struct
type BabelLink struct {
// How need this:
RXCost int `json:"rxcost"`
TXCost int `json:"txcost"`
Cost int `json:"cost"`
Reachability int `json:"reachability"`
}

// BatadvNeighbours struct
type BatadvNeighbours struct {
Neighbours map[string]BatmanLink `json:"neighbours"`
}

// BabelNeighbours struct
type BabelNeighbours struct {
Protocol string `json:"protocol"`
LinkLocalAddress string `json:"ll-addr"`
Neighbours map[string]BabelLink `json:"neighbours"`
}

// WifiNeighbours struct
type WifiNeighbours struct {
Neighbours map[string]WifiLink `json:"neighbours"`
Expand Down
18 changes: 11 additions & 7 deletions data/nodeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type NodeInfo struct {
Wireless *Wireless `json:"wireless,omitempty"`
}

// BatInterface struct
type BatInterface struct {
// NetworkInterface struct
type NetworkInterface struct {
Interfaces struct {
Wireless []string `json:"wireless,omitempty"`
Other []string `json:"other,omitempty"`
Expand All @@ -24,16 +24,17 @@ type BatInterface struct {
}

// Addresses returns a flat list of all MAC addresses
func (iface *BatInterface) Addresses() []string {
func (iface *NetworkInterface) Addresses() []string {
return append(append(iface.Interfaces.Other, iface.Interfaces.Tunnel...), iface.Interfaces.Wireless...)
}

// Network struct
type Network struct {
Mac string `json:"mac"`
Addresses []string `json:"addresses"`
Mesh map[string]*BatInterface `json:"mesh"`
MeshInterfaces []string `json:"mesh_interfaces"`
Mac string `json:"mac"`
Addresses []string `json:"addresses"`
Mesh map[string]*NetworkInterface `json:"mesh"`
// still used in gluon?
MeshInterfaces []string `json:"mesh_interfaces"`
}

// Owner struct
Expand Down Expand Up @@ -63,6 +64,9 @@ type Software struct {
Version string `json:"version,omitempty"`
Compat int `json:"compat,omitempty"`
} `json:"batman-adv,omitempty"`
Babeld struct {
Version string `json:"version,omitempty"`
} `json:"babeld,omitempty"`
Fastd struct {
Enabled bool `json:"enabled,omitempty"`
Version string `json:"version,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions data/nodeinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestNodeinfoBatAddresses(t *testing.T) {
assert := assert.New(t)
batIface := &BatInterface{
iface := &NetworkInterface{
Interfaces: struct {
Wireless []string `json:"wireless,omitempty"`
Other []string `json:"other,omitempty"`
Expand All @@ -20,7 +20,7 @@ func TestNodeinfoBatAddresses(t *testing.T) {
},
}

addr := batIface.Addresses()
addr := iface.Addresses()
assert.NotNil(addr)
assert.Equal([]string{"aa:aa:aa:aa:aa", "aa:aa:aa:aa:ab"}, addr)
}
6 changes: 3 additions & 3 deletions database/influxdb/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
func (conn *Connection) InsertLink(link *runtime.Link, t time.Time) {
tags := models.Tags{}
tags.SetString("source.id", link.SourceID)
tags.SetString("source.mac", link.SourceMAC)
tags.SetString("source.addr", link.SourceAddress)
tags.SetString("target.id", link.TargetID)
tags.SetString("target.mac", link.TargetMAC)
tags.SetString("target.addr", link.TargetAddress)

conn.addPoint(MeasurementLink, tags, models.Fields{"tq": float32(link.TQ) / 2.55}, t)
conn.addPoint(MeasurementLink, tags, models.Fields{"tq": link.TQ * 100}, t)
}
8 changes: 4 additions & 4 deletions database/influxdb/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func TestToInflux(t *testing.T) {
fields, _ = nPoint.Fields()
assert.EqualValues("link", nPoint.Name())
assert.EqualValues(map[string]string{
"source.id": "deadbeef",
"source.mac": "a-interface",
"target.id": "foobar",
"target.mac": "BAFF1E5",
"source.id": "deadbeef",
"source.addr": "a-interface",
"target.id": "foobar",
"target.addr": "BAFF1E5",
}, tags)
assert.EqualValues(80, fields["tq"])

Expand Down
56 changes: 47 additions & 9 deletions docs/docs_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ Group for configuration of respondd request.
enable = true
# synchronize = "1m"
collect_interval = "1m"
interfaces = ["br-ffhb"]
sites = ["ffhb"]
#port = 10001

[[respondd.interfaces]]
ifname = "br-ffhb"
#ip_address = "fe80::..."
#multicast_address = "ff02::2:1001"
#port = 10001
```
{% endmethod %}

Expand Down Expand Up @@ -45,7 +49,7 @@ synchronize = "1m"
{% method %}
How often send request per respondd.

It will send UDP packets with multicast group `ff02::2:1001` and port `1001`.
It will send UDP packets with multicast address `ff02::2:1001` and port `1001`.
If a node does not answer after the half time, it will request with the last know address under the port `1001`.
{% sample lang="toml" %}
```toml
Expand All @@ -54,25 +58,59 @@ collect_interval = "1m"
{% endmethod %}


### interfaces
### sites
{% method %}
Interface that has an IP in your mesh network
List of sites to save stats for (empty for global only)
{% sample lang="toml" %}
```toml
interfaces = ["br-ffhb"]
sites = ["ffhb"]
```
{% endmethod %}


### sites
### [[respondd.interfaces]]
{% method %}
List of sites to save stats for (empty for global only)
Interface that has an ip address in your mesh network.
It is possible to have multiple interfaces, just add this group again with new parameters (see toml [[array of table]]).
{% sample lang="toml" %}
```toml
sites = ["ffhb"]
[[respondd.interfaces]]
ifname = "br-ffhb"
#ip_address = "fe80::..."
#multicast_address = "ff02::2:1001"
#port = 10001
```
{% endmethod %}

### ifname
{% method %}
name of interface on which this collector is running.
{% sample lang="toml" %}
```toml
ifname = "br-ffhb"
```
{% endmethod %}

### ip_address
{% method %}
ip address is the own address which is used for sending.
If not set or set with empty string it will take an address of ifname.
{% sample lang="toml" %}
```toml
ip_address = "fe80::..."
```
{% endmethod %}

### multicast_address
{% method %}
Multicast address to destination of respondd.
If not set or set with empty string it will take the batman default multicast address `ff02::2:1001`
(Needed in babel for a mesh-network wide routeable multicast addreess `ff05::2:1001`)
{% sample lang="toml" %}
```toml
multicast_address = "ff02::2:1001"
```
{% endmethod %}

### port
{% method %}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_quick_conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cp /opt/go/src/github.com/FreifunkBremen/yanic/config_example.toml /etc/yanic.co
```

# Quick configuration
For an easy startup you only need to edit the `interfaces` in section
For an easy startup you only need to edit the `[[respondd.interfaces]]` in section
`[respondd]` in file `/etc/yanic.conf`.

Then create the following files and folders:
Expand Down
2 changes: 1 addition & 1 deletion docs/home_about.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A little overview of yanic in connection with other software:

It sends the `gluon-neighbour-info` request and collects the answers.

It will send UDP packets with multicast group `ff02:0:0:0:0:0:2:1001` and port `1001`.
It will send UDP packets with multicast address `ff02:0:0:0:0:0:2:1001` and port `1001`.

If a node does not answer, it will request with the last know address under the port `1001`.

Expand Down
Loading

0 comments on commit e5bb275

Please sign in to comment.