blob: 964234f05d5f9e435ff4e4092b0ae214bb54ed1b [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 abstract
18
Author Namea594e632018-08-10 11:33:58 -040019/*
20GenerateChassis - constructs a new AbstractOLT Chassis
21*/
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040022func GenerateChassis(CLLI string, rack int, shelf int) Chassis {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040023 chassis := Chassis{CLLI: CLLI, Rack: rack, Shelf: shelf}
Author Namea594e632018-08-10 11:33:58 -040024
25 var slots [16]Slot
26 for i := 0; i < 16; i++ {
27 slots[i] = generateSlot(i, &chassis)
28 }
29
30 chassis.Slots = slots
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040031 return chassis
Author Namea594e632018-08-10 11:33:58 -040032}
33
34func generateSlot(n int, c *Chassis) Slot {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040035 slot := Slot{Number: n + 3, Parent: c}
Author Namea594e632018-08-10 11:33:58 -040036
37 var ports [16]Port
38 for i := 0; i < 16; i++ {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040039 ports[i] = generatePort(i+1, &slot)
Author Namea594e632018-08-10 11:33:58 -040040 }
41
42 slot.Ports = ports
43 return slot
44}
45func generatePort(n int, s *Slot) Port {
46 port := Port{Number: n, Parent: s}
47
48 var onts [64]Ont
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040049 //i starts with 1 because :P Architects - blah
Don Newton281e0252018-10-22 14:38:50 -040050 var i uint32
51 for i = 1; i < 65; i++ {
Author Namea594e632018-08-10 11:33:58 -040052 /* adding one because the system that provisions is 1 based on everything not 0 based*/
Don Newton281e0252018-10-22 14:38:50 -040053 onts[int(i-1)] = Ont{Number: int(i), Svlan: calculateSvlan(s.Number, n, int(i)),
54 Cvlan: calculateCvlan(s.Number, n, int(i+1)), Parent: &port}
Author Namea594e632018-08-10 11:33:58 -040055 }
56
57 port.Onts = onts
58 return port
59}
60
Don Newton281e0252018-10-22 14:38:50 -040061func calculateCvlan(slot int, port int, ont int) uint32 {
Author Namea594e632018-08-10 11:33:58 -040062 ontPortOffset := 120 // Max(ONT_SLOT) * Max(ONT_PORT) = 10 * 12 = 120
63 ontSlotOffset := 12 //= Max(ONT_PORT) = 12
64 vlanOffset := 1 //(VID 1 is reserved)
65
Don Newton281e0252018-10-22 14:38:50 -040066 cVid := uint32(((ont-2)%32)*ontPortOffset + (slot-3)*ontSlotOffset + port + vlanOffset)
Author Namea594e632018-08-10 11:33:58 -040067
68 return cVid
69}
70
Don Newton281e0252018-10-22 14:38:50 -040071func calculateSvlan(slot int, port int, ont int) uint32 {
Author Namea594e632018-08-10 11:33:58 -040072 ltSlotOffset := 16
73 vlanGap := 288 // Max(LT_SLOT) * Max(ltSlotOffset) = 18 * 16 = 288
74 vlanOffset := 1 //(VID 1 is reserved)
Don Newton281e0252018-10-22 14:38:50 -040075 sVid := uint32(((slot-3)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset)
Author Namea594e632018-08-10 11:33:58 -040076
77 return sVid
78}
79
80/*
81NextPort pulls the first unMapped port in the abstract chassis so the next physical port can be mapped to it
82*/