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 physical |
| 18 | |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 19 | import ( |
| 20 | "fmt" |
| 21 | ) |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 22 | |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 23 | /* |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 24 | PONPort represents a single PON port on the OLT chassis |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 25 | */ |
| 26 | type PONPort struct { |
| 27 | Number int |
| 28 | DeviceID string |
| 29 | Onts [64]Ont |
donNewtonAlpha | c997d64 | 2018-10-17 13:22:48 -0400 | [diff] [blame] | 30 | Parent *SimpleOLT `json:"-" bson:"-"` |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 31 | } |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 32 | |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 33 | /* |
| 34 | AllReadyActiveError - thrown when an attempt to activate a ONT which is already activated |
| 35 | */ |
| 36 | type AllReadyActiveError struct { |
| 37 | slotNum int |
| 38 | clli string |
| 39 | ponportNum int |
| 40 | ontNumber int |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | Error - the interface method that must be implemented on error |
| 45 | */ |
| 46 | func (e *AllReadyActiveError) Error() string { |
| 47 | return fmt.Sprintf("Attempt to Activate ONT %d on PONPort %d Slot %d on %s but already active", e.ontNumber, e.ponportNum, e.slotNum, e.clli) |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | AllReadyDeactivatedError - thrown when an attempt to activate a ONT which is already activated |
| 52 | */ |
| 53 | type AllReadyDeactivatedError struct { |
| 54 | slotNum int |
| 55 | clli string |
| 56 | ponportNum int |
| 57 | ontNumber int |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | Error - the interface method that must be implemented on error |
| 62 | */ |
| 63 | func (e *AllReadyDeactivatedError) Error() string { |
| 64 | return fmt.Sprintf("Attempt to De-Activate ONT %d on PONPort %d Slot %d on %s but not active", e.ontNumber, e.ponportNum, e.slotNum, e.clli) |
| 65 | } |
| 66 | |
| 67 | /* |
donNewtonAlpha | 292d143 | 2018-11-08 19:01:21 -0500 | [diff] [blame] | 68 | PreProvisionOnt - passes ont information to chassis to make call to NEM to activate (whitelist) ont |
| 69 | */ |
| 70 | func (port *PONPort) PreProvisionOnt(number int, sVlan uint32, cVlan uint32, nasPortID string, circuitID string, techProfile string, speedProfile string) error { |
Don Newton | 276cd1f | 2019-02-06 17:14:03 -0500 | [diff] [blame] | 71 | fmt.Printf("PrPreProvisionOnt(number %d, sVlan %d, cVlan %d, nasPortID %s, circuitID %s, techProfile %s, speedProfile %s\n", number, sVlan, cVlan, nasPortID, circuitID, techProfile, speedProfile) |
donNewtonAlpha | 292d143 | 2018-11-08 19:01:21 -0500 | [diff] [blame] | 72 | slot := port.Parent |
| 73 | chassis := slot.Parent |
| 74 | |
| 75 | if port.Onts[number-1].Active { |
| 76 | e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI} |
| 77 | return &e |
| 78 | } |
| 79 | ont := &port.Onts[number-1] |
| 80 | ont.Number = number |
| 81 | ont.Svlan = sVlan |
| 82 | ont.Cvlan = cVlan |
| 83 | ont.Parent = port |
| 84 | ont.NasPortID = nasPortID |
| 85 | ont.CircuitID = circuitID |
| 86 | ont.TechProfile = techProfile |
| 87 | ont.SpeedProfile = speedProfile |
Don Newton | 276cd1f | 2019-02-06 17:14:03 -0500 | [diff] [blame] | 88 | fmt.Printf("ponPort PreProvision ont :%v\n", ont) |
donNewtonAlpha | 292d143 | 2018-11-08 19:01:21 -0500 | [diff] [blame] | 89 | return nil |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | ActivateSerial - passes ont information to chassis to make call to NEM to activate (whitelist) ont assumes pre provisioned ont |
| 94 | */ |
| 95 | func (port *PONPort) ActivateSerial(number int, serialNumber string) error { |
| 96 | slot := port.Parent |
| 97 | chassis := slot.Parent |
| 98 | |
| 99 | if port.Onts[number-1].Active { |
| 100 | e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI} |
| 101 | return &e |
| 102 | } |
Don Newton | 276cd1f | 2019-02-06 17:14:03 -0500 | [diff] [blame] | 103 | ont := &port.Onts[number-1] |
donNewtonAlpha | 292d143 | 2018-11-08 19:01:21 -0500 | [diff] [blame] | 104 | ont.SerialNumber = serialNumber |
| 105 | fmt.Println(ont) |
Don Newton | 276cd1f | 2019-02-06 17:14:03 -0500 | [diff] [blame] | 106 | port.Parent.Parent.provisionONT(*ont) |
donNewtonAlpha | 292d143 | 2018-11-08 19:01:21 -0500 | [diff] [blame] | 107 | port.Onts[number-1].Active = true |
| 108 | return nil |
| 109 | |
| 110 | } |
| 111 | |
| 112 | /* |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 113 | ActivateOnt - passes ont information to chassis to make call to NEM to activate (whitelist) ont |
| 114 | */ |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 115 | func (port *PONPort) ActivateOnt(number int, sVlan uint32, cVlan uint32, serialNumber string, nasPortID string, circuitID string) error { |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 116 | slot := port.Parent |
| 117 | chassis := slot.Parent |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 118 | |
| 119 | if port.Onts[number-1].Active { |
| 120 | e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI} |
| 121 | return &e |
| 122 | } |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 123 | ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port, NasPortID: nasPortID, CircuitID: circuitID} |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 124 | port.Onts[number-1] = ont |
| 125 | port.Parent.Parent.provisionONT(ont) |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 126 | port.Onts[number-1].Active = true |
| 127 | return nil |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 128 | |
| 129 | } |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | DeleteOnt - passes ont information to chassis to make call to NEM to de-activate (de-whitelist) ont |
| 133 | */ |
Don Newton | 281e025 | 2018-10-22 14:38:50 -0400 | [diff] [blame] | 134 | func (port *PONPort) DeleteOnt(number int, sVlan uint32, cVlan uint32, serialNumber string) error { |
Don Newton | 276cd1f | 2019-02-06 17:14:03 -0500 | [diff] [blame] | 135 | |
| 136 | fmt.Printf("DeleteOnt(number %d, sVlan %d, cVlan %d, serialNumber %s)\n", number, sVlan, cVlan, serialNumber) |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 137 | slot := port.Parent |
| 138 | chassis := slot.Parent |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 139 | if port.Onts[number-1].Active != true { |
| 140 | e := AllReadyDeactivatedError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI} |
| 141 | return &e |
| 142 | } |
| 143 | ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port} |
| 144 | chassis.deleteONT(ont) |
| 145 | port.Onts[number-1].Active = false |
| 146 | |
| 147 | return nil |
| 148 | } |