blob: 738d65effec14f3769e7176ddb8ec44e5cc41aa2 [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 physical
18
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040019import (
20 "fmt"
21)
donNewtonAlphaf7cc9992018-08-29 14:23:02 -040022
Author Namea594e632018-08-10 11:33:58 -040023/*
donNewtonAlpha5234b132018-08-16 14:12:28 -040024PONPort represents a single PON port on the OLT chassis
Author Namea594e632018-08-10 11:33:58 -040025*/
26type PONPort struct {
27 Number int
28 DeviceID string
29 Onts [64]Ont
donNewtonAlphac997d642018-10-17 13:22:48 -040030 Parent *SimpleOLT `json:"-" bson:"-"`
Author Namea594e632018-08-10 11:33:58 -040031}
donNewtonAlpha5234b132018-08-16 14:12:28 -040032
donNewtonAlphaf7cc9992018-08-29 14:23:02 -040033/*
34AllReadyActiveError - thrown when an attempt to activate a ONT which is already activated
35*/
36type AllReadyActiveError struct {
37 slotNum int
38 clli string
39 ponportNum int
40 ontNumber int
41}
42
43/*
44Error - the interface method that must be implemented on error
45*/
46func (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/*
51AllReadyDeactivatedError - thrown when an attempt to activate a ONT which is already activated
52*/
53type AllReadyDeactivatedError struct {
54 slotNum int
55 clli string
56 ponportNum int
57 ontNumber int
58}
59
60/*
61Error - the interface method that must be implemented on error
62*/
63func (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/*
donNewtonAlpha292d1432018-11-08 19:01:21 -050068PreProvisionOnt - passes ont information to chassis to make call to NEM to activate (whitelist) ont
69*/
70func (port *PONPort) PreProvisionOnt(number int, sVlan uint32, cVlan uint32, nasPortID string, circuitID string, techProfile string, speedProfile string) error {
71 slot := port.Parent
72 chassis := slot.Parent
73
74 if port.Onts[number-1].Active {
75 e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
76 return &e
77 }
78 ont := &port.Onts[number-1]
79 ont.Number = number
80 ont.Svlan = sVlan
81 ont.Cvlan = cVlan
82 ont.Parent = port
83 ont.NasPortID = nasPortID
84 ont.CircuitID = circuitID
85 ont.TechProfile = techProfile
86 ont.SpeedProfile = speedProfile
87 return nil
88}
89
90/*
91ActivateSerial - passes ont information to chassis to make call to NEM to activate (whitelist) ont assumes pre provisioned ont
92*/
93func (port *PONPort) ActivateSerial(number int, serialNumber string) error {
94 slot := port.Parent
95 chassis := slot.Parent
96
97 if port.Onts[number-1].Active {
98 e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
99 return &e
100 }
101 ont := port.Onts[number-1]
102 ont.SerialNumber = serialNumber
103 fmt.Println(ont)
104 port.Parent.Parent.provisionONT(ont)
105 port.Onts[number-1].Active = true
106 return nil
107
108}
109
110/*
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400111ActivateOnt - passes ont information to chassis to make call to NEM to activate (whitelist) ont
112*/
Don Newton281e0252018-10-22 14:38:50 -0400113func (port *PONPort) ActivateOnt(number int, sVlan uint32, cVlan uint32, serialNumber string, nasPortID string, circuitID string) error {
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400114 slot := port.Parent
115 chassis := slot.Parent
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400116
117 if port.Onts[number-1].Active {
118 e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
119 return &e
120 }
donNewtonAlpha1d2d6812018-09-14 16:00:02 -0400121 ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port, NasPortID: nasPortID, CircuitID: circuitID}
donNewtonAlpha5234b132018-08-16 14:12:28 -0400122 port.Onts[number-1] = ont
123 port.Parent.Parent.provisionONT(ont)
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400124 port.Onts[number-1].Active = true
125 return nil
donNewtonAlpha5234b132018-08-16 14:12:28 -0400126
127}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400128
129/*
130DeleteOnt - passes ont information to chassis to make call to NEM to de-activate (de-whitelist) ont
131*/
Don Newton281e0252018-10-22 14:38:50 -0400132func (port *PONPort) DeleteOnt(number int, sVlan uint32, cVlan uint32, serialNumber string) error {
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400133 slot := port.Parent
134 chassis := slot.Parent
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400135 if port.Onts[number-1].Active != true {
136 e := AllReadyDeactivatedError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
137 return &e
138 }
139 ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port}
140 chassis.deleteONT(ont)
141 port.Onts[number-1].Active = false
142
143 return nil
144}