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 | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 91 | const NumMibUploads byte = 26 |
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 | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 98 | gemPortId uint16 |
| 99 | mibUploadCtr uint16 |
| 100 | uniGInstance uint8 |
| 101 | tcontInstance uint8 |
| 102 | pptpInstance uint8 |
| 103 | init istate |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 106 | type istate int |
| 107 | |
| 108 | const ( |
| 109 | INCOMPLETE istate = iota |
| 110 | DONE |
| 111 | ) |
| 112 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 113 | type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 114 | |
| 115 | var Handlers = map[OmciMsgType]OmciMsgHandler{ |
| 116 | MibReset: mibReset, |
| 117 | MibUpload: mibUpload, |
| 118 | MibUploadNext: mibUploadNext, |
| 119 | Set: set, |
| 120 | Create: create, |
| 121 | Get: get, |
| 122 | GetAllAlarms: getAllAlarms, |
| 123 | } |
| 124 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 125 | var OnuOmciStateMap = map[OnuKey]*OnuOmciState{} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 126 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 127 | 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] | 128 | go func() { //For monitoring the OMCI states |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 129 | t := time.NewTicker(1 * time.Second) |
| 130 | defer t.Stop() |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 131 | for { |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 132 | select { |
| 133 | case <-t.C: |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 134 | logger.Debug("Monitor omci init state") |
| 135 | if isAllOmciInitDone(onumap) { |
| 136 | logger.Info("OmciRun - All the omci initialization wes done") |
| 137 | close(errch) |
| 138 | return |
| 139 | } |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 140 | case <-ctx.Done(): |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 141 | logger.Debug("Omci Monitoring process was done") |
| 142 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 143 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 144 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 145 | }() |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 146 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 147 | go func() { |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 148 | defer logger.Debug("Omci response process was done") |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 149 | for { |
| 150 | var resp openolt.OmciIndication |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 151 | select { |
| 152 | case m := <-omciOut: |
| 153 | transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt) |
| 154 | if err != nil { |
| 155 | errch <- err |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 156 | return |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d", |
| 160 | transactionId, msgType, class, instance) |
| 161 | |
| 162 | key := OnuKey{m.IntfId, m.OnuId} |
| 163 | if _, ok := OnuOmciStateMap[key]; !ok { |
| 164 | OnuOmciStateMap[key] = NewOnuOmciState() |
| 165 | } |
| 166 | |
| 167 | if _, ok := Handlers[msgType]; !ok { |
| 168 | logger.Warn("Ignore omci msg (msgType %d not handled)", msgType) |
| 169 | continue |
| 170 | } |
| 171 | |
| 172 | resp.Pkt, err = Handlers[msgType](class, content, key) |
| 173 | if err != nil { |
| 174 | errch <- err |
| 175 | return |
| 176 | } |
| 177 | resp.Pkt[0] = byte(transactionId >> 8) |
| 178 | resp.Pkt[1] = byte(transactionId & 0xFF) |
| 179 | resp.Pkt[2] = 0x2<<4 | byte(msgType) |
| 180 | resp.Pkt[3] = deviceId |
| 181 | resp.IntfId = m.IntfId |
| 182 | resp.OnuId = m.OnuId |
| 183 | omciIn <- resp |
| 184 | case <-ctx.Done(): |
| 185 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 186 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 187 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 188 | }() |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 189 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 190 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 191 | func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 192 | var m OmciMessage |
| 193 | |
| 194 | r := bytes.NewReader(HexDecode(pkt)) |
| 195 | |
| 196 | if err := binary.Read(r, binary.BigEndian, &m); err != nil { |
| 197 | logger.Error("binary.Read failed: %s", err) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 198 | return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed") |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 199 | } |
| 200 | logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x", |
| 201 | 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] | 202 | 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] | 203 | } |
| 204 | |
| 205 | func HexDecode(pkt []byte) []byte { |
| 206 | // Convert the hex encoding to binary |
| 207 | // TODO - Change openolt adapter to send raw binary instead of hex encoded |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 208 | p := make([]byte, len(pkt)/2) |
| 209 | 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] | 210 | // Go figure this ;) |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 211 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 212 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 213 | p[j] = u<<4 + l |
| 214 | } |
| 215 | logger.Debug("Omci decoded: %x.", p) |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 216 | return p |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 219 | func NewOnuOmciState() *OnuOmciState { |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 220 | return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 223 | func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 224 | var pkt []byte |
| 225 | |
| 226 | logger.Debug("Omci MibReset") |
| 227 | |
| 228 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 229 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 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, |
| 233 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 234 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 235 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 238 | func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 239 | var pkt []byte |
| 240 | |
| 241 | logger.Debug("Omci MibUpload") |
| 242 | |
| 243 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 244 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 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, |
| 248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 249 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 250 | |
| 251 | pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds |
| 252 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 253 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 256 | func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 257 | var pkt []byte |
| 258 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 259 | state := OnuOmciStateMap[key] |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 260 | |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 261 | logger.Debug("Omci MibUploadNext %d", state.mibUploadCtr) |
| 262 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 263 | switch state.mibUploadCtr { |
| 264 | case 0: |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 265 | // ONT Data (2) |
| 266 | pkt = []byte{ |
| 267 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 268 | 0x00, 0x02, 0x00, 0x00, 0x80, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 273 | case 1: |
| 274 | // Circuit Pack (6) - #1 |
| 275 | pkt = []byte{ |
| 276 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 277 | 0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04, |
| 278 | 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80, |
| 279 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 281 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 282 | case 2: |
| 283 | // Circuit Pack (6) - #2 |
| 284 | pkt = []byte{ |
| 285 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 286 | 0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52, |
| 287 | 0x43, 0x4d, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 291 | case 3: |
| 292 | // Circuit Pack (6) - #3 |
| 293 | pkt = []byte{ |
| 294 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 295 | 0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20, |
| 296 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 297 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 298 | 0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 299 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 300 | case 4: |
| 301 | // Circuit Pack (6) - #4 |
| 302 | pkt = []byte{ |
| 303 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 304 | 0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 309 | case 5: |
| 310 | // Circuit Pack (6) - #5 |
| 311 | pkt = []byte{ |
| 312 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 313 | 0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01, |
| 314 | 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80, |
| 315 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 316 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 317 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 318 | case 6: |
| 319 | // Circuit Pack (6) - #6 |
| 320 | pkt = []byte{ |
| 321 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 322 | 0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52, |
| 323 | 0x43, 0x4d, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 327 | case 7: |
| 328 | // Circuit Pack (6) - #7 |
| 329 | pkt = []byte{ |
| 330 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 331 | 0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20, |
| 332 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 333 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 334 | 0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00, |
| 335 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 336 | case 8: |
| 337 | // Circuit Pack (6) - #8 |
| 338 | pkt = []byte{ |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 339 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 340 | 0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 345 | case 9, 10, 11, 12: |
| 346 | // PPTP (11) |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 347 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 348 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 349 | 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f, |
| 350 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00, |
| 351 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 352 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 353 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 354 | pkt[11] = state.pptpInstance // ME Instance |
| 355 | state.pptpInstance++ |
Shad Ansari | fd29844 | 2019-01-08 16:19:35 -0800 | [diff] [blame^] | 356 | case 13, 14, 15, 16, 17, 18, 19, 20: |
| 357 | // T-CONT (262) |
| 358 | pkt = []byte{ |
| 359 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 360 | 0x01, 0x06, 0x80, 0x00, 0xe0, 0x00, 0xff, 0xff, |
| 361 | 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 362 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 363 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 364 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 365 | pkt[11] = state.tcontInstance // TCONT ME Instance |
| 366 | state.tcontInstance++ |
| 367 | case 21: |
| 368 | // ANI-G (263) |
| 369 | pkt = []byte{ |
| 370 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 371 | 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00, |
| 372 | 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00, |
| 373 | 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c, |
| 374 | 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 375 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 376 | case 22, 23, 24, 25: |
| 377 | // UNI-G (264) |
| 378 | pkt = []byte{ |
| 379 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 380 | 0x01, 0x08, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x00, |
| 381 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 382 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 383 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 384 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 385 | pkt[11] = state.uniGInstance // UNI-G ME Instance |
| 386 | state.uniGInstance++ |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 387 | default: |
| 388 | logger.Error("Invalid MibUpload request %d", state.mibUploadCtr) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 389 | return nil, errors.New("Invalid MibUpload request") |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | state.mibUploadCtr++ |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 393 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 396 | func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 397 | var pkt []byte |
| 398 | |
| 399 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 400 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 401 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 402 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 403 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 404 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 405 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 406 | |
| 407 | logger.Debug("Omci Set") |
| 408 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 409 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 412 | func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 413 | var pkt []byte |
| 414 | |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 415 | if class == GEMPortNetworkCTP { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 416 | if onuOmciState, ok := OnuOmciStateMap[key]; !ok { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 417 | logger.Error("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 418 | return nil, errors.New("ONU Key Error") |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 419 | } else { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 420 | onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2]) |
| 421 | logger.Debug("Gem Port Id %d", onuOmciState.gemPortId) |
| 422 | OnuOmciStateMap[key].init = DONE |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 426 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 427 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 428 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 429 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 430 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 431 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 432 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 433 | |
| 434 | logger.Debug("Omci Create") |
| 435 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 436 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 439 | func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 440 | var pkt []byte |
| 441 | |
| 442 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 443 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 444 | 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 445 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 446 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 447 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 448 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 449 | |
| 450 | logger.Debug("Omci Get") |
| 451 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 452 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 453 | } |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 454 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 455 | func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 456 | var pkt []byte |
| 457 | |
| 458 | pkt = []byte{ |
| 459 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 460 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 461 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 462 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 463 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 464 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 465 | |
| 466 | logger.Debug("Omci GetAllAlarms") |
| 467 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame] | 468 | return pkt, nil |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 469 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 470 | |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 471 | func isAllOmciInitDone(onumap map[uint32][]*device.Onu) bool { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 472 | for _, onus := range onumap { |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 473 | for _, onu := range onus { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 474 | key := OnuKey{onu.IntfID, onu.OnuID} |
| 475 | state := OnuOmciStateMap[key] |
Shad Ansari | a3384b0 | 2019-01-03 15:11:11 -0800 | [diff] [blame] | 476 | if state.init == INCOMPLETE { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 477 | return false |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | return true |
| 482 | } |