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