f-41: api, vpc: champ l3vni des VPC #41
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
bf0e83862f
commit
3dd94f35dd
11 changed files with 295 additions and 10 deletions
15
internal/vpc/l3vni.go
Normal file
15
internal/vpc/l3vni.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package vpc
|
||||
|
||||
import "fmt"
|
||||
|
||||
const maxL3VNI = 1<<24 - 1
|
||||
|
||||
func ValidL3VNI(id uint32) error {
|
||||
if id == 0 || id > maxL3VNI {
|
||||
return fmt.Errorf("l3vni %d does not fit in 24 bits (1-%d)", id, maxL3VNI)
|
||||
}
|
||||
if id >= 253 && id <= 255 {
|
||||
return fmt.Errorf("l3vni %d is reserved: it is also the routing table id, and tables 253-255 belong to the kernel", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
29
internal/vpc/l3vni_test.go
Normal file
29
internal/vpc/l3vni_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package vpc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidL3VNI_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) {
|
||||
for _, id := range []uint32{1, 252, 256, 4001, 16777215} {
|
||||
if err := ValidL3VNI(id); err != nil {
|
||||
t.Errorf("ValidL3VNI(%d) = %v", id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidL3VNI_RejectsOutOfRangeAndReservedTables(t *testing.T) {
|
||||
cases := map[uint32]string{
|
||||
0: "does not fit in 24 bits",
|
||||
16777216: "does not fit in 24 bits",
|
||||
253: "is reserved",
|
||||
254: "is reserved",
|
||||
255: "is reserved",
|
||||
}
|
||||
for id, want := range cases {
|
||||
if err := ValidL3VNI(id); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("ValidL3VNI(%d) = %v, attendu %q", id, err, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue