blob: 04e024007a35575bbfd04f46e30e8e1a7e22f8fa [file] [log] [blame]
Matteo Scandolof65e6872020-04-15 15:18:43 -07001/*
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
17package sadis
18
19import (
20 "fmt"
Shrey Baide72b3cc2020-05-12 00:03:06 +053021 "net"
22 "testing"
23
Matteo Scandolof65e6872020-04-15 15:18:43 -070024 "github.com/opencord/bbsim/internal/bbsim/devices"
25 "github.com/opencord/bbsim/internal/common"
26 "gotest.tools/assert"
Matteo Scandolof65e6872020-04-15 15:18:43 -070027)
28
Shrey Baid688b4242020-07-10 20:40:10 +053029func createMockDevices() (*devices.OltDevice, *devices.Onu) {
30 olt := &devices.OltDevice{
Matteo Scandolof65e6872020-04-15 15:18:43 -070031 ID: 0,
32 }
33
Shrey Baid688b4242020-07-10 20:40:10 +053034 onu := &devices.Onu{
Matteo Scandolof65e6872020-04-15 15:18:43 -070035 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
47func TestSadisServer_GetOnuEntryV1(t *testing.T) {
48
49 olt, onu := createMockDevices()
50
51 uni := "1"
52
Shrey Baid688b4242020-07-10 20:40:10 +053053 res, err := GetOnuEntryV1(olt, onu, uni)
Matteo Scandolof65e6872020-04-15 15:18:43 -070054 if err != nil {
55 t.Fatal(err)
56 }
57
Shrey Baide72b3cc2020-05-12 00:03:06 +053058 assert.Equal(t, res.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni))
Matteo Scandolof65e6872020-04-15 15:18:43 -070059 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
68func TestSadisServer_GetOnuEntryV2_Att(t *testing.T) {
69 olt, onu := createMockDevices()
70
71 uni := "1"
72
Shrey Baid688b4242020-07-10 20:40:10 +053073 res, err := GetOnuEntryV2(olt, onu, uni)
Matteo Scandolof65e6872020-04-15 15:18:43 -070074 if err != nil {
75 t.Fatal(err)
76 }
77
Shrey Baide72b3cc2020-05-12 00:03:06 +053078 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 Scandolof65e6872020-04-15 15:18:43 -070080
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 Baide72b3cc2020-05-12 00:03:06 +053092 assert.Equal(t, uniTagList.IsDhcpRequired, false)
93 assert.Equal(t, uniTagList.IsIgmpRequired, false)
Matteo Scandolof65e6872020-04-15 15:18:43 -070094}
95
96func TestSadisServer_GetOnuEntryV2_Dt(t *testing.T) {
97 common.Options.BBSim.SadisFormat = common.SadisFormatDt
98 olt, onu := createMockDevices()
99
100 uni := "1"
101
Shrey Baid688b4242020-07-10 20:40:10 +0530102 res, err := GetOnuEntryV2(olt, onu, uni)
Matteo Scandolof65e6872020-04-15 15:18:43 -0700103 if err != nil {
104 t.Fatal(err)
105 }
106
Shrey Baide72b3cc2020-05-12 00:03:06 +0530107 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 Scandolof65e6872020-04-15 15:18:43 -0700109
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 Baide72b3cc2020-05-12 00:03:06 +0530122}