Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -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 sadis |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 21 | "net" |
| 22 | "testing" |
| 23 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 24 | "github.com/opencord/bbsim/internal/bbsim/devices" |
| 25 | "github.com/opencord/bbsim/internal/common" |
| 26 | "gotest.tools/assert" |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 29 | func createMockDevices() (*devices.OltDevice, *devices.Onu) { |
| 30 | olt := &devices.OltDevice{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 31 | ID: 0, |
| 32 | } |
| 33 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 34 | onu := &devices.Onu{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 35 | ID: 1, |
| 36 | PonPortID: 1, |
| 37 | STag: 900, |
| 38 | CTag: 923, |
| 39 | HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(1), byte(1)}, |
| 40 | PortNo: 0, |
| 41 | } |
| 42 | onu.SerialNumber = onu.NewSN(0, onu.PonPortID, onu.ID) |
| 43 | |
| 44 | return olt, onu |
| 45 | } |
| 46 | |
| 47 | func TestSadisServer_GetOnuEntryV1(t *testing.T) { |
| 48 | |
| 49 | olt, onu := createMockDevices() |
| 50 | |
| 51 | uni := "1" |
| 52 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 53 | res, err := GetOnuEntryV1(olt, onu, uni) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 54 | if err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 58 | assert.Equal(t, res.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni)) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 59 | assert.Equal(t, res.CTag, 923) |
| 60 | assert.Equal(t, res.STag, 900) |
| 61 | assert.Equal(t, res.RemoteID, string(olt.SerialNumber)) |
| 62 | assert.Equal(t, res.DownstreamBandwidthProfile, "Default") |
| 63 | assert.Equal(t, res.UpstreamBandwidthProfile, "User_Bandwidth1") |
| 64 | assert.Equal(t, res.TechnologyProfileID, 64) |
| 65 | |
| 66 | } |
| 67 | |
| 68 | func TestSadisServer_GetOnuEntryV2_Att(t *testing.T) { |
| 69 | olt, onu := createMockDevices() |
| 70 | |
| 71 | uni := "1" |
| 72 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 73 | res, err := GetOnuEntryV2(olt, onu, uni) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 74 | if err != nil { |
| 75 | t.Fatal(err) |
| 76 | } |
| 77 | |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 78 | assert.Equal(t, res.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni)) |
| 79 | assert.Equal(t, res.RemoteID, fmt.Sprintf("%s-%s", onu.Sn(), uni)) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 80 | |
| 81 | // assert the correct type |
| 82 | uniTagList, ok := res.UniTagList[0].(SadisUniTagAtt) |
| 83 | if !ok { |
| 84 | t.Fatal("UniTagList has the wrong type") |
| 85 | } |
| 86 | |
| 87 | assert.Equal(t, uniTagList.PonCTag, 923) |
| 88 | assert.Equal(t, uniTagList.PonSTag, 900) |
| 89 | assert.Equal(t, uniTagList.DownstreamBandwidthProfile, "User_Bandwidth1") |
| 90 | assert.Equal(t, uniTagList.UpstreamBandwidthProfile, "Default") |
| 91 | assert.Equal(t, uniTagList.TechnologyProfileID, 64) |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 92 | assert.Equal(t, uniTagList.IsDhcpRequired, false) |
| 93 | assert.Equal(t, uniTagList.IsIgmpRequired, false) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | func TestSadisServer_GetOnuEntryV2_Dt(t *testing.T) { |
| 97 | common.Options.BBSim.SadisFormat = common.SadisFormatDt |
| 98 | olt, onu := createMockDevices() |
| 99 | |
| 100 | uni := "1" |
| 101 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 102 | res, err := GetOnuEntryV2(olt, onu, uni) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 103 | if err != nil { |
| 104 | t.Fatal(err) |
| 105 | } |
| 106 | |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 107 | assert.Equal(t, res.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni)) |
| 108 | assert.Equal(t, res.RemoteID, fmt.Sprintf("%s-%s", onu.Sn(), uni)) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 109 | |
| 110 | // assert the correct type |
| 111 | uniTagList, ok := res.UniTagList[0].(SadisUniTagDt) |
| 112 | if !ok { |
| 113 | t.Fatal("UniTagList has the wrong type") |
| 114 | } |
| 115 | |
| 116 | assert.Equal(t, uniTagList.PonCTag, 4096) |
| 117 | assert.Equal(t, uniTagList.PonSTag, 900) |
| 118 | assert.Equal(t, uniTagList.DownstreamBandwidthProfile, "User_Bandwidth1") |
| 119 | assert.Equal(t, uniTagList.UpstreamBandwidthProfile, "Default") |
| 120 | assert.Equal(t, uniTagList.TechnologyProfileID, 64) |
| 121 | assert.Equal(t, uniTagList.UniTagMatch, 4096) |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 122 | } |