blob: a225fd9868641fcc58d9f9b26a7263b50e9877f8 [file] [log] [blame]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 core
18
19import (
Matteo Scandolo88e91892018-11-06 16:29:19 -080020 "net"
21
22 "gerrit.opencord.org/voltha-bbsim/common/logger"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090023 "gerrit.opencord.org/voltha-bbsim/device"
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020024 flowHandler "gerrit.opencord.org/voltha-bbsim/flow"
25 openolt "gerrit.opencord.org/voltha-bbsim/protos"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090026 "github.com/google/gopacket"
27 "github.com/google/gopacket/layers"
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +090028 omci "github.com/opencord/omci-sim"
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080029 log "github.com/sirupsen/logrus"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090030 "golang.org/x/net/context"
31 "google.golang.org/grpc"
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020032 "google.golang.org/grpc/codes"
33 "google.golang.org/grpc/status"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090034)
35
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020036// DisableOlt method sends OLT down indication
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090037func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080038 logger.Debug("OLT receives DisableOLT()")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020039
40 err := flowHandler.PortDown(0)
41 if err != nil {
42 logger.Error("Failed in port down %v", err)
43 }
44
Keita NISHIMOTOb8417492018-10-19 17:37:38 +090045 if s.EnableServer != nil {
46 if err := sendOltIndDown(*s.EnableServer); err != nil {
47 return new(openolt.Empty), err
48 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080049 logger.Debug("Successfuly sent OLT DOWN indication")
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090050 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090051 return new(openolt.Empty), nil
52}
53
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020054// ReenableOlt method sends OLT up indication for re-enabling OLT
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090055func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080056 logger.Debug("OLT receives Reenable()")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020057
58 err := flowHandler.PortUp(0)
59 if err != nil {
60 logger.Error("Failed in port up %v", err)
61 }
62
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020063 if s.EnableServer != nil {
64 if err := sendOltIndUp(*s.EnableServer, s.Olt); err != nil {
65 logger.Error("Failed to send OLT UP indication for reenable OLT: %v", err)
66 return new(openolt.Empty), err
67 }
68 logger.Debug("Successfuly sent OLT UP indication")
69 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090070 return new(openolt.Empty), nil
71}
72
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020073// CollectStatistics method invoked by VOLTHA to get OLT statistics
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090074func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080075 logger.Debug("OLT receives CollectStatistics()")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090076 return new(openolt.Empty), nil
77}
78
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020079// GetDeviceInfo returns OLT info
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090080func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080081 logger.Debug("OLT receives GetDeviceInfo()")
82 devinfo := new(openolt.DeviceInfo)
83 devinfo.Vendor = "EdgeCore"
84 devinfo.Model = "asfvolt16"
85 devinfo.HardwareVersion = ""
86 devinfo.FirmwareVersion = ""
87 devinfo.Technology = "xgspon"
Shad Ansari704c6f22018-11-13 14:57:53 -080088 devinfo.PonPorts = 16
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080089 devinfo.OnuIdStart = 1
90 devinfo.OnuIdEnd = 255
91 devinfo.AllocIdStart = 1024
92 devinfo.AllocIdEnd = 16383
93 devinfo.GemportIdStart = 1024
94 devinfo.GemportIdEnd = 65535
95 devinfo.FlowIdStart = 1
96 devinfo.FlowIdEnd = 16383
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020097 devinfo.DeviceSerialNumber = s.Olt.SerialNumber
Shad Ansari010c1942018-11-08 09:32:24 -080098
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090099 return devinfo, nil
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900100}
101
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200102// ActivateOnu method handles ONU activation request from VOLTHA
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900103func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800104 logger.Debug("OLT receives ActivateONU()")
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200105
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200106 matched, exist := s.getOnuFromSNmap(onu.SerialNumber)
107 if !exist {
108 logger.Fatal("ONU not found with serial nnumber %v", onu.SerialNumber)
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200109 return new(openolt.Empty), status.Errorf(codes.NotFound, "ONU not found with serial number %v", onu.SerialNumber)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900110 }
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200111 onuid := onu.OnuId
112 matched.OnuID = onuid
113 s.updateDevIntState(matched, device.ONU_ACTIVE)
114 logger.Debug("ONU IntfID: %d OnuID: %d activated succesufully.", onu.IntfId, onu.OnuId)
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200115 if err := sendOnuInd(*s.EnableServer, matched, s.IndInterval, "up", "up"); err != nil {
116 logger.Error("Failed to send ONU Indication intfID %d, onuID %d", matched.IntfID, matched.OnuID)
117 return new(openolt.Empty), err
118 }
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200119
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900120 return new(openolt.Empty), nil
121}
122
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200123// CreateTconts method should handle Tcont creation
Shad Ansarifd298442019-01-08 16:19:35 -0800124func (s *Server) CreateTconts(c context.Context, tconts *openolt.Tconts) (*openolt.Empty, error) {
125 logger.Debug("OLT receives CreateTconts()")
126 return new(openolt.Empty), nil
127}
128
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200129// RemoveTconts method should handle t-cont removal
Shad Ansarifd298442019-01-08 16:19:35 -0800130func (s *Server) RemoveTconts(c context.Context, tconts *openolt.Tconts) (*openolt.Empty, error) {
131 logger.Debug("OLT receives RemoveTconts()")
132 return new(openolt.Empty), nil
133}
134
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200135// DeactivateOnu method should handle ONU deactivation
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900136func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800137 logger.Debug("OLT receives DeactivateONU()")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900138 return new(openolt.Empty), nil
139}
140
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200141// DeleteOnu handles ONU deletion request from VOLTHA
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900142func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200143 logger.Debug("OLT receives DeleteONU() intfID: %d, onuID: %d", onu.IntfId, onu.OnuId)
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200144 Onu, err := s.GetOnuByID(onu.OnuId, onu.IntfId)
145 if err != nil {
146 return new(openolt.Empty), err
147 }
148
149 // Mark ONU internal state as ONU_FREE and reset onuID
150 Onu.InternalState = device.ONU_FREE
151 Onu.OnuID = 0
152
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200153 // Get snMap key for the ONU serial number
154 snkey := stringifySerialNumber(Onu.SerialNumber)
155
156 // Delete Serial number entry from SNmap
157 logger.Info("Deleting serial number %s from SNmap", snkey)
158 s.SNmap.Delete(snkey)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900159 return new(openolt.Empty), nil
160}
161
Anjali Thontakudi66659202019-07-03 23:14:02 +0000162func (s *Server) GetOnuInfo(c context.Context, onu *openolt.Onu) (*openolt.OnuIndication, error){
163 logger.Debug("Olt receives GetOnuInfo() intfID: %d, onuID: %d", onu.IntfId, onu.OnuId)
164
165 if onu.IntfId > (s.Olt.NumPonIntf-1){
166 logger.Error("PON ID %d out of bounds. %d ports total", onu.IntfId, s.Olt.NumPonIntf)
167 return nil, status.Errorf(codes.OutOfRange, "PON ID %d out of bounds. %d ports total (indexing starts at 0)", onu.IntfId, s.Olt.NumPonIntf)
168 } else if nonus:=len(s.Onumap[onu.IntfId]); int(onu.OnuId) > nonus-1{
169 logger.Error("ONU ID %d out of bounds. %d onus total", onu.OnuId, s.Olt.NumPonIntf)
170 return nil, status.Errorf(codes.OutOfRange, "ONU ID %d out of bounds. %d ONUs total (indexing starts at 0)", onu.OnuId, nonus)
171 } else{
172 stat := new(openolt.OnuIndication)
173 stat.IntfId = onu.IntfId
174 stat.OnuId = onu.OnuId
175 stat.OperState = "up"
176 return stat, nil
177 }
178}
179
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200180// OmciMsgOut receives OMCI messages from voltha
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900181func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800182 logger.Debug("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt)
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200183 // Get ONU state
184 onu, err := s.GetOnuByID(msg.OnuId, msg.IntfId)
185 if err != nil {
186 logger.Error("ONU not found intfID %d, onuID %d", msg.IntfId, msg.OnuId)
187 return new(openolt.Empty), err
188 }
189 state := onu.GetIntState()
190 logger.Debug("ONU-ID: %v, ONU state: %d", msg.OnuId, state)
191
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200192 // If ONU is ONU_INACTIVE, ONU_FREE or ONU_OMCI_CHANNEL_LOS_RAISED drop
193 if state != device.ONU_ACTIVE && state != device.ONU_OMCIACTIVE {
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200194 logger.Info("ONU (IF %v ONU-ID: %v) is not ACTIVE, so not processing OmciMsg", msg.IntfId, msg.OnuId)
195 return new(openolt.Empty), nil
196 }
Shad Ansaria5c79892018-11-29 16:32:59 -0800197 s.omciOut <- *msg
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900198 return new(openolt.Empty), nil
199}
200
201func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200202 onu, err := s.GetOnuByID(packet.OnuId, packet.IntfId)
203 if err != nil {
204 logger.Error("Failed in OnuPacketOut, %v", err)
205 return new(openolt.Empty), err
206 }
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900207 device.LoggerWithOnu(onu).Debugf("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.", s.Olt.ID, packet.IntfId, packet.OnuId)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900208 onuid := packet.OnuId
209 intfid := packet.IntfId
210 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
211 if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil {
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900212 device.LoggerWithOnu(onu).WithField("error", err).Errorf("OnuPacketOut Error ")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900213 return new(openolt.Empty), err
214 }
215 return new(openolt.Empty), nil
216}
217
218func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800219 logger.Debug("OLT %d receives UplinkPacketOut().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900220 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
221 if err := s.uplinkPacketOut(rawpkt); err != nil {
222 return new(openolt.Empty), err
223 }
224 return new(openolt.Empty), nil
225}
226
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200227// FlowAdd method should handle flows addition to datapath for OLT and ONU
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900228func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200229 logger.Debug("OLT %d receives FlowAdd() %v", s.Olt.ID, flow)
230 // Check if flow already present
231 flowKey := FlowKey{
232 FlowID: flow.FlowId,
233 FlowDirection: flow.FlowType,
234 }
235 if _, exist := s.FlowMap[flowKey]; exist {
236 logger.Error("Flow already exists %v", flow)
237 return new(openolt.Empty), status.Errorf(codes.AlreadyExists, "Flow already exists")
238 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800239
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200240 // Send flow to flowHandler
241 err := flowHandler.AddFlow(flow)
242 if err != nil {
243 logger.Error("Error in pushing flow to datapath")
244 return new(openolt.Empty), err
245 }
246
247 // Update flowMap
248 s.FlowMap[flowKey] = flow
249
250 onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId))
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900251 if err == nil {
Keita NISHIMOTO26ebaa82019-03-07 10:00:35 +0900252 onu.GemportID = uint16(flow.GemportId)
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800253
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900254 device.LoggerWithOnu(onu).WithFields(log.Fields{
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900255 "olt": s.Olt.ID,
256 "c_tag": flow.Action.IVid,
257 }).Debug("OLT receives FlowAdd().")
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800258
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900259 // EAPOL flow
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900260 if flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) {
Kailash95bb5ac2019-07-01 20:56:37 -0700261 logger.Debug("OLT %d receives EAPOL flow IntfID:%d OnuID:%d EType:%x", s.Olt.ID, flow.AccessIntfId, flow.OnuId, flow.Classifier.EthType)
Keita NISHIMOTO42db49e2019-01-29 07:49:41 +0900262 omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID)
Keita NISHIMOTO26ebaa82019-03-07 10:00:35 +0900263 if omcistate != omci.DONE {
264 logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID))
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900265 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200266 _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_OMCIACTIVE)
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900267 }
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900268
269 // DHCP flow
270 if flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) {
271 logger.Debug("Received flow's srcPort:%d dstPort:%d", flow.Classifier.SrcPort, flow.Classifier.DstPort)
272 if flow.Classifier.SrcPort == uint32(68) && flow.Classifier.DstPort == uint32(67) {
273 logger.Debug("OLT %d receives DHCP flow IntfID:%d OnuID:%d EType:%x GemPortID:%d", s.Olt.ID, flow.AccessIntfId, flow.OnuId, flow.Classifier.EthType, flow.GemportId)
274 omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID)
275 if omcistate != omci.DONE {
276 logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID))
277 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200278 _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_AUTHENTICATED)
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900279 }
280 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200281 // Update flow ID in ONU object
282 onu.FlowIDs = append(onu.FlowIDs, flow.FlowId)
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900283 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900284 return new(openolt.Empty), nil
285}
286
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200287// FlowRemove handles flow deletion from datapath
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900288func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200289 logger.Debug("OLT %d receives FlowRemove(): %v", s.Olt.ID, flow)
290
291 // Check if flow exists
292 flowKey := FlowKey{
293 FlowID: flow.FlowId,
294 FlowDirection: flow.FlowType,
295 }
296 if _, exist := s.FlowMap[flowKey]; !exist {
297 logger.Error("Flow %v not found", flow)
298 return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found")
299 }
300
301 flow = s.FlowMap[flowKey]
302 // Send delete flow to flowHandler
303 err := flowHandler.DeleteFlow(flow)
304 if err != nil {
305 return new(openolt.Empty), err
306 }
307
Keita NISHIMOTO7057aa62019-05-28 01:24:08 +0900308 onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId))
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200309 if err != nil {
310 logger.Warn("Failed flow remove %v", err)
311 } else {
312 // Delete flowID from onu
313 onu.DeleteFlowID(flow.FlowId)
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900314 device.LoggerWithOnu(onu).WithFields(log.Fields{
Keita NISHIMOTO7057aa62019-05-28 01:24:08 +0900315 "olt": s.Olt.ID,
316 "c_tag": flow.Action.IVid,
317 }).Debug("OLT receives FlowRemove().")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200318 logger.Debug("Flows %v in ONU %d", onu.FlowIDs, onu.OnuID)
Keita NISHIMOTO7057aa62019-05-28 01:24:08 +0900319 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200320
321 // Delete flow from flowMap
322 delete(s.FlowMap, flowKey)
323
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900324 return new(openolt.Empty), nil
325}
326
327func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800328 logger.Debug("OLT %d receives HeartbeatCheck().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900329 signature := new(openolt.Heartbeat)
330 signature.HeartbeatSignature = s.Olt.HeartbeatSignature
331 return signature, nil
332}
333
334func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800335 logger.Debug("OLT %d receives EnablePonIf().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900336 return new(openolt.Empty), nil
337}
338
Anjali Thontakudib871c502019-07-03 18:26:12 +0000339func (s *Server) GetPonIf(c context.Context, intf *openolt.Interface) (*openolt.IntfIndication, error){
340 logger.Debug("OLT %d receives GetPonIf().", s.Olt.ID)
Anjali Thontakudi66659202019-07-03 23:14:02 +0000341 stat:=new(openolt.IntfIndication)
Anjali Thontakudib871c502019-07-03 18:26:12 +0000342
343 if intf.IntfId > (s.Olt.NumPonIntf-1){
344 logger.Error("PON ID %d out of bounds. %d ports total", intf.IntfId, s.Olt.NumPonIntf)
345 return stat, status.Errorf(codes.OutOfRange, "PON ID %d out of bounds. %d ports total (indexing starts at 0)", intf.IntfId, s.Olt.NumPonIntf)
346 } else{
347 stat.IntfId = intf.IntfId
348 stat.OperState = "up"
349 return stat, nil
350 }
351}
352
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900353func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800354 logger.Debug("OLT %d receives DisablePonIf().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900355 return new(openolt.Empty), nil
356}
357
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200358// Reboot method handles reboot of OLT
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900359func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800360 logger.Debug("OLT %d receives Reboot ().", s.Olt.ID)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +0900361 // Initialize OLT & Env
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900362 logger.Debug("Initialized by Reboot")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200363 s.handleOLTReboot()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900364 return new(openolt.Empty), nil
365}
366
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200367// EnableIndication starts sending indications for OLT and ONU
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900368func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800369 logger.Debug("OLT receives EnableInd.")
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900370 defer func() {
371 logger.Debug("grpc EnableIndication Done")
372 }()
373 if err := s.Enable(&stream); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800374 logger.Error("Failed to Enable Core: %v", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900375 return err
376 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900377 return nil
378}
379
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200380// NewGrpcServer starts openolt gRPC server
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900381func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200382 logger.Debug("OpenOLT gRPC server listening %s ...", addrport)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900383 g = grpc.NewServer()
384 l, e = net.Listen("tcp", addrport)
385 return
386}