Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 20 | "github.com/opencord/voltha-protos/go/tech_profile" |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 21 | "net" |
| 22 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 23 | "github.com/google/gopacket" |
| 24 | "github.com/google/gopacket/layers" |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 25 | omci "github.com/opencord/omci-sim" |
Zack Williams | 2abf393 | 2019-08-05 14:07:05 -0700 | [diff] [blame] | 26 | "github.com/opencord/voltha-bbsim/common/logger" |
| 27 | "github.com/opencord/voltha-bbsim/device" |
| 28 | flowHandler "github.com/opencord/voltha-bbsim/flow" |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 29 | openolt "github.com/opencord/voltha-protos/go/openolt" |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 30 | log "github.com/sirupsen/logrus" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 31 | "golang.org/x/net/context" |
| 32 | "google.golang.org/grpc" |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 33 | "google.golang.org/grpc/codes" |
| 34 | "google.golang.org/grpc/status" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 35 | ) |
| 36 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 37 | // DisableOlt method sends OLT down indication |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 38 | func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 39 | logger.Debug("OLT receives DisableOLT()") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 40 | |
| 41 | err := flowHandler.PortDown(0) |
| 42 | if err != nil { |
| 43 | logger.Error("Failed in port down %v", err) |
| 44 | } |
| 45 | |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 46 | if s.EnableServer != nil { |
| 47 | if err := sendOltIndDown(*s.EnableServer); err != nil { |
| 48 | return new(openolt.Empty), err |
| 49 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 50 | logger.Debug("Successfuly sent OLT DOWN indication") |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 51 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 52 | return new(openolt.Empty), nil |
| 53 | } |
| 54 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 55 | // ReenableOlt method sends OLT up indication for re-enabling OLT |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 56 | func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 57 | logger.Debug("OLT receives Reenable()") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 58 | |
| 59 | err := flowHandler.PortUp(0) |
| 60 | if err != nil { |
| 61 | logger.Error("Failed in port up %v", err) |
| 62 | } |
| 63 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 64 | 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 NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 71 | return new(openolt.Empty), nil |
| 72 | } |
| 73 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 74 | // CollectStatistics method invoked by VOLTHA to get OLT statistics |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 75 | func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 76 | logger.Debug("OLT receives CollectStatistics()") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 77 | return new(openolt.Empty), nil |
| 78 | } |
| 79 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 80 | // GetDeviceInfo returns OLT info |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 81 | func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 82 | 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 Ansari | 704c6f2 | 2018-11-13 14:57:53 -0800 | [diff] [blame] | 89 | devinfo.PonPorts = 16 |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 90 | 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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 98 | devinfo.DeviceSerialNumber = s.Olt.SerialNumber |
Shad Ansari | 010c194 | 2018-11-08 09:32:24 -0800 | [diff] [blame] | 99 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 100 | return devinfo, nil |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 101 | } |
| 102 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 103 | // ActivateOnu method handles ONU activation request from VOLTHA |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 104 | func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 105 | logger.Debug("OLT receives ActivateONU()") |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 106 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 107 | matched, exist := s.getOnuFromSNmap(onu.SerialNumber) |
| 108 | if !exist { |
| 109 | logger.Fatal("ONU not found with serial nnumber %v", onu.SerialNumber) |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 110 | return new(openolt.Empty), status.Errorf(codes.NotFound, "ONU not found with serial number %v", onu.SerialNumber) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 111 | } |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 112 | 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 Gunyel | 32dfd72 | 2019-08-05 16:18:06 +0300 | [diff] [blame] | 116 | if err := sendOnuInd(*s.EnableServer, matched, "up", "up"); err != nil { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 117 | logger.Error("Failed to send ONU Indication intfID %d, onuID %d", matched.IntfID, matched.OnuID) |
| 118 | return new(openolt.Empty), err |
| 119 | } |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 120 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 121 | return new(openolt.Empty), nil |
| 122 | } |
| 123 | |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 124 | // CreateTrafficSchedulers method should handle TrafficScheduler creation |
| 125 | func (s *Server) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
| 126 | logger.Debug("OLT receives CreateTrafficSchedulers()") |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame] | 127 | return new(openolt.Empty), nil |
| 128 | } |
| 129 | |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 130 | // RemoveTrafficSchedulers method should handle TrafficScheduler removal |
| 131 | func (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 |
| 137 | func (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 |
| 143 | func (s *Server) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
| 144 | logger.Debug("OLT receives RemoveTrafficQueues()") |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame] | 145 | return new(openolt.Empty), nil |
| 146 | } |
| 147 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 148 | // DeactivateOnu method should handle ONU deactivation |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 149 | func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 150 | logger.Debug("OLT receives DeactivateONU()") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 151 | return new(openolt.Empty), nil |
| 152 | } |
| 153 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 154 | // DeleteOnu handles ONU deletion request from VOLTHA |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 155 | func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 156 | logger.Debug("OLT receives DeleteONU() intfID: %d, onuID: %d", onu.IntfId, onu.OnuId) |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 157 | 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 Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 166 | // 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 NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 172 | return new(openolt.Empty), nil |
| 173 | } |
| 174 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 175 | func (s *Server) GetOnuInfo(c context.Context, onu *openolt.Onu) (*openolt.OnuIndication, error) { |
Anjali Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 176 | logger.Debug("Olt receives GetOnuInfo() intfID: %d, onuID: %d", onu.IntfId, onu.OnuId) |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 177 | 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 Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 181 | } |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 182 | 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 Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 190 | // OmciMsgOut receives OMCI messages from voltha |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 191 | func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 192 | logger.Debug("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt) |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 193 | // 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 Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 202 | // 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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 204 | 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 Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 207 | s.omciOut <- *msg |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 208 | return new(openolt.Empty), nil |
| 209 | } |
| 210 | |
| 211 | func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) { |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 212 | 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 NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 217 | device.LoggerWithOnu(onu).Debugf("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.", s.Olt.ID, packet.IntfId, packet.OnuId) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 218 | 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 NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 222 | device.LoggerWithOnu(onu).WithField("error", err).Errorf("OnuPacketOut Error ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 223 | return new(openolt.Empty), err |
| 224 | } |
| 225 | return new(openolt.Empty), nil |
| 226 | } |
| 227 | |
| 228 | func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 229 | logger.Debug("OLT %d receives UplinkPacketOut().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 230 | 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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 237 | // FlowAdd method should handle flows addition to datapath for OLT and ONU |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 238 | func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 239 | 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 Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 249 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 250 | // 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 NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 261 | if err == nil { |
Keita NISHIMOTO | 26ebaa8 | 2019-03-07 10:00:35 +0900 | [diff] [blame] | 262 | onu.GemportID = uint16(flow.GemportId) |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 263 | |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 264 | device.LoggerWithOnu(onu).WithFields(log.Fields{ |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 265 | "olt": s.Olt.ID, |
| 266 | "c_tag": flow.Action.IVid, |
| 267 | }).Debug("OLT receives FlowAdd().") |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 268 | |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 269 | // EAPOL flow |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 270 | if flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) { |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 271 | logger.WithFields(log.Fields{ |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 272 | "Classifier.OVid": flow.Classifier.OVid, |
| 273 | "Classifier.IVid": flow.Classifier.IVid, |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 274 | "Classifier.EthType": flow.Classifier.EthType, |
| 275 | "Classifier.SrcPort": flow.Classifier.SrcPort, |
| 276 | "Classifier.DstPort": flow.Classifier.DstPort, |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 277 | "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 Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 286 | }).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 NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 294 | } |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 295 | |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 296 | } |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 297 | |
| 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 Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 302 | 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 NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 304 | 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 Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 308 | _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_AUTHENTICATED) |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 309 | } |
| 310 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 311 | // Update flow ID in ONU object |
| 312 | onu.FlowIDs = append(onu.FlowIDs, flow.FlowId) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 313 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 314 | return new(openolt.Empty), nil |
| 315 | } |
| 316 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 317 | // FlowRemove handles flow deletion from datapath |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 318 | func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 319 | 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 NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 338 | onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId)) |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 339 | if err != nil { |
| 340 | logger.Warn("Failed flow remove %v", err) |
| 341 | } else { |
| 342 | // Delete flowID from onu |
| 343 | onu.DeleteFlowID(flow.FlowId) |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 344 | device.LoggerWithOnu(onu).WithFields(log.Fields{ |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 345 | "olt": s.Olt.ID, |
| 346 | "c_tag": flow.Action.IVid, |
| 347 | }).Debug("OLT receives FlowRemove().") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 348 | logger.Debug("Flows %v in ONU %d", onu.FlowIDs, onu.OnuID) |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 349 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 350 | |
| 351 | // Delete flow from flowMap |
| 352 | delete(s.FlowMap, flowKey) |
| 353 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 354 | return new(openolt.Empty), nil |
| 355 | } |
| 356 | |
| 357 | func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 358 | logger.Debug("OLT %d receives HeartbeatCheck().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 359 | signature := new(openolt.Heartbeat) |
| 360 | signature.HeartbeatSignature = s.Olt.HeartbeatSignature |
| 361 | return signature, nil |
| 362 | } |
| 363 | |
| 364 | func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 365 | logger.Debug("OLT %d receives EnablePonIf().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 366 | return new(openolt.Empty), nil |
| 367 | } |
| 368 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 369 | func (s *Server) GetPonIf(c context.Context, intf *openolt.Interface) (*openolt.IntfIndication, error) { |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 370 | logger.Debug("OLT %d receives GetPonIf().", s.Olt.ID) |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 371 | stat := new(openolt.IntfIndication) |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 372 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 373 | if intf.IntfId > (s.Olt.NumPonIntf - 1) { |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 374 | 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 Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 376 | } |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 377 | stat.IntfId = intf.IntfId |
| 378 | stat.OperState = s.Olt.PonIntfs[intf.IntfId].OperState |
| 379 | return stat, nil |
| 380 | |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 383 | func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 384 | logger.Debug("OLT %d receives DisablePonIf().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 385 | return new(openolt.Empty), nil |
| 386 | } |
| 387 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 388 | // Reboot method handles reboot of OLT |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 389 | func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 390 | logger.Debug("OLT %d receives Reboot ().", s.Olt.ID) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 391 | // Initialize OLT & Env |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 392 | logger.Debug("Initialized by Reboot") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 393 | s.handleOLTReboot() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 394 | return new(openolt.Empty), nil |
| 395 | } |
| 396 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 397 | // EnableIndication starts sending indications for OLT and ONU |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 398 | func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 399 | logger.Debug("OLT receives EnableInd.") |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 400 | defer func() { |
| 401 | logger.Debug("grpc EnableIndication Done") |
| 402 | }() |
| 403 | if err := s.Enable(&stream); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 404 | logger.Error("Failed to Enable Core: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 405 | return err |
| 406 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 407 | return nil |
| 408 | } |
| 409 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 410 | // NewGrpcServer starts openolt gRPC server |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 411 | func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 412 | logger.Debug("OpenOLT gRPC server listening %s ...", addrport) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 413 | g = grpc.NewServer() |
| 414 | l, e = net.Listen("tcp", addrport) |
| 415 | return |
| 416 | } |