blob: 27e43bc8a57cd2c65383759fb7415ff4d5c422bb [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"
Matteo Scandolof65e6872020-04-15 15:18:43 -070025 "gotest.tools/assert"
Matteo Scandolof65e6872020-04-15 15:18:43 -070026)
27
Shrey Baid688b4242020-07-10 20:40:10 +053028func createMockDevices() (*devices.OltDevice, *devices.Onu) {
29 olt := &devices.OltDevice{
Matteo Scandolof65e6872020-04-15 15:18:43 -070030 ID: 0,
31 }
32
Shrey Baid688b4242020-07-10 20:40:10 +053033 onu := &devices.Onu{
Matteo Scandolof65e6872020-04-15 15:18:43 -070034 ID: 1,
35 PonPortID: 1,
Matteo Scandolof65e6872020-04-15 15:18:43 -070036 PortNo: 0,
37 }
Matteo Scandolo4a036262020-08-17 15:56:13 -070038
39 mac := net.HardwareAddr{0x2e, 0x60, 0x01, byte(1), byte(1), byte(0)}
40
Matteo Scandolof65e6872020-04-15 15:18:43 -070041 onu.SerialNumber = onu.NewSN(0, onu.PonPortID, onu.ID)
Matteo Scandolo4a036262020-08-17 15:56:13 -070042 onu.Services = []devices.ServiceIf{
43 &devices.Service{Name: "hsia", CTag: 923, STag: 900, NeedsEapol: true, NeedsDhcp: true, NeedsIgmp: true, HwAddress: mac, TechnologyProfileID: 64},
44 }
Matteo Scandolof65e6872020-04-15 15:18:43 -070045
46 return olt, onu
47}
48
Matteo Scandolo4a036262020-08-17 15:56:13 -070049func TestSadisServer_GetOnuEntryV2(t *testing.T) {
Matteo Scandolof65e6872020-04-15 15:18:43 -070050
51 olt, onu := createMockDevices()
52
53 uni := "1"
54
Matteo Scandolo4a036262020-08-17 15:56:13 -070055 entry, err := GetOnuEntryV2(olt, onu, uni)
Matteo Scandolof65e6872020-04-15 15:18:43 -070056
Matteo Scandolo4a036262020-08-17 15:56:13 -070057 assert.NilError(t, err)
Matteo Scandolof65e6872020-04-15 15:18:43 -070058
Matteo Scandolo4a036262020-08-17 15:56:13 -070059 assert.Equal(t, entry.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni))
60 assert.Equal(t, entry.RemoteID, fmt.Sprintf("%s-%s", onu.Sn(), uni))
61
62 assert.Equal(t, entry.UniTagList[0].PonCTag, 923)
63 assert.Equal(t, entry.UniTagList[0].PonSTag, 900)
64 assert.Equal(t, entry.UniTagList[0].DownstreamBandwidthProfile, "User_Bandwidth2")
65 assert.Equal(t, entry.UniTagList[0].UpstreamBandwidthProfile, "User_Bandwidth1")
66 assert.Equal(t, entry.UniTagList[0].TechnologyProfileID, 64)
67 assert.Equal(t, entry.UniTagList[0].IsDhcpRequired, true)
68 assert.Equal(t, entry.UniTagList[0].IsIgmpRequired, true)
Matteo Scandolof65e6872020-04-15 15:18:43 -070069}
70
Matteo Scandolo4a036262020-08-17 15:56:13 -070071func TestSadisServer_GetOnuEntryV2_multi_service(t *testing.T) {
72
73 mac := net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(2)}
74
75 hsia := devices.Service{Name: "hsia", HwAddress: net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(1)},
76 CTag: 900, STag: 900, TechnologyProfileID: 64}
77
78 voip := devices.Service{Name: "voip", HwAddress: mac,
79 CTag: 901, STag: 900, TechnologyProfileID: 65}
80
81 vod := devices.Service{Name: "vod", HwAddress: net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(3)},
82 CTag: 902, STag: 900, TechnologyProfileID: 66}
83
Matteo Scandolof65e6872020-04-15 15:18:43 -070084 olt, onu := createMockDevices()
85
Matteo Scandolo4a036262020-08-17 15:56:13 -070086 onu.Services = []devices.ServiceIf{&hsia, &voip, &vod}
87
Matteo Scandolof65e6872020-04-15 15:18:43 -070088 uni := "1"
89
Matteo Scandolo4a036262020-08-17 15:56:13 -070090 entry, err := GetOnuEntryV2(olt, onu, uni)
Matteo Scandolof65e6872020-04-15 15:18:43 -070091
Matteo Scandolo4a036262020-08-17 15:56:13 -070092 assert.NilError(t, err)
Matteo Scandolof65e6872020-04-15 15:18:43 -070093
Matteo Scandolo4a036262020-08-17 15:56:13 -070094 assert.Equal(t, entry.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni))
95 assert.Equal(t, entry.RemoteID, fmt.Sprintf("%s-%s", onu.Sn(), uni))
Matteo Scandolof65e6872020-04-15 15:18:43 -070096
Matteo Scandolo4a036262020-08-17 15:56:13 -070097 assert.Equal(t, len(entry.UniTagList), 3)
Matteo Scandolof65e6872020-04-15 15:18:43 -070098
Matteo Scandolo4a036262020-08-17 15:56:13 -070099 assert.Equal(t, entry.UniTagList[0].PonCTag, 900)
100 assert.Equal(t, entry.UniTagList[0].PonSTag, 900)
101 assert.Equal(t, entry.UniTagList[0].TechnologyProfileID, 64)
Matteo Scandolof65e6872020-04-15 15:18:43 -0700102
Matteo Scandolo4a036262020-08-17 15:56:13 -0700103 assert.Equal(t, entry.UniTagList[1].PonCTag, 901)
104 assert.Equal(t, entry.UniTagList[1].PonSTag, 900)
105 assert.Equal(t, entry.UniTagList[1].TechnologyProfileID, 65)
Matteo Scandolof65e6872020-04-15 15:18:43 -0700106
Matteo Scandolo4a036262020-08-17 15:56:13 -0700107 assert.Equal(t, entry.UniTagList[2].PonCTag, 902)
108 assert.Equal(t, entry.UniTagList[2].PonSTag, 900)
109 assert.Equal(t, entry.UniTagList[2].TechnologyProfileID, 66)
Shrey Baide72b3cc2020-05-12 00:03:06 +0530110}