Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISIS: Refactor area to include AFI #475

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocols/isis/server/hello_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (nifa *netIfa) p2pHello() *packet.P2PHello {

areas := make([]types.AreaID, 0)
for _, net := range nifa.srv.nets {
areas = append(areas, append([]byte{net.AFI}, net.AreaID...))
areas = append(areas, net.AreaID)
}
h.TLVs = append(h.TLVs, packet.NewAreaAddressesTLV(areas))

Expand Down
2 changes: 1 addition & 1 deletion protocols/isis/server/neighbor_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (nm *neighborManager) validateP2PHello(hello *packet.P2PHello) error {
func (nifa *netIfa) validateAreasL1(receivedAreas []types.AreaID) bool {
localAreas := make([]types.AreaID, 0)
for _, net := range nifa.srv.nets {
localAreas = append(localAreas, append([]byte{net.AFI}, net.AreaID...))
localAreas = append(localAreas, net.AreaID)
}

for _, needle := range receivedAreas {
Expand Down
15 changes: 5 additions & 10 deletions protocols/isis/server/neighbor_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func TestValidateAreasL1(t *testing.T) {
srv: &Server{
nets: []*types.NET{
{
AFI: 0x49,
AreaID: []byte{1},
AreaID: []byte{0x49, 1},
},
},
},
Expand All @@ -41,12 +40,10 @@ func TestValidateAreasL1(t *testing.T) {
srv: &Server{
nets: []*types.NET{
{
AFI: 0x49,
AreaID: []byte{1},
AreaID: []byte{0x49},
},
{
AFI: 0x49,
AreaID: []byte{0xff},
AreaID: []byte{0x49, 0xff},
},
},
},
Expand All @@ -64,12 +61,10 @@ func TestValidateAreasL1(t *testing.T) {
srv: &Server{
nets: []*types.NET{
{
AFI: 0x49,
AreaID: []byte{1},
AreaID: []byte{0x49, 1},
},
{
AFI: 0x49,
AreaID: []byte{0xff},
AreaID: []byte{0x49, 0xff},
},
},
},
Expand Down
6 changes: 2 additions & 4 deletions protocols/isis/types/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const (

// NET represents an ISO network entity title
type NET struct {
AFI byte
AreaID AreaID
SystemID SystemID
SEL byte
Expand All @@ -29,8 +28,8 @@ func ParseNET(addr []byte) (*NET, error) {

areaID := []byte{}

for i := 0; i < addrLen-systemIDLen-2; i++ { // -2 for SEL and "off by one"
areaID = append(areaID, addr[i+1])
for i := 0; i < addrLen-systemIDLen-1; i++ {
areaID = append(areaID, addr[i])
}

systemID := SystemID{
Expand All @@ -43,7 +42,6 @@ func ParseNET(addr []byte) (*NET, error) {
}

return &NET{
AFI: addr[0],
AreaID: areaID,
SystemID: systemID,
SEL: addr[addrLen-1],
Expand Down
85 changes: 85 additions & 0 deletions protocols/isis/types/net_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package types

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseNET(t *testing.T) {
tests := []struct {
name string
input []byte
expected *NET
wantFail bool
}{
{
name: "Simple long valid NET",
input: []byte{
0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Area (including AFI)
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID
0x00, // SEL
},
expected: &NET{
AreaID: []byte{
0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
SystemID: SystemID{
0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
},
SEL: 0x00,
},
},
{
name: "Simple short valid NET",
input: []byte{
0x49, // Area (including AFI)
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID
0x00, // SEL
},
expected: &NET{
AreaID: []byte{
0x49,
},
SystemID: SystemID{
0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
},
SEL: 0x00,
},
},
{
name: "Too long NET",
input: []byte{
0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, // Area (including AFI)
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID
0x00, // SEL
},
wantFail: true,
},
{
name: "Too short NET",
input: []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID
0x00, // SEL
},
wantFail: true,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
n, err := ParseNET([]byte(test.input))
if err != nil && !test.wantFail {
t.Errorf("unexpected failure for test %q: %v", test.name, err)
return
}

if err == nil && test.wantFail {
t.Errorf("unexpected success for test %q", test.name)
return
}

assert.Equal(t, test.expected, n, test.name)
})
}
}
11 changes: 5 additions & 6 deletions tests/isis_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ var (
0, // Reserved
0, // Max. Area addresses
// LSP
0, 0x5f, // Length
0, 0x60, // Length
7, 6, // Remaining Lifetime
12, 12, 12, 13, 13, 13, 0, 0, // LSP ID
0, 0, 0, 3, // Sequence number
0x52, 0xca, // Checksum
0x58, 0x79, // Checksum
0, // Type block
// TLVs
1, // Area
2, // Length
1, 0,
3, // Length
2, 0x49, 0,
129, // Protocols Supported
2, // Length
204, 142, // IPv4 + IPv6
Expand Down Expand Up @@ -294,8 +294,7 @@ func TestISISServer(t *testing.T) {
du := &device.MockServer{}
s, err := server.New([]*types.NET{
{
AFI: 0x49,
AreaID: types.AreaID{0x00},
AreaID: types.AreaID{0x49, 0x00},
SystemID: types.SystemID{12, 12, 12, 13, 13, 13},
SEL: 0x00,
},
Expand Down
Loading