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