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 | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 22 | func GenerateChassis(CLLI string, rack int, shelf int) Chassis { |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 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 |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 31 | return chassis |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 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 |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 50 | var i uint32 |
| 51 | for i = 1; i < 65; i++ { |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 52 | /* adding one because the system that provisions is 1 based on everything not 0 based*/ |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 53 | 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 Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | port.Onts = onts |
| 58 | return port |
| 59 | } |
| 60 | |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 61 | func calculateCvlan(slot int, port int, ont int) uint32 { |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 62 | 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 Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 66 | cVid := uint32(((ont-2)%32)*ontPortOffset + (slot-3)*ontSlotOffset + port + vlanOffset) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 67 | |
| 68 | return cVid |
| 69 | } |
| 70 | |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 71 | func calculateSvlan(slot int, port int, ont int) uint32 { |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 72 | ltSlotOffset := 16 |
| 73 | vlanGap := 288 // Max(LT_SLOT) * Max(ltSlotOffset) = 18 * 16 = 288 |
| 74 | vlanOffset := 1 //(VID 1 is reserved) |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 75 | sVid := uint32(((slot-3)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 76 | |
| 77 | return sVid |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | NextPort pulls the first unMapped port in the abstract chassis so the next physical port can be mapped to it |
| 82 | */ |