Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [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 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 20 | "context" |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 21 | "encoding/hex" |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 22 | "fmt" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 23 | pb "github.com/opencord/bbsim/api/bbsim" |
| 24 | "github.com/opencord/bbsim/internal/bbsim/alarmsim" |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 25 | "sync" |
| 26 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 27 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
| 28 | "github.com/opencord/bbsim/internal/bbsim/responders/dhcp" |
| 29 | "github.com/opencord/bbsim/internal/bbsim/responders/eapol" |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 30 | bbsim "github.com/opencord/bbsim/internal/bbsim/types" |
| 31 | me "github.com/opencord/omci-lib-go/generated" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 32 | "net" |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 33 | "strconv" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 34 | "time" |
| 35 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 36 | "github.com/google/gopacket/layers" |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 37 | "github.com/jpillora/backoff" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 38 | "github.com/looplab/fsm" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 39 | "github.com/opencord/bbsim/internal/common" |
| 40 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 41 | "github.com/opencord/omci-lib-go" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 42 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 43 | "github.com/opencord/voltha-protos/v4/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 44 | log "github.com/sirupsen/logrus" |
| 45 | ) |
| 46 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 47 | var onuLogger = log.WithFields(log.Fields{ |
| 48 | "module": "ONU", |
| 49 | }) |
| 50 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 51 | const ( |
| 52 | // ONU transitions |
| 53 | OnuTxInitialize = "initialize" |
| 54 | OnuTxDiscover = "discover" |
| 55 | OnuTxEnable = "enable" |
| 56 | OnuTxDisable = "disable" |
| 57 | OnuTxPonDisable = "pon_disable" |
| 58 | OnuTxStartImageDownload = "start_image_download" |
| 59 | OnuTxProgressImageDownload = "progress_image_download" |
| 60 | OnuTxCompleteImageDownload = "complete_image_download" |
| 61 | OnuTxFailImageDownload = "fail_image_download" |
| 62 | OnuTxActivateImage = "activate_image" |
| 63 | OnuTxCommitImage = "commit_image" |
| 64 | |
| 65 | // ONU States |
| 66 | OnuStateCreated = "created" |
| 67 | OnuStateInitialized = "initialized" |
| 68 | OnuStateDiscovered = "discovered" |
| 69 | OnuStateEnabled = "enabled" |
| 70 | OnuStateDisabled = "disabled" |
| 71 | OnuStatePonDisabled = "pon_disabled" |
| 72 | OnuStateImageDownloadStarted = "image_download_started" |
| 73 | OnuStateImageDownloadInProgress = "image_download_in_progress" |
| 74 | OnuStateImageDownloadComplete = "image_download_completed" |
| 75 | OnuStateImageDownloadError = "image_download_error" |
| 76 | OnuStateImageActivated = "software_image_activated" |
| 77 | OnuStateImageCommitted = "software_image_committed" |
| 78 | |
| 79 | // BBR ONU States and Transitions |
| 80 | BbrOnuTxSendEapolFlow = "send_eapol_flow" |
| 81 | BbrOnuStateEapolFlowSent = "eapol_flow_sent" |
| 82 | BbrOnuTxSendDhcpFlow = "send_dhcp_flow" |
| 83 | BbrOnuStateDhcpFlowSent = "dhcp_flow_sent" |
| 84 | ) |
| 85 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 86 | type FlowKey struct { |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 87 | ID uint64 |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 88 | Direction string |
| 89 | } |
| 90 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 91 | type Onu struct { |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 92 | ID uint32 |
| 93 | PonPortID uint32 |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 94 | PonPort *PonPort |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 95 | InternalState *fsm.FSM |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 96 | DiscoveryRetryDelay time.Duration // this is the time between subsequent Discovery Indication |
| 97 | DiscoveryDelay time.Duration // this is the time to send the first Discovery Indication |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 98 | |
| 99 | Services []ServiceIf |
| 100 | |
| 101 | Backoff *backoff.Backoff |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 102 | // ONU State |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 103 | // PortNo comes with flows and it's used when sending packetIndications, |
| 104 | // There is one PortNo per UNI Port, for now we're only storing the first one |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 105 | // FIXME add support for multiple UNIs (each UNI has a different PortNo) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 106 | PortNo uint32 |
| 107 | Flows []FlowKey |
| 108 | FlowIds []uint64 // keep track of the flows we currently have in the ONU |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 109 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 110 | OperState *fsm.FSM |
| 111 | SerialNumber *openolt.SerialNumber |
| 112 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 113 | Channel chan bbsim.Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 114 | |
| 115 | // OMCI params |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 116 | MibDataSync uint8 |
| 117 | ImageSoftwareExpectedSections int |
| 118 | ImageSoftwareReceivedSections int |
| 119 | ActiveImageEntityId uint16 |
| 120 | CommittedImageEntityId uint16 |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 121 | |
| 122 | // OMCI params (Used in BBR) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 123 | tid uint16 |
| 124 | hpTid uint16 |
| 125 | seqNumber uint16 |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 126 | |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 127 | DoneChannel chan bool // this channel is used to signal once the onu is complete (when the struct is used by BBR) |
| 128 | TrafficSchedulers *tech_profile.TrafficSchedulers |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 129 | onuAlarmsInfoLock sync.RWMutex |
| 130 | onuAlarmsInfo map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 133 | func (o *Onu) Sn() string { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 134 | return common.OnuSnToString(o.SerialNumber) |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 137 | func CreateONU(olt *OltDevice, pon *PonPort, id uint32, delay time.Duration, isMock bool) *Onu { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 138 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 139 | o := Onu{ |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 140 | ID: id, |
| 141 | PonPortID: pon.ID, |
| 142 | PonPort: pon, |
| 143 | PortNo: 0, |
| 144 | tid: 0x1, |
| 145 | hpTid: 0x8000, |
| 146 | seqNumber: 0, |
| 147 | DoneChannel: make(chan bool, 1), |
| 148 | DiscoveryRetryDelay: 60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received |
| 149 | Flows: []FlowKey{}, |
| 150 | DiscoveryDelay: delay, |
| 151 | MibDataSync: 0, |
| 152 | ImageSoftwareExpectedSections: 0, // populated during OMCI StartSoftwareDownloadRequest |
| 153 | ImageSoftwareReceivedSections: 0, |
| 154 | ActiveImageEntityId: 0, // when we start the SoftwareImage with ID 0 is active and committed |
| 155 | CommittedImageEntityId: 0, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 156 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 157 | o.SerialNumber = NewSN(olt.ID, pon.ID, id) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 158 | // NOTE this state machine is used to track the operational |
| 159 | // state as requested by VOLTHA |
| 160 | o.OperState = getOperStateFSM(func(e *fsm.Event) { |
| 161 | onuLogger.WithFields(log.Fields{ |
| 162 | "ID": o.ID, |
| 163 | }).Debugf("Changing ONU OperState from %s to %s", e.Src, e.Dst) |
| 164 | }) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 165 | o.onuAlarmsInfo = make(map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 166 | // NOTE this state machine is used to activate the OMCI, EAPOL and DHCP clients |
| 167 | o.InternalState = fsm.NewFSM( |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 168 | OnuStateCreated, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 169 | fsm.Events{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 170 | // DEVICE Lifecycle |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 171 | {Name: OnuTxInitialize, Src: []string{OnuStateCreated, OnuStateDisabled, OnuStatePonDisabled}, Dst: OnuStateInitialized}, |
| 172 | {Name: OnuTxDiscover, Src: []string{OnuStateInitialized}, Dst: OnuStateDiscovered}, |
| 173 | {Name: OnuTxEnable, Src: []string{OnuStateDiscovered, OnuStatePonDisabled}, Dst: OnuStateEnabled}, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 174 | // NOTE should disabled state be different for oper_disabled (emulating an error) and admin_disabled (received a disabled call via VOLTHA)? |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 175 | {Name: OnuTxDisable, Src: []string{OnuStateEnabled, OnuStatePonDisabled, OnuStateImageActivated, OnuStateImageDownloadError, OnuStateImageCommitted}, Dst: OnuStateDisabled}, |
Pragya Arya | 6a708d6 | 2020-01-01 17:17:20 +0530 | [diff] [blame] | 176 | // ONU state when PON port is disabled but ONU is power ON(more states should be added in src?) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 177 | {Name: OnuTxPonDisable, Src: []string{OnuStateEnabled, OnuStateImageActivated, OnuStateImageDownloadError, OnuStateImageCommitted}, Dst: OnuStatePonDisabled}, |
| 178 | // Software Image Download related states |
| 179 | {Name: OnuTxStartImageDownload, Src: []string{OnuStateEnabled, OnuStateImageDownloadComplete, OnuStateImageDownloadError}, Dst: OnuStateImageDownloadStarted}, |
| 180 | {Name: OnuTxProgressImageDownload, Src: []string{OnuStateImageDownloadStarted}, Dst: OnuStateImageDownloadInProgress}, |
| 181 | {Name: OnuTxCompleteImageDownload, Src: []string{OnuStateImageDownloadInProgress}, Dst: OnuStateImageDownloadComplete}, |
| 182 | {Name: OnuTxFailImageDownload, Src: []string{OnuStateImageDownloadInProgress}, Dst: OnuStateImageDownloadError}, |
| 183 | {Name: OnuTxActivateImage, Src: []string{OnuStateImageDownloadComplete}, Dst: OnuStateImageActivated}, |
| 184 | {Name: OnuTxCommitImage, Src: []string{OnuStateEnabled}, Dst: OnuStateImageCommitted}, // the image is committed after a ONU reboot |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 185 | // BBR States |
| 186 | // TODO add start OMCI state |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 187 | {Name: BbrOnuTxSendEapolFlow, Src: []string{OnuStateInitialized}, Dst: BbrOnuStateEapolFlowSent}, |
| 188 | {Name: BbrOnuTxSendDhcpFlow, Src: []string{BbrOnuStateEapolFlowSent}, Dst: BbrOnuStateDhcpFlowSent}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 189 | }, |
| 190 | fsm.Callbacks{ |
| 191 | "enter_state": func(e *fsm.Event) { |
| 192 | o.logStateChange(e.Src, e.Dst) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 193 | }, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 194 | "enter_initialized": func(e *fsm.Event) { |
| 195 | // create new channel for ProcessOnuMessages Go routine |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 196 | o.Channel = make(chan bbsim.Message, 2048) |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 197 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 198 | if err := o.OperState.Event(OnuTxEnable); err != nil { |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 199 | onuLogger.WithFields(log.Fields{ |
| 200 | "OnuId": o.ID, |
| 201 | "IntfId": o.PonPortID, |
| 202 | "OnuSn": o.Sn(), |
| 203 | }).Errorf("Cannot change ONU OperState to up: %s", err.Error()) |
| 204 | } |
| 205 | |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 206 | if !isMock { |
| 207 | // start ProcessOnuMessages Go routine |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 208 | go o.ProcessOnuMessages(olt.enableContext, olt.OpenoltStream, nil) |
Pragya Arya | 1cbefa4 | 2020-01-13 12:15:29 +0530 | [diff] [blame] | 209 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 210 | }, |
| 211 | "enter_discovered": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 212 | msg := bbsim.Message{ |
| 213 | Type: bbsim.OnuDiscIndication, |
| 214 | Data: bbsim.OnuDiscIndicationMessage{ |
| 215 | OperState: bbsim.UP, |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 216 | }, |
| 217 | } |
| 218 | o.Channel <- msg |
| 219 | }, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 220 | "enter_enabled": func(event *fsm.Event) { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 221 | |
| 222 | if used, sn := o.PonPort.isOnuIdAllocated(o.ID); used { |
| 223 | onuLogger.WithFields(log.Fields{ |
| 224 | "IntfId": o.PonPortID, |
| 225 | "OnuId": o.ID, |
| 226 | "SerialNumber": o.Sn(), |
| 227 | }).Errorf("received-omci-with-sn-%s", common.OnuSnToString(sn)) |
| 228 | return |
| 229 | } else { |
| 230 | o.PonPort.storeOnuId(o.ID, o.SerialNumber) |
| 231 | } |
| 232 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 233 | msg := bbsim.Message{ |
| 234 | Type: bbsim.OnuIndication, |
| 235 | Data: bbsim.OnuIndicationMessage{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 236 | OnuSN: o.SerialNumber, |
| 237 | PonPortID: o.PonPortID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 238 | OperState: bbsim.UP, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 239 | }, |
| 240 | } |
| 241 | o.Channel <- msg |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 242 | |
| 243 | // Once the ONU is enabled start listening for packets |
| 244 | for _, s := range o.Services { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 245 | s.Initialize(o.PonPort.Olt.OpenoltStream) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 246 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 247 | }, |
| 248 | "enter_disabled": func(event *fsm.Event) { |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 249 | |
| 250 | // clean the ONU state |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 251 | o.PortNo = 0 |
| 252 | o.Flows = []FlowKey{} |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 253 | o.PonPort.removeOnuId(o.ID) |
| 254 | o.PonPort.removeAllocId(o.SerialNumber) |
| 255 | o.PonPort.removeGemPortBySn(o.SerialNumber) |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 256 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 257 | // set the OperState to disabled |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 258 | if err := o.OperState.Event("disable"); err != nil { |
| 259 | onuLogger.WithFields(log.Fields{ |
| 260 | "OnuId": o.ID, |
| 261 | "IntfId": o.PonPortID, |
| 262 | "OnuSn": o.Sn(), |
| 263 | }).Errorf("Cannot change ONU OperState to down: %s", err.Error()) |
| 264 | } |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 265 | // send the OnuIndication DOWN event |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 266 | msg := bbsim.Message{ |
| 267 | Type: bbsim.OnuIndication, |
| 268 | Data: bbsim.OnuIndicationMessage{ |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 269 | OnuSN: o.SerialNumber, |
| 270 | PonPortID: o.PonPortID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 271 | OperState: bbsim.DOWN, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 272 | }, |
| 273 | } |
| 274 | o.Channel <- msg |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 275 | |
| 276 | // verify all the flows removes are handled and |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 277 | // terminate the ONU's ProcessOnuMessages Go routine |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 278 | if len(o.FlowIds) == 0 { |
| 279 | close(o.Channel) |
| 280 | } |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 281 | |
| 282 | for _, s := range o.Services { |
| 283 | s.Disable() |
| 284 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 285 | o.onuAlarmsInfoLock.Lock() |
| 286 | o.onuAlarmsInfo = make(map[omcilib.OnuAlarmInfoMapKey]omcilib.OnuAlarmInfo) //Basically reset everything on onu disable |
| 287 | o.onuAlarmsInfoLock.Unlock() |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 288 | }, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 289 | // BBR states |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 290 | "enter_eapol_flow_sent": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 291 | msg := bbsim.Message{ |
| 292 | Type: bbsim.SendEapolFlow, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 293 | } |
| 294 | o.Channel <- msg |
| 295 | }, |
| 296 | "enter_dhcp_flow_sent": func(e *fsm.Event) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 297 | msg := bbsim.Message{ |
| 298 | Type: bbsim.SendDhcpFlow, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 299 | } |
| 300 | o.Channel <- msg |
| 301 | }, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 302 | }, |
| 303 | ) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 304 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 305 | return &o |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 306 | } |
| 307 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 308 | func (o *Onu) logStateChange(src string, dst string) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 309 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 310 | "OnuId": o.ID, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 311 | "IntfId": o.PonPortID, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 312 | "OnuSn": o.Sn(), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 313 | }).Debugf("Changing ONU InternalState from %s to %s", src, dst) |
| 314 | } |
| 315 | |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 316 | // ProcessOnuMessages starts indication channel for each ONU |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 317 | func (o *Onu) ProcessOnuMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, client openolt.OpenoltClient) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 318 | onuLogger.WithFields(log.Fields{ |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 319 | "onuID": o.ID, |
| 320 | "onuSN": o.Sn(), |
| 321 | "ponPort": o.PonPortID, |
| 322 | }).Debug("Starting ONU Indication Channel") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 323 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 324 | loop: |
| 325 | for { |
| 326 | select { |
| 327 | case <-ctx.Done(): |
| 328 | onuLogger.WithFields(log.Fields{ |
| 329 | "onuID": o.ID, |
| 330 | "onuSN": o.Sn(), |
| 331 | }).Tracef("ONU message handling canceled via context") |
| 332 | break loop |
| 333 | case message, ok := <-o.Channel: |
| 334 | if !ok || ctx.Err() != nil { |
| 335 | onuLogger.WithFields(log.Fields{ |
| 336 | "onuID": o.ID, |
| 337 | "onuSN": o.Sn(), |
| 338 | }).Tracef("ONU message handling canceled via channel close") |
| 339 | break loop |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 340 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 341 | onuLogger.WithFields(log.Fields{ |
| 342 | "onuID": o.ID, |
| 343 | "onuSN": o.Sn(), |
| 344 | "messageType": message.Type, |
| 345 | }).Tracef("Received message on ONU Channel") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 346 | |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 347 | switch message.Type { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 348 | case bbsim.OnuDiscIndication: |
| 349 | msg, _ := message.Data.(bbsim.OnuDiscIndicationMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 350 | // NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 351 | time.Sleep(o.DiscoveryDelay) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 352 | o.sendOnuDiscIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 353 | case bbsim.OnuIndication: |
| 354 | msg, _ := message.Data.(bbsim.OnuIndicationMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 355 | o.sendOnuIndication(msg, stream) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 356 | case bbsim.OMCI: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 357 | // these are OMCI messages received by the ONU |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 358 | msg, _ := message.Data.(bbsim.OmciMessage) |
| 359 | o.handleOmciRequest(msg, stream) |
| 360 | case bbsim.UniStatusAlarm: |
| 361 | msg, _ := message.Data.(bbsim.UniStatusAlarmMessage) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 362 | onuAlarmMapKey := omcilib.OnuAlarmInfoMapKey{ |
| 363 | MeInstance: msg.EntityID, |
| 364 | MeClassID: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 365 | } |
| 366 | seqNo := o.IncrementAlarmSequenceNumber(onuAlarmMapKey) |
| 367 | o.onuAlarmsInfoLock.Lock() |
| 368 | var alarmInfo = o.onuAlarmsInfo[onuAlarmMapKey] |
| 369 | pkt, alarmBitMap := omcilib.CreateUniStatusAlarm(msg.RaiseOMCIAlarm, msg.EntityID, seqNo) |
| 370 | if pkt != nil { //pkt will be nil if we are unable to create the alarm |
| 371 | if err := o.sendOmciIndication(pkt, 0, stream); err != nil { |
| 372 | onuLogger.WithFields(log.Fields{ |
| 373 | "IntfId": o.PonPortID, |
| 374 | "SerialNumber": o.Sn(), |
| 375 | "omciPacket": pkt, |
| 376 | "adminState": msg.AdminState, |
| 377 | "entityID": msg.EntityID, |
| 378 | }).Errorf("failed-to-send-UNI-Link-Alarm: %v", err) |
| 379 | alarmInfo.SequenceNo-- |
| 380 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 381 | onuLogger.WithFields(log.Fields{ |
| 382 | "IntfId": o.PonPortID, |
| 383 | "SerialNumber": o.Sn(), |
| 384 | "omciPacket": pkt, |
| 385 | "adminState": msg.AdminState, |
| 386 | "entityID": msg.EntityID, |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 387 | }).Trace("UNI-Link-alarm-sent") |
| 388 | if alarmBitMap == [28]byte{0} { |
| 389 | delete(o.onuAlarmsInfo, onuAlarmMapKey) |
| 390 | } else { |
| 391 | alarmInfo.AlarmBitMap = alarmBitMap |
| 392 | o.onuAlarmsInfo[onuAlarmMapKey] = alarmInfo |
| 393 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 394 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 395 | o.onuAlarmsInfoLock.Unlock() |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 396 | case bbsim.FlowAdd: |
| 397 | msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 398 | o.handleFlowAdd(msg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 399 | case bbsim.FlowRemoved: |
| 400 | msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 401 | o.handleFlowRemove(msg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 402 | case bbsim.OnuPacketOut: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 403 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 404 | msg, _ := message.Data.(bbsim.OnuPacketMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 405 | |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 406 | onuLogger.WithFields(log.Fields{ |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 407 | "IntfId": msg.IntfId, |
| 408 | "OnuId": msg.OnuId, |
| 409 | "pktType": msg.Type, |
| 410 | }).Trace("Received OnuPacketOut Message") |
| 411 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 412 | if msg.Type == packetHandlers.EAPOL || msg.Type == packetHandlers.DHCP { |
| 413 | |
| 414 | service, err := o.findServiceByMacAddress(msg.MacAddress) |
| 415 | if err != nil { |
| 416 | onuLogger.WithFields(log.Fields{ |
| 417 | "IntfId": msg.IntfId, |
| 418 | "OnuId": msg.OnuId, |
| 419 | "pktType": msg.Type, |
| 420 | "MacAddress": msg.MacAddress, |
| 421 | "Pkt": hex.EncodeToString(msg.Packet.Data()), |
| 422 | "OnuSn": o.Sn(), |
| 423 | }).Error("Cannot find Service associated with packet") |
| 424 | return |
| 425 | } |
| 426 | service.PacketCh <- msg |
| 427 | } else if msg.Type == packetHandlers.IGMP { |
| 428 | // if it's an IGMP packet we assume we have a single IGMP service |
| 429 | for _, s := range o.Services { |
| 430 | service := s.(*Service) |
| 431 | |
| 432 | if service.NeedsIgmp { |
| 433 | service.PacketCh <- msg |
| 434 | } |
| 435 | } |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 436 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 437 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 438 | case bbsim.OnuPacketIn: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 439 | // NOTE we only receive BBR packets here. |
| 440 | // Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same |
| 441 | // in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 442 | msg, _ := message.Data.(bbsim.OnuPacketMessage) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 443 | |
| 444 | log.WithFields(log.Fields{ |
| 445 | "IntfId": msg.IntfId, |
| 446 | "OnuId": msg.OnuId, |
| 447 | "pktType": msg.Type, |
| 448 | }).Trace("Received OnuPacketIn Message") |
| 449 | |
| 450 | if msg.Type == packetHandlers.EAPOL { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 451 | eapol.HandleNextPacket(msg.OnuId, msg.IntfId, msg.GemPortId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 452 | } else if msg.Type == packetHandlers.DHCP { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 453 | _ = dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.DoneChannel, msg.Packet, client) |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 454 | } |
Matteo Scandolo | 7f656fb | 2020-09-08 15:18:15 -0700 | [diff] [blame] | 455 | // BBR specific messages |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 456 | case bbsim.OmciIndication: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 457 | // these are OMCI messages received by BBR (VOLTHA emulator) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 458 | msg, _ := message.Data.(bbsim.OmciIndicationMessage) |
| 459 | o.handleOmciResponse(msg, client) |
| 460 | case bbsim.SendEapolFlow: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 461 | o.sendEapolFlow(client) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 462 | case bbsim.SendDhcpFlow: |
David Bainbridge | 103cf02 | 2019-12-16 20:11:35 +0000 | [diff] [blame] | 463 | o.sendDhcpFlow(client) |
| 464 | default: |
| 465 | onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 466 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 469 | onuLogger.WithFields(log.Fields{ |
| 470 | "onuID": o.ID, |
| 471 | "onuSN": o.Sn(), |
| 472 | }).Debug("Stopped handling ONU Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 475 | func NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 476 | sn := new(openolt.SerialNumber) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 477 | sn.VendorId = []byte("BBSM") |
| 478 | sn.VendorSpecific = []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)} |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 479 | return sn |
| 480 | } |
| 481 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 482 | func (o *Onu) sendOnuDiscIndication(msg bbsim.OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 483 | discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 484 | IntfId: o.PonPortID, |
| 485 | SerialNumber: o.SerialNumber, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 486 | }} |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 487 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 488 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 489 | log.Errorf("Failed to send Indication_OnuDiscInd: %v", err) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 490 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 491 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 492 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 493 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 494 | "IntfId": o.PonPortID, |
| 495 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 496 | "OnuId": o.ID, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 497 | }).Debug("Sent Indication_OnuDiscInd") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 498 | publishEvent("ONU-discovery-indication-sent", int32(o.PonPortID), int32(o.ID), o.Sn()) |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 499 | |
| 500 | // after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication |
| 501 | go func(delay time.Duration) { |
Matteo Scandolo | 569e717 | 2019-12-20 11:51:51 -0800 | [diff] [blame] | 502 | time.Sleep(delay) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 503 | if o.InternalState.Current() == OnuStateDiscovered { |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 504 | o.sendOnuDiscIndication(msg, stream) |
| 505 | } |
| 506 | }(o.DiscoveryRetryDelay) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 509 | func (o *Onu) sendOnuIndication(msg bbsim.OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 510 | // NOTE the ONU ID is set by VOLTHA in the ActivateOnu call (via openolt.proto) |
| 511 | // and stored in the Onu struct via onu.SetID |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 512 | |
| 513 | indData := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 514 | IntfId: o.PonPortID, |
| 515 | OnuId: o.ID, |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 516 | OperState: msg.OperState.String(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 517 | AdminState: o.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 518 | SerialNumber: o.SerialNumber, |
| 519 | }} |
| 520 | if err := stream.Send(&openolt.Indication{Data: indData}); err != nil { |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 521 | // NOTE do we need to transition to a broken state? |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 522 | log.Errorf("Failed to send Indication_OnuInd: %v", err) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 523 | return |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 524 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 525 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 526 | "IntfId": o.PonPortID, |
| 527 | "OnuId": o.ID, |
| 528 | "VolthaOnuId": msg.OnuID, |
| 529 | "OperState": msg.OperState.String(), |
| 530 | "AdminState": msg.OperState.String(), |
| 531 | "OnuSn": o.Sn(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 532 | }).Debug("Sent Indication_OnuInd") |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 533 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 536 | func (o *Onu) HandleShutdownONU() error { |
| 537 | |
| 538 | dyingGasp := pb.ONUAlarmRequest{ |
| 539 | AlarmType: "DYING_GASP", |
| 540 | SerialNumber: o.Sn(), |
| 541 | Status: "on", |
| 542 | } |
| 543 | |
| 544 | if err := alarmsim.SimulateOnuAlarm(&dyingGasp, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil { |
| 545 | onuLogger.WithFields(log.Fields{ |
| 546 | "OnuId": o.ID, |
| 547 | "IntfId": o.PonPortID, |
| 548 | "OnuSn": o.Sn(), |
| 549 | }).Errorf("Cannot send Dying Gasp: %s", err.Error()) |
| 550 | return err |
| 551 | } |
| 552 | |
| 553 | losReq := pb.ONUAlarmRequest{ |
| 554 | AlarmType: "ONU_ALARM_LOS", |
| 555 | SerialNumber: o.Sn(), |
| 556 | Status: "on", |
| 557 | } |
| 558 | |
| 559 | if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil { |
| 560 | onuLogger.WithFields(log.Fields{ |
| 561 | "OnuId": o.ID, |
| 562 | "IntfId": o.PonPortID, |
| 563 | "OnuSn": o.Sn(), |
| 564 | }).Errorf("Cannot send LOS: %s", err.Error()) |
| 565 | |
| 566 | return err |
| 567 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 568 | o.SendOMCIAlarmNotificationMsg(true, losReq.AlarmType) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 569 | // TODO if it's the last ONU on the PON, then send a PON LOS |
| 570 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 571 | if err := o.InternalState.Event(OnuTxDisable); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 572 | onuLogger.WithFields(log.Fields{ |
| 573 | "OnuId": o.ID, |
| 574 | "IntfId": o.PonPortID, |
| 575 | "OnuSn": o.Sn(), |
| 576 | }).Errorf("Cannot shutdown ONU: %s", err.Error()) |
| 577 | return err |
| 578 | } |
| 579 | |
| 580 | return nil |
| 581 | } |
| 582 | |
| 583 | func (o *Onu) HandlePowerOnONU() error { |
| 584 | intitalState := o.InternalState.Current() |
| 585 | |
| 586 | // initialize the ONU |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 587 | if intitalState == OnuStateCreated || intitalState == OnuStateDisabled { |
| 588 | if err := o.InternalState.Event(OnuTxInitialize); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 589 | onuLogger.WithFields(log.Fields{ |
| 590 | "OnuId": o.ID, |
| 591 | "IntfId": o.PonPortID, |
| 592 | "OnuSn": o.Sn(), |
| 593 | }).Errorf("Cannot poweron ONU: %s", err.Error()) |
| 594 | return err |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // turn off the LOS Alarm |
| 599 | losReq := pb.ONUAlarmRequest{ |
| 600 | AlarmType: "ONU_ALARM_LOS", |
| 601 | SerialNumber: o.Sn(), |
| 602 | Status: "off", |
| 603 | } |
| 604 | |
| 605 | if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil { |
| 606 | onuLogger.WithFields(log.Fields{ |
| 607 | "OnuId": o.ID, |
| 608 | "IntfId": o.PonPortID, |
| 609 | "OnuSn": o.Sn(), |
| 610 | }).Errorf("Cannot send LOS: %s", err.Error()) |
| 611 | return err |
| 612 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 613 | o.SendOMCIAlarmNotificationMsg(false, losReq.AlarmType) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 614 | |
| 615 | // Send a ONU Discovery indication |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 616 | if err := o.InternalState.Event(OnuTxDiscover); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 617 | onuLogger.WithFields(log.Fields{ |
| 618 | "OnuId": o.ID, |
| 619 | "IntfId": o.PonPortID, |
| 620 | "OnuSn": o.Sn(), |
| 621 | }).Errorf("Cannot poweron ONU: %s", err.Error()) |
| 622 | return err |
| 623 | } |
| 624 | |
| 625 | // move o directly to enable state only when its a powercycle case |
| 626 | // in case of first time o poweron o will be moved to enable on |
| 627 | // receiving ActivateOnu request from openolt adapter |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 628 | if intitalState == OnuStateDisabled { |
| 629 | if err := o.InternalState.Event(OnuTxEnable); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 630 | onuLogger.WithFields(log.Fields{ |
| 631 | "OnuId": o.ID, |
| 632 | "IntfId": o.PonPortID, |
| 633 | "OnuSn": o.Sn(), |
| 634 | }).Errorf("Cannot enable ONU: %s", err.Error()) |
| 635 | return err |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | return nil |
| 640 | } |
| 641 | |
| 642 | func (o *Onu) SetAlarm(alarmType string, status string) error { |
| 643 | alarmReq := pb.ONUAlarmRequest{ |
| 644 | AlarmType: alarmType, |
| 645 | SerialNumber: o.Sn(), |
| 646 | Status: status, |
| 647 | } |
| 648 | |
| 649 | err := alarmsim.SimulateOnuAlarm(&alarmReq, o.ID, o.PonPortID, o.PonPort.Olt.channel) |
| 650 | if err != nil { |
| 651 | return err |
| 652 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 653 | raiseAlarm := false |
| 654 | if alarmReq.Status == "on" { |
| 655 | raiseAlarm = true |
| 656 | } |
| 657 | o.SendOMCIAlarmNotificationMsg(raiseAlarm, alarmReq.AlarmType) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 658 | return nil |
| 659 | } |
| 660 | |
| 661 | func (o *Onu) publishOmciEvent(msg bbsim.OmciMessage) { |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 662 | if olt.PublishEvents { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 663 | _, omciMsg, err := omcilib.ParseOpenOltOmciPacket(msg.OmciPkt.Data()) |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 664 | if err != nil { |
| 665 | log.Errorf("error in getting msgType %v", err) |
| 666 | return |
| 667 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 668 | if omciMsg.MessageType == omci.MibUploadRequestType { |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 669 | o.seqNumber = 0 |
| 670 | publishEvent("MIB-upload-received", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber)) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 671 | } else if omciMsg.MessageType == omci.MibUploadNextRequestType { |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 672 | o.seqNumber++ |
| 673 | if o.seqNumber > 290 { |
| 674 | publishEvent("MIB-upload-done", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber)) |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 680 | // Create a TestResponse packet and send it |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 681 | func (o *Onu) sendTestResult(msg bbsim.OmciMessage, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 682 | resp, err := omcilib.BuildTestResult(msg.OmciPkt.Data()) |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 683 | if err != nil { |
| 684 | return err |
| 685 | } |
| 686 | |
| 687 | var omciInd openolt.OmciIndication |
| 688 | omciInd.IntfId = o.PonPortID |
| 689 | omciInd.OnuId = o.ID |
| 690 | omciInd.Pkt = resp |
| 691 | |
| 692 | omci := &openolt.Indication_OmciInd{OmciInd: &omciInd} |
| 693 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 694 | return err |
| 695 | } |
| 696 | onuLogger.WithFields(log.Fields{ |
| 697 | "IntfId": o.PonPortID, |
| 698 | "SerialNumber": o.Sn(), |
| 699 | "omciPacket": omciInd.Pkt, |
| 700 | }).Tracef("Sent TestResult OMCI message") |
| 701 | |
| 702 | return nil |
| 703 | } |
| 704 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 705 | // handleOmciRequest is responsible to parse the OMCI packets received from the openolt adapter |
| 706 | // and generate the appropriate response to it |
| 707 | func (o *Onu) handleOmciRequest(msg bbsim.OmciMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 708 | |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 709 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 710 | "omciMsgType": msg.OmciMsg.MessageType, |
| 711 | "transCorrId": strconv.FormatInt(int64(msg.OmciMsg.TransactionID), 16), |
| 712 | "DeviceIdent": msg.OmciMsg.DeviceIdentifier, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 713 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 714 | "SerialNumber": o.Sn(), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 715 | }).Trace("omci-message-decoded") |
| 716 | |
| 717 | var responsePkt []byte |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 718 | var errResp error |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 719 | switch msg.OmciMsg.MessageType { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 720 | case omci.MibResetRequestType: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 721 | onuLogger.WithFields(log.Fields{ |
| 722 | "IntfId": o.PonPortID, |
| 723 | "OnuId": o.ID, |
| 724 | "SerialNumber": o.Sn(), |
| 725 | }).Debug("received-mib-reset-request-resetting-mds") |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 726 | if responsePkt, errResp = omcilib.CreateMibResetResponse(msg.OmciMsg.TransactionID); errResp == nil { |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 727 | o.MibDataSync = 0 |
| 728 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 729 | case omci.MibUploadRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 730 | responsePkt, _ = omcilib.CreateMibUploadResponse(msg.OmciMsg.TransactionID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 731 | case omci.MibUploadNextRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 732 | responsePkt, _ = omcilib.CreateMibUploadNextResponse(msg.OmciPkt, msg.OmciMsg, o.MibDataSync) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 733 | case omci.GetRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 734 | responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId, o.CommittedImageEntityId) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 735 | case omci.SetRequestType: |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 736 | success := true |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 737 | msgObj, _ := omcilib.ParseSetRequest(msg.OmciPkt) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 738 | switch msgObj.EntityClass { |
| 739 | case me.PhysicalPathTerminationPointEthernetUniClassID: |
| 740 | // if we're Setting a PPTP state |
| 741 | // we need to send the appropriate alarm |
| 742 | |
| 743 | if msgObj.EntityInstance == 257 { |
| 744 | // for now we're only caring about the first UNI |
| 745 | // NOTE that the EntityID for the UNI port is for now hardcoded in |
| 746 | // omci/mibpackets.go where the PhysicalPathTerminationPointEthernetUni |
| 747 | // are reported during the MIB Upload sequence |
| 748 | adminState := msgObj.Attributes["AdministrativeState"].(uint8) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 749 | raiseOMCIAlarm := false |
| 750 | if adminState == 1 { |
| 751 | raiseOMCIAlarm = true |
| 752 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 753 | msg := bbsim.Message{ |
| 754 | Type: bbsim.UniStatusAlarm, |
| 755 | Data: bbsim.UniStatusAlarmMessage{ |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 756 | OnuSN: o.SerialNumber, |
| 757 | OnuID: o.ID, |
| 758 | AdminState: adminState, |
| 759 | EntityID: msgObj.EntityInstance, |
| 760 | RaiseOMCIAlarm: raiseOMCIAlarm, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 761 | }, |
| 762 | } |
| 763 | o.Channel <- msg |
| 764 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 765 | case me.TContClassID: |
| 766 | allocId := msgObj.Attributes["AllocId"].(uint16) |
| 767 | |
| 768 | // if the AllocId is 255 (0xFF) or 65535 (0xFFFF) it means we are removing it, |
| 769 | // otherwise we are adding it |
| 770 | if allocId == 255 || allocId == 65535 { |
| 771 | onuLogger.WithFields(log.Fields{ |
| 772 | "IntfId": o.PonPortID, |
| 773 | "OnuId": o.ID, |
| 774 | "TContId": msgObj.EntityInstance, |
| 775 | "AllocId": allocId, |
| 776 | "SerialNumber": o.Sn(), |
| 777 | }).Trace("freeing-alloc-id-via-omci") |
| 778 | o.PonPort.removeAllocId(o.SerialNumber) |
| 779 | } else { |
| 780 | if used, sn := o.PonPort.isAllocIdAllocated(allocId); used { |
| 781 | onuLogger.WithFields(log.Fields{ |
| 782 | "IntfId": o.PonPortID, |
| 783 | "OnuId": o.ID, |
| 784 | "AllocId": allocId, |
| 785 | "SerialNumber": o.Sn(), |
| 786 | }).Errorf("allocid-already-allocated-to-onu-with-sn-%s", common.OnuSnToString(sn)) |
| 787 | success = false |
| 788 | } else { |
| 789 | onuLogger.WithFields(log.Fields{ |
| 790 | "IntfId": o.PonPortID, |
| 791 | "OnuId": o.ID, |
| 792 | "TContId": msgObj.EntityInstance, |
| 793 | "AllocId": allocId, |
| 794 | "SerialNumber": o.Sn(), |
| 795 | }).Trace("storing-alloc-id-via-omci") |
| 796 | o.PonPort.storeAllocId(allocId, o.SerialNumber) |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | } |
| 801 | |
| 802 | if success { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 803 | if responsePkt, errResp = omcilib.CreateSetResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 804 | o.MibDataSync++ |
| 805 | } |
| 806 | } else { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 807 | responsePkt, _ = omcilib.CreateSetResponse(msg.OmciPkt, msg.OmciMsg, me.AttributeFailure) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 808 | } |
| 809 | case omci.CreateRequestType: |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 810 | // check for GemPortNetworkCtp and make sure there are no duplicates on the same PON |
| 811 | var used bool |
| 812 | var sn *openolt.SerialNumber |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 813 | msgObj, err := omcilib.ParseCreateRequest(msg.OmciPkt) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 814 | if err == nil { |
| 815 | if msgObj.EntityClass == me.GemPortNetworkCtpClassID { |
| 816 | if used, sn = o.PonPort.isGemPortAllocated(msgObj.EntityInstance); used { |
| 817 | onuLogger.WithFields(log.Fields{ |
| 818 | "IntfId": o.PonPortID, |
| 819 | "OnuId": o.ID, |
| 820 | "GemPortId": msgObj.EntityInstance, |
| 821 | "SerialNumber": o.Sn(), |
| 822 | }).Errorf("gemport-already-allocated-to-onu-with-sn-%s", common.OnuSnToString(sn)) |
| 823 | } else { |
| 824 | onuLogger.WithFields(log.Fields{ |
| 825 | "IntfId": o.PonPortID, |
| 826 | "OnuId": o.ID, |
| 827 | "GemPortId": msgObj.EntityInstance, |
| 828 | "SerialNumber": o.Sn(), |
| 829 | }).Trace("storing-gem-port-id-via-omci") |
| 830 | o.PonPort.storeGemPort(msgObj.EntityInstance, o.SerialNumber) |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | // if the gemPort is valid then increment the MDS and return a successful response |
| 836 | // otherwise fail the request |
| 837 | // for now the CreateRequeste for the gemPort is the only one that can fail, if we start supporting multiple |
| 838 | // validation this check will need to be rewritten |
| 839 | if !used { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 840 | if responsePkt, errResp = omcilib.CreateCreateResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil { |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 841 | o.MibDataSync++ |
| 842 | } |
| 843 | } else { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 844 | responsePkt, _ = omcilib.CreateCreateResponse(msg.OmciPkt, msg.OmciMsg, me.ProcessingError) |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 845 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 846 | case omci.DeleteRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 847 | msgObj, err := omcilib.ParseDeleteRequest(msg.OmciPkt) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 848 | if err == nil { |
| 849 | if msgObj.EntityClass == me.GemPortNetworkCtpClassID { |
| 850 | onuLogger.WithFields(log.Fields{ |
| 851 | "IntfId": o.PonPortID, |
| 852 | "OnuId": o.ID, |
| 853 | "GemPortId": msgObj.EntityInstance, |
| 854 | "SerialNumber": o.Sn(), |
| 855 | }).Trace("freeing-gem-port-id-via-omci") |
| 856 | o.PonPort.removeGemPort(msgObj.EntityInstance) |
| 857 | } |
| 858 | } |
| 859 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 860 | if responsePkt, errResp = omcilib.CreateDeleteResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Girish Gowdra | e268310 | 2021-03-05 08:24:26 -0800 | [diff] [blame] | 861 | o.MibDataSync++ |
| 862 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 863 | case omci.RebootRequestType: |
| 864 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 865 | responsePkt, _ = omcilib.CreateRebootResponse(msg.OmciPkt, msg.OmciMsg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 866 | |
| 867 | // powercycle the ONU |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 868 | // we run this in a separate goroutine so that |
| 869 | // the RebootRequestResponse is sent to VOLTHA |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 870 | go func() { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 871 | if err := o.Reboot(10 * time.Second); err != nil { |
| 872 | log.WithFields(log.Fields{ |
| 873 | "IntfId": o.PonPortID, |
| 874 | "OnuId": o.ID, |
| 875 | "SerialNumber": o.Sn(), |
| 876 | "err": err, |
| 877 | }).Error("cannot-reboot-onu-after-omci-reboot-request") |
| 878 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 879 | }() |
| 880 | case omci.TestRequestType: |
| 881 | |
| 882 | // Test message is special, it requires sending two packets: |
| 883 | // first packet: TestResponse, says whether test was started successully, handled by omci-sim |
| 884 | // second packet, TestResult, reports the result of running the self-test |
| 885 | // TestResult can come some time after a TestResponse |
| 886 | // TODO: Implement some delay between the TestResponse and the TestResult |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 887 | isTest, err := omcilib.IsTestRequest(msg.OmciPkt.Data()) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 888 | if (err == nil) && (isTest) { |
| 889 | if sendErr := o.sendTestResult(msg, stream); sendErr != nil { |
| 890 | onuLogger.WithFields(log.Fields{ |
| 891 | "IntfId": o.PonPortID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 892 | "OnuId": o.ID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 893 | "SerialNumber": o.Sn(), |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 894 | "omciPacket": msg.OmciPkt.Data(), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 895 | "msg": msg, |
| 896 | "err": sendErr, |
| 897 | }).Error("send-TestResult-indication-failed") |
| 898 | } |
| 899 | } |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 900 | case omci.SynchronizeTimeRequestType: |
| 901 | // MDS counter increment is not required for this message type |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 902 | responsePkt, _ = omcilib.CreateSyncTimeResponse(msg.OmciPkt, msg.OmciMsg) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 903 | case omci.StartSoftwareDownloadRequestType: |
| 904 | |
| 905 | o.ImageSoftwareReceivedSections = 0 |
| 906 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 907 | o.ImageSoftwareExpectedSections = omcilib.ComputeDownloadSectionsCount(msg.OmciPkt) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 908 | |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 909 | if responsePkt, errResp = omcilib.CreateStartSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 910 | o.MibDataSync++ |
| 911 | if err := o.InternalState.Event(OnuTxStartImageDownload); err != nil { |
| 912 | onuLogger.WithFields(log.Fields{ |
| 913 | "OnuId": o.ID, |
| 914 | "IntfId": o.PonPortID, |
| 915 | "OnuSn": o.Sn(), |
| 916 | "Err": err.Error(), |
| 917 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadStarted) |
| 918 | } |
| 919 | } else { |
| 920 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 921 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 922 | "TransCorrId": msg.OmciMsg.TransactionID, |
| 923 | "Err": errResp.Error(), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 924 | "IntfId": o.PonPortID, |
| 925 | "SerialNumber": o.Sn(), |
| 926 | }).Error("error-while-processing-start-software-download-request") |
| 927 | } |
| 928 | case omci.DownloadSectionRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 929 | if msgObj, err := omcilib.ParseDownloadSectionRequest(msg.OmciPkt); err == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 930 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 931 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 932 | "TransCorrId": msg.OmciMsg.TransactionID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 933 | "EntityInstance": msgObj.EntityInstance, |
| 934 | "SectionNumber": msgObj.SectionNumber, |
| 935 | "SectionData": msgObj.SectionData, |
| 936 | }).Trace("received-download-section-request") |
| 937 | o.ImageSoftwareReceivedSections++ |
| 938 | if o.InternalState.Current() != OnuStateImageDownloadInProgress { |
| 939 | if err := o.InternalState.Event(OnuTxProgressImageDownload); err != nil { |
| 940 | onuLogger.WithFields(log.Fields{ |
| 941 | "OnuId": o.ID, |
| 942 | "IntfId": o.PonPortID, |
| 943 | "OnuSn": o.Sn(), |
| 944 | "Err": err.Error(), |
| 945 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadInProgress) |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | case omci.DownloadSectionRequestWithResponseType: |
| 950 | // NOTE we only need to respond if an ACK is requested |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 951 | responsePkt, errResp = omcilib.CreateDownloadSectionResponse(msg.OmciPkt, msg.OmciMsg) |
| 952 | if errResp != nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 953 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 954 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 955 | "TransCorrId": msg.OmciMsg.TransactionID, |
| 956 | "Err": errResp.Error(), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 957 | "IntfId": o.PonPortID, |
| 958 | "SerialNumber": o.Sn(), |
| 959 | }).Error("error-while-processing-create-download-section-response") |
| 960 | return |
| 961 | } |
| 962 | o.ImageSoftwareReceivedSections++ |
| 963 | |
| 964 | case omci.EndSoftwareDownloadRequestType: |
| 965 | |
| 966 | // In the startSoftwareDownload we get the image size and the window size. |
| 967 | // We calculate how many DownloadSection we should receive and validate |
| 968 | // that we got the correct amount when we receive this message |
| 969 | success := true |
| 970 | if o.ImageSoftwareExpectedSections != o.ImageSoftwareReceivedSections { |
| 971 | onuLogger.WithFields(log.Fields{ |
| 972 | "OnuId": o.ID, |
| 973 | "IntfId": o.PonPortID, |
| 974 | "OnuSn": o.Sn(), |
| 975 | "ExpectedSections": o.ImageSoftwareExpectedSections, |
| 976 | "ReceivedSections": o.ImageSoftwareReceivedSections, |
| 977 | }).Errorf("onu-did-not-receive-all-image-sections") |
| 978 | success = false |
| 979 | } |
| 980 | |
| 981 | if success { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 982 | if responsePkt, errResp = omcilib.CreateEndSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg, me.Success); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 983 | o.MibDataSync++ |
| 984 | if err := o.InternalState.Event(OnuTxCompleteImageDownload); err != nil { |
| 985 | onuLogger.WithFields(log.Fields{ |
| 986 | "OnuId": o.ID, |
| 987 | "IntfId": o.PonPortID, |
| 988 | "OnuSn": o.Sn(), |
| 989 | "Err": err.Error(), |
| 990 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadComplete) |
| 991 | } |
| 992 | } else { |
| 993 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 994 | "OmciMsgType": msg.OmciMsg.MessageType, |
| 995 | "TransCorrId": msg.OmciMsg.TransactionID, |
| 996 | "Err": errResp.Error(), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 997 | "IntfId": o.PonPortID, |
| 998 | "SerialNumber": o.Sn(), |
| 999 | }).Error("error-while-processing-end-software-download-request") |
| 1000 | } |
| 1001 | } else { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1002 | if responsePkt, errResp = omcilib.CreateEndSoftwareDownloadResponse(msg.OmciPkt, msg.OmciMsg, me.ProcessingError); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1003 | if err := o.InternalState.Event(OnuTxFailImageDownload); err != nil { |
| 1004 | onuLogger.WithFields(log.Fields{ |
| 1005 | "OnuId": o.ID, |
| 1006 | "IntfId": o.PonPortID, |
| 1007 | "OnuSn": o.Sn(), |
| 1008 | "Err": err.Error(), |
| 1009 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageDownloadError) |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | case omci.ActivateSoftwareRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1015 | if responsePkt, errResp = omcilib.CreateActivateSoftwareResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1016 | o.MibDataSync++ |
| 1017 | if err := o.InternalState.Event(OnuTxActivateImage); err != nil { |
| 1018 | onuLogger.WithFields(log.Fields{ |
| 1019 | "OnuId": o.ID, |
| 1020 | "IntfId": o.PonPortID, |
| 1021 | "OnuSn": o.Sn(), |
| 1022 | "Err": err.Error(), |
| 1023 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageActivated) |
| 1024 | } |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1025 | if msgObj, err := omcilib.ParseActivateSoftwareRequest(msg.OmciPkt); err == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1026 | o.ActiveImageEntityId = msgObj.EntityInstance |
| 1027 | } else { |
| 1028 | onuLogger.Errorf("something-went-wrong-while-activating: %s", err) |
| 1029 | } |
| 1030 | onuLogger.WithFields(log.Fields{ |
| 1031 | "OnuId": o.ID, |
| 1032 | "IntfId": o.PonPortID, |
| 1033 | "OnuSn": o.Sn(), |
| 1034 | "ActiveImageEntityId": o.ActiveImageEntityId, |
| 1035 | "CommittedImageEntityId": o.CommittedImageEntityId, |
| 1036 | }).Info("onu-software-image-activated") |
| 1037 | |
| 1038 | // powercycle the ONU |
| 1039 | // we run this in a separate goroutine so that |
| 1040 | // the ActivateSoftwareResponse is sent to VOLTHA |
| 1041 | // NOTE do we need to wait before rebooting? |
| 1042 | go func() { |
| 1043 | if err := o.Reboot(10 * time.Second); err != nil { |
| 1044 | log.WithFields(log.Fields{ |
| 1045 | "IntfId": o.PonPortID, |
| 1046 | "OnuId": o.ID, |
| 1047 | "SerialNumber": o.Sn(), |
| 1048 | "err": err, |
| 1049 | }).Error("cannot-reboot-onu-after-omci-activate-software-request") |
| 1050 | } |
| 1051 | }() |
| 1052 | } |
| 1053 | case omci.CommitSoftwareRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1054 | if responsePkt, errResp = omcilib.CreateCommitSoftwareResponse(msg.OmciPkt, msg.OmciMsg); errResp == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1055 | o.MibDataSync++ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1056 | if msgObj, err := omcilib.ParseCommitSoftwareRequest(msg.OmciPkt); err == nil { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1057 | // TODO validate that the image to commit is: |
| 1058 | // - active |
| 1059 | // - not already committed |
| 1060 | o.CommittedImageEntityId = msgObj.EntityInstance |
| 1061 | } else { |
| 1062 | onuLogger.Errorf("something-went-wrong-while-committing: %s", err) |
| 1063 | } |
| 1064 | if err := o.InternalState.Event(OnuTxCommitImage); err != nil { |
| 1065 | onuLogger.WithFields(log.Fields{ |
| 1066 | "OnuId": o.ID, |
| 1067 | "IntfId": o.PonPortID, |
| 1068 | "OnuSn": o.Sn(), |
| 1069 | "Err": err.Error(), |
| 1070 | }).Errorf("cannot-change-onu-internal-state-to-%s", OnuStateImageCommitted) |
| 1071 | } |
| 1072 | onuLogger.WithFields(log.Fields{ |
| 1073 | "OnuId": o.ID, |
| 1074 | "IntfId": o.PonPortID, |
| 1075 | "OnuSn": o.Sn(), |
| 1076 | "ActiveImageEntityId": o.ActiveImageEntityId, |
| 1077 | "CommittedImageEntityId": o.CommittedImageEntityId, |
| 1078 | }).Info("onu-software-image-committed") |
| 1079 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1080 | case omci.GetAllAlarmsRequestType: |
| 1081 | // Reset the alarm sequence number on receiving get all alarms request. |
| 1082 | o.onuAlarmsInfoLock.Lock() |
| 1083 | for key, alarmInfo := range o.onuAlarmsInfo { |
| 1084 | // reset the alarm sequence no |
| 1085 | alarmInfo.SequenceNo = 0 |
| 1086 | o.onuAlarmsInfo[key] = alarmInfo |
| 1087 | } |
| 1088 | o.onuAlarmsInfoLock.Unlock() |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1089 | responsePkt, _ = omcilib.CreateGetAllAlarmsResponse(msg.OmciMsg.TransactionID, o.onuAlarmsInfo) |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1090 | case omci.GetAllAlarmsNextRequestType: |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1091 | if responsePkt, errResp = omcilib.CreateGetAllAlarmsNextResponse(msg.OmciPkt, msg.OmciMsg, o.onuAlarmsInfo); errResp != nil { |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1092 | responsePkt = nil //Do not send any response for error case |
| 1093 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1094 | default: |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1095 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1096 | "omciBytes": hex.EncodeToString(msg.OmciPkt.Data()), |
| 1097 | "omciPkt": msg.OmciPkt, |
| 1098 | "omciMsgType": msg.OmciMsg.MessageType, |
| 1099 | "transCorrId": msg.OmciMsg.TransactionID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1100 | "IntfId": o.PonPortID, |
| 1101 | "SerialNumber": o.Sn(), |
| 1102 | }).Warnf("OMCI-message-not-supported") |
| 1103 | } |
| 1104 | |
| 1105 | if responsePkt != nil { |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1106 | if err := o.sendOmciIndication(responsePkt, msg.OmciMsg.TransactionID, stream); err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1107 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | b591314 | 2021-03-19 16:10:18 -0700 | [diff] [blame^] | 1108 | "IntfId": o.PonPortID, |
| 1109 | "SerialNumber": o.Sn(), |
| 1110 | "omciPacket": responsePkt, |
| 1111 | "msg.OmciMsgType": msg.OmciMsg.MessageType, |
| 1112 | "transCorrId": msg.OmciMsg.TransactionID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1113 | }).Errorf("failed-to-send-omci-message: %v", err) |
| 1114 | } |
| 1115 | } |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1116 | |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1117 | o.publishOmciEvent(msg) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1118 | } |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 1119 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1120 | // sendOmciIndication takes an OMCI packet and sends it up to VOLTHA |
| 1121 | func (o *Onu) sendOmciIndication(responsePkt []byte, txId uint16, stream bbsim.Stream) error { |
| 1122 | indication := &openolt.Indication_OmciInd{ |
| 1123 | OmciInd: &openolt.OmciIndication{ |
| 1124 | IntfId: o.PonPortID, |
| 1125 | OnuId: o.ID, |
| 1126 | Pkt: responsePkt, |
| 1127 | }, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1128 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1129 | if err := stream.Send(&openolt.Indication{Data: indication}); err != nil { |
| 1130 | return fmt.Errorf("failed-to-send-omci-message: %v", err) |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1131 | } |
| 1132 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1133 | "IntfId": o.PonPortID, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1134 | "SerialNumber": o.Sn(), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1135 | "omciPacket": indication.OmciInd.Pkt, |
| 1136 | "transCorrId": txId, |
| 1137 | }).Trace("omci-message-sent") |
| 1138 | return nil |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1141 | func (o *Onu) storePortNumber(portNo uint32) { |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1142 | // NOTE this needed only as long as we don't support multiple UNIs |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1143 | // we need to add support for multiple UNIs |
| 1144 | // the action plan is: |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1145 | // - refactor the omcisim-sim library to use https://github.com/cboling/omci instead of canned messages |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1146 | // - change the library so that it reports a single UNI and remove this workaroung |
| 1147 | // - add support for multiple UNIs in BBSim |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1148 | if o.PortNo == 0 || portNo < o.PortNo { |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1149 | onuLogger.WithFields(log.Fields{ |
| 1150 | "IntfId": o.PonPortID, |
| 1151 | "OnuId": o.ID, |
| 1152 | "SerialNumber": o.Sn(), |
| 1153 | "OnuPortNo": o.PortNo, |
| 1154 | "FlowPortNo": portNo, |
| 1155 | }).Debug("Storing ONU portNo") |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1156 | o.PortNo = portNo |
| 1157 | } |
| 1158 | } |
| 1159 | |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 1160 | func (o *Onu) SetID(id uint32) { |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 1161 | onuLogger.WithFields(log.Fields{ |
| 1162 | "IntfId": o.PonPortID, |
| 1163 | "OnuId": id, |
| 1164 | "SerialNumber": o.Sn(), |
| 1165 | }).Debug("Storing OnuId ") |
William Kurkian | 0418bc8 | 2019-11-06 12:16:24 -0500 | [diff] [blame] | 1166 | o.ID = id |
| 1167 | } |
| 1168 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1169 | func (o *Onu) handleFlowAdd(msg bbsim.OnuFlowUpdateMessage) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1170 | onuLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1171 | "AllocId": msg.Flow.AllocId, |
Matteo Scandolo | edf30c7 | 2020-09-18 18:15:28 -0700 | [diff] [blame] | 1172 | "Cookie": msg.Flow.Cookie, |
| 1173 | "DstPort": msg.Flow.Classifier.DstPort, |
| 1174 | "FlowId": msg.Flow.FlowId, |
| 1175 | "FlowType": msg.Flow.FlowType, |
| 1176 | "GemportId": msg.Flow.GemportId, |
| 1177 | "InnerVlan": msg.Flow.Classifier.IVid, |
| 1178 | "IntfId": msg.Flow.AccessIntfId, |
| 1179 | "IpProto": msg.Flow.Classifier.IpProto, |
| 1180 | "OnuId": msg.Flow.OnuId, |
| 1181 | "OnuSn": o.Sn(), |
| 1182 | "OuterVlan": msg.Flow.Classifier.OVid, |
| 1183 | "PortNo": msg.Flow.PortNo, |
| 1184 | "SrcPort": msg.Flow.Classifier.SrcPort, |
| 1185 | "UniID": msg.Flow.UniId, |
| 1186 | "ClassifierEthType": fmt.Sprintf("%x", msg.Flow.Classifier.EthType), |
| 1187 | "ClassifierOPbits": msg.Flow.Classifier.OPbits, |
| 1188 | "ClassifierIVid": msg.Flow.Classifier.IVid, |
| 1189 | "ClassifierOVid": msg.Flow.Classifier.OVid, |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1190 | "ReplicateFlow": msg.Flow.ReplicateFlow, |
| 1191 | "PbitToGemport": msg.Flow.PbitToGemport, |
Matteo Scandolo | edf30c7 | 2020-09-18 18:15:28 -0700 | [diff] [blame] | 1192 | }).Debug("OLT receives FlowAdd for ONU") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1193 | |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1194 | if msg.Flow.UniId != 0 { |
| 1195 | // as of now BBSim only support a single UNI, so ignore everything that is not targeted to it |
| 1196 | onuLogger.WithFields(log.Fields{ |
| 1197 | "IntfId": o.PonPortID, |
| 1198 | "OnuId": o.ID, |
| 1199 | "SerialNumber": o.Sn(), |
| 1200 | }).Debug("Ignoring flow as it's not for the first UNI") |
| 1201 | return |
| 1202 | } |
| 1203 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1204 | o.FlowIds = append(o.FlowIds, msg.Flow.FlowId) |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1205 | |
| 1206 | var gemPortId uint32 |
| 1207 | if msg.Flow.ReplicateFlow { |
| 1208 | // This means that the OLT should replicate the flow for each PBIT, for BBSim it's enough to use the |
| 1209 | // first available gemport (we only need to send one packet) |
| 1210 | // NOTE different TP may create different mapping between PBits and GemPorts, this may require some changes |
| 1211 | gemPortId = msg.Flow.PbitToGemport[0] |
| 1212 | } else { |
| 1213 | // if replicateFlows is false, then the flow is carrying the correct GemPortId |
| 1214 | gemPortId = uint32(msg.Flow.GemportId) |
| 1215 | } |
| 1216 | o.addGemPortToService(gemPortId, msg.Flow.Classifier.EthType, msg.Flow.Classifier.OVid, msg.Flow.Classifier.IVid) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1217 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1218 | if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) && msg.Flow.Classifier.OVid == 4091 { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 1219 | // NOTE storing the PortNO, it's needed when sending PacketIndications |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1220 | o.storePortNumber(uint32(msg.Flow.PortNo)) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1221 | |
| 1222 | for _, s := range o.Services { |
Matteo Scandolo | adc72a8 | 2020-09-08 18:46:08 -0700 | [diff] [blame] | 1223 | s.HandleAuth() |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1224 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1225 | } else if msg.Flow.Classifier.EthType == uint32(layers.EthernetTypeIPv4) && |
| 1226 | msg.Flow.Classifier.SrcPort == uint32(68) && |
Matteo Scandolo | bd875b3 | 2020-09-18 17:46:31 -0700 | [diff] [blame] | 1227 | msg.Flow.Classifier.DstPort == uint32(67) { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 1228 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1229 | for _, s := range o.Services { |
Matteo Scandolo | bd875b3 | 2020-09-18 17:46:31 -0700 | [diff] [blame] | 1230 | s.HandleDhcp(uint8(msg.Flow.Classifier.OPbits), int(msg.Flow.Classifier.OVid)) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 1231 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1235 | func (o *Onu) handleFlowRemove(msg bbsim.OnuFlowUpdateMessage) { |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1236 | onuLogger.WithFields(log.Fields{ |
| 1237 | "IntfId": o.PonPortID, |
| 1238 | "OnuId": o.ID, |
| 1239 | "SerialNumber": o.Sn(), |
| 1240 | "FlowId": msg.Flow.FlowId, |
| 1241 | "FlowType": msg.Flow.FlowType, |
| 1242 | }).Debug("ONU receives FlowRemove") |
| 1243 | |
| 1244 | for idx, flow := range o.FlowIds { |
| 1245 | // If the gemport is found, delete it from local cache. |
| 1246 | if flow == msg.Flow.FlowId { |
| 1247 | o.FlowIds = append(o.FlowIds[:idx], o.FlowIds[idx+1:]...) |
| 1248 | break |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | if len(o.FlowIds) == 0 { |
| 1253 | onuLogger.WithFields(log.Fields{ |
| 1254 | "IntfId": o.PonPortID, |
| 1255 | "OnuId": o.ID, |
| 1256 | "SerialNumber": o.Sn(), |
| 1257 | }).Info("Resetting GemPort") |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1258 | |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1259 | // check if ONU delete is performed and |
| 1260 | // terminate the ONU's ProcessOnuMessages Go routine |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1261 | if o.InternalState.Current() == OnuStateDisabled { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1262 | close(o.Channel) |
| 1263 | } |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1267 | func (o *Onu) Reboot(timeout time.Duration) error { |
| 1268 | onuLogger.WithFields(log.Fields{ |
| 1269 | "IntfId": o.PonPortID, |
| 1270 | "OnuId": o.ID, |
| 1271 | "SerialNumber": o.Sn(), |
| 1272 | }).Debug("shutting-down-onu") |
| 1273 | if err := o.HandleShutdownONU(); err != nil { |
| 1274 | return err |
| 1275 | } |
| 1276 | time.Sleep(timeout) |
| 1277 | onuLogger.WithFields(log.Fields{ |
| 1278 | "IntfId": o.PonPortID, |
| 1279 | "OnuId": o.ID, |
| 1280 | "SerialNumber": o.Sn(), |
| 1281 | }).Debug("power-on-onu") |
| 1282 | if err := o.HandlePowerOnONU(); err != nil { |
| 1283 | return err |
| 1284 | } |
| 1285 | return nil |
| 1286 | } |
| 1287 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1288 | // BBR methods |
| 1289 | |
| 1290 | func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) { |
| 1291 | omciMsg := openolt.OmciMsg{ |
| 1292 | IntfId: intfId, |
| 1293 | OnuId: onuId, |
| 1294 | Pkt: pktBytes, |
| 1295 | } |
| 1296 | |
| 1297 | if _, err := client.OmciMsgOut(context.Background(), &omciMsg); err != nil { |
| 1298 | log.WithFields(log.Fields{ |
| 1299 | "IntfId": intfId, |
| 1300 | "OnuId": onuId, |
| 1301 | "SerialNumber": common.OnuSnToString(sn), |
| 1302 | "Pkt": omciMsg.Pkt, |
| 1303 | }).Fatalf("Failed to send MIB Reset") |
| 1304 | } |
| 1305 | log.WithFields(log.Fields{ |
| 1306 | "IntfId": intfId, |
| 1307 | "OnuId": onuId, |
| 1308 | "SerialNumber": common.OnuSnToString(sn), |
| 1309 | "Pkt": omciMsg.Pkt, |
| 1310 | }).Tracef("Sent OMCI message %s", msgType) |
| 1311 | } |
| 1312 | |
| 1313 | func (onu *Onu) getNextTid(highPriority ...bool) uint16 { |
| 1314 | var next uint16 |
| 1315 | if len(highPriority) > 0 && highPriority[0] { |
| 1316 | next = onu.hpTid |
| 1317 | onu.hpTid += 1 |
| 1318 | if onu.hpTid < 0x8000 { |
| 1319 | onu.hpTid = 0x8000 |
| 1320 | } |
| 1321 | } else { |
| 1322 | next = onu.tid |
| 1323 | onu.tid += 1 |
| 1324 | if onu.tid >= 0x8000 { |
| 1325 | onu.tid = 1 |
| 1326 | } |
| 1327 | } |
| 1328 | return next |
| 1329 | } |
| 1330 | |
| 1331 | // TODO move this method in responders/omcisim |
| 1332 | func (o *Onu) StartOmci(client openolt.OpenoltClient) { |
| 1333 | mibReset, _ := omcilib.CreateMibResetRequest(o.getNextTid(false)) |
| 1334 | sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client) |
| 1335 | } |
| 1336 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1337 | // handleOmciResponse is used in BBR to generate the OMCI packets the openolt-adapter would send to the device |
| 1338 | func (o *Onu) handleOmciResponse(msg bbsim.OmciIndicationMessage, client openolt.OpenoltClient) { |
| 1339 | |
| 1340 | // we need to encode the packet in HEX |
| 1341 | pkt := make([]byte, len(msg.OmciInd.Pkt)*2) |
| 1342 | hex.Encode(pkt, msg.OmciInd.Pkt) |
| 1343 | packet, omciMsg, err := omcilib.ParseOpenOltOmciPacket(pkt) |
| 1344 | if err != nil { |
| 1345 | log.WithFields(log.Fields{ |
| 1346 | "IntfId": o.PonPortID, |
| 1347 | "SerialNumber": o.Sn(), |
| 1348 | "omciPacket": msg.OmciInd.Pkt, |
| 1349 | }).Error("BBR Cannot parse OMCI packet") |
| 1350 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1351 | |
| 1352 | log.WithFields(log.Fields{ |
| 1353 | "IntfId": msg.OmciInd.IntfId, |
| 1354 | "OnuId": msg.OmciInd.OnuId, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1355 | "OnuSn": o.Sn(), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1356 | "Pkt": msg.OmciInd.Pkt, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1357 | "msgType": omciMsg.MessageType, |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 1358 | }).Trace("ONU Receives OMCI Msg") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1359 | switch omciMsg.MessageType { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1360 | default: |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1361 | log.WithFields(log.Fields{ |
| 1362 | "IntfId": msg.OmciInd.IntfId, |
| 1363 | "OnuId": msg.OmciInd.OnuId, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1364 | "OnuSn": o.Sn(), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1365 | "Pkt": msg.OmciInd.Pkt, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1366 | "msgType": omciMsg.MessageType, |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1367 | }).Fatalf("unexpected frame: %v", packet) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1368 | case omci.MibResetResponseType: |
| 1369 | mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false)) |
| 1370 | sendOmciMsg(mibUpload, o.PonPortID, o.ID, o.SerialNumber, "mibUpload", client) |
| 1371 | case omci.MibUploadResponseType: |
| 1372 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 1373 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
| 1374 | case omci.MibUploadNextResponseType: |
| 1375 | o.seqNumber++ |
| 1376 | |
| 1377 | if o.seqNumber > 290 { |
| 1378 | // NOTE we are done with the MIB Upload (290 is the number of messages the omci-sim library will respond to) |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1379 | // start sending the flows, we don't care about the OMCI setup in BBR, just that a lot of messages can go through |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1380 | if err := o.InternalState.Event(BbrOnuTxSendEapolFlow); err != nil { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1381 | onuLogger.WithFields(log.Fields{ |
| 1382 | "OnuId": o.ID, |
| 1383 | "IntfId": o.PonPortID, |
| 1384 | "OnuSn": o.Sn(), |
| 1385 | }).Errorf("Error while transitioning ONU State %v", err) |
| 1386 | } |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1387 | } else { |
| 1388 | mibUploadNext, _ := omcilib.CreateMibUploadNextRequest(o.getNextTid(false), o.seqNumber) |
| 1389 | sendOmciMsg(mibUploadNext, o.PonPortID, o.ID, o.SerialNumber, "mibUploadNext", client) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1390 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | func (o *Onu) sendEapolFlow(client openolt.OpenoltClient) { |
| 1395 | |
| 1396 | classifierProto := openolt.Classifier{ |
| 1397 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 1398 | OVid: 4091, |
| 1399 | } |
| 1400 | |
| 1401 | actionProto := openolt.Action{} |
| 1402 | |
| 1403 | downstreamFlow := openolt.Flow{ |
| 1404 | AccessIntfId: int32(o.PonPortID), |
| 1405 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1406 | UniId: int32(0), // NOTE do not hardcode this, we need to support multiple UNIs |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1407 | FlowId: uint64(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1408 | FlowType: "downstream", |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1409 | NetworkIntfId: int32(0), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1410 | Classifier: &classifierProto, |
| 1411 | Action: &actionProto, |
| 1412 | Priority: int32(100), |
| 1413 | Cookie: uint64(o.ID), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1414 | PortNo: o.ID, // NOTE we are using this to map an incoming packetIndication to an ONU |
| 1415 | // AllocId and GemPorts need to be unique per PON |
| 1416 | // for now use the ONU-ID, will need to change once we support multiple UNIs |
| 1417 | AllocId: int32(o.ID), |
| 1418 | GemportId: int32(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 1422 | log.WithFields(log.Fields{ |
| 1423 | "IntfId": o.PonPortID, |
| 1424 | "OnuId": o.ID, |
| 1425 | "FlowId": downstreamFlow.FlowId, |
| 1426 | "PortNo": downstreamFlow.PortNo, |
| 1427 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1428 | "Err": err, |
Matteo Scandolo | b0e3e62 | 2020-04-23 17:00:29 -0700 | [diff] [blame] | 1429 | }).Fatalf("Failed to add EAPOL Flow") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1430 | } |
| 1431 | log.WithFields(log.Fields{ |
| 1432 | "IntfId": o.PonPortID, |
| 1433 | "OnuId": o.ID, |
| 1434 | "FlowId": downstreamFlow.FlowId, |
| 1435 | "PortNo": downstreamFlow.PortNo, |
| 1436 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 1437 | }).Info("Sent EAPOL Flow") |
| 1438 | } |
| 1439 | |
| 1440 | func (o *Onu) sendDhcpFlow(client openolt.OpenoltClient) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1441 | |
| 1442 | // BBR only works with a single service (ATT HSIA) |
| 1443 | hsia := o.Services[0].(*Service) |
| 1444 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1445 | classifierProto := openolt.Classifier{ |
| 1446 | EthType: uint32(layers.EthernetTypeIPv4), |
| 1447 | SrcPort: uint32(68), |
| 1448 | DstPort: uint32(67), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1449 | OVid: uint32(hsia.CTag), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | actionProto := openolt.Action{} |
| 1453 | |
| 1454 | downstreamFlow := openolt.Flow{ |
| 1455 | AccessIntfId: int32(o.PonPortID), |
| 1456 | OnuId: int32(o.ID), |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1457 | UniId: int32(0), // FIXME do not hardcode this |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 1458 | FlowId: uint64(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1459 | FlowType: "downstream", |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1460 | NetworkIntfId: int32(0), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1461 | Classifier: &classifierProto, |
| 1462 | Action: &actionProto, |
| 1463 | Priority: int32(100), |
| 1464 | Cookie: uint64(o.ID), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1465 | PortNo: o.ID, // NOTE we are using this to map an incoming packetIndication to an ONU |
| 1466 | // AllocId and GemPorts need to be unique per PON |
| 1467 | // for now use the ONU-ID, will need to change once we support multiple UNIs |
| 1468 | AllocId: int32(o.ID), |
| 1469 | GemportId: int32(o.ID), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | if _, err := client.FlowAdd(context.Background(), &downstreamFlow); err != nil { |
| 1473 | log.WithFields(log.Fields{ |
| 1474 | "IntfId": o.PonPortID, |
| 1475 | "OnuId": o.ID, |
| 1476 | "FlowId": downstreamFlow.FlowId, |
| 1477 | "PortNo": downstreamFlow.PortNo, |
| 1478 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
Matteo Scandolo | 4b077aa | 2021-02-16 17:33:37 -0800 | [diff] [blame] | 1479 | "Err": err, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1480 | }).Fatalf("Failed to send DHCP Flow") |
| 1481 | } |
| 1482 | log.WithFields(log.Fields{ |
| 1483 | "IntfId": o.PonPortID, |
| 1484 | "OnuId": o.ID, |
| 1485 | "FlowId": downstreamFlow.FlowId, |
| 1486 | "PortNo": downstreamFlow.PortNo, |
| 1487 | "SerialNumber": common.OnuSnToString(o.SerialNumber), |
| 1488 | }).Info("Sent DHCP Flow") |
| 1489 | } |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 1490 | |
| 1491 | // DeleteFlow method search and delete flowKey from the onu flows slice |
| 1492 | func (onu *Onu) DeleteFlow(key FlowKey) { |
| 1493 | for pos, flowKey := range onu.Flows { |
| 1494 | if flowKey == key { |
| 1495 | // delete the flowKey by shifting all flowKeys by one |
| 1496 | onu.Flows = append(onu.Flows[:pos], onu.Flows[pos+1:]...) |
| 1497 | t := make([]FlowKey, len(onu.Flows)) |
| 1498 | copy(t, onu.Flows) |
| 1499 | onu.Flows = t |
| 1500 | break |
| 1501 | } |
| 1502 | } |
| 1503 | } |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1504 | |
| 1505 | func (onu *Onu) ReDiscoverOnu() { |
| 1506 | // Wait for few seconds to be sure of the cleanup |
| 1507 | time.Sleep(5 * time.Second) |
| 1508 | |
| 1509 | onuLogger.WithFields(log.Fields{ |
| 1510 | "IntfId": onu.PonPortID, |
| 1511 | "OnuId": onu.ID, |
| 1512 | "OnuSn": onu.Sn(), |
| 1513 | }).Debug("Send ONU Re-Discovery") |
| 1514 | |
| 1515 | // ONU Re-Discovery |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1516 | if err := onu.InternalState.Event(OnuTxInitialize); err != nil { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1517 | log.WithFields(log.Fields{ |
| 1518 | "IntfId": onu.PonPortID, |
| 1519 | "OnuSn": onu.Sn(), |
| 1520 | "OnuId": onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1521 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateInitialized, err.Error()) |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1522 | } |
| 1523 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1524 | if err := onu.InternalState.Event(OnuTxDiscover); err != nil { |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1525 | log.WithFields(log.Fields{ |
| 1526 | "IntfId": onu.PonPortID, |
| 1527 | "OnuSn": onu.Sn(), |
| 1528 | "OnuId": onu.ID, |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 1529 | }).Infof("Failed to transition ONU to %s state: %s", OnuStateDiscovered, err.Error()) |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 1530 | } |
| 1531 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 1532 | |
| 1533 | func (onu *Onu) addGemPortToService(gemport uint32, ethType uint32, oVlan uint32, iVlan uint32) { |
| 1534 | for _, s := range onu.Services { |
| 1535 | if service, ok := s.(*Service); ok { |
| 1536 | // EAPOL is a strange case, as packets are untagged |
| 1537 | // but we assume we will have a single service requiring EAPOL |
| 1538 | if ethType == uint32(layers.EthernetTypeEAPOL) && service.NeedsEapol { |
| 1539 | service.GemPort = gemport |
| 1540 | } |
| 1541 | |
| 1542 | // For DHCP services we single tag the outgoing packets, |
| 1543 | // thus the flow only contains the CTag and we can use that to match the service |
| 1544 | if ethType == uint32(layers.EthernetTypeIPv4) && service.NeedsDhcp && service.CTag == int(oVlan) { |
| 1545 | service.GemPort = gemport |
| 1546 | } |
| 1547 | |
| 1548 | // for dataplane services match both C and S tags |
| 1549 | if service.CTag == int(iVlan) && service.STag == int(oVlan) { |
| 1550 | service.GemPort = gemport |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | func (onu *Onu) findServiceByMacAddress(macAddress net.HardwareAddr) (*Service, error) { |
| 1557 | for _, s := range onu.Services { |
| 1558 | service := s.(*Service) |
| 1559 | if service.HwAddress.String() == macAddress.String() { |
| 1560 | return service, nil |
| 1561 | } |
| 1562 | } |
| 1563 | return nil, fmt.Errorf("cannot-find-service-with-mac-address-%s", macAddress.String()) |
| 1564 | } |
Himani Chawla | 13b1ee0 | 2021-03-15 01:43:53 +0530 | [diff] [blame] | 1565 | |
| 1566 | func (o *Onu) SendOMCIAlarmNotificationMsg(raiseOMCIAlarm bool, alarmType string) { |
| 1567 | switch alarmType { |
| 1568 | case "ONU_ALARM_LOS": |
| 1569 | msg := bbsim.Message{ |
| 1570 | Type: bbsim.UniStatusAlarm, |
| 1571 | Data: bbsim.UniStatusAlarmMessage{ |
| 1572 | OnuSN: o.SerialNumber, |
| 1573 | OnuID: o.ID, |
| 1574 | EntityID: 257, |
| 1575 | RaiseOMCIAlarm: raiseOMCIAlarm, |
| 1576 | }, |
| 1577 | } |
| 1578 | o.Channel <- msg |
| 1579 | } |
| 1580 | |
| 1581 | } |
| 1582 | |
| 1583 | func (o *Onu) IncrementAlarmSequenceNumber(key omcilib.OnuAlarmInfoMapKey) uint8 { |
| 1584 | o.onuAlarmsInfoLock.Lock() |
| 1585 | defer o.onuAlarmsInfoLock.Unlock() |
| 1586 | if alarmInfo, ok := o.onuAlarmsInfo[key]; ok { |
| 1587 | if alarmInfo.SequenceNo == 255 { |
| 1588 | alarmInfo.SequenceNo = 1 |
| 1589 | } else { |
| 1590 | alarmInfo.SequenceNo++ |
| 1591 | } |
| 1592 | o.onuAlarmsInfo[key] = alarmInfo |
| 1593 | return alarmInfo.SequenceNo |
| 1594 | } else { |
| 1595 | // This is the first time alarm notification message is being sent |
| 1596 | o.onuAlarmsInfo[key] = omcilib.OnuAlarmInfo{ |
| 1597 | SequenceNo: 1, |
| 1598 | } |
| 1599 | return 1 |
| 1600 | } |
| 1601 | } |