blob: e9be95a732f1906f0261e9ac13e41238fd1d12ba [file] [log] [blame]
Matteo Scandolo618a6582020-09-09 12:21:29 -07001/*
Joey Armstrong2c039362024-02-04 18:51:52 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo618a6582020-09-09 12:21:29 -07003
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package igmp
18
19import (
20 "encoding/hex"
21 "fmt"
Baris Ertas0ce2f7c2023-04-11 11:44:24 +030022 "net"
23 "testing"
24
Matteo Scandolo618a6582020-09-09 12:21:29 -070025 "github.com/google/gopacket"
26 "github.com/google/gopacket/layers"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000027 "github.com/opencord/voltha-protos/v5/go/openolt"
Matteo Scandolo618a6582020-09-09 12:21:29 -070028 "github.com/stretchr/testify/assert"
29 "google.golang.org/grpc"
Matteo Scandolo618a6582020-09-09 12:21:29 -070030)
31
32type mockStream struct {
33 CallCount int
34 Calls map[int]*openolt.Indication
35 grpc.ServerStream
36}
37
38func (s *mockStream) Send(ind *openolt.Indication) error {
39 s.CallCount++
40 s.Calls[s.CallCount] = ind
41 return nil
42}
43
44func TestHandleNextPacket(t *testing.T) {
45
46 t.Skip("Need to find how to serialize an IGMP packet")
47
48 stream := &mockStream{
49 CallCount: 0,
50 Calls: make(map[int]*openolt.Indication),
51 }
52
53 mac := net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, 0x15, 0x16}
54
55 packetData := []byte{
56 1, 0, 94, 0, 0, 22, 222, 173, 190, 239, 186, 17, 8, 0, 70, 0, 0, 32, 0, 0, 0, 0, 120, 2, 191,
57 215, 10, 244, 2, 246, 224, 0, 0, 22, 148, 4, 0, 0, 17, 10, 14, 223, 224, 0, 0, 22, 0, 0, 0, 0,
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 }
60 fmt.Println(hex.EncodeToString(packetData))
61
62 packet := gopacket.NewPacket(packetData, layers.LayerTypeIPv4, gopacket.Default)
63
64 fmt.Println(hex.EncodeToString(packet.Data()))
65
66 fmt.Println(packet.Layers())
67
Baris Ertas53ab13c2023-05-25 16:31:48 +030068 err := HandleNextPacket(0, 0, "FOO", 1, 1024, 0, mac, packet, 55, 5, nil, stream)
Matteo Scandolo618a6582020-09-09 12:21:29 -070069 assert.Nil(t, err)
70
71 assert.Equal(t, 1, stream.CallCount)
72}