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