blob: 4b56895bb13aefc25cb45c3bc6ea34e848d315a8 [file] [log] [blame]
Shad Ansari2eac6a42018-11-14 22:35:39 -08001/*
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
17package core
18
Shad Ansari45806172018-11-19 17:13:08 -080019import (
20 "gerrit.opencord.org/voltha-bbsim/common/logger"
21)
22
Shad Ansari2eac6a42018-11-14 22:35:39 -080023type OmciMsg struct {
24 IntfId uint32
25 OnuId uint32
26 Pkt []byte
27}
28
Shad Ansari45806172018-11-19 17:13:08 -080029const NumMibUploads byte = 9
30
31type OnuKey struct {
32 IntfId, OnuId uint32
33}
34
35type OnuState struct {
36 mibUploadCtr uint16
37 uniGInstance uint8
38 pptpInstance uint8
39}
40
Shad Ansari2eac6a42018-11-14 22:35:39 -080041func OmciRun(omciOut chan OmciMsg, omciIn chan OmciMsg) {
Shad Ansari45806172018-11-19 17:13:08 -080042
43 onus := make(map[OnuKey]*OnuState)
44
Shad Ansari2eac6a42018-11-14 22:35:39 -080045 for {
Shad Ansari5bb48db2018-11-17 22:03:41 -080046 var resp OmciMsg
47
Shad Ansari45806172018-11-19 17:13:08 -080048 m := <-omciOut
Shad Ansari5bb48db2018-11-17 22:03:41 -080049
Shad Ansari45806172018-11-19 17:13:08 -080050 msgType, transactionId, meClass, meInstance := ParsePkt(m.Pkt)
Shad Ansari5bb48db2018-11-17 22:03:41 -080051
Shad Ansari45806172018-11-19 17:13:08 -080052 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:
73 logger.Debug("Omci msg type not handled: %d", msgType)
74 }
75
76 resp.Pkt[0] = byte(transactionId >> 8)
77 resp.Pkt[1] = byte(transactionId & 0xFF)
78 resp.IntfId = m.IntfId
79 resp.OnuId = m.OnuId
Shad Ansari5bb48db2018-11-17 22:03:41 -080080 omciIn <- resp
Shad Ansari2eac6a42018-11-14 22:35:39 -080081 }
82}
Shad Ansari45806172018-11-19 17:13:08 -080083
84func ParsePkt(pkt []byte) (byte, uint16, uint16, uint16) {
85 p := make([]byte, len(pkt)/2)
86 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
87 u := (pkt[i] & 15) + (pkt[i]>>6)*9
88 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
89 p[j] = u<<4 + l
90 }
91 logger.Debug("Omci decoded: %x.", p)
92 msgType := p[2] & 0x0F
93 transactionId := (uint16(p[0]) << 8) | uint16(p[1])
94 meClass := (uint16(p[4]) << 8) | uint16(p[5])
95 meInstance := (uint16(p[6]) << 8) | uint16(p[7])
96 return msgType, transactionId, meClass, meInstance
97}
98
99func NewOnuState() *OnuState {
100 return &OnuState{mibUploadCtr: 0, uniGInstance: 1, pptpInstance: 1}
101}
102
103func MibReset() []byte {
104 var pkt []byte
105
106 logger.Debug("Omci MibReset")
107
108 pkt = []byte{
109 0x00, 0x01, 0x2f, 0x0a, 0x00, 0x02, 0x00, 0x00,
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x28, 0x1f, 0x75, 0x69, 0xaa}
115 return pkt
116}
117
118func MibUpload() []byte {
119 var pkt []byte
120
121 logger.Debug("Omci MibUpload")
122
123 pkt = []byte{
124 0x00, 0x02, 0x2d, 0x0a, 0x00, 0x02, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x28, 0x0c, 0x63, 0x21, 0x65}
130
131 pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds
132
133 return pkt
134}
135
136func MibUploadNext(state *OnuState) []byte {
137 var pkt []byte
138
139 logger.Debug("Omci MibUploadNext")
140
141 switch state.mibUploadCtr {
142 case 0:
143 // ANI-G
144 pkt = []byte{
145 0x00, 0x03, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
146 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00,
147 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00,
148 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c,
149 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x28, 0x2c, 0x4d, 0xa9, 0xc8}
151 case 1, 2, 3, 4:
152 // UNI-G
153 pkt = []byte{
154 0x00, 0x04, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
155 0x01, 0x08, 0x01, 0x01, 0xf8, 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 0x00, 0x00, 0x00, 0x28, 0x05, 0x19, 0xae, 0x66}
160 pkt[11] = state.uniGInstance // ME Instance
161 state.uniGInstance++
162 case 5, 6, 7, 8:
163 pkt = []byte{
164 0x00, 0x16, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
165 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f,
166 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00,
167 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169 0x00, 0x00, 0x00, 0x28, 0x6f, 0x10, 0x9b, 0x27}
170 pkt[11] = state.pptpInstance // ME Instance
171 state.pptpInstance++
172 default:
173 logger.Error("Invalid MibUpload request %d", state.mibUploadCtr)
174 }
175
176 state.mibUploadCtr++
177
178 return pkt
179}
180
181func Set() []byte {
182 var pkt []byte
183
184 pkt = []byte{
185 0x01, 0x15, 0x28, 0x0a, 0x01, 0x00, 0x00, 0x00,
186 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x28, 0x41, 0xb3, 0x95, 0x12}
191
192 logger.Debug("Omci Set")
193
194 return pkt
195}
196
197func Create() []byte {
198 var pkt []byte
199
200 pkt = []byte{
201 0x01, 0x17, 0x24, 0x0a, 0x01, 0x10, 0x00, 0x01,
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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, 0x28, 0x85, 0xcb, 0x98, 0x86}
207
208 logger.Debug("Omci Create")
209
210 return pkt
211}
212
213func Get() []byte {
214 var pkt []byte
215
216 pkt = []byte{
217 0x01, 0x26, 0x29, 0x0a, 0x00, 0x2d, 0x02, 0x01,
218 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 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, 0x28, 0xbc, 0x0c, 0xa4, 0x18}
223
224 logger.Debug("Omci Get")
225
226 return pkt
227}