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 ( |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 20 | "net" |
| 21 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 22 | "github.com/google/gopacket" |
| 23 | "github.com/google/gopacket/layers" |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 24 | omci "github.com/opencord/omci-sim" |
Zack Williams | 2abf393 | 2019-08-05 14:07:05 -0700 | [diff] [blame] | 25 | "github.com/opencord/voltha-bbsim/common/logger" |
| 26 | "github.com/opencord/voltha-bbsim/device" |
| 27 | flowHandler "github.com/opencord/voltha-bbsim/flow" |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 28 | openolt "github.com/opencord/voltha-protos/go/openolt" |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/go/tech_profile" |
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 { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 65 | s.Olt.OperState = "up" |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 66 | if err := sendOltIndUp(*s.EnableServer, s.Olt); err != nil { |
| 67 | logger.Error("Failed to send OLT UP indication for reenable OLT: %v", err) |
| 68 | return new(openolt.Empty), err |
| 69 | } |
| 70 | logger.Debug("Successfuly sent OLT UP indication") |
| 71 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 72 | return new(openolt.Empty), nil |
| 73 | } |
| 74 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 75 | // CollectStatistics method invoked by VOLTHA to get OLT statistics |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 76 | 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] | 77 | logger.Debug("OLT receives CollectStatistics()") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 78 | return new(openolt.Empty), nil |
| 79 | } |
| 80 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 81 | // GetDeviceInfo returns OLT info |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 82 | 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] | 83 | logger.Debug("OLT receives GetDeviceInfo()") |
| 84 | devinfo := new(openolt.DeviceInfo) |
| 85 | devinfo.Vendor = "EdgeCore" |
| 86 | devinfo.Model = "asfvolt16" |
| 87 | devinfo.HardwareVersion = "" |
| 88 | devinfo.FirmwareVersion = "" |
| 89 | devinfo.Technology = "xgspon" |
Shad Ansari | 704c6f2 | 2018-11-13 14:57:53 -0800 | [diff] [blame] | 90 | devinfo.PonPorts = 16 |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 91 | devinfo.OnuIdStart = 1 |
| 92 | devinfo.OnuIdEnd = 255 |
| 93 | devinfo.AllocIdStart = 1024 |
| 94 | devinfo.AllocIdEnd = 16383 |
| 95 | devinfo.GemportIdStart = 1024 |
| 96 | devinfo.GemportIdEnd = 65535 |
| 97 | devinfo.FlowIdStart = 1 |
| 98 | devinfo.FlowIdEnd = 16383 |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 99 | devinfo.DeviceSerialNumber = s.Olt.SerialNumber |
Shad Ansari | 010c194 | 2018-11-08 09:32:24 -0800 | [diff] [blame] | 100 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 101 | return devinfo, nil |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 104 | // ActivateOnu method handles ONU activation request from VOLTHA |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 105 | func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 106 | logger.Trace("OLT receives ActivateONU()") |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 107 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 108 | matched, exist := s.getOnuFromSNmap(onu.SerialNumber) |
| 109 | if !exist { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 110 | logger.Error("ONU not found with serial nnumber %v", onu.SerialNumber) |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 111 | 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] | 112 | } |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 113 | onuid := onu.OnuId |
| 114 | matched.OnuID = onuid |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 115 | s.updateDevIntState(matched, device.OnuActive) |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 116 | 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] | 117 | if err := sendOnuInd(*s.EnableServer, matched, "up", "up"); err != nil { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 118 | logger.Error("Failed to send ONU Indication intfID %d, onuID %d", matched.IntfID, matched.OnuID) |
| 119 | return new(openolt.Empty), err |
| 120 | } |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 121 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 122 | return new(openolt.Empty), nil |
| 123 | } |
| 124 | |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 125 | // CreateTrafficSchedulers method should handle TrafficScheduler creation |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 126 | func (s *Server) CreateTrafficSchedulers(c context.Context, traffScheduler *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
| 127 | logger.Debug("OLT receives CreateTrafficSchedulers %v", traffScheduler) |
| 128 | onu, err := s.GetOnuByID(traffScheduler.OnuId, traffScheduler.IntfId) |
| 129 | if err != nil { |
| 130 | return new(openolt.Empty), err |
| 131 | } |
| 132 | onu.Tconts = traffScheduler |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame] | 133 | return new(openolt.Empty), nil |
| 134 | } |
| 135 | |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 136 | // RemoveTrafficSchedulers method should handle TrafficScheduler removal |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 137 | func (s *Server) RemoveTrafficSchedulers(c context.Context, traffScheduler *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
| 138 | logger.Debug("OLT receives RemoveTrafficSchedulers %v", traffScheduler) |
| 139 | onu, err := s.GetOnuByID(traffScheduler.OnuId, traffScheduler.IntfId) |
| 140 | if err != nil { |
| 141 | return new(openolt.Empty), err |
| 142 | } |
| 143 | for _, tcont := range traffScheduler.TrafficScheds { |
| 144 | if _, exist := onu.GemPortMap[tcont.AllocId]; exist { |
| 145 | delete(onu.GemPortMap, tcont.AllocId) |
| 146 | } |
| 147 | } |
| 148 | onu.Tconts = nil |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 149 | return new(openolt.Empty), nil |
| 150 | } |
| 151 | |
| 152 | // CreateTrafficQueues method should handle TrafficQueues creation |
| 153 | func (s *Server) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
| 154 | logger.Debug("OLT receives CreateTrafficQueues()") |
| 155 | return new(openolt.Empty), nil |
| 156 | } |
| 157 | |
| 158 | // RemoveTrafficQueues method should handle TrafficQueues removal |
| 159 | func (s *Server) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
| 160 | logger.Debug("OLT receives RemoveTrafficQueues()") |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame] | 161 | return new(openolt.Empty), nil |
| 162 | } |
| 163 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 164 | // DeactivateOnu method should handle ONU deactivation |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 165 | 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] | 166 | logger.Debug("OLT receives DeactivateONU()") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 167 | return new(openolt.Empty), nil |
| 168 | } |
| 169 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 170 | // DeleteOnu handles ONU deletion request from VOLTHA |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 171 | 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] | 172 | 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] | 173 | Onu, err := s.GetOnuByID(onu.OnuId, onu.IntfId) |
| 174 | if err != nil { |
| 175 | return new(openolt.Empty), err |
| 176 | } |
| 177 | |
| 178 | // Mark ONU internal state as ONU_FREE and reset onuID |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 179 | Onu.InternalState = device.OnuFree |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 180 | Onu.OnuID = 0 |
| 181 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 182 | // Get snMap key for the ONU serial number |
| 183 | snkey := stringifySerialNumber(Onu.SerialNumber) |
| 184 | |
| 185 | // Delete Serial number entry from SNmap |
| 186 | logger.Info("Deleting serial number %s from SNmap", snkey) |
| 187 | s.SNmap.Delete(snkey) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 188 | return new(openolt.Empty), nil |
| 189 | } |
| 190 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 191 | // GetOnuInfo returns ONU info to VOLTHA |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 192 | 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] | 193 | 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] | 194 | Onu, err := s.GetOnuByID(onu.OnuId, onu.IntfId) |
| 195 | if err != nil { |
| 196 | logger.Error("ONU not found intfID %d, onuID %d", onu.IntfId, onu.OnuId) |
| 197 | return new(openolt.OnuIndication), err |
Anjali Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 198 | } |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 199 | onuIndication := new(openolt.OnuIndication) |
| 200 | onuIndication.IntfId = Onu.IntfID |
| 201 | onuIndication.OnuId = Onu.OnuID |
| 202 | onuIndication.OperState = Onu.OperState |
| 203 | |
| 204 | return onuIndication, nil |
Anjali Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 207 | // OmciMsgOut receives OMCI messages from voltha |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 208 | 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] | 209 | 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] | 210 | // Get ONU state |
| 211 | onu, err := s.GetOnuByID(msg.OnuId, msg.IntfId) |
| 212 | if err != nil { |
| 213 | logger.Error("ONU not found intfID %d, onuID %d", msg.IntfId, msg.OnuId) |
| 214 | return new(openolt.Empty), err |
| 215 | } |
| 216 | state := onu.GetIntState() |
| 217 | logger.Debug("ONU-ID: %v, ONU state: %d", msg.OnuId, state) |
| 218 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 219 | // If ONU is not ACTIVE drop OMCI message |
| 220 | if state < device.OnuActive { |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 221 | logger.Info("ONU (IF %v ONU-ID: %v) is not ACTIVE, so not processing OmciMsg", msg.IntfId, msg.OnuId) |
| 222 | return new(openolt.Empty), nil |
| 223 | } |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 224 | s.omciOut <- *msg |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 225 | return new(openolt.Empty), nil |
| 226 | } |
| 227 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 228 | // OnuPacketOut is used by voltha to send OnuPackets to BBSIM |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 229 | 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] | 230 | onu, err := s.GetOnuByID(packet.OnuId, packet.IntfId) |
| 231 | if err != nil { |
| 232 | logger.Error("Failed in OnuPacketOut, %v", err) |
| 233 | return new(openolt.Empty), err |
| 234 | } |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 235 | 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] | 236 | onuid := packet.OnuId |
| 237 | intfid := packet.IntfId |
| 238 | rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 239 | if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil { |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 240 | device.LoggerWithOnu(onu).WithField("error", err).Errorf("OnuPacketOut Error ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 241 | return new(openolt.Empty), err |
| 242 | } |
| 243 | return new(openolt.Empty), nil |
| 244 | } |
| 245 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 246 | // UplinkPacketOut sends uplink packets to BBSIM |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 247 | 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] | 248 | logger.Debug("OLT %d receives UplinkPacketOut().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 249 | rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 250 | if err := s.uplinkPacketOut(rawpkt); err != nil { |
| 251 | return new(openolt.Empty), err |
| 252 | } |
| 253 | return new(openolt.Empty), nil |
| 254 | } |
| 255 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 256 | // FlowAdd method should handle flows addition to datapath for OLT and ONU |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 257 | 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] | 258 | logger.Debug("OLT %d receives FlowAdd() %v", s.Olt.ID, flow) |
| 259 | // Check if flow already present |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 260 | flowKey := device.FlowKey{ |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 261 | FlowID: flow.FlowId, |
| 262 | FlowDirection: flow.FlowType, |
| 263 | } |
| 264 | if _, exist := s.FlowMap[flowKey]; exist { |
| 265 | logger.Error("Flow already exists %v", flow) |
| 266 | return new(openolt.Empty), status.Errorf(codes.AlreadyExists, "Flow already exists") |
| 267 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 268 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 269 | // Send flow to flowHandler |
| 270 | err := flowHandler.AddFlow(flow) |
| 271 | if err != nil { |
| 272 | logger.Error("Error in pushing flow to datapath") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | // Update flowMap |
| 276 | s.FlowMap[flowKey] = flow |
| 277 | |
| 278 | onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId)) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 279 | if err == nil { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 280 | exist := false |
| 281 | // check if gemport already present in ONU |
| 282 | for _, gemport := range onu.GemPortMap[uint32(flow.AllocId)] { |
| 283 | if gemport == uint32(flow.GemportId) { |
| 284 | exist = true |
| 285 | break |
| 286 | } |
| 287 | } |
| 288 | // if not present already, then append in gemport list |
| 289 | if !exist { |
| 290 | onu.GemPortMap[uint32(flow.AllocId)] = append(onu.GemPortMap[uint32(flow.AllocId)], uint32(flow.GemportId)) |
| 291 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 292 | |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 293 | // EAPOL flow |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 294 | if flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) { |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 295 | logger.WithFields(log.Fields{ |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 296 | "Classifier.OVid": flow.Classifier.OVid, |
| 297 | "Classifier.IVid": flow.Classifier.IVid, |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 298 | "Classifier.EthType": flow.Classifier.EthType, |
| 299 | "Classifier.SrcPort": flow.Classifier.SrcPort, |
| 300 | "Classifier.DstPort": flow.Classifier.DstPort, |
Matt Jeanneret | 7c9c5f2 | 2019-08-09 14:40:12 -0400 | [diff] [blame] | 301 | "Action.OVid": flow.Action.OVid, |
| 302 | "Action.IVid": flow.Action.IVid, |
| 303 | "IntfID": flow.AccessIntfId, |
| 304 | "OltID": s.Olt.ID, |
| 305 | "OnuID": flow.OnuId, |
| 306 | "FlowId": flow.FlowId, |
| 307 | "UniID": flow.UniId, |
| 308 | "PortNo": flow.PortNo, |
| 309 | "FlowType": flow.FlowType, |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 310 | }).Debug("OLT receives EAPOL flow") |
| 311 | |
| 312 | if flow.Classifier.OVid == 4091 { |
| 313 | omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID) |
| 314 | if omcistate != omci.DONE { |
| 315 | logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID)) |
| 316 | } |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 317 | _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.OnuOmciActive) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 318 | } |
| 319 | } |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 320 | |
| 321 | // DHCP flow |
| 322 | if flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) { |
| 323 | logger.Debug("Received flow's srcPort:%d dstPort:%d", flow.Classifier.SrcPort, flow.Classifier.DstPort) |
| 324 | if flow.Classifier.SrcPort == uint32(68) && flow.Classifier.DstPort == uint32(67) { |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 325 | logger.Debug("OLT %d receives DHCP flow IntfID:%d OnuID:%d EType:%x GemPortID:%d VLanIDs: %d/%d", |
| 326 | 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] | 327 | omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID) |
| 328 | if omcistate != omci.DONE { |
| 329 | logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID)) |
| 330 | } |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 331 | _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.OnuAuthenticated) |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 332 | } |
| 333 | } |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 334 | // Update flows in ONU object |
| 335 | onu.Flows = append(onu.Flows, flowKey) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 336 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 337 | return new(openolt.Empty), nil |
| 338 | } |
| 339 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 340 | // FlowRemove handles flow deletion from datapath |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 341 | 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] | 342 | logger.Debug("OLT %d receives FlowRemove(): %v", s.Olt.ID, flow) |
| 343 | |
| 344 | // Check if flow exists |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 345 | flowKey := device.FlowKey{ |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 346 | FlowID: flow.FlowId, |
| 347 | FlowDirection: flow.FlowType, |
| 348 | } |
| 349 | if _, exist := s.FlowMap[flowKey]; !exist { |
| 350 | logger.Error("Flow %v not found", flow) |
| 351 | return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found") |
| 352 | } |
| 353 | |
| 354 | flow = s.FlowMap[flowKey] |
| 355 | // Send delete flow to flowHandler |
| 356 | err := flowHandler.DeleteFlow(flow) |
| 357 | if err != nil { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 358 | logger.Error("failed to delete flow") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 361 | onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId)) |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 362 | if err != nil { |
| 363 | logger.Warn("Failed flow remove %v", err) |
| 364 | } else { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 365 | // Delete flows from onu |
| 366 | onu.DeleteFlow(flowKey) |
| 367 | logger.Debug("Flows %v in onu %d", onu.Flows, onu.OnuID) |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 368 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 369 | |
| 370 | // Delete flow from flowMap |
| 371 | delete(s.FlowMap, flowKey) |
| 372 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 373 | return new(openolt.Empty), nil |
| 374 | } |
| 375 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 376 | // HeartbeatCheck is currently not used by voltha |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 377 | 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] | 378 | logger.Debug("OLT %d receives HeartbeatCheck().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 379 | signature := new(openolt.Heartbeat) |
| 380 | signature.HeartbeatSignature = s.Olt.HeartbeatSignature |
| 381 | return signature, nil |
| 382 | } |
| 383 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 384 | // EnablePonIf enables pon interfaces at BBSIM |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 385 | 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] | 386 | logger.Debug("OLT %d receives EnablePonIf().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 387 | return new(openolt.Empty), nil |
| 388 | } |
| 389 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 390 | // GetPonIf returns interface info to VOLTHA |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 391 | 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] | 392 | logger.Debug("OLT %d receives GetPonIf().", s.Olt.ID) |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 393 | stat := new(openolt.IntfIndication) |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 394 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 395 | if intf.IntfId > (s.Olt.NumPonIntf - 1) { |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 396 | logger.Error("PON ID %d out of bounds. %d ports total", intf.IntfId, s.Olt.NumPonIntf) |
| 397 | 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] | 398 | } |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 399 | stat.IntfId = intf.IntfId |
| 400 | stat.OperState = s.Olt.PonIntfs[intf.IntfId].OperState |
| 401 | return stat, nil |
| 402 | |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 405 | // DisablePonIf disables pon interface at BBSIM |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 406 | 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] | 407 | logger.Debug("OLT %d receives DisablePonIf().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 408 | return new(openolt.Empty), nil |
| 409 | } |
| 410 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 411 | // Reboot method handles reboot of OLT |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 412 | 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] | 413 | logger.Debug("OLT %d receives Reboot ().", s.Olt.ID) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 414 | // Initialize OLT & Env |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 415 | logger.Debug("Initialized by Reboot") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 416 | s.handleOLTReboot() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 417 | return new(openolt.Empty), nil |
| 418 | } |
| 419 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 420 | // EnableIndication starts sending indications for OLT and ONU |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 421 | func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 422 | logger.Debug("OLT receives EnableInd.") |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 423 | defer func() { |
| 424 | logger.Debug("grpc EnableIndication Done") |
| 425 | }() |
| 426 | if err := s.Enable(&stream); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 427 | logger.Error("Failed to Enable Core: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 428 | return err |
| 429 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 430 | return nil |
| 431 | } |
| 432 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 433 | // NewGrpcServer starts openolt gRPC server |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 434 | func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) { |
Zdravko Bozakov | 078a271 | 2019-07-19 23:25:15 +0200 | [diff] [blame] | 435 | logger.Info("OpenOLT gRPC server listening %s ...", addrport) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 436 | g = grpc.NewServer() |
| 437 | l, e = net.Listen("tcp", addrport) |
| 438 | return |
| 439 | } |