Matteo Scandolo | 378b8c9 | 2020-04-16 14:34:22 -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 devices |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 20 | omcisim "github.com/opencord/omci-sim" |
Matteo Scandolo | 378b8c9 | 2020-04-16 14:34:22 -0700 | [diff] [blame] | 21 | "gotest.tools/assert" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | func Test_Onu_CreateOnu(t *testing.T) { |
| 26 | |
| 27 | olt := OltDevice{ |
| 28 | ID: 0, |
| 29 | } |
| 30 | pon := PonPort{ |
| 31 | ID: 1, |
| 32 | Olt: &olt, |
| 33 | } |
| 34 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame^] | 35 | onu := CreateONU(&olt, &pon, 1, 900, 900, true, false, 0, false) |
Matteo Scandolo | 378b8c9 | 2020-04-16 14:34:22 -0700 | [diff] [blame] | 36 | |
| 37 | assert.Equal(t, onu.Sn(), "BBSM00000101") |
| 38 | assert.Equal(t, onu.STag, 900) |
| 39 | assert.Equal(t, onu.CTag, 900) |
| 40 | assert.Equal(t, onu.Auth, true) |
| 41 | assert.Equal(t, onu.Dhcp, false) |
| 42 | assert.Equal(t, onu.HwAddress.String(), "2e:60:70:00:01:01") |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | func TestOnu_processOmciMessage_GemPortAdded(t *testing.T) { |
| 46 | |
| 47 | receivedValues := []bool{} |
| 48 | |
| 49 | checker := func(ch chan bool, done chan int) { |
| 50 | for v := range ch { |
| 51 | receivedValues = append(receivedValues, v) |
| 52 | } |
| 53 | done <- 0 |
| 54 | } |
| 55 | |
| 56 | onu := createTestOnu() |
| 57 | |
| 58 | // create two listeners on the GemPortAdded event |
| 59 | ch1 := onu.GetGemPortChan() |
| 60 | ch2 := onu.GetGemPortChan() |
| 61 | |
| 62 | msg := omcisim.OmciChMessage{ |
| 63 | Type: omcisim.GemPortAdded, |
| 64 | Data: omcisim.OmciChMessageData{ |
| 65 | IntfId: 1, |
| 66 | OnuId: 1, |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | onu.processOmciMessage(msg, nil) |
| 71 | |
| 72 | done := make(chan int) |
| 73 | |
| 74 | go checker(ch1, done) |
| 75 | go checker(ch2, done) |
| 76 | |
| 77 | // wait for the messages to be received on the "done" channel |
| 78 | <-done |
| 79 | <-done |
| 80 | |
| 81 | // make sure all channel are closed and removed |
| 82 | assert.Equal(t, len(onu.GemPortChannels), 0) |
| 83 | assert.Equal(t, len(receivedValues), 2) |
| 84 | } |