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 ( |
| 20 | "net" |
| 21 | "testing" |
| 22 | |
| 23 | "gerrit.opencord.org/abstract-olt/internal/pkg/chassisSerialize" |
| 24 | "gerrit.opencord.org/abstract-olt/models/abstract" |
| 25 | ) |
| 26 | |
| 27 | func TestSerialize(t *testing.T) { |
| 28 | chassis1 := generateTestChassis() |
| 29 | bytes1, err1 := chassisSerialize.Serialize(chassis1) |
| 30 | chassis2, err2 := chassisSerialize.Deserialize(bytes1) |
| 31 | bytes2, err3 := chassisSerialize.Serialize(chassis2) |
| 32 | chassis3, err4 := chassisSerialize.Deserialize(bytes2) |
| 33 | |
| 34 | ok(t, err1) |
| 35 | ok(t, err2) |
| 36 | ok(t, err3) |
| 37 | ok(t, err4) |
| 38 | equals(t, chassis1, chassis3) |
| 39 | equals(t, chassis3.Slots[2].Parent, chassis3) |
| 40 | equals(t, chassis3.Slots[15].Ports[8].Parent, &chassis3.Slots[15]) |
| 41 | equals(t, chassis3.Slots[0].Ports[10].Onts[15].Parent, &chassis3.Slots[0].Ports[10]) |
| 42 | } |
| 43 | |
| 44 | func generateTestChassis() *abstract.Chassis { |
| 45 | addr := net.TCPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 500, Zone: "VCore ZONE"} |
| 46 | chassis := abstract.Chassis{VCoreAddress: addr, CLLI: "CLLI STRING"} |
| 47 | |
| 48 | var slots [16]abstract.Slot |
| 49 | for i := 0; i < 16; i++ { |
| 50 | slots[i] = generateTestSlot(i, &chassis) |
| 51 | } |
| 52 | |
| 53 | chassis.Slots = slots |
| 54 | return &chassis |
| 55 | } |
| 56 | |
| 57 | func generateTestSlot(n int, c *abstract.Chassis) abstract.Slot { |
| 58 | addr := net.TCPAddr{IP: net.IPv4(1, 2, 3, byte(n)), Port: 400 + n, Zone: "Slot " + string(n) + "Zone"} |
| 59 | slot := abstract.Slot{DeviceID: "Device Slot " + string(n), Hostname: "Host " + string(n), |
| 60 | Address: addr, Number: n, Parent: c} |
| 61 | |
| 62 | var ports [16]abstract.Port |
| 63 | for i := 0; i < 16; i++ { |
| 64 | ports[i] = generateTestPort(16*n+i, &slot) |
| 65 | } |
| 66 | |
| 67 | slot.Ports = ports |
| 68 | return slot |
| 69 | } |
| 70 | |
| 71 | func generateTestPort(n int, s *abstract.Slot) abstract.Port { |
| 72 | port := abstract.Port{Number: n, DeviceID: "Device Port " + string(n), Parent: s} |
| 73 | |
| 74 | var onts [64]abstract.Ont |
| 75 | for i := 0; i < 64; i++ { |
| 76 | j := n*64 + i |
| 77 | onts[i] = abstract.Ont{Number: j, Svlan: j * 10, Cvlan: j*10 + 5, Parent: &port} |
| 78 | } |
| 79 | |
| 80 | port.Onts = onts |
| 81 | return port |
| 82 | } |