Skip to content
Snippets Groups Projects
Commit 59949ac9 authored by Marcus Weiner's avatar Marcus Weiner
Browse files

Test LSA flooding indicators

parent 79d4324f
No related branches found
No related tags found
1 merge request!2Packet/ospfv3
...@@ -17,7 +17,7 @@ func (t LSAType) Serialize(buf *bytes.Buffer) { ...@@ -17,7 +17,7 @@ func (t LSAType) Serialize(buf *bytes.Buffer) {
buf.Write(convert.Uint16Byte(uint16(t))) buf.Write(convert.Uint16Byte(uint16(t)))
} }
func (t LSAType) ShouldFlood() bool { func (t LSAType) FloodIfUnknown() bool {
return t&(1<<15) != 0 // test for top bit return t&(1<<15) != 0 // test for top bit
} }
......
package packetv3_test
import (
"testing"
ospf "github.com/bio-routing/bio-rd/protocols/ospf/packetv3"
"github.com/stretchr/testify/assert"
)
func TestLSATypeFlooding(t *testing.T) {
tests := []struct {
input ospf.LSAType
expectUnknownFlood bool
expectedFlooding ospf.FloodingScope
}{
{
input: ospf.LSATypeRouter,
expectedFlooding: ospf.FloodArea,
},
{
input: ospf.LSATypeNetwork,
expectedFlooding: ospf.FloodArea,
},
{
input: ospf.LSATypeInterAreaPrefix,
expectedFlooding: ospf.FloodArea,
},
{
input: ospf.LSATypeInterAreaRouter,
expectedFlooding: ospf.FloodArea,
},
{
input: ospf.LSATypeASExternal,
expectedFlooding: ospf.FloodAS,
},
{
input: ospf.LSATypeDeprecated,
expectedFlooding: ospf.FloodArea,
},
{
input: ospf.LSATypeNSSA,
expectedFlooding: ospf.FloodArea,
},
{
input: ospf.LSATypeLink,
expectedFlooding: ospf.FloodLinkLocal,
},
{
input: ospf.LSATypeIntraAreaPrefix,
expectedFlooding: ospf.FloodArea,
},
{
// Unknown with local scope
input: 0x0022,
expectUnknownFlood: false,
},
{
// Unknown with flooding scope
input: 0xa022,
expectUnknownFlood: true,
expectedFlooding: ospf.FloodArea,
},
{
// Unknown with reserved flooding scope
input: 0x6022,
expectedFlooding: ospf.FloodReserved,
},
}
for _, test := range tests {
assert.Equal(t, test.expectedFlooding, test.input.FloodingScope())
assert.Equal(t, test.expectUnknownFlood, test.input.FloodIfUnknown())
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment