Skip to content

Commit

Permalink
Configurable amount of interfaces and neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Oct 10, 2024
1 parent 9a01121 commit 789a7e8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
18 changes: 10 additions & 8 deletions cmd/network/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import (

// Network provides networking operations.
type Network struct {
IPAddress string
Started time.Time
MachineUUID string
LLDPClient *LLDPClient
Eth0Mac string // this mac is used to calculate the IPMI Port offset in the metal-lab environment.
Log *slog.Logger
IPAddress string
Started time.Time
MachineUUID string
LLDPClient *LLDPClient
Eth0Mac string // this mac is used to calculate the IPMI Port offset in the metal-lab environment.
Log *slog.Logger
MinimumInterfaces int32
MinimumNeighbors int32
}

// We expect to have storage and MTU of 9000 supports efficient transmission.
// In our clos topology MTU 9000 (non vxlan)/9216 (vxlan) is status quo.
// In our switch topology MTU 9000 (non vxlan)/9216 (vxlan) is status quo.
const MTU = 9000

// UpAllInterfaces set all available eth* interfaces up
Expand Down Expand Up @@ -62,7 +64,7 @@ func (n *Network) UpAllInterfaces() error {
lldpd.Start()
}

lc := NewLLDPClient(n.Log, interfaces, 2, 2, 0)
lc := NewLLDPClient(n.Log, interfaces, n.MinimumInterfaces, n.MinimumNeighbors, 0)
n.LLDPClient = lc
go lc.Start()

Expand Down
10 changes: 5 additions & 5 deletions cmd/network/lldpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Host struct {
start time.Time
done bool
timeout time.Duration
minimumInterfaces int
minimumNeighbors int
minimumInterfaces int32
minimumNeighbors int32
}

const (
Expand All @@ -37,7 +37,7 @@ const (
)

// NewLLDPClient create a lldp client.
func NewLLDPClient(log *slog.Logger, interfaces []string, minimumInterfaces, minimumNeighbors int, timeout time.Duration) *LLDPClient {
func NewLLDPClient(log *slog.Logger, interfaces []string, minimumInterfaces, minimumNeighbors int32, timeout time.Duration) *LLDPClient {
if timeout == 0 {
timeout = LLDPTxIntervalTimeout
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (l *LLDPClient) requirementsMet() bool {
if l.Host.minimumInterfaces == 0 && l.Host.minimumNeighbors == 0 {
return true
}
if len(l.Host.neighbors) < l.Host.minimumInterfaces {
if int32(len(l.Host.neighbors)) < l.Host.minimumInterfaces {
return false
}

Expand All @@ -123,5 +123,5 @@ func (l *LLDPClient) requirementsMet() bool {
}
}
// Requirements are met if we found at least 2 distinct chassis mac's
return len(neighMap) >= l.Host.minimumNeighbors
return int32(len(neighMap)) >= l.Host.minimumNeighbors
}
29 changes: 25 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,32 @@ func Run(log *slog.Logger, spec *Specification, hal hal.InBand) (*event.EventEmi
return eventEmitter, err
}

bootResp, err := bootService.Boot(context.Background(), &v1.BootServiceBootRequest{PartitionId: spec.MetalConfig.Partition})
if err != nil {
return nil, err
}

var (
minimumInterfaces = int32(2)
minimumNeighbors = int32(2)
)

if bootResp.NetworkRequirements != nil {
if bootResp.NetworkRequirements.MinimumInterfaces != nil {
minimumInterfaces = bootResp.GetNetworkRequirements().GetMinimumInterfaces()
}
if bootResp.NetworkRequirements.MinimumNeighbors != nil {
minimumNeighbors = bootResp.GetNetworkRequirements().GetMinimumNeighbors()
}
}

n := &network.Network{
MachineUUID: spec.MachineUUID,
IPAddress: spec.IP,
Started: time.Now(),
Log: log,
MachineUUID: spec.MachineUUID,
IPAddress: spec.IP,
Started: time.Now(),
Log: log,
MinimumInterfaces: minimumInterfaces,
MinimumNeighbors: minimumNeighbors,
}

// TODO: Does not work yet, needs to be done manually
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ require (
github.com/jaypipes/ghw v0.12.0
github.com/metal-stack/go-hal v0.5.5
github.com/metal-stack/go-lldpd v0.4.8
github.com/metal-stack/metal-api v0.37.1
github.com/metal-stack/metal-api v0.37.3-0.20241010063016-58c6457e00ba
github.com/metal-stack/metal-go v0.37.1
github.com/metal-stack/pixie v0.3.4
github.com/metal-stack/pixie v0.3.5-0.20241010063858-83bb4a8acd64
github.com/metal-stack/v v1.0.3
// archiver must stay in version v2.1.0, see replace below
github.com/mholt/archiver v3.1.1+incompatible
Expand All @@ -27,7 +27,7 @@ require (
golang.org/x/sync v0.8.0
golang.org/x/sys v0.26.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.34.2
google.golang.org/protobuf v1.35.1
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -95,7 +95,7 @@ require (
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
github.com/mdlayher/lldp v0.0.0-20150915211757-afd9f83164c5 // indirect
github.com/metal-stack/metal-lib v0.18.3 // indirect
github.com/metal-stack/security v0.8.1 // indirect
github.com/metal-stack/security v0.8.3 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down Expand Up @@ -131,7 +131,7 @@ require (
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ github.com/metal-stack/go-hal v0.5.5 h1:f+St8fZQEsUIwspy9fW5gkziKMIvFrGXP5kM9wJp
github.com/metal-stack/go-hal v0.5.5/go.mod h1:2yeab7N8ApBd44z7mEwWCb+CL7o3ioZu41kSsra50Dw=
github.com/metal-stack/go-lldpd v0.4.8 h1:xQxvbS0a2X663EQL9BR4r87xBb7tZolJ4G5HRij0+EU=
github.com/metal-stack/go-lldpd v0.4.8/go.mod h1:jI8gpcb57+CuZjaPP4nQRDsGG6dljHOM9sOL5pMUEIs=
github.com/metal-stack/metal-api v0.37.1 h1:ZXnn66Aae2BXuLmK9oqnl5Y31pcciPPXXJXmuOmr570=
github.com/metal-stack/metal-api v0.37.1/go.mod h1:MZPVXEdUbm9pwOR2jtpR60gaLFtB9sP7cRw+0VJvT1Y=
github.com/metal-stack/metal-api v0.37.3-0.20241010063016-58c6457e00ba h1:YMlvPF8AKb8CDBhEdiIuDw/vF2BD0G6dmVn8r2zN1mw=
github.com/metal-stack/metal-api v0.37.3-0.20241010063016-58c6457e00ba/go.mod h1:rQHSAouoPmw+jgPj0Zlac6ozZeI0TFvHhLBV01xW5p0=
github.com/metal-stack/metal-go v0.37.1 h1:vlvg/MY9Ep61h86GF54DER1VYADcqyHbFPZH3DqEbdM=
github.com/metal-stack/metal-go v0.37.1/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-lib v0.18.3 h1:bovFiJPB9SMvuGLqcXVWz6jFB8HrdzwnCX7TFlen4r0=
github.com/metal-stack/metal-lib v0.18.3/go.mod h1:Ctyi6zaXFr2NVrQZLFsDLnFCzupKnYErTtgRFKAsnbw=
github.com/metal-stack/pixie v0.3.4 h1:Z/hhh1BAF3Dmj+e1aex+8ikFUEUYUZGU90pwcsNBhcs=
github.com/metal-stack/pixie v0.3.4/go.mod h1:hL8yGQxrba821VKmOT2gDsr/ib8a8oet62b3muYjspg=
github.com/metal-stack/security v0.8.1 h1:4zmVUxZvDWShVvVIxM3XhIv7pTmPe9DvACRIHW6YTsk=
github.com/metal-stack/security v0.8.1/go.mod h1:OO8ZilZO6fUV5QEmwc7HP/RAjqYrGQxXoYIddJ9TvqE=
github.com/metal-stack/pixie v0.3.5-0.20241010063858-83bb4a8acd64 h1:EqN4C3NXPGomGhLZmF6N5ZJlUw5B9X6oDHr0LBCMisA=
github.com/metal-stack/pixie v0.3.5-0.20241010063858-83bb4a8acd64/go.mod h1:Jaf8nFAQ/CJbfq8MtgMScVodCWipqKgXpctHkqNKfX4=
github.com/metal-stack/security v0.8.3 h1:1Ugps5Ju9chCi3rkIPBXWLOLJKsIWnoLLzijsN6s8Bg=
github.com/metal-stack/security v0.8.3/go.mod h1:4+UAI/rqNbASyskDE/Ll/YoCW3kv/Q3pCW+CDwmB9YY=
github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=
github.com/metal-stack/v v1.0.3/go.mod h1:YTahEu7/ishwpYKnp/VaW/7nf8+PInogkfGwLcGPdXg=
github.com/mholt/archiver v2.1.0+incompatible h1:1ivm7KAHPtPere1YDOdrY6xGdbMNGRWThZbYh5lWZT0=
Expand Down Expand Up @@ -351,12 +351,12 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f h1:cUMEy+8oS78BWIH9OWazBkzbr090Od9tWBNtZHkOhf0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down

0 comments on commit 789a7e8

Please sign in to comment.