github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/tcpip/header/mld_test.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package header 16 17 import ( 18 "encoding/binary" 19 "testing" 20 "time" 21 22 "github.com/SagerNet/gvisor/pkg/tcpip" 23 ) 24 25 func TestMLD(t *testing.T) { 26 b := []byte{ 27 // Maximum Response Delay 28 0, 0, 29 30 // Reserved 31 0, 0, 32 33 // MulticastAddress 34 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 35 } 36 37 const maxRespDelay = 513 38 binary.BigEndian.PutUint16(b, maxRespDelay) 39 40 mld := MLD(b) 41 42 if got, want := mld.MaximumResponseDelay(), maxRespDelay*time.Millisecond; got != want { 43 t.Errorf("got mld.MaximumResponseDelay() = %s, want = %s", got, want) 44 } 45 46 const newMaxRespDelay = 1234 47 mld.SetMaximumResponseDelay(newMaxRespDelay) 48 if got, want := mld.MaximumResponseDelay(), newMaxRespDelay*time.Millisecond; got != want { 49 t.Errorf("got mld.MaximumResponseDelay() = %s, want = %s", got, want) 50 } 51 52 if got, want := mld.MulticastAddress(), tcpip.Address([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}); got != want { 53 t.Errorf("got mld.MulticastAddress() = %s, want = %s", got, want) 54 } 55 56 multicastAddress := tcpip.Address([]byte{15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}) 57 mld.SetMulticastAddress(multicastAddress) 58 if got := mld.MulticastAddress(); got != multicastAddress { 59 t.Errorf("got mld.MulticastAddress() = %s, want = %s", got, multicastAddress) 60 } 61 }