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