summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6relay_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6/dhcpv6relay_test.go')
-rw-r--r--dhcpv6/dhcpv6relay_test.go72
1 files changed, 21 insertions, 51 deletions
diff --git a/dhcpv6/dhcpv6relay_test.go b/dhcpv6/dhcpv6relay_test.go
index 87eabbf..270dd52 100644
--- a/dhcpv6/dhcpv6relay_test.go
+++ b/dhcpv6/dhcpv6relay_test.go
@@ -12,60 +12,30 @@ func TestRelayMessage(t *testing.T) {
ll := net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0xff, 0xfe, 0xdd, 0xee, 0xff}
ma := net.IP{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
r := RelayMessage{
- messageType: MessageTypeRelayForward,
- hopCount: 10,
- linkAddr: ll,
- peerAddr: ma,
+ MessageType: MessageTypeRelayForward,
+ HopCount: 10,
+ LinkAddr: ll,
+ PeerAddr: ma,
// options is left empty here for testing purposes, even if it's
// mandatory to have at least a relay message option
}
if mt := r.Type(); mt != MessageTypeRelayForward {
t.Fatalf("Invalid message type. Expected %v, got %v", MessageTypeRelayForward, mt)
}
- if hc := r.HopCount(); hc != 10 {
+ if hc := r.HopCount; hc != 10 {
t.Fatalf("Invalid hop count. Expected 10, got %v", hc)
}
- if la := r.LinkAddr(); !bytes.Equal(la, ll) {
+ if la := r.LinkAddr; !bytes.Equal(la, ll) {
t.Fatalf("Invalid link address. Expected %v, got %v", ll, la)
}
- if pa := r.PeerAddr(); !bytes.Equal(pa, ma) {
+ if pa := r.PeerAddr; !bytes.Equal(pa, ma) {
t.Fatalf("Invalid peer address. Expected %v, got %v", ma, pa)
}
- if opts := r.Options(); len(opts) != 0 {
+ if opts := r.Options; len(opts) != 0 {
t.Fatalf("Invalid options. Expected none, got %v", opts)
}
}
-func TestRelayMessageSettersAndGetters(t *testing.T) {
- r := RelayMessage{}
- // set and get message type
- r.SetMessageType(MessageTypeRelayReply)
- if mt := r.Type(); mt != MessageTypeRelayReply {
- t.Fatalf("Invalid message type. Expected %v, got %v", MessageTypeRelayReply, mt)
- }
- // set and get hop count
- r.SetHopCount(5)
- if hc := r.HopCount(); hc != 5 {
- t.Fatalf("Invalid hop count. Expected 5, got %v", hc)
- }
- // set and get link address
- r.SetLinkAddr(net.IPv6loopback)
- if la := r.LinkAddr(); !bytes.Equal(la, net.IPv6loopback) {
- t.Fatalf("Invalid link address. Expected %v, got %v", net.IPv6loopback, la)
- }
- // set and get peer address
- r.SetPeerAddr(net.IPv6loopback)
- if pa := r.PeerAddr(); !bytes.Equal(pa, net.IPv6loopback) {
- t.Fatalf("Invalid peer address. Expected %v, got %v", net.IPv6loopback, pa)
- }
- // set and get options
- oneOpt := []Option{&OptRelayMsg{relayMessage: &Message{}}}
- r.SetOptions(oneOpt)
- if opts := r.Options(); len(opts) != 1 || opts[0] != oneOpt[0] {
- t.Fatalf("Invalid options. Expected %v, got %v", oneOpt, opts)
- }
-}
-
func TestRelayMessageToBytes(t *testing.T) {
expected := []byte{
12, // MessageTypeRelayForward
@@ -84,16 +54,16 @@ func TestRelayMessageToBytes(t *testing.T) {
0, 0,
}
r := RelayMessage{
- messageType: MessageTypeRelayForward,
- hopCount: 1,
- linkAddr: net.IPv6interfacelocalallnodes,
- peerAddr: net.IPv6linklocalallrouters,
+ MessageType: MessageTypeRelayForward,
+ HopCount: 1,
+ LinkAddr: net.IPv6interfacelocalallnodes,
+ PeerAddr: net.IPv6linklocalallrouters,
}
opt := OptRelayMsg{
relayMessage: &Message{
- messageType: MessageTypeSolicit,
- transactionID: TransactionID{0xaa, 0xbb, 0xcc},
- options: []Option{
+ MessageType: MessageTypeSolicit,
+ TransactionID: TransactionID{0xaa, 0xbb, 0xcc},
+ Options: []Option{
&OptElapsedTime{
ElapsedTime: 0,
},
@@ -110,9 +80,9 @@ func TestRelayMessageToBytes(t *testing.T) {
func TestNewRelayRepFromRelayForw(t *testing.T) {
// create a new relay forward
rf := RelayMessage{}
- rf.SetMessageType(MessageTypeRelayForward)
- rf.SetPeerAddr(net.IPv6linklocalallrouters)
- rf.SetLinkAddr(net.IPv6interfacelocalallnodes)
+ rf.MessageType = MessageTypeRelayForward
+ rf.PeerAddr = net.IPv6linklocalallrouters
+ rf.LinkAddr = net.IPv6interfacelocalallnodes
rf.AddOption(&OptInterfaceId{})
rf.AddOption(&OptRemoteId{})
@@ -130,9 +100,9 @@ func TestNewRelayRepFromRelayForw(t *testing.T) {
require.NoError(t, err)
relay := rr.(*RelayMessage)
require.Equal(t, rr.Type(), MessageTypeRelayReply)
- require.Equal(t, relay.HopCount(), rf.HopCount())
- require.Equal(t, relay.PeerAddr(), rf.PeerAddr())
- require.Equal(t, relay.LinkAddr(), rf.LinkAddr())
+ require.Equal(t, relay.HopCount, rf.HopCount)
+ require.Equal(t, relay.PeerAddr, rf.PeerAddr)
+ require.Equal(t, relay.LinkAddr, rf.LinkAddr)
require.NotNil(t, rr.GetOneOption(OptionInterfaceID))
require.NotNil(t, rr.GetOneOption(OptionRemoteID))
m, err := relay.GetInnerMessage()