blob: 15b7328ad954a21919784113a4e46ddc6c62f9e6 [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
donNewtonAlphaf7cc9992018-08-29 14:23:02 -040019import "fmt"
20
Author Namea594e632018-08-10 11:33:58 -040021/*
donNewtonAlpha5234b132018-08-16 14:12:28 -040022PONPort represents a single PON port on the OLT chassis
Author Namea594e632018-08-10 11:33:58 -040023*/
24type PONPort struct {
25 Number int
26 DeviceID string
27 Onts [64]Ont
28 Parent *Edgecore `json:"-"`
29}
donNewtonAlpha5234b132018-08-16 14:12:28 -040030
donNewtonAlphaf7cc9992018-08-29 14:23:02 -040031/*
32AllReadyActiveError - thrown when an attempt to activate a ONT which is already activated
33*/
34type AllReadyActiveError struct {
35 slotNum int
36 clli string
37 ponportNum int
38 ontNumber int
39}
40
41/*
42Error - the interface method that must be implemented on error
43*/
44func (e *AllReadyActiveError) Error() string {
45 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)
46}
47
48/*
49AllReadyDeactivatedError - thrown when an attempt to activate a ONT which is already activated
50*/
51type AllReadyDeactivatedError struct {
52 slotNum int
53 clli string
54 ponportNum int
55 ontNumber int
56}
57
58/*
59Error - the interface method that must be implemented on error
60*/
61func (e *AllReadyDeactivatedError) Error() string {
62 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)
63}
64
65/*
66ActivateOnt - passes ont information to chassis to make call to NEM to activate (whitelist) ont
67*/
68func (port *PONPort) ActivateOnt(number int, sVlan int, cVlan int, serialNumber string) error {
69 slot := port.Parent
70 chassis := slot.Parent
71 fmt.Printf("Calling ActivateOnt and port state is %t\n", port.Onts[number-1].Active)
72
73 if port.Onts[number-1].Active {
74 e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
75 return &e
76 }
donNewtonAlpha5234b132018-08-16 14:12:28 -040077 ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port}
78 port.Onts[number-1] = ont
79 port.Parent.Parent.provisionONT(ont)
donNewtonAlphaf7cc9992018-08-29 14:23:02 -040080 port.Onts[number-1].Active = true
81 return nil
donNewtonAlpha5234b132018-08-16 14:12:28 -040082
83}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -040084
85/*
86DeleteOnt - passes ont information to chassis to make call to NEM to de-activate (de-whitelist) ont
87*/
88func (port *PONPort) DeleteOnt(number int, sVlan int, cVlan int, serialNumber string) error {
89 slot := port.Parent
90 chassis := slot.Parent
91 fmt.Printf("Calling ActivateOnt and port state is %t\n", port.Onts[number-1].Active)
92 if port.Onts[number-1].Active != true {
93 e := AllReadyDeactivatedError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
94 return &e
95 }
96 ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port}
97 chassis.deleteONT(ont)
98 port.Onts[number-1].Active = false
99
100 return nil
101}