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