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 | |
| 19 | import "errors" |
| 20 | |
| 21 | /* |
| 22 | GenerateChassis - constructs a new AbstractOLT Chassis |
| 23 | */ |
| 24 | func GenerateChassis(CLLI string) *Chassis { |
| 25 | chassis := Chassis{CLLI: CLLI} |
| 26 | |
| 27 | var slots [16]Slot |
| 28 | for i := 0; i < 16; i++ { |
| 29 | slots[i] = generateSlot(i, &chassis) |
| 30 | } |
| 31 | |
| 32 | chassis.Slots = slots |
| 33 | return &chassis |
| 34 | } |
| 35 | |
| 36 | func generateSlot(n int, c *Chassis) Slot { |
| 37 | slot := Slot{Number: n, Parent: c} |
| 38 | |
| 39 | var ports [16]Port |
| 40 | for i := 0; i < 16; i++ { |
| 41 | ports[i] = generatePort(i, &slot) |
| 42 | } |
| 43 | |
| 44 | slot.Ports = ports |
| 45 | return slot |
| 46 | } |
| 47 | func generatePort(n int, s *Slot) Port { |
| 48 | port := Port{Number: n, Parent: s} |
| 49 | |
| 50 | var onts [64]Ont |
| 51 | for i := 0; i < 64; i++ { |
| 52 | /* adding one because the system that provisions is 1 based on everything not 0 based*/ |
| 53 | onts[i] = Ont{Number: i, Svlan: calculateSvlan(s.Number+1, n+1, i+1), |
| 54 | Cvlan: calculateCvlan(s.Number+1, n+1, i+1), Parent: &port} |
| 55 | } |
| 56 | |
| 57 | port.Onts = onts |
| 58 | return port |
| 59 | } |
| 60 | |
| 61 | func calculateCvlan(slot int, port int, ont int) int { |
| 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 | |
| 66 | cVid := ((ont-1)%32)*ontPortOffset + |
| 67 | (slot-1)*ontSlotOffset + port + vlanOffset |
| 68 | |
| 69 | return cVid |
| 70 | } |
| 71 | |
| 72 | func calculateSvlan(slot int, port int, ont int) int { |
| 73 | ltSlotOffset := 16 |
| 74 | vlanGap := 288 // Max(LT_SLOT) * Max(ltSlotOffset) = 18 * 16 = 288 |
| 75 | vlanOffset := 1 //(VID 1 is reserved) |
| 76 | |
| 77 | sVid := ((slot-1)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset |
| 78 | |
| 79 | return sVid |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | NextPort pulls the first unMapped port in the abstract chassis so the next physical port can be mapped to it |
| 84 | */ |
| 85 | func (chassis *Chassis) NextPort() (*Port, error) { |
| 86 | info := &chassis.AllocInfo |
| 87 | |
| 88 | if info.outOfPorts { |
| 89 | return nil, errors.New("Abstract chassis out of ports") |
| 90 | } |
| 91 | |
| 92 | nextPort := &chassis.Slots[info.slot].Ports[info.port] |
| 93 | |
| 94 | info.port++ |
| 95 | if info.port == MAX_PORTS { |
| 96 | info.port = 0 |
| 97 | info.slot++ |
| 98 | if info.slot == MAX_SLOTS { |
| 99 | info.slot = 0 |
| 100 | info.outOfPorts = true |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return nextPort, nil |
| 105 | } |