blob: ef4413a2bea0bb596e32104fc5f5306b72ba12ed [file] [log] [blame]
Shad Ansari1106b022019-01-16 22:22:35 -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
19import (
20 "encoding/binary"
21 "errors"
Shad Ansari53935c02019-01-17 16:41:45 -080022 "log"
Shad Ansari1106b022019-01-16 22:22:35 -080023)
24
25type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error)
26
27var 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
37func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
38 var pkt []byte
39
Shad Ansari53935c02019-01-17 16:41:45 -080040 log.Printf("Omci MibReset")
Shad Ansari1106b022019-01-16 22:22:35 -080041
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
52func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
53 var pkt []byte
54
Shad Ansari53935c02019-01-17 16:41:45 -080055 log.Printf("Omci MibUpload")
Shad Ansari1106b022019-01-16 22:22:35 -080056
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
70func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
71 var pkt []byte
72
73 state := OnuOmciStateMap[key]
74
Shad Ansari53935c02019-01-17 16:41:45 -080075 log.Printf("Omci MibUploadNext %d", state.mibUploadCtr)
Shad Ansari1106b022019-01-16 22:22:35 -080076
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 Ansari53935c02019-01-17 16:41:45 -0800202 log.Printf("Invalid MibUpload request %d", state.mibUploadCtr)
Shad Ansari1106b022019-01-16 22:22:35 -0800203 return nil, errors.New("Invalid MibUpload request")
204 }
205
206 state.mibUploadCtr++
207 return pkt, nil
208}
209
210func 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 Ansari53935c02019-01-17 16:41:45 -0800221 log.Printf("Omci Set")
Shad Ansari1106b022019-01-16 22:22:35 -0800222
223 return pkt, nil
224}
225
226func 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 Ansari53935c02019-01-17 16:41:45 -0800231 log.Printf("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId)
Shad Ansari1106b022019-01-16 22:22:35 -0800232 return nil, errors.New("ONU Key Error")
233 } else {
234 onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
Shad Ansari53935c02019-01-17 16:41:45 -0800235 log.Printf("Gem Port Id %d", onuOmciState.gemPortId)
Shad Ansari1106b022019-01-16 22:22:35 -0800236 // 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 Ansari53935c02019-01-17 16:41:45 -0800249 log.Printf("Omci Create")
Shad Ansari1106b022019-01-16 22:22:35 -0800250
251 return pkt, nil
252}
253
254func 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 Ansari53935c02019-01-17 16:41:45 -0800265 log.Printf("Omci Get")
Shad Ansari1106b022019-01-16 22:22:35 -0800266
267 return pkt, nil
268}
269
270func 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 Ansari53935c02019-01-17 16:41:45 -0800281 log.Printf("Omci GetAllAlarms")
Shad Ansari1106b022019-01-16 22:22:35 -0800282
283 return pkt, nil
284}