Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 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 | |
| 17 | package igmp |
| 18 | |
| 19 | import ( |
| 20 | "encoding/hex" |
| 21 | "fmt" |
| 22 | "github.com/google/gopacket" |
| 23 | "github.com/google/gopacket/layers" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame^] | 24 | "github.com/opencord/voltha-protos/v4/go/openolt" |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 25 | "github.com/stretchr/testify/assert" |
| 26 | "google.golang.org/grpc" |
| 27 | "net" |
| 28 | "testing" |
| 29 | ) |
| 30 | |
| 31 | type mockStream struct { |
| 32 | CallCount int |
| 33 | Calls map[int]*openolt.Indication |
| 34 | grpc.ServerStream |
| 35 | } |
| 36 | |
| 37 | func (s *mockStream) Send(ind *openolt.Indication) error { |
| 38 | s.CallCount++ |
| 39 | s.Calls[s.CallCount] = ind |
| 40 | return nil |
| 41 | } |
| 42 | |
| 43 | func TestHandleNextPacket(t *testing.T) { |
| 44 | |
| 45 | t.Skip("Need to find how to serialize an IGMP packet") |
| 46 | |
| 47 | stream := &mockStream{ |
| 48 | CallCount: 0, |
| 49 | Calls: make(map[int]*openolt.Indication), |
| 50 | } |
| 51 | |
| 52 | mac := net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, 0x15, 0x16} |
| 53 | |
| 54 | packetData := []byte{ |
| 55 | 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, |
| 56 | 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, |
| 57 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 58 | } |
| 59 | fmt.Println(hex.EncodeToString(packetData)) |
| 60 | |
| 61 | packet := gopacket.NewPacket(packetData, layers.LayerTypeIPv4, gopacket.Default) |
| 62 | |
| 63 | fmt.Println(hex.EncodeToString(packet.Data())) |
| 64 | |
| 65 | fmt.Println(packet.Layers()) |
| 66 | |
| 67 | err := HandleNextPacket(0, 0, "FOO", 1, 1024, mac, packet, 55, 5, stream) |
| 68 | assert.Nil(t, err) |
| 69 | |
| 70 | assert.Equal(t, 1, stream.CallCount) |
| 71 | } |