blob: fbc6932c58708ece55435afc0b77ef7fa7b91889 [file] [log] [blame]
Author Namea594e632018-08-10 11:33:58 -04001/*
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
17package integration
18
19import (
Author Namea594e632018-08-10 11:33:58 -040020 "testing"
21
22 "gerrit.opencord.org/abstract-olt/internal/pkg/chassisSerialize"
23 "gerrit.opencord.org/abstract-olt/models/abstract"
24)
25
26func 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
43func generateTestChassis() *abstract.Chassis {
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040044 chassis := abstract.GenerateChassis("My_CLLI")
Author Namea594e632018-08-10 11:33:58 -040045
46 var slots [16]abstract.Slot
47 for i := 0; i < 16; i++ {
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040048 slots[i] = generateTestSlot(i, chassis)
Author Namea594e632018-08-10 11:33:58 -040049 }
50
51 chassis.Slots = slots
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040052 return chassis
Author Namea594e632018-08-10 11:33:58 -040053}
54
55func generateTestSlot(n int, c *abstract.Chassis) abstract.Slot {
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040056 slot := abstract.Slot{Number: n, Parent: c}
Author Namea594e632018-08-10 11:33:58 -040057
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
67func generateTestPort(n int, s *abstract.Slot) abstract.Port {
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040068 port := abstract.Port{Number: n, Parent: s}
Author Namea594e632018-08-10 11:33:58 -040069
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}