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 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 23 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 24 | "gerrit.opencord.org/voltha-bbsim/protos" |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 25 | "gerrit.opencord.org/voltha-bbsim/device" |
| 26 | "time" |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 27 | "context" |
| 28 | "errors" |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 31 | // |
| 32 | // OMCI definitions |
| 33 | // |
| 34 | |
| 35 | // OmciMsgType represents a OMCI message-type |
| 36 | type OmciMsgType byte |
| 37 | |
| 38 | const ( |
| 39 | // Message Types |
| 40 | _ = iota |
| 41 | Create OmciMsgType = 4 |
| 42 | Delete OmciMsgType = 6 |
| 43 | Set OmciMsgType = 8 |
| 44 | Get OmciMsgType = 9 |
| 45 | GetAllAlarms OmciMsgType = 11 |
| 46 | GetAllAlarmsNext OmciMsgType = 12 |
| 47 | MibUpload OmciMsgType = 13 |
| 48 | MibUploadNext OmciMsgType = 14 |
| 49 | MibReset OmciMsgType = 15 |
| 50 | AlarmNotification OmciMsgType = 16 |
| 51 | AttributeValueChange OmciMsgType = 17 |
| 52 | Test OmciMsgType = 18 |
| 53 | StartSoftwareDownload OmciMsgType = 19 |
| 54 | DownloadSection OmciMsgType = 20 |
| 55 | EndSoftwareDownload OmciMsgType = 21 |
| 56 | ActivateSoftware OmciMsgType = 22 |
| 57 | CommitSoftware OmciMsgType = 23 |
| 58 | SynchronizeTime OmciMsgType = 24 |
| 59 | Reboot OmciMsgType = 25 |
| 60 | GetNext OmciMsgType = 26 |
| 61 | TestResult OmciMsgType = 27 |
| 62 | GetCurrentData OmciMsgType = 28 |
| 63 | SetTable OmciMsgType = 29 // Defined in Extended Message Set Only |
| 64 | ) |
| 65 | |
| 66 | const ( |
| 67 | // Managed Entity Class values |
| 68 | GEMPortNetworkCTP OmciClass = 268 |
| 69 | ) |
| 70 | |
| 71 | // OMCI Managed Entity Class |
| 72 | type OmciClass uint16 |
| 73 | |
| 74 | // OMCI Message Identifier |
| 75 | type OmciMessageIdentifier struct { |
| 76 | Class OmciClass |
| 77 | Instance uint16 |
| 78 | } |
| 79 | |
| 80 | type OmciContent [32]byte |
| 81 | |
| 82 | type OmciMessage struct { |
| 83 | TransactionId uint16 |
| 84 | MessageType OmciMsgType |
| 85 | DeviceId uint8 |
| 86 | MessageId OmciMessageIdentifier |
| 87 | Content OmciContent |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 90 | const NumMibUploads byte = 9 |
| 91 | |
| 92 | type OnuKey struct { |
| 93 | IntfId, OnuId uint32 |
| 94 | } |
| 95 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 96 | type OnuOmciState struct { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 97 | gemPortId uint16 |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 98 | mibUploadCtr uint16 |
| 99 | uniGInstance uint8 |
| 100 | pptpInstance uint8 |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 101 | init istate |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 104 | type istate int |
| 105 | |
| 106 | const ( |
| 107 | INCOMPLETE istate = iota |
| 108 | DONE |
| 109 | ) |
| 110 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 111 | type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 112 | |
| 113 | var Handlers = map[OmciMsgType]OmciMsgHandler{ |
| 114 | MibReset: mibReset, |
| 115 | MibUpload: mibUpload, |
| 116 | MibUploadNext: mibUploadNext, |
| 117 | Set: set, |
| 118 | Create: create, |
| 119 | Get: get, |
| 120 | GetAllAlarms: getAllAlarms, |
| 121 | } |
| 122 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 123 | var OnuOmciStateMap = map[OnuKey]*OnuOmciState{} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 124 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 125 | 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] | 126 | go func() { //For monitoring the OMCI states |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 127 | t := time.NewTicker(1 * time.Second) |
| 128 | defer t.Stop() |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 129 | for { |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 130 | select{ |
| 131 | case <- t.C: |
| 132 | logger.Debug("Monitor omci init state") |
| 133 | if isAllOmciInitDone(onumap) { |
| 134 | logger.Info("OmciRun - All the omci initialization wes done") |
| 135 | close(errch) |
| 136 | return |
| 137 | } |
| 138 | case <- ctx.Done(): |
| 139 | logger.Debug("Omci Monitoring process was done") |
| 140 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 141 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 142 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 143 | }() |
Shad Ansari | 8213c53 | 2018-12-11 13:53:34 -0800 | [diff] [blame] | 144 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 145 | go func(){ |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 146 | defer logger.Debug("Omci response process was done") |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 147 | for { |
| 148 | var resp openolt.OmciIndication |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 149 | select{ |
| 150 | case m := <-omciOut: |
| 151 | transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt) |
| 152 | if err != nil { |
| 153 | errch <- err |
| 154 | return |
| 155 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 156 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 157 | logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d", |
| 158 | transactionId, msgType, class, instance) |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 159 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 160 | key := OnuKey{m.IntfId, m.OnuId} |
| 161 | if _, ok := OnuOmciStateMap[key]; !ok { |
| 162 | OnuOmciStateMap[key] = NewOnuOmciState() |
| 163 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 164 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 165 | if _, ok := Handlers[msgType]; !ok { |
| 166 | logger.Warn("Ignore omci msg (msgType %d not handled)", msgType) |
| 167 | continue |
| 168 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 169 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 170 | resp.Pkt, err = Handlers[msgType](class, content, key) |
| 171 | if err != nil { |
| 172 | errch <- err |
| 173 | return |
| 174 | } |
| 175 | resp.Pkt[0] = byte(transactionId >> 8) |
| 176 | resp.Pkt[1] = byte(transactionId & 0xFF) |
| 177 | resp.Pkt[2] = 0x2<<4 | byte(msgType) |
| 178 | resp.Pkt[3] = deviceId |
| 179 | resp.IntfId = m.IntfId |
| 180 | resp.OnuId = m.OnuId |
| 181 | omciIn <- resp |
| 182 | case <-ctx.Done(): |
| 183 | return |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 184 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 185 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 186 | }() |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 187 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 188 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 189 | func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 190 | var m OmciMessage |
| 191 | |
| 192 | r := bytes.NewReader(HexDecode(pkt)) |
| 193 | |
| 194 | if err := binary.Read(r, binary.BigEndian, &m); err != nil { |
| 195 | logger.Error("binary.Read failed: %s", err) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 196 | return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed") |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 197 | } |
| 198 | logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x", |
| 199 | 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^] | 200 | 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] | 201 | } |
| 202 | |
| 203 | func HexDecode(pkt []byte) []byte { |
| 204 | // Convert the hex encoding to binary |
| 205 | // TODO - Change openolt adapter to send raw binary instead of hex encoded |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 206 | p := make([]byte, len(pkt)/2) |
| 207 | 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] | 208 | // Go figure this ;) |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 209 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 210 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 211 | p[j] = u<<4 + l |
| 212 | } |
| 213 | logger.Debug("Omci decoded: %x.", p) |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 214 | return p |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 217 | func NewOnuOmciState() *OnuOmciState { |
| 218 | return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, pptpInstance: 1} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 221 | func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 222 | var pkt []byte |
| 223 | |
| 224 | logger.Debug("Omci MibReset") |
| 225 | |
| 226 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 227 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 228 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 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, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 232 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 233 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 236 | func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 237 | var pkt []byte |
| 238 | |
| 239 | logger.Debug("Omci MibUpload") |
| 240 | |
| 241 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 242 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 243 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 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, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 247 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 248 | |
| 249 | pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds |
| 250 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 251 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 254 | func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 255 | var pkt []byte |
| 256 | |
| 257 | logger.Debug("Omci MibUploadNext") |
| 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 | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 261 | switch state.mibUploadCtr { |
| 262 | case 0: |
| 263 | // ANI-G |
| 264 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 265 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 266 | 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00, |
| 267 | 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00, |
| 268 | 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c, |
| 269 | 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 270 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 271 | case 1, 2, 3, 4: |
| 272 | // UNI-G |
| 273 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 274 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 275 | 0x01, 0x08, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x00, |
| 276 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 277 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 278 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 279 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 280 | pkt[11] = state.uniGInstance // ME Instance |
| 281 | state.uniGInstance++ |
| 282 | case 5, 6, 7, 8: |
| 283 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 284 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 285 | 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f, |
| 286 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00, |
| 287 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 288 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 289 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 290 | pkt[11] = state.pptpInstance // ME Instance |
| 291 | state.pptpInstance++ |
| 292 | default: |
| 293 | logger.Error("Invalid MibUpload request %d", state.mibUploadCtr) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 294 | return nil, errors.New("Invalid MibUpload request") |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | state.mibUploadCtr++ |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 298 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 301 | func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 302 | var pkt []byte |
| 303 | |
| 304 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 305 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 310 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 311 | |
| 312 | logger.Debug("Omci Set") |
| 313 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 314 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 317 | func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 318 | var pkt []byte |
| 319 | |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 320 | if class == GEMPortNetworkCTP { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 321 | if onuOmciState, ok := OnuOmciStateMap[key]; !ok { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 322 | logger.Error("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId) |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 323 | return nil, errors.New("ONU Key Error") |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 324 | } else { |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 325 | onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2]) |
| 326 | logger.Debug("Gem Port Id %d", onuOmciState.gemPortId) |
| 327 | OnuOmciStateMap[key].init = DONE |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 331 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 332 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 333 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 334 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 335 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 336 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 337 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 338 | |
| 339 | logger.Debug("Omci Create") |
| 340 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 341 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 344 | func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 345 | var pkt []byte |
| 346 | |
| 347 | pkt = []byte{ |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 348 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01, |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 349 | 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 350 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 351 | 0x00, 0x00, 0x00, 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 | |
| 355 | logger.Debug("Omci Get") |
| 356 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 357 | return pkt, nil |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 358 | } |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 359 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 360 | func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 361 | var pkt []byte |
| 362 | |
| 363 | pkt = []byte{ |
| 364 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 365 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 366 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 367 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 368 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 369 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 370 | |
| 371 | logger.Debug("Omci GetAllAlarms") |
| 372 | |
Keita NISHIMOTO | 2b69420 | 2018-12-18 07:30:55 +0900 | [diff] [blame^] | 373 | return pkt, nil |
Shad Ansari | a5c7989 | 2018-11-29 16:32:59 -0800 | [diff] [blame] | 374 | } |
Keita NISHIMOTO | 3af86da | 2018-12-12 10:34:43 +0900 | [diff] [blame] | 375 | |
| 376 | func isAllOmciInitDone(onumap map[uint32][] *device.Onu) bool { |
| 377 | for _, onus := range onumap { |
| 378 | for _, onu := range onus{ |
| 379 | key := OnuKey{onu.IntfID, onu.OnuID} |
| 380 | state := OnuOmciStateMap[key] |
| 381 | if state.init == INCOMPLETE{ |
| 382 | return false |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | return true |
| 387 | } |
| 388 | |