Skip to content

Commit

Permalink
Refactor to use net.IP as pointer
Browse files Browse the repository at this point in the history
Also removes generated tests
  • Loading branch information
mraerino committed Jan 5, 2020
1 parent 2083e61 commit 3f46ce5
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 2,447 deletions.
6 changes: 3 additions & 3 deletions protocols/ospf/packetv3/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ type deserializableIP struct {
Lower uint64
}

func (ip deserializableIP) ToNetIP() net.IP {
return *(net.IPv6(ip.Higher, ip.Lower))
func (ip deserializableIP) ToNetIP() *net.IP {
return net.IPv6(ip.Higher, ip.Lower)
}

func serializeIPv6(ip net.IP, buf *bytes.Buffer) {
func serializeIPv6(ip *net.IP, buf *bytes.Buffer) {
if ip.IsIPv4() {
for i := 0; i < 16; i++ {
buf.WriteByte(0)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions protocols/ospf/packetv3/fixtures/packets/base.go

This file was deleted.

192 changes: 0 additions & 192 deletions protocols/ospf/packetv3/fixtures/packets/gen/gen.go

This file was deleted.

8 changes: 4 additions & 4 deletions protocols/ospf/packetv3/lsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ type ASExternalLSA struct {
Metric InterfaceMetric
Prefix LSAPrefix

ForwardingAddress net.IP // optional
ExternalRouteTag uint32 // optional
ReferencedLinkStateID ID // optional
ForwardingAddress *net.IP // optional
ExternalRouteTag uint32 // optional
ReferencedLinkStateID ID // optional
}

func (a *ASExternalLSA) FlagE() bool {
Expand Down Expand Up @@ -454,7 +454,7 @@ func DeserializeASExternalLSA(buf *bytes.Buffer) (*ASExternalLSA, int, error) {
type LinkLSA struct {
RouterPriority uint8
Options RouterOptions
LinkLocalInterfaceAddress net.IP
LinkLocalInterfaceAddress *net.IP
PrefixNum uint32
Prefixes []LSAPrefix
}
Expand Down
48 changes: 0 additions & 48 deletions protocols/ospf/packetv3/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"testing"

ospf "github.com/bio-routing/bio-rd/protocols/ospf/packetv3"
"github.com/bio-routing/bio-rd/protocols/ospf/packetv3/fixtures"
"github.com/bio-routing/bio-rd/protocols/ospf/packetv3/fixtures/packets"
"github.com/stretchr/testify/assert"
)

var files = []string{
Expand Down Expand Up @@ -69,48 +66,3 @@ func testDecodeFile(t *testing.T, path string) {
packetCount++
}
}

func TestEncode(t *testing.T) {
for _, path := range files {
t.Run(path, func(t *testing.T) {
testEncodeFile(t, dir+path)
})
}
}

func testEncodeFile(t *testing.T, path string) {
fmt.Printf("Testing on file: %s\n", path)
r, f := fixtures.PacketReader(t, path)
defer f.Close()

packets, ok := packets.Packets[filepath.Base(path)]
if !ok {
t.Errorf("Raw Go values not found for file %s", filepath.Base(path))
}

var packetCount int
for {
data, _, err := r.ReadPacketData()
if err == io.EOF {
break
}
if err != nil {
t.Error(err)
return
}

pl, src, dst, err := fixtures.Payload(data)
if err != nil {
t.Error(err)
return
}

t.Run(fmt.Sprintf("Packet_%03d", packetCount+1), func(t *testing.T) {
buf := &bytes.Buffer{}
msg := packets[packetCount]
msg.Serialize(buf, src, dst)
assert.Equal(t, buf.Bytes(), pl)
})
packetCount++
}
}

0 comments on commit 3f46ce5

Please sign in to comment.