Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package core |
| 18 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 19 | import ( |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 20 | "bytes" |
| 21 | "encoding/binary" |
| 22 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 23 | "context" |
| 24 | "errors" |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 25 | "time" |
| 26 | |
| 27 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 28 | "gerrit.opencord.org/voltha-bbsim/device" |
| 29 | "gerrit.opencord.org/voltha-bbsim/protos" |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 30 | ) |
| 31 | |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 32 | // |
| 33 | // OMCI definitions |
| 34 | // |
| 35 | |
| 36 | // OmciMsgType represents a OMCI message-type |
| 37 | type OmciMsgType byte |
| 38 | |
| 39 | const ( |
| 40 | // Message Types |
| 41 | _ = iota |
| 42 | Create OmciMsgType = 4 |
| 43 | Delete OmciMsgType = 6 |
| 44 | Set OmciMsgType = 8 |
| 45 | Get OmciMsgType = 9 |
| 46 | GetAllAlarms OmciMsgType = 11 |
| 47 | GetAllAlarmsNext OmciMsgType = 12 |
| 48 | MibUpload OmciMsgType = 13 |
| 49 | MibUploadNext OmciMsgType = 14 |
| 50 | MibReset OmciMsgType = 15 |
| 51 | AlarmNotification OmciMsgType = 16 |
| 52 | AttributeValueChange OmciMsgType = 17 |
| 53 | Test OmciMsgType = 18 |
| 54 | StartSoftwareDownload OmciMsgType = 19 |
| 55 | DownloadSection OmciMsgType = 20 |
| 56 | EndSoftwareDownload OmciMsgType = 21 |
| 57 | ActivateSoftware OmciMsgType = 22 |
| 58 | CommitSoftware OmciMsgType = 23 |
| 59 | SynchronizeTime OmciMsgType = 24 |
| 60 | Reboot OmciMsgType = 25 |
| 61 | GetNext OmciMsgType = 26 |
| 62 | TestResult OmciMsgType = 27 |
| 63 | GetCurrentData OmciMsgType = 28 |
| 64 | SetTable OmciMsgType = 29 // Defined in Extended Message Set Only |
| 65 | ) |
| 66 | |
| 67 | const ( |
| 68 | // Managed Entity Class values |
| 69 | GEMPortNetworkCTP OmciClass = 268 |
| 70 | ) |
| 71 | |
| 72 | // OMCI Managed Entity Class |
| 73 | type OmciClass uint16 |
| 74 | |
| 75 | // OMCI Message Identifier |
| 76 | type OmciMessageIdentifier struct { |
| 77 | Class OmciClass |
| 78 | Instance uint16 |
| 79 | } |
| 80 | |
| 81 | type OmciContent [32]byte |
| 82 | |
| 83 | type OmciMessage struct { |
| 84 | TransactionId uint16 |
| 85 | MessageType OmciMsgType |
| 86 | DeviceId uint8 |
| 87 | MessageId OmciMessageIdentifier |
| 88 | Content OmciContent |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 91 | const NumMibUploads byte = 18 |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 92 | |
| 93 | type OnuKey struct { |
| 94 | IntfId, OnuId uint32 |
| 95 | } |
| 96 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 97 | type OnuOmciState struct { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 98 | gemPortId uint16 |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 99 | mibUploadCtr uint16 |
| 100 | uniGInstance uint8 |
| 101 | pptpInstance uint8 |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 102 | init istate |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 105 | type istate int |
| 106 | |
| 107 | const ( |
| 108 | INCOMPLETE istate = iota |
| 109 | DONE |
| 110 | ) |
| 111 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 112 | type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 113 | |
| 114 | var Handlers = map[OmciMsgType]OmciMsgHandler{ |
| 115 | MibReset: mibReset, |
| 116 | MibUpload: mibUpload, |
| 117 | MibUploadNext: mibUploadNext, |
| 118 | Set: set, |
| 119 | Create: create, |
| 120 | Get: get, |
| 121 | GetAllAlarms: getAllAlarms, |
| 122 | } |
| 123 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 124 | var OnuOmciStateMap = map[OnuKey]*OnuOmciState{} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 125 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 126 | func OmciRun(ctx context.Context, omciOut chan openolt.OmciMsg, omciIn chan openolt.OmciIndication, onumap map[uint32][]*device.Onu, errch chan error) { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 127 | go func() { //For monitoring the OMCI states |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 128 | t := time.NewTicker(1 * time.Second) |
| 129 | defer t.Stop() |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 130 | for { |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 131 | select { |
| 132 | case <-t.C: |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 133 | logger.Debug("Monitor omci init state") |
| 134 | if isAllOmciInitDone(onumap) { |
| 135 | logger.Info("OmciRun - All the omci initialization wes done") |
| 136 | close(errch) |
| 137 | return |
| 138 | } |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 139 | case <-ctx.Done(): |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 140 | logger.Debug("Omci Monitoring process was done") |
| 141 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 142 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 143 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 144 | }() |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 145 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 146 | go func() { |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 147 | defer logger.Debug("Omci response process was done") |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 148 | for { |
| 149 | var resp openolt.OmciIndication |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 150 | select { |
| 151 | case m := <-omciOut: |
| 152 | transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt) |
| 153 | if err != nil { |
| 154 | errch <- err |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 155 | return |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 156 | } |
| 157 | |
| 158 | logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d", |
| 159 | transactionId, msgType, class, instance) |
| 160 | |
| 161 | key := OnuKey{m.IntfId, m.OnuId} |
| 162 | if _, ok := OnuOmciStateMap[key]; !ok { |
| 163 | OnuOmciStateMap[key] = NewOnuOmciState() |
| 164 | } |
| 165 | |
| 166 | if _, ok := Handlers[msgType]; !ok { |
| 167 | logger.Warn("Ignore omci msg (msgType %d not handled)", msgType) |
| 168 | continue |
| 169 | } |
| 170 | |
| 171 | resp.Pkt, err = Handlers[msgType](class, content, key) |
| 172 | if err != nil { |
| 173 | errch <- err |
| 174 | return |
| 175 | } |
| 176 | resp.Pkt[0] = byte(transactionId >> 8) |
| 177 | resp.Pkt[1] = byte(transactionId & 0xFF) |
| 178 | resp.Pkt[2] = 0x2<<4 | byte(msgType) |
| 179 | resp.Pkt[3] = deviceId |
| 180 | resp.IntfId = m.IntfId |
| 181 | resp.OnuId = m.OnuId |
| 182 | omciIn <- resp |
| 183 | case <-ctx.Done(): |
| 184 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 185 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 186 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 187 | }() |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 188 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 189 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 190 | func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 191 | var m OmciMessage |
| 192 | |
| 193 | r := bytes.NewReader(HexDecode(pkt)) |
| 194 | |
| 195 | if err := binary.Read(r, binary.BigEndian, &m); err != nil { |
| 196 | logger.Error("binary.Read failed: %s", err) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 197 | return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed") |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 198 | } |
| 199 | logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x", |
| 200 | m.TransactionId, m.MessageType&0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 201 | return m.TransactionId, m.DeviceId, m.MessageType & 0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | func HexDecode(pkt []byte) []byte { |
| 205 | // Convert the hex encoding to binary |
| 206 | // TODO - Change openolt adapter to send raw binary instead of hex encoded |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 207 | p := make([]byte, len(pkt)/2) |
| 208 | for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 209 | // Go figure this ;) |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 210 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 211 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 212 | p[j] = u<<4 + l |
| 213 | } |
| 214 | logger.Debug("Omci decoded: %x.", p) |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 215 | return p |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 218 | func NewOnuOmciState() *OnuOmciState { |
| 219 | return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, pptpInstance: 1} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 222 | func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 223 | var pkt []byte |
| 224 | |
| 225 | logger.Debug("Omci MibReset") |
| 226 | |
| 227 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 228 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 229 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 230 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 231 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 232 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 233 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 234 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 237 | func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 238 | var pkt []byte |
| 239 | |
| 240 | logger.Debug("Omci MibUpload") |
| 241 | |
| 242 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 243 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 244 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 245 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 246 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 247 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 249 | |
| 250 | pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds |
| 251 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 252 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 255 | func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 256 | var pkt []byte |
| 257 | |
| 258 | logger.Debug("Omci MibUploadNext") |
| 259 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 260 | state := OnuOmciStateMap[key] |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 261 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 262 | switch state.mibUploadCtr { |
| 263 | case 0: |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 264 | // ONT Data (2) |
| 265 | pkt = []byte{ |
| 266 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 267 | 0x00, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, |
| 268 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 269 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 270 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 271 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 272 | case 1: |
| 273 | // Circuit Pack (6) - #1 |
| 274 | pkt = []byte{ |
| 275 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 276 | 0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04, |
| 277 | 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80, |
| 278 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 279 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 281 | case 2: |
| 282 | // Circuit Pack (6) - #2 |
| 283 | pkt = []byte{ |
| 284 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 285 | 0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52, |
| 286 | 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 287 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 288 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 289 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 290 | case 3: |
| 291 | // Circuit Pack (6) - #3 |
| 292 | pkt = []byte{ |
| 293 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 294 | 0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20, |
| 295 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 296 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 297 | 0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 298 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 299 | case 4: |
| 300 | // Circuit Pack (6) - #4 |
| 301 | pkt = []byte{ |
| 302 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 303 | 0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 0x00, 0x00, |
| 304 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 305 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 306 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 307 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 308 | case 5: |
| 309 | // Circuit Pack (6) - #5 |
| 310 | pkt = []byte{ |
| 311 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 312 | 0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01, |
| 313 | 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80, |
| 314 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 315 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 316 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 317 | case 6: |
| 318 | // Circuit Pack (6) - #6 |
| 319 | pkt = []byte{ |
| 320 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 321 | 0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52, |
| 322 | 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 323 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 324 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 325 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 326 | case 7: |
| 327 | // Circuit Pack (6) - #7 |
| 328 | pkt = []byte{ |
| 329 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 330 | 0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20, |
| 331 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 332 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 333 | 0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00, |
| 334 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 335 | case 8: |
| 336 | // Circuit Pack (6) - #8 |
| 337 | pkt = []byte{ |
| 338 | 0x00, 0x0f, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00, |
| 339 | 0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00, |
| 340 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 341 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 342 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 343 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 344 | case 9: |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 345 | // ANI-G |
| 346 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 347 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 348 | 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00, |
| 349 | 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00, |
| 350 | 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c, |
| 351 | 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 352 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 353 | case 10, 11, 12, 13: |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 354 | // UNI-G |
| 355 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 356 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 357 | 0x01, 0x08, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x00, |
| 358 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 359 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 360 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 361 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 362 | pkt[11] = state.uniGInstance // ME Instance |
| 363 | state.uniGInstance++ |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 364 | case 14, 15, 16, 17: |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 365 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 366 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 367 | 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f, |
| 368 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00, |
| 369 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 370 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 371 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 372 | pkt[11] = state.pptpInstance // ME Instance |
| 373 | state.pptpInstance++ |
| 374 | default: |
| 375 | logger.Error("Invalid MibUpload request %d", state.mibUploadCtr) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 376 | return nil, errors.New("Invalid MibUpload request") |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | state.mibUploadCtr++ |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 380 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 383 | func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 384 | var pkt []byte |
| 385 | |
| 386 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 387 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 388 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 389 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 390 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 391 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 392 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 393 | |
| 394 | logger.Debug("Omci Set") |
| 395 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 396 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 399 | func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 400 | var pkt []byte |
| 401 | |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 402 | if class == GEMPortNetworkCTP { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 403 | if onuOmciState, ok := OnuOmciStateMap[key]; !ok { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 404 | logger.Error("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 405 | return nil, errors.New("ONU Key Error") |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 406 | } else { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 407 | onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2]) |
| 408 | logger.Debug("Gem Port Id %d", onuOmciState.gemPortId) |
| 409 | OnuOmciStateMap[key].init = DONE |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 413 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 414 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 415 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 416 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 417 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 418 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 419 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 420 | |
| 421 | logger.Debug("Omci Create") |
| 422 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 423 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 426 | func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 427 | var pkt []byte |
| 428 | |
| 429 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 430 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 431 | 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 432 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 433 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 434 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 435 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 436 | |
| 437 | logger.Debug("Omci Get") |
| 438 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 439 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 440 | } |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 441 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 442 | func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 443 | var pkt []byte |
| 444 | |
| 445 | pkt = []byte{ |
| 446 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 447 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 448 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 449 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 450 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 451 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 452 | |
| 453 | logger.Debug("Omci GetAllAlarms") |
| 454 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 455 | return pkt, nil |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 456 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 457 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 458 | func isAllOmciInitDone(onumap map[uint32][]*device.Onu) bool { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 459 | for _, onus := range onumap { |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 460 | for _, onu := range onus { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 461 | key := OnuKey{onu.IntfID, onu.OnuID} |
| 462 | state := OnuOmciStateMap[key] |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame^] | 463 | if state.init == INCOMPLETE { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 464 | return false |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | return true |
| 469 | } |