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