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 abstract |
| 18 | |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 19 | /* |
| 20 | GenerateChassis - constructs a new AbstractOLT Chassis |
| 21 | */ |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 22 | func GenerateChassis(CLLI string, rack int, shelf int) *Chassis { |
| 23 | chassis := Chassis{CLLI: CLLI, Rack: rack, Shelf: shelf} |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 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 | |
| 34 | func generateSlot(n int, c *Chassis) Slot { |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 35 | slot := Slot{Number: n + 3, Parent: c} |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 36 | |
| 37 | var ports [16]Port |
| 38 | for i := 0; i < 16; i++ { |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 39 | ports[i] = generatePort(i+1, &slot) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | slot.Ports = ports |
| 43 | return slot |
| 44 | } |
| 45 | func generatePort(n int, s *Slot) Port { |
| 46 | port := Port{Number: n, Parent: s} |
| 47 | |
| 48 | var onts [64]Ont |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 49 | //i starts with 1 because :P Architects - blah |
| 50 | for i := 1; i < 65; i++ { |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 51 | /* adding one because the system that provisions is 1 based on everything not 0 based*/ |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 52 | onts[i-1] = Ont{Number: i, Svlan: calculateSvlan(s.Number, n, i), |
| 53 | Cvlan: calculateCvlan(s.Number, n, i+1), Parent: &port} |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | port.Onts = onts |
| 57 | return port |
| 58 | } |
| 59 | |
| 60 | func 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 | |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 65 | cVid := ((ont-2)%32)*ontPortOffset + (slot-3)*ontSlotOffset + port + vlanOffset |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 66 | |
| 67 | return cVid |
| 68 | } |
| 69 | |
| 70 | func 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) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 74 | sVid := ((slot-3)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 75 | |
| 76 | return sVid |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | NextPort pulls the first unMapped port in the abstract chassis so the next physical port can be mapped to it |
| 81 | */ |