blob: 2377453330baa113e31e4c8012609c6ef19b5102 [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*/
22func GenerateChassis(CLLI string) *Chassis {
23 chassis := Chassis{CLLI: CLLI}
24
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 {
35 slot := Slot{Number: n, Parent: c}
36
37 var ports [16]Port
38 for i := 0; i < 16; i++ {
39 ports[i] = generatePort(i, &slot)
40 }
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
49 for i := 0; i < 64; i++ {
50 /* adding one because the system that provisions is 1 based on everything not 0 based*/
51 onts[i] = Ont{Number: i, Svlan: calculateSvlan(s.Number+1, n+1, i+1),
52 Cvlan: calculateCvlan(s.Number+1, n+1, i+1), Parent: &port}
53 }
54
55 port.Onts = onts
56 return port
57}
58
59func calculateCvlan(slot int, port int, ont int) int {
60 ontPortOffset := 120 // Max(ONT_SLOT) * Max(ONT_PORT) = 10 * 12 = 120
61 ontSlotOffset := 12 //= Max(ONT_PORT) = 12
62 vlanOffset := 1 //(VID 1 is reserved)
63
64 cVid := ((ont-1)%32)*ontPortOffset +
65 (slot-1)*ontSlotOffset + port + vlanOffset
66
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)
74
75 sVid := ((slot-1)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset
76
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*/