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 ( |
| 20 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 21 | ) |
| 22 | |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 23 | type OmciMsg struct { |
| 24 | IntfId uint32 |
| 25 | OnuId uint32 |
| 26 | Pkt []byte |
| 27 | } |
| 28 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 29 | const NumMibUploads byte = 9 |
| 30 | |
| 31 | type OnuKey struct { |
| 32 | IntfId, OnuId uint32 |
| 33 | } |
| 34 | |
| 35 | type OnuState struct { |
| 36 | mibUploadCtr uint16 |
| 37 | uniGInstance uint8 |
| 38 | pptpInstance uint8 |
| 39 | } |
| 40 | |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 41 | func OmciRun(omciOut chan OmciMsg, omciIn chan OmciMsg) { |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 42 | |
| 43 | onus := make(map[OnuKey]*OnuState) |
| 44 | |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 45 | for { |
Shad Ansari | 5bb48db | 2018-11-17 22:03:41 -0800 | [diff] [blame] | 46 | var resp OmciMsg |
| 47 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 48 | m := <-omciOut |
Shad Ansari | 5bb48db | 2018-11-17 22:03:41 -0800 | [diff] [blame] | 49 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 50 | msgType, transactionId, meClass, meInstance := ParsePkt(m.Pkt) |
Shad Ansari | 5bb48db | 2018-11-17 22:03:41 -0800 | [diff] [blame] | 51 | |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 52 | logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d", |
| 53 | transactionId, msgType, meClass, meInstance) |
| 54 | |
| 55 | key := OnuKey{m.IntfId, m.OnuId} |
| 56 | if _, ok := onus[key]; !ok { |
| 57 | onus[key] = NewOnuState() |
| 58 | } |
| 59 | switch msgType { |
| 60 | case 15: |
| 61 | resp.Pkt = MibReset() |
| 62 | case 13: |
| 63 | resp.Pkt = MibUpload() |
| 64 | case 14: |
| 65 | resp.Pkt = MibUploadNext(onus[key]) |
| 66 | case 8: |
| 67 | resp.Pkt = Set() |
| 68 | case 4: |
| 69 | resp.Pkt = Create() |
| 70 | case 9: |
| 71 | resp.Pkt = Get() |
| 72 | default: |
Shad Ansari | ab44c21 | 2018-11-26 11:54:26 -0800 | [diff] [blame] | 73 | logger.Warn("Omci msg type not handled: %d", msgType) |
| 74 | continue |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | resp.Pkt[0] = byte(transactionId >> 8) |
| 78 | resp.Pkt[1] = byte(transactionId & 0xFF) |
| 79 | resp.IntfId = m.IntfId |
| 80 | resp.OnuId = m.OnuId |
Shad Ansari | 5bb48db | 2018-11-17 22:03:41 -0800 | [diff] [blame] | 81 | omciIn <- resp |
Shad Ansari | 2eac6a4 | 2018-11-14 22:35:39 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
Shad Ansari | 4580617 | 2018-11-19 17:13:08 -0800 | [diff] [blame] | 84 | |
| 85 | func ParsePkt(pkt []byte) (byte, uint16, uint16, uint16) { |
| 86 | p := make([]byte, len(pkt)/2) |
| 87 | for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 { |
| 88 | u := (pkt[i] & 15) + (pkt[i]>>6)*9 |
| 89 | l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9 |
| 90 | p[j] = u<<4 + l |
| 91 | } |
| 92 | logger.Debug("Omci decoded: %x.", p) |
| 93 | msgType := p[2] & 0x0F |
| 94 | transactionId := (uint16(p[0]) << 8) | uint16(p[1]) |
| 95 | meClass := (uint16(p[4]) << 8) | uint16(p[5]) |
| 96 | meInstance := (uint16(p[6]) << 8) | uint16(p[7]) |
| 97 | return msgType, transactionId, meClass, meInstance |
| 98 | } |
| 99 | |
| 100 | func NewOnuState() *OnuState { |
| 101 | return &OnuState{mibUploadCtr: 0, uniGInstance: 1, pptpInstance: 1} |
| 102 | } |
| 103 | |
| 104 | func MibReset() []byte { |
| 105 | var pkt []byte |
| 106 | |
| 107 | logger.Debug("Omci MibReset") |
| 108 | |
| 109 | pkt = []byte{ |
| 110 | 0x00, 0x01, 0x2f, 0x0a, 0x00, 0x02, 0x00, 0x00, |
| 111 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 112 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 113 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 114 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 115 | 0x00, 0x00, 0x00, 0x28, 0x1f, 0x75, 0x69, 0xaa} |
| 116 | return pkt |
| 117 | } |
| 118 | |
| 119 | func MibUpload() []byte { |
| 120 | var pkt []byte |
| 121 | |
| 122 | logger.Debug("Omci MibUpload") |
| 123 | |
| 124 | pkt = []byte{ |
| 125 | 0x00, 0x02, 0x2d, 0x0a, 0x00, 0x02, 0x00, 0x00, |
| 126 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 128 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 129 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 130 | 0x00, 0x00, 0x00, 0x28, 0x0c, 0x63, 0x21, 0x65} |
| 131 | |
| 132 | pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds |
| 133 | |
| 134 | return pkt |
| 135 | } |
| 136 | |
| 137 | func MibUploadNext(state *OnuState) []byte { |
| 138 | var pkt []byte |
| 139 | |
| 140 | logger.Debug("Omci MibUploadNext") |
| 141 | |
| 142 | switch state.mibUploadCtr { |
| 143 | case 0: |
| 144 | // ANI-G |
| 145 | pkt = []byte{ |
| 146 | 0x00, 0x03, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00, |
| 147 | 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00, |
| 148 | 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00, |
| 149 | 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c, |
| 150 | 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 151 | 0x00, 0x00, 0x00, 0x28, 0x2c, 0x4d, 0xa9, 0xc8} |
| 152 | case 1, 2, 3, 4: |
| 153 | // UNI-G |
| 154 | pkt = []byte{ |
| 155 | 0x00, 0x04, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00, |
| 156 | 0x01, 0x08, 0x01, 0x01, 0xf8, 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 | 0x00, 0x00, 0x00, 0x28, 0x05, 0x19, 0xae, 0x66} |
| 161 | pkt[11] = state.uniGInstance // ME Instance |
| 162 | state.uniGInstance++ |
| 163 | case 5, 6, 7, 8: |
| 164 | pkt = []byte{ |
| 165 | 0x00, 0x16, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00, |
| 166 | 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f, |
| 167 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00, |
| 168 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 169 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 170 | 0x00, 0x00, 0x00, 0x28, 0x6f, 0x10, 0x9b, 0x27} |
| 171 | pkt[11] = state.pptpInstance // ME Instance |
| 172 | state.pptpInstance++ |
| 173 | default: |
| 174 | logger.Error("Invalid MibUpload request %d", state.mibUploadCtr) |
| 175 | } |
| 176 | |
| 177 | state.mibUploadCtr++ |
| 178 | |
| 179 | return pkt |
| 180 | } |
| 181 | |
| 182 | func Set() []byte { |
| 183 | var pkt []byte |
| 184 | |
| 185 | pkt = []byte{ |
| 186 | 0x01, 0x15, 0x28, 0x0a, 0x01, 0x00, 0x00, 0x00, |
| 187 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 189 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 191 | 0x00, 0x00, 0x00, 0x28, 0x41, 0xb3, 0x95, 0x12} |
| 192 | |
| 193 | logger.Debug("Omci Set") |
| 194 | |
| 195 | return pkt |
| 196 | } |
| 197 | |
| 198 | func Create() []byte { |
| 199 | var pkt []byte |
| 200 | |
| 201 | pkt = []byte{ |
| 202 | 0x01, 0x17, 0x24, 0x0a, 0x01, 0x10, 0x00, 0x01, |
| 203 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 204 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 205 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 206 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 207 | 0x00, 0x00, 0x00, 0x28, 0x85, 0xcb, 0x98, 0x86} |
| 208 | |
| 209 | logger.Debug("Omci Create") |
| 210 | |
| 211 | return pkt |
| 212 | } |
| 213 | |
| 214 | func Get() []byte { |
| 215 | var pkt []byte |
| 216 | |
| 217 | pkt = []byte{ |
| 218 | 0x01, 0x26, 0x29, 0x0a, 0x00, 0x2d, 0x02, 0x01, |
| 219 | 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 220 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 221 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 222 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 223 | 0x00, 0x00, 0x00, 0x28, 0xbc, 0x0c, 0xa4, 0x18} |
| 224 | |
| 225 | logger.Debug("Omci Get") |
| 226 | |
| 227 | return pkt |
| 228 | } |