Shad Ansari | 65fed64 | 2019-01-16 14:04:19 -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 | |
| 19 | import ( |
| 20 | "encoding/binary" |
| 21 | "errors" |
| 22 | |
| 23 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 24 | ) |
| 25 | |
| 26 | type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) |
| 27 | |
| 28 | var Handlers = map[OmciMsgType]OmciMsgHandler{ |
| 29 | MibReset: mibReset, |
| 30 | MibUpload: mibUpload, |
| 31 | MibUploadNext: mibUploadNext, |
| 32 | Set: set, |
| 33 | Create: create, |
| 34 | Get: get, |
| 35 | GetAllAlarms: getAllAlarms, |
| 36 | } |
| 37 | |
| 38 | func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 39 | var pkt []byte |
| 40 | |
| 41 | logger.Debug("Omci MibReset") |
| 42 | |
| 43 | pkt = []byte{ |
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 50 | return pkt, nil |
| 51 | } |
| 52 | |
| 53 | func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 54 | var pkt []byte |
| 55 | |
| 56 | logger.Debug("Omci MibUpload") |
| 57 | |
| 58 | pkt = []byte{ |
| 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 65 | |
| 66 | pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds |
| 67 | |
| 68 | return pkt, nil |
| 69 | } |
| 70 | |
| 71 | func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 72 | var pkt []byte |
| 73 | |
| 74 | state := OnuOmciStateMap[key] |
| 75 | |
| 76 | logger.Debug("Omci MibUploadNext %d", state.mibUploadCtr) |
| 77 | |
| 78 | switch state.mibUploadCtr { |
| 79 | case 0: |
| 80 | // ONT Data (2) |
| 81 | pkt = []byte{ |
| 82 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 83 | 0x00, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, |
| 84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 85 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 86 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 87 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 88 | case 1: |
| 89 | // Circuit Pack (6) - #1 |
| 90 | pkt = []byte{ |
| 91 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 92 | 0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04, |
| 93 | 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80, |
| 94 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 97 | case 2: |
| 98 | // Circuit Pack (6) - #2 |
| 99 | pkt = []byte{ |
| 100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 101 | 0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52, |
| 102 | 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 103 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 105 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 106 | case 3: |
| 107 | // Circuit Pack (6) - #3 |
| 108 | pkt = []byte{ |
| 109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 110 | 0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20, |
| 111 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 112 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 113 | 0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 114 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 115 | case 4: |
| 116 | // Circuit Pack (6) - #4 |
| 117 | pkt = []byte{ |
| 118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 119 | 0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 0x00, 0x00, |
| 120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 123 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 124 | case 5: |
| 125 | // Circuit Pack (6) - #5 |
| 126 | pkt = []byte{ |
| 127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 128 | 0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01, |
| 129 | 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80, |
| 130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 131 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 132 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 133 | case 6: |
| 134 | // Circuit Pack (6) - #6 |
| 135 | pkt = []byte{ |
| 136 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 137 | 0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52, |
| 138 | 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 139 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 141 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 142 | case 7: |
| 143 | // Circuit Pack (6) - #7 |
| 144 | pkt = []byte{ |
| 145 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 146 | 0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20, |
| 147 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 148 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 149 | 0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00, |
| 150 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 151 | case 8: |
| 152 | // Circuit Pack (6) - #8 |
| 153 | pkt = []byte{ |
| 154 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 155 | 0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00, |
| 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} |
| 160 | case 9, 10, 11, 12: |
| 161 | // PPTP (11) |
| 162 | pkt = []byte{ |
| 163 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 164 | 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f, |
| 165 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00, |
| 166 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 167 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 168 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 169 | pkt[11] = state.pptpInstance // ME Instance |
| 170 | state.pptpInstance++ |
| 171 | case 13, 14, 15, 16, 17, 18, 19, 20: |
| 172 | // T-CONT (262) |
| 173 | pkt = []byte{ |
| 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 175 | 0x01, 0x06, 0x80, 0x00, 0xe0, 0x00, 0xff, 0xff, |
| 176 | 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 177 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 178 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 179 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 180 | pkt[11] = state.tcontInstance // TCONT ME Instance |
| 181 | state.tcontInstance++ |
| 182 | case 21: |
| 183 | // ANI-G (263) |
| 184 | pkt = []byte{ |
| 185 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 186 | 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00, |
| 187 | 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00, |
| 188 | 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c, |
| 189 | 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 191 | case 22, 23, 24, 25: |
| 192 | // UNI-G (264) |
| 193 | pkt = []byte{ |
| 194 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 195 | 0x01, 0x08, 0x01, 0x01, 0xf8, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 200 | pkt[11] = state.uniGInstance // UNI-G ME Instance |
| 201 | state.uniGInstance++ |
| 202 | default: |
| 203 | logger.Error("Invalid MibUpload request %d", state.mibUploadCtr) |
| 204 | return nil, errors.New("Invalid MibUpload request") |
| 205 | } |
| 206 | |
| 207 | state.mibUploadCtr++ |
| 208 | return pkt, nil |
| 209 | } |
| 210 | |
| 211 | func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 212 | var pkt []byte |
| 213 | |
| 214 | pkt = []byte{ |
| 215 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 216 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 217 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 218 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 219 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 220 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 221 | |
| 222 | logger.Debug("Omci Set") |
| 223 | |
| 224 | return pkt, nil |
| 225 | } |
| 226 | |
| 227 | func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 228 | var pkt []byte |
| 229 | |
| 230 | if class == GEMPortNetworkCTP { |
| 231 | if onuOmciState, ok := OnuOmciStateMap[key]; !ok { |
| 232 | logger.Error("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId) |
| 233 | return nil, errors.New("ONU Key Error") |
| 234 | } else { |
| 235 | onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2]) |
| 236 | logger.Debug("Gem Port Id %d", onuOmciState.gemPortId) |
| 237 | // FIXME |
| 238 | OnuOmciStateMap[key].state = DONE |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | pkt = []byte{ |
| 243 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01, |
| 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, |
| 248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 249 | |
| 250 | logger.Debug("Omci Create") |
| 251 | |
| 252 | return pkt, nil |
| 253 | } |
| 254 | |
| 255 | func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 256 | var pkt []byte |
| 257 | |
| 258 | pkt = []byte{ |
| 259 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01, |
| 260 | 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 261 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 262 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 263 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 264 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 265 | |
| 266 | logger.Debug("Omci Get") |
| 267 | |
| 268 | return pkt, nil |
| 269 | } |
| 270 | |
| 271 | func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) { |
| 272 | var pkt []byte |
| 273 | |
| 274 | pkt = []byte{ |
| 275 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 276 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 277 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 278 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 279 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 281 | |
| 282 | logger.Debug("Omci GetAllAlarms") |
| 283 | |
| 284 | return pkt, nil |
| 285 | } |