blob: 5e38890a1fc66c84a20cfe6c476229774c28a506 [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*/
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040022func GenerateChassis(CLLI string, rack int, shelf int) *Chassis {
23 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
31 return &chassis
32}
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
50 for i := 1; i < 65; i++ {
Author Namea594e632018-08-10 11:33:58 -040051 /* adding one because the system that provisions is 1 based on everything not 0 based*/
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040052 onts[i-1] = Ont{Number: i, Svlan: calculateSvlan(s.Number, n, i),
53 Cvlan: calculateCvlan(s.Number, n, i+1), Parent: &port}
Author Namea594e632018-08-10 11:33:58 -040054 }
55
56 port.Onts = onts
57 return port
58}
59
60func calculateCvlan(slot int, port int, ont int) int {
61 ontPortOffset := 120 // Max(ONT_SLOT) * Max(ONT_PORT) = 10 * 12 = 120
62 ontSlotOffset := 12 //= Max(ONT_PORT) = 12
63 vlanOffset := 1 //(VID 1 is reserved)
64
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040065 cVid := ((ont-2)%32)*ontPortOffset + (slot-3)*ontSlotOffset + port + vlanOffset
Author Namea594e632018-08-10 11:33:58 -040066
67 return cVid
68}
69
70func calculateSvlan(slot int, port int, ont int) int {
71 ltSlotOffset := 16
72 vlanGap := 288 // Max(LT_SLOT) * Max(ltSlotOffset) = 18 * 16 = 288
73 vlanOffset := 1 //(VID 1 is reserved)
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040074 sVid := ((slot-3)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset
Author Namea594e632018-08-10 11:33:58 -040075
76 return sVid
77}
78
79/*
80NextPort pulls the first unMapped port in the abstract chassis so the next physical port can be mapped to it
81*/