blob: ee70d74700446c1102cd2c8072046719497c05b3 [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 api
18
19import (
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040020 "errors"
Author Namea594e632018-08-10 11:33:58 -040021 "fmt"
Author Namea594e632018-08-10 11:33:58 -040022 "net"
donNewtonAlphac997d642018-10-17 13:22:48 -040023 "sync"
Author Namea594e632018-08-10 11:33:58 -040024
Don Newtone973d342018-10-26 16:44:12 -040025 "gerrit.opencord.org/abstract-olt/internal/pkg/impl"
Author Namea594e632018-08-10 11:33:58 -040026 context "golang.org/x/net/context"
27)
28
29/*
30Server instance of the grpc server
31*/
32type Server struct {
33}
34
donNewtonAlphac997d642018-10-17 13:22:48 -040035var syncChan chan bool
36var isDirty bool
37
38var runOnce sync.Once
39
40func getSyncChannel() chan bool {
41 runOnce.Do(func() {
42 syncChan = make(chan bool, 1)
43 syncChan <- true
44 })
45
46 return syncChan
47}
48func done(myChan chan bool, done bool) {
49 myChan <- done
50}
51
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040052/*
53Echo - Tester function which just returns same string sent to it
54*/
donNewtonAlphab3279ea2018-09-18 15:55:32 -040055func (s *Server) Echo(ctx context.Context, in *EchoMessage) (*EchoReplyMessage, error) {
donNewtonAlphac997d642018-10-17 13:22:48 -040056 myChan := getSyncChannel()
57 <-myChan
58 defer done(myChan, true)
donNewtonAlphab8f30752018-10-04 11:57:41 -040059 fmt.Println("HELLO WTF")
donNewtonAlphab3279ea2018-09-18 15:55:32 -040060 ping := in.GetPing()
61 pong := EchoReplyMessage{Pong: ping}
62 return &pong, nil
63}
64
Author Namea594e632018-08-10 11:33:58 -040065/*
66CreateChassis - allocates a new Chassis struct and stores it in chassisMap
67*/
68func (s *Server) CreateChassis(ctx context.Context, in *AddChassisMessage) (*AddChassisReturn, error) {
Author Namea594e632018-08-10 11:33:58 -040069 clli := in.GetCLLI()
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040070
71 xosIP := net.ParseIP(in.GetXOSIP())
72 xosPort := int(in.GetXOSPort())
73 if xosIP == nil {
74 errStr := fmt.Sprintf("Invalid IP %s supplied for XOSIP", in.GetXOSIP())
75 return nil, errors.New(errStr)
76 }
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040077 xosAddress := net.TCPAddr{IP: xosIP, Port: xosPort}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040078 xosUser := in.GetXOSUser()
79 xosPassword := in.GetXOSPassword()
80 if xosUser == "" || xosPassword == "" {
81 return nil, errors.New("Either XOSUser or XOSPassword supplied were empty")
82 }
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040083 shelf := int(in.GetShelf())
84 rack := int(in.GetRack())
Don Newtone973d342018-10-26 16:44:12 -040085 deviceID, err := impl.CreateChassis(clli, xosAddress, xosUser, xosPassword, shelf, rack)
86 if err != nil {
87 return nil, err
Author Namea594e632018-08-10 11:33:58 -040088 }
Don Newtone973d342018-10-26 16:44:12 -040089 return &AddChassisReturn{DeviceID: deviceID}, nil
Author Namea594e632018-08-10 11:33:58 -040090}
91
92/*
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040093ChangeXOSUserPassword - allows update of xos credentials
94*/
95func (s *Server) ChangeXOSUserPassword(ctx context.Context, in *ChangeXOSUserPasswordMessage) (*ChangeXOSUserPasswordReturn, error) {
96 clli := in.GetCLLI()
97 xosUser := in.GetXOSUser()
98 xosPassword := in.GetXOSPassword()
99 if xosUser == "" || xosPassword == "" {
100 return nil, errors.New("Either XOSUser or XOSPassword supplied were empty")
101 }
Don Newtone973d342018-10-26 16:44:12 -0400102 success, err := impl.ChangeXOSUserPassword(clli, xosUser, xosPassword)
103 return &ChangeXOSUserPasswordReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400104
105}
106
107/*
donNewtonAlphab9b85eb2018-08-14 14:28:22 -0400108CreateOLTChassis adds an OLT chassis/line card to the Physical chassis
Author Namea594e632018-08-10 11:33:58 -0400109*/
110func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
Author Namea594e632018-08-10 11:33:58 -0400111 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400112 oltType := in.GetType().String()
Author Namea594e632018-08-10 11:33:58 -0400113 address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
Don Newtone973d342018-10-26 16:44:12 -0400114 hostname := in.GetHostname()
115 clli, err := impl.CreateOLTChassis(clli, oltType, address, hostname)
116 return &AddOLTChassisReturn{DeviceID: hostname, ChassisDeviceID: clli}, err
Author Namea594e632018-08-10 11:33:58 -0400117}
118
119/*
donNewtonAlpha5234b132018-08-16 14:12:28 -0400120ProvisionOnt provisions an ONT on a specific Chassis/LineCard/Port
121*/
122func (s *Server) ProvisionOnt(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
donNewtonAlpha5234b132018-08-16 14:12:28 -0400123 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400124 slotNumber := int(in.GetSlotNumber())
125 portNumber := int(in.GetPortNumber())
126 ontNumber := int(in.GetOntNumber())
127 serialNumber := in.GetSerialNumber()
128 success, err := impl.ProvisionOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
129 return &AddOntReturn{Success: success}, err
donNewtonAlpha5234b132018-08-16 14:12:28 -0400130}
Don Newton281e0252018-10-22 14:38:50 -0400131
Don Newtone973d342018-10-26 16:44:12 -0400132/*
133ProvsionOntFull - provisions ont using sTag,cTag,NasPortID, and CircuitID passed in
134*/
135func (s *Server) ProvisionOntFull(ctx context.Context, in *AddOntFullMessage) (*AddOntReturn, error) {
136 clli := in.GetCLLI()
137 slotNumber := int(in.GetSlotNumber())
138 portNumber := int(in.GetPortNumber())
139 ontNumber := int(in.GetOntNumber())
140 serialNumber := in.GetSerialNumber()
141 cTag := in.GetCTag()
142 sTag := in.GetSTag()
143 nasPortID := in.GetNasPortID()
144 circuitID := in.GetCircuitID()
145 success, err := impl.ProvisionOntFull(clli, slotNumber, portNumber, ontNumber, serialNumber, cTag, sTag, nasPortID, circuitID)
146 return &AddOntReturn{Success: success}, err
Don Newton281e0252018-10-22 14:38:50 -0400147}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400148
149/*
150DeleteOnt - deletes a previously provision ont
151*/
152func (s *Server) DeleteOnt(ctx context.Context, in *DeleteOntMessage) (*DeleteOntReturn, error) {
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400153 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400154 slotNumber := int(in.GetSlotNumber())
155 portNumber := int(in.GetPortNumber())
156 ontNumber := int(in.GetOntNumber())
157 serialNumber := in.GetSerialNumber()
158 success, err := impl.DeleteOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
159 return &DeleteOntReturn{Success: success}, err
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400160}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400161
Don Newtone973d342018-10-26 16:44:12 -0400162func (s *Server) Reflow(ctx context.Context, in *ReflowMessage) (*ReflowReturn, error) {
163 success, err := impl.Reflow()
164 return &ReflowReturn{Success: success}, err
165
166}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400167func (s *Server) Output(ctx context.Context, in *OutputMessage) (*OutputReturn, error) {
Don Newtone973d342018-10-26 16:44:12 -0400168 success, err := impl.DoOutput()
169 return &OutputReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400170
171}