Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2017 the original author or authors. |
| 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 integration |
| 18 | |
| 19 | import ( |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "gerrit.opencord.org/abstract-olt/internal/pkg/chassisSerialize" |
| 23 | "gerrit.opencord.org/abstract-olt/models/abstract" |
| 24 | ) |
| 25 | |
| 26 | func TestSerialize(t *testing.T) { |
| 27 | chassis1 := generateTestChassis() |
| 28 | bytes1, err1 := chassisSerialize.Serialize(chassis1) |
| 29 | chassis2, err2 := chassisSerialize.Deserialize(bytes1) |
| 30 | bytes2, err3 := chassisSerialize.Serialize(chassis2) |
| 31 | chassis3, err4 := chassisSerialize.Deserialize(bytes2) |
| 32 | |
| 33 | ok(t, err1) |
| 34 | ok(t, err2) |
| 35 | ok(t, err3) |
| 36 | ok(t, err4) |
| 37 | equals(t, chassis1, chassis3) |
| 38 | equals(t, chassis3.Slots[2].Parent, chassis3) |
| 39 | equals(t, chassis3.Slots[15].Ports[8].Parent, &chassis3.Slots[15]) |
| 40 | equals(t, chassis3.Slots[0].Ports[10].Onts[15].Parent, &chassis3.Slots[0].Ports[10]) |
| 41 | } |
| 42 | |
| 43 | func generateTestChassis() *abstract.Chassis { |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 44 | chassis := abstract.GenerateChassis("My_CLLI") |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 45 | |
| 46 | var slots [16]abstract.Slot |
| 47 | for i := 0; i < 16; i++ { |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 48 | slots[i] = generateTestSlot(i, chassis) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | chassis.Slots = slots |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 52 | return chassis |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | func generateTestSlot(n int, c *abstract.Chassis) abstract.Slot { |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 56 | slot := abstract.Slot{Number: n, Parent: c} |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 57 | |
| 58 | var ports [16]abstract.Port |
| 59 | for i := 0; i < 16; i++ { |
| 60 | ports[i] = generateTestPort(16*n+i, &slot) |
| 61 | } |
| 62 | |
| 63 | slot.Ports = ports |
| 64 | return slot |
| 65 | } |
| 66 | |
| 67 | func generateTestPort(n int, s *abstract.Slot) abstract.Port { |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 68 | port := abstract.Port{Number: n, Parent: s} |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 69 | |
| 70 | var onts [64]abstract.Ont |
| 71 | for i := 0; i < 64; i++ { |
| 72 | j := n*64 + i |
| 73 | onts[i] = abstract.Ont{Number: j, Svlan: j * 10, Cvlan: j*10 + 5, Parent: &port} |
| 74 | } |
| 75 | |
| 76 | port.Onts = onts |
| 77 | return port |
| 78 | } |