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" |
| 28 | openolt "github.com/opencord/voltha-bbsim/protos" |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 29 | log "github.com/sirupsen/logrus" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 30 | "golang.org/x/net/context" |
| 31 | "google.golang.org/grpc" |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 32 | "google.golang.org/grpc/codes" |
| 33 | "google.golang.org/grpc/status" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 34 | ) |
| 35 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 36 | // DisableOlt method sends OLT down indication |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 37 | 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] | 38 | logger.Debug("OLT receives DisableOLT()") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 39 | |
| 40 | err := flowHandler.PortDown(0) |
| 41 | if err != nil { |
| 42 | logger.Error("Failed in port down %v", err) |
| 43 | } |
| 44 | |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 45 | if s.EnableServer != nil { |
| 46 | if err := sendOltIndDown(*s.EnableServer); err != nil { |
| 47 | return new(openolt.Empty), err |
| 48 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 49 | logger.Debug("Successfuly sent OLT DOWN indication") |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 50 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 51 | return new(openolt.Empty), nil |
| 52 | } |
| 53 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 54 | // ReenableOlt method sends OLT up indication for re-enabling OLT |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 55 | 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] | 56 | logger.Debug("OLT receives Reenable()") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 57 | |
| 58 | err := flowHandler.PortUp(0) |
| 59 | if err != nil { |
| 60 | logger.Error("Failed in port up %v", err) |
| 61 | } |
| 62 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 63 | 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 NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 70 | return new(openolt.Empty), nil |
| 71 | } |
| 72 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 73 | // CollectStatistics method invoked by VOLTHA to get OLT statistics |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 74 | 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] | 75 | logger.Debug("OLT receives CollectStatistics()") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 76 | return new(openolt.Empty), nil |
| 77 | } |
| 78 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 79 | // GetDeviceInfo returns OLT info |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 80 | 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] | 81 | 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 Ansari | 704c6f2 | 2018-11-13 14:57:53 -0800 | [diff] [blame] | 88 | devinfo.PonPorts = 16 |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 89 | 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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 97 | devinfo.DeviceSerialNumber = s.Olt.SerialNumber |
Shad Ansari | 010c194 | 2018-11-08 09:32:24 -0800 | [diff] [blame] | 98 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 99 | return devinfo, nil |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 100 | } |
| 101 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 102 | // ActivateOnu method handles ONU activation request from VOLTHA |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 103 | 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] | 104 | logger.Debug("OLT receives ActivateONU()") |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 105 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 106 | matched, exist := s.getOnuFromSNmap(onu.SerialNumber) |
| 107 | if !exist { |
| 108 | logger.Fatal("ONU not found with serial nnumber %v", onu.SerialNumber) |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 109 | 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] | 110 | } |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 111 | 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 Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 115 | 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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 119 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 120 | return new(openolt.Empty), nil |
| 121 | } |
| 122 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 123 | // CreateTconts method should handle Tcont creation |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame] | 124 | func (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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 129 | // RemoveTconts method should handle t-cont removal |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame] | 130 | func (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 Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 135 | // DeactivateOnu method should handle ONU deactivation |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 136 | 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] | 137 | logger.Debug("OLT receives DeactivateONU()") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 138 | return new(openolt.Empty), nil |
| 139 | } |
| 140 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 141 | // DeleteOnu handles ONU deletion request from VOLTHA |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 142 | 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] | 143 | 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] | 144 | 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 Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 153 | // 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 NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 159 | return new(openolt.Empty), nil |
| 160 | } |
| 161 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 162 | 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] | 163 | 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] | 164 | Onu, err := s.GetOnuByID(onu.OnuId, onu.IntfId) |
| 165 | if err != nil { |
| 166 | logger.Error("ONU not found intfID %d, onuID %d", onu.IntfId, onu.OnuId) |
| 167 | return new(openolt.OnuIndication), err |
Anjali Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 168 | } |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 169 | onuIndication := new(openolt.OnuIndication) |
| 170 | onuIndication.IntfId = Onu.IntfID |
| 171 | onuIndication.OnuId = Onu.OnuID |
| 172 | onuIndication.OperState = Onu.OperState |
| 173 | |
| 174 | return onuIndication, nil |
Anjali Thontakudi | 6665920 | 2019-07-03 23:14:02 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 177 | // OmciMsgOut receives OMCI messages from voltha |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 178 | 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] | 179 | 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] | 180 | // Get ONU state |
| 181 | onu, err := s.GetOnuByID(msg.OnuId, msg.IntfId) |
| 182 | if err != nil { |
| 183 | logger.Error("ONU not found intfID %d, onuID %d", msg.IntfId, msg.OnuId) |
| 184 | return new(openolt.Empty), err |
| 185 | } |
| 186 | state := onu.GetIntState() |
| 187 | logger.Debug("ONU-ID: %v, ONU state: %d", msg.OnuId, state) |
| 188 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 189 | // If ONU is ONU_INACTIVE, ONU_FREE or ONU_OMCI_CHANNEL_LOS_RAISED drop |
| 190 | if state != device.ONU_ACTIVE && state != device.ONU_OMCIACTIVE { |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 191 | logger.Info("ONU (IF %v ONU-ID: %v) is not ACTIVE, so not processing OmciMsg", msg.IntfId, msg.OnuId) |
| 192 | return new(openolt.Empty), nil |
| 193 | } |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 194 | s.omciOut <- *msg |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 195 | return new(openolt.Empty), nil |
| 196 | } |
| 197 | |
| 198 | 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] | 199 | onu, err := s.GetOnuByID(packet.OnuId, packet.IntfId) |
| 200 | if err != nil { |
| 201 | logger.Error("Failed in OnuPacketOut, %v", err) |
| 202 | return new(openolt.Empty), err |
| 203 | } |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 204 | 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] | 205 | onuid := packet.OnuId |
| 206 | intfid := packet.IntfId |
| 207 | rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 208 | if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil { |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 209 | device.LoggerWithOnu(onu).WithField("error", err).Errorf("OnuPacketOut Error ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 210 | return new(openolt.Empty), err |
| 211 | } |
| 212 | return new(openolt.Empty), nil |
| 213 | } |
| 214 | |
| 215 | 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] | 216 | logger.Debug("OLT %d receives UplinkPacketOut().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 217 | rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 218 | if err := s.uplinkPacketOut(rawpkt); err != nil { |
| 219 | return new(openolt.Empty), err |
| 220 | } |
| 221 | return new(openolt.Empty), nil |
| 222 | } |
| 223 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 224 | // FlowAdd method should handle flows addition to datapath for OLT and ONU |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 225 | 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] | 226 | logger.Debug("OLT %d receives FlowAdd() %v", s.Olt.ID, flow) |
| 227 | // Check if flow already present |
| 228 | flowKey := FlowKey{ |
| 229 | FlowID: flow.FlowId, |
| 230 | FlowDirection: flow.FlowType, |
| 231 | } |
| 232 | if _, exist := s.FlowMap[flowKey]; exist { |
| 233 | logger.Error("Flow already exists %v", flow) |
| 234 | return new(openolt.Empty), status.Errorf(codes.AlreadyExists, "Flow already exists") |
| 235 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 236 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 237 | // Send flow to flowHandler |
| 238 | err := flowHandler.AddFlow(flow) |
| 239 | if err != nil { |
| 240 | logger.Error("Error in pushing flow to datapath") |
| 241 | return new(openolt.Empty), err |
| 242 | } |
| 243 | |
| 244 | // Update flowMap |
| 245 | s.FlowMap[flowKey] = flow |
| 246 | |
| 247 | onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId)) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 248 | if err == nil { |
Keita NISHIMOTO | 26ebaa8 | 2019-03-07 10:00:35 +0900 | [diff] [blame] | 249 | onu.GemportID = uint16(flow.GemportId) |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 250 | |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 251 | device.LoggerWithOnu(onu).WithFields(log.Fields{ |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 252 | "olt": s.Olt.ID, |
| 253 | "c_tag": flow.Action.IVid, |
| 254 | }).Debug("OLT receives FlowAdd().") |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 255 | |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 256 | |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 257 | // EAPOL flow |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 258 | if flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) { |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 259 | logger.WithFields(log.Fields{ |
| 260 | "Classifier.OVid": flow.Classifier.OVid, |
| 261 | "Classifier.IVid": flow.Classifier.IVid, |
| 262 | "Classifier.EthType": flow.Classifier.EthType, |
| 263 | "Classifier.SrcPort": flow.Classifier.SrcPort, |
| 264 | "Classifier.DstPort": flow.Classifier.DstPort, |
| 265 | "Action.OVid": flow.Action.OVid, |
| 266 | "Action.IVid": flow.Action.IVid, |
| 267 | "IntfID": flow.AccessIntfId, |
| 268 | "OltID": s.Olt.ID, |
| 269 | "OnuID": flow.OnuId, |
| 270 | "FlowId": flow.FlowId, |
| 271 | "UniID": flow.UniId, |
| 272 | "PortNo": flow.PortNo, |
| 273 | "FlowType": flow.FlowType, |
| 274 | }).Debug("OLT receives EAPOL flow") |
| 275 | |
| 276 | if flow.Classifier.OVid == 4091 { |
| 277 | omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID) |
| 278 | if omcistate != omci.DONE { |
| 279 | logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID)) |
| 280 | } |
| 281 | _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_OMCIACTIVE) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 282 | } |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 283 | |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 284 | } |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 285 | |
| 286 | // DHCP flow |
| 287 | if flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) { |
| 288 | logger.Debug("Received flow's srcPort:%d dstPort:%d", flow.Classifier.SrcPort, flow.Classifier.DstPort) |
| 289 | if flow.Classifier.SrcPort == uint32(68) && flow.Classifier.DstPort == uint32(67) { |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 290 | logger.Debug("OLT %d receives DHCP flow IntfID:%d OnuID:%d EType:%x GemPortID:%d VLanIDs: %d/%d", |
| 291 | 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] | 292 | omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID) |
| 293 | if omcistate != omci.DONE { |
| 294 | logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID)) |
| 295 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 296 | _ = s.updateOnuIntState(onu.IntfID, onu.OnuID, device.ONU_AUTHENTICATED) |
Keita NISHIMOTO | 2807c54 | 2019-06-04 22:58:32 +0900 | [diff] [blame] | 297 | } |
| 298 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 299 | // Update flow ID in ONU object |
| 300 | onu.FlowIDs = append(onu.FlowIDs, flow.FlowId) |
Keita NISHIMOTO | 7bce769 | 2019-01-19 09:31:09 +0900 | [diff] [blame] | 301 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 302 | return new(openolt.Empty), nil |
| 303 | } |
| 304 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 305 | // FlowRemove handles flow deletion from datapath |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 306 | 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] | 307 | logger.Debug("OLT %d receives FlowRemove(): %v", s.Olt.ID, flow) |
| 308 | |
| 309 | // Check if flow exists |
| 310 | flowKey := FlowKey{ |
| 311 | FlowID: flow.FlowId, |
| 312 | FlowDirection: flow.FlowType, |
| 313 | } |
| 314 | if _, exist := s.FlowMap[flowKey]; !exist { |
| 315 | logger.Error("Flow %v not found", flow) |
| 316 | return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found") |
| 317 | } |
| 318 | |
| 319 | flow = s.FlowMap[flowKey] |
| 320 | // Send delete flow to flowHandler |
| 321 | err := flowHandler.DeleteFlow(flow) |
| 322 | if err != nil { |
| 323 | return new(openolt.Empty), err |
| 324 | } |
| 325 | |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 326 | onu, err := s.GetOnuByID(uint32(flow.OnuId), uint32(flow.AccessIntfId)) |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 327 | if err != nil { |
| 328 | logger.Warn("Failed flow remove %v", err) |
| 329 | } else { |
| 330 | // Delete flowID from onu |
| 331 | onu.DeleteFlowID(flow.FlowId) |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 332 | device.LoggerWithOnu(onu).WithFields(log.Fields{ |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 333 | "olt": s.Olt.ID, |
| 334 | "c_tag": flow.Action.IVid, |
| 335 | }).Debug("OLT receives FlowRemove().") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 336 | logger.Debug("Flows %v in ONU %d", onu.FlowIDs, onu.OnuID) |
Keita NISHIMOTO | 7057aa6 | 2019-05-28 01:24:08 +0900 | [diff] [blame] | 337 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 338 | |
| 339 | // Delete flow from flowMap |
| 340 | delete(s.FlowMap, flowKey) |
| 341 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 342 | return new(openolt.Empty), nil |
| 343 | } |
| 344 | |
| 345 | 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] | 346 | logger.Debug("OLT %d receives HeartbeatCheck().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 347 | signature := new(openolt.Heartbeat) |
| 348 | signature.HeartbeatSignature = s.Olt.HeartbeatSignature |
| 349 | return signature, nil |
| 350 | } |
| 351 | |
| 352 | 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] | 353 | logger.Debug("OLT %d receives EnablePonIf().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 354 | return new(openolt.Empty), nil |
| 355 | } |
| 356 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 357 | 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] | 358 | logger.Debug("OLT %d receives GetPonIf().", s.Olt.ID) |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 359 | stat := new(openolt.IntfIndication) |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 360 | |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 361 | if intf.IntfId > (s.Olt.NumPonIntf - 1) { |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 362 | logger.Error("PON ID %d out of bounds. %d ports total", intf.IntfId, s.Olt.NumPonIntf) |
| 363 | 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] | 364 | } |
Zdravko Bozakov | d975d30 | 2019-07-19 22:52:44 +0200 | [diff] [blame] | 365 | stat.IntfId = intf.IntfId |
| 366 | stat.OperState = s.Olt.PonIntfs[intf.IntfId].OperState |
| 367 | return stat, nil |
| 368 | |
Anjali Thontakudi | b871c50 | 2019-07-03 18:26:12 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 371 | 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] | 372 | logger.Debug("OLT %d receives DisablePonIf().", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 373 | return new(openolt.Empty), nil |
| 374 | } |
| 375 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 376 | // Reboot method handles reboot of OLT |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 377 | 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] | 378 | logger.Debug("OLT %d receives Reboot ().", s.Olt.ID) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 379 | // Initialize OLT & Env |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 380 | logger.Debug("Initialized by Reboot") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 381 | s.handleOLTReboot() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 382 | return new(openolt.Empty), nil |
| 383 | } |
| 384 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 385 | // EnableIndication starts sending indications for OLT and ONU |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 386 | func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 387 | logger.Debug("OLT receives EnableInd.") |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 388 | defer func() { |
| 389 | logger.Debug("grpc EnableIndication Done") |
| 390 | }() |
| 391 | if err := s.Enable(&stream); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 392 | logger.Error("Failed to Enable Core: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 393 | return err |
| 394 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 395 | return nil |
| 396 | } |
| 397 | |
Zdravko Bozakov | 8b9328c | 2019-05-15 05:13:34 +0200 | [diff] [blame] | 398 | // NewGrpcServer starts openolt gRPC server |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 399 | func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 400 | logger.Debug("OpenOLT gRPC server listening %s ...", addrport) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 401 | g = grpc.NewServer() |
| 402 | l, e = net.Listen("tcp", addrport) |
| 403 | return |
| 404 | } |