blob: 9640458d10554f29cee445e433cbd11cf66da472 [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 (
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -040020 "github.com/opencord/voltha-protos/go/tech_profile"
Matteo Scandolo88e91892018-11-06 16:29:19 -080021 "net"
22
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090023 "github.com/google/gopacket"
24 "github.com/google/gopacket/layers"
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +090025 omci "github.com/opencord/omci-sim"
Zack Williams2abf3932019-08-05 14:07:05 -070026 "github.com/opencord/voltha-bbsim/common/logger"
27 "github.com/opencord/voltha-bbsim/device"
28 flowHandler "github.com/opencord/voltha-bbsim/flow"
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -040029 openolt "github.com/opencord/voltha-protos/go/openolt"
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080030 log "github.com/sirupsen/logrus"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090031 "golang.org/x/net/context"
32 "google.golang.org/grpc"
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020033 "google.golang.org/grpc/codes"
34 "google.golang.org/grpc/status"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090035)
36
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020037// DisableOlt method sends OLT down indication
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090038func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080039 logger.Debug("OLT receives DisableOLT()")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020040
41 err := flowHandler.PortDown(0)
42 if err != nil {
43 logger.Error("Failed in port down %v", err)
44 }
45
Keita NISHIMOTOb8417492018-10-19 17:37:38 +090046 if s.EnableServer != nil {
47 if err := sendOltIndDown(*s.EnableServer); err != nil {
48 return new(openolt.Empty), err
49 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080050 logger.Debug("Successfuly sent OLT DOWN indication")
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090051 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090052 return new(openolt.Empty), nil
53}
54
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020055// ReenableOlt method sends OLT up indication for re-enabling OLT
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090056func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080057 logger.Debug("OLT receives Reenable()")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020058
59 err := flowHandler.PortUp(0)
60 if err != nil {
61 logger.Error("Failed in port up %v", err)
62 }
63
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020064 if s.EnableServer != nil {
65 if err := sendOltIndUp(*s.EnableServer, s.Olt); err != nil {
66 logger.Error("Failed to send OLT UP indication for reenable OLT: %v", err)
67 return new(openolt.Empty), err
68 }
69 logger.Debug("Successfuly sent OLT UP indication")
70 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090071 return new(openolt.Empty), nil
72}
73
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020074// CollectStatistics method invoked by VOLTHA to get OLT statistics
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090075func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080076 logger.Debug("OLT receives CollectStatistics()")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090077 return new(openolt.Empty), nil
78}
79
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020080// GetDeviceInfo returns OLT info
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090081func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080082 logger.Debug("OLT receives GetDeviceInfo()")
83 devinfo := new(openolt.DeviceInfo)
84 devinfo.Vendor = "EdgeCore"
85 devinfo.Model = "asfvolt16"
86 devinfo.HardwareVersion = ""
87 devinfo.FirmwareVersion = ""
88 devinfo.Technology = "xgspon"
Shad Ansari704c6f22018-11-13 14:57:53 -080089 devinfo.PonPorts = 16
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080090 devinfo.OnuIdStart = 1
91 devinfo.OnuIdEnd = 255
92 devinfo.AllocIdStart = 1024
93 devinfo.AllocIdEnd = 16383
94 devinfo.GemportIdStart = 1024
95 devinfo.GemportIdEnd = 65535
96 devinfo.FlowIdStart = 1
97 devinfo.FlowIdEnd = 16383
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +020098 devinfo.DeviceSerialNumber = s.Olt.SerialNumber
Shad Ansari010c1942018-11-08 09:32:24 -080099
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +0900100 return devinfo, nil
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900101}
102
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200103// ActivateOnu method handles ONU activation request from VOLTHA
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900104func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800105 logger.Debug("OLT receives ActivateONU()")
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200106
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200107 matched, exist := s.getOnuFromSNmap(onu.SerialNumber)
108 if !exist {
109 logger.Fatal("ONU not found with serial nnumber %v", onu.SerialNumber)
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200110 return new(openolt.Empty), status.Errorf(codes.NotFound, "ONU not found with serial number %v", onu.SerialNumber)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900111 }
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200112 onuid := onu.OnuId
113 matched.OnuID = onuid
114 s.updateDevIntState(matched, device.ONU_ACTIVE)
115 logger.Debug("ONU IntfID: %d OnuID: %d activated succesufully.", onu.IntfId, onu.OnuId)
Mahir Gunyel32dfd722019-08-05 16:18:06 +0300116 if err := sendOnuInd(*s.EnableServer, matched, "up", "up"); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200117 logger.Error("Failed to send ONU Indication intfID %d, onuID %d", matched.IntfID, matched.OnuID)
118 return new(openolt.Empty), err
119 }
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200120
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900121 return new(openolt.Empty), nil
122}
123
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -0400124// CreateTrafficSchedulers method should handle TrafficScheduler creation
125func (s *Server) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
126 logger.Debug("OLT receives CreateTrafficSchedulers()")
Shad Ansarifd298442019-01-08 16:19:35 -0800127 return new(openolt.Empty), nil
128}
129
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -0400130// RemoveTrafficSchedulers method should handle TrafficScheduler removal
131func (s *Server) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
132 logger.Debug("OLT receives RemoveTrafficSchedulers()")
133 return new(openolt.Empty), nil
134}
135
136// CreateTrafficQueues method should handle TrafficQueues creation
137func (s *Server) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
138 logger.Debug("OLT receives CreateTrafficQueues()")
139 return new(openolt.Empty), nil
140}
141
142// RemoveTrafficQueues method should handle TrafficQueues removal
143func (s *Server) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
144 logger.Debug("OLT receives RemoveTrafficQueues()")
Shad Ansarifd298442019-01-08 16:19:35 -0800145 return new(openolt.Empty), nil
146}
147
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200148// DeactivateOnu method should handle ONU deactivation
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900149func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800150 logger.Debug("OLT receives DeactivateONU()")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900151 return new(openolt.Empty), nil
152}
153
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200154// DeleteOnu handles ONU deletion request from VOLTHA
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900155func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200156 logger.Debug("OLT receives DeleteONU() intfID: %d, onuID: %d", onu.IntfId, onu.OnuId)
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200157 Onu, err := s.GetOnuByID(onu.OnuId, onu.IntfId)
158 if err != nil {
159 return new(openolt.Empty), err
160 }
161
162 // Mark ONU internal state as ONU_FREE and reset onuID
163 Onu.InternalState = device.ONU_FREE
164 Onu.OnuID = 0
165
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200166 // Get snMap key for the ONU serial number
167 snkey := stringifySerialNumber(Onu.SerialNumber)
168
169 // Delete Serial number entry from SNmap
170 logger.Info("Deleting serial number %s from SNmap", snkey)
171 s.SNmap.Delete(snkey)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900172 return new(openolt.Empty), nil
173}
174
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200175func (s *Server) GetOnuInfo(c context.Context, onu *openolt.Onu) (*openolt.OnuIndication, error) {
Anjali Thontakudi66659202019-07-03 23:14:02 +0000176 logger.Debug("Olt receives GetOnuInfo() intfID: %d, onuID: %d", onu.IntfId, onu.OnuId)
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200177 Onu, err := s.GetOnuByID(onu.OnuId, onu.IntfId)
178 if err != nil {
179 logger.Error("ONU not found intfID %d, onuID %d", onu.IntfId, onu.OnuId)
180 return new(openolt.OnuIndication), err
Anjali Thontakudi66659202019-07-03 23:14:02 +0000181 }
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200182 onuIndication := new(openolt.OnuIndication)
183 onuIndication.IntfId = Onu.IntfID
184 onuIndication.OnuId = Onu.OnuID
185 onuIndication.OperState = Onu.OperState
186
187 return onuIndication, nil
Anjali Thontakudi66659202019-07-03 23:14:02 +0000188}
189
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200190// OmciMsgOut receives OMCI messages from voltha
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900191func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800192 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 +0200193 // Get ONU state
194 onu, err := s.GetOnuByID(msg.OnuId, msg.IntfId)
195 if err != nil {
196 logger.Error("ONU not found intfID %d, onuID %d", msg.IntfId, msg.OnuId)
197 return new(openolt.Empty), err
198 }
199 state := onu.GetIntState()
200 logger.Debug("ONU-ID: %v, ONU state: %d", msg.OnuId, state)
201
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200202 // If ONU is ONU_INACTIVE, ONU_FREE or ONU_OMCI_CHANNEL_LOS_RAISED drop
203 if state != device.ONU_ACTIVE && state != device.ONU_OMCIACTIVE {
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200204 logger.Info("ONU (IF %v ONU-ID: %v) is not ACTIVE, so not processing OmciMsg", msg.IntfId, msg.OnuId)
205 return new(openolt.Empty), nil
206 }
Shad Ansaria5c79892018-11-29 16:32:59 -0800207 s.omciOut <- *msg
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900208 return new(openolt.Empty), nil
209}
210
211func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200212 onu, err := s.GetOnuByID(packet.OnuId, packet.IntfId)
213 if err != nil {
214 logger.Error("Failed in OnuPacketOut, %v", err)
215 return new(openolt.Empty), err
216 }
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900217 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 +0900218 onuid := packet.OnuId
219 intfid := packet.IntfId
220 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
221 if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil {
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900222 device.LoggerWithOnu(onu).WithField("error", err).Errorf("OnuPacketOut Error ")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900223 return new(openolt.Empty), err
224 }
225 return new(openolt.Empty), nil
226}
227
228func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800229 logger.Debug("OLT %d receives UplinkPacketOut().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900230 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
231 if err := s.uplinkPacketOut(rawpkt); err != nil {
232 return new(openolt.Empty), err
233 }
234 return new(openolt.Empty), nil
235}
236
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200237// FlowAdd method should handle flows addition to datapath for OLT and ONU
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900238func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200239 logger.Debug("OLT %d receives FlowAdd() %v", s.Olt.ID, flow)
240 // Check if flow already present
241 flowKey := FlowKey{
242 FlowID: flow.FlowId,
243 FlowDirection: flow.FlowType,
244 }
245 if _, exist := s.FlowMap[flowKey]; exist {
246 logger.Error("Flow already exists %v", flow)
247 return new(openolt.Empty), status.Errorf(codes.AlreadyExists, "Flow already exists")
248 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800249
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200250 // Send flow to flowHandler
251 err := flowHandler.AddFlow(flow)
252 if err != nil {
253 logger.Error("Error in pushing flow to datapath")
254 return new(openolt.Empty), err
255 }
256
257 // Update flowMap
258 s.FlowMap[flowKey] = flow
259
260 onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId))
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900261 if err == nil {
Keita NISHIMOTO26ebaa82019-03-07 10:00:35 +0900262 onu.GemportID = uint16(flow.GemportId)
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800263
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900264 device.LoggerWithOnu(onu).WithFields(log.Fields{
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900265 "olt": s.Olt.ID,
266 "c_tag": flow.Action.IVid,
267 }).Debug("OLT receives FlowAdd().")
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800268
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900269 // EAPOL flow
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900270 if flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) {
Matteo Scandolo67add0c2019-08-01 16:41:14 -0700271 logger.WithFields(log.Fields{
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -0400272 "Classifier.OVid": flow.Classifier.OVid,
273 "Classifier.IVid": flow.Classifier.IVid,
Matteo Scandolo67add0c2019-08-01 16:41:14 -0700274 "Classifier.EthType": flow.Classifier.EthType,
275 "Classifier.SrcPort": flow.Classifier.SrcPort,
276 "Classifier.DstPort": flow.Classifier.DstPort,
Matt Jeanneret7c9c5f22019-08-09 14:40:12 -0400277 "Action.OVid": flow.Action.OVid,
278 "Action.IVid": flow.Action.IVid,
279 "IntfID": flow.AccessIntfId,
280 "OltID": s.Olt.ID,
281 "OnuID": flow.OnuId,
282 "FlowId": flow.FlowId,
283 "UniID": flow.UniId,
284 "PortNo": flow.PortNo,
285 "FlowType": flow.FlowType,
Matteo Scandolo67add0c2019-08-01 16:41:14 -0700286 }).Debug("OLT receives EAPOL flow")
287
288 if flow.Classifier.OVid == 4091 {
289 omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID)
290 if omcistate != omci.DONE {
291 logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID))
292 }
293 _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_OMCIACTIVE)
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900294 }
Matteo Scandolo67add0c2019-08-01 16:41:14 -0700295
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900296 }
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900297
298 // DHCP flow
299 if flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) {
300 logger.Debug("Received flow's srcPort:%d dstPort:%d", flow.Classifier.SrcPort, flow.Classifier.DstPort)
301 if flow.Classifier.SrcPort == uint32(68) && flow.Classifier.DstPort == uint32(67) {
Matteo Scandolo67add0c2019-08-01 16:41:14 -0700302 logger.Debug("OLT %d receives DHCP flow IntfID:%d OnuID:%d EType:%x GemPortID:%d VLanIDs: %d/%d",
303 s.Olt.ID, flow.AccessIntfId, flow.OnuId, flow.Classifier.EthType, flow.GemportId, flow.Classifier.OVid, flow.Classifier.IVid)
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900304 omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID)
305 if omcistate != omci.DONE {
306 logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID))
307 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200308 _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_AUTHENTICATED)
Keita NISHIMOTO2807c542019-06-04 22:58:32 +0900309 }
310 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200311 // Update flow ID in ONU object
312 onu.FlowIDs = append(onu.FlowIDs, flow.FlowId)
Keita NISHIMOTO7bce7692019-01-19 09:31:09 +0900313 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900314 return new(openolt.Empty), nil
315}
316
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200317// FlowRemove handles flow deletion from datapath
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900318func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200319 logger.Debug("OLT %d receives FlowRemove(): %v", s.Olt.ID, flow)
320
321 // Check if flow exists
322 flowKey := FlowKey{
323 FlowID: flow.FlowId,
324 FlowDirection: flow.FlowType,
325 }
326 if _, exist := s.FlowMap[flowKey]; !exist {
327 logger.Error("Flow %v not found", flow)
328 return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found")
329 }
330
331 flow = s.FlowMap[flowKey]
332 // Send delete flow to flowHandler
333 err := flowHandler.DeleteFlow(flow)
334 if err != nil {
335 return new(openolt.Empty), err
336 }
337
Keita NISHIMOTO7057aa62019-05-28 01:24:08 +0900338 onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId))
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200339 if err != nil {
340 logger.Warn("Failed flow remove %v", err)
341 } else {
342 // Delete flowID from onu
343 onu.DeleteFlowID(flow.FlowId)
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900344 device.LoggerWithOnu(onu).WithFields(log.Fields{
Keita NISHIMOTO7057aa62019-05-28 01:24:08 +0900345 "olt": s.Olt.ID,
346 "c_tag": flow.Action.IVid,
347 }).Debug("OLT receives FlowRemove().")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200348 logger.Debug("Flows %v in ONU %d", onu.FlowIDs, onu.OnuID)
Keita NISHIMOTO7057aa62019-05-28 01:24:08 +0900349 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200350
351 // Delete flow from flowMap
352 delete(s.FlowMap, flowKey)
353
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900354 return new(openolt.Empty), nil
355}
356
357func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800358 logger.Debug("OLT %d receives HeartbeatCheck().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900359 signature := new(openolt.Heartbeat)
360 signature.HeartbeatSignature = s.Olt.HeartbeatSignature
361 return signature, nil
362}
363
364func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800365 logger.Debug("OLT %d receives EnablePonIf().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900366 return new(openolt.Empty), nil
367}
368
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200369func (s *Server) GetPonIf(c context.Context, intf *openolt.Interface) (*openolt.IntfIndication, error) {
Anjali Thontakudib871c502019-07-03 18:26:12 +0000370 logger.Debug("OLT %d receives GetPonIf().", s.Olt.ID)
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200371 stat := new(openolt.IntfIndication)
Anjali Thontakudib871c502019-07-03 18:26:12 +0000372
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200373 if intf.IntfId > (s.Olt.NumPonIntf - 1) {
Anjali Thontakudib871c502019-07-03 18:26:12 +0000374 logger.Error("PON ID %d out of bounds. %d ports total", intf.IntfId, s.Olt.NumPonIntf)
375 return stat, status.Errorf(codes.OutOfRange, "PON ID %d out of bounds. %d ports total (indexing starts at 0)", intf.IntfId, s.Olt.NumPonIntf)
Anjali Thontakudib871c502019-07-03 18:26:12 +0000376 }
Zdravko Bozakovd975d302019-07-19 22:52:44 +0200377 stat.IntfId = intf.IntfId
378 stat.OperState = s.Olt.PonIntfs[intf.IntfId].OperState
379 return stat, nil
380
Anjali Thontakudib871c502019-07-03 18:26:12 +0000381}
382
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900383func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800384 logger.Debug("OLT %d receives DisablePonIf().", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900385 return new(openolt.Empty), nil
386}
387
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200388// Reboot method handles reboot of OLT
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900389func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800390 logger.Debug("OLT %d receives Reboot ().", s.Olt.ID)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +0900391 // Initialize OLT & Env
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900392 logger.Debug("Initialized by Reboot")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200393 s.handleOLTReboot()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900394 return new(openolt.Empty), nil
395}
396
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200397// EnableIndication starts sending indications for OLT and ONU
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900398func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800399 logger.Debug("OLT receives EnableInd.")
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900400 defer func() {
401 logger.Debug("grpc EnableIndication Done")
402 }()
403 if err := s.Enable(&stream); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -0800404 logger.Error("Failed to Enable Core: %v", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900405 return err
406 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900407 return nil
408}
409
Zdravko Bozakov8b9328c2019-05-15 05:13:34 +0200410// NewGrpcServer starts openolt gRPC server
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900411func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200412 logger.Debug("OpenOLT gRPC server listening %s ...", addrport)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900413 g = grpc.NewServer()
414 l, e = net.Listen("tcp", addrport)
415 return
416}