blob: 5ba28f993b213aba36fe7683c64e3f49c1604154 [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001/*
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"
22 "fmt"
23 log "github.com/sirupsen/logrus"
24)
25
26type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error)
27
28var 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 GetAllAlarmsNext: getAllAlarmsNext,
37 SynchronizeTime: syncTime,
38 Delete: delete,
39 Reboot: reboot,
Matteo Scandoloca08fc72019-12-04 14:17:39 -080040 Test: testHandler,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070041}
42
43func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
44 var pkt []byte
45
46 log.WithFields(log.Fields{
47 "IntfId": key.IntfId,
48 "OnuId": key.OnuId,
49 }).Tracef("Omci MibReset")
50 OnuOmciStateMapLock.RLock()
51 if state, ok := OnuOmciStateMap[key]; ok {
52 log.WithFields(log.Fields{
53 "IntfId": key.IntfId,
54 "OnuId": key.OnuId,
55 }).Tracef("Reseting OnuOmciState")
56 state.ResetOnuOmciState()
57 }
58 OnuOmciStateMapLock.RUnlock()
59
60 pkt = []byte{
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
67 return pkt, nil
68}
69
70func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
71 var pkt []byte
72
73 log.WithFields(log.Fields{
74 "IntfId": key.IntfId,
75 "OnuId": key.OnuId,
76 }).Tracef("Omci MibUpload")
77
78 pkt = []byte{
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
85
86 pkt[8] = NumMibUploadsHigherByte
87 pkt[9] = NumMibUploadsLowerByte
88
89 return pkt, nil
90}
91
92func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
93 var pkt []byte
94 OnuOmciStateMapLock.RLock()
95 state := OnuOmciStateMap[key]
96 OnuOmciStateMapLock.RUnlock()
97 // commandNumber is the "Command number" attribute received in "MIB Upload Next" OMCI message
98 commandNumber := (uint16(content[1])) | (uint16(content[0])<<8)
99 log.WithFields(log.Fields{
100 "IntfId": key.IntfId,
101 "OnuId": key.OnuId,
102 "CommandNumber": commandNumber,
103 }).Tracef("Omci MibUploadNext")
104
105 switch commandNumber {
106 case 0:
107 // ONT Data (2)
108 // log.Println("ONT DATA")
109 pkt = []byte{
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
111 0x00, 0x02, 0x00, 0x00, 0x80, 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, 0x00, 0x00, 0x00, 0x00, 0x00}
116 case 1:
117 // Circuit Pack (6) - #1
118 // log.Println("Circuit Pack")
119 pkt = []byte{
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
121 0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04,
122 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
126 case 2:
127 // Circuit Pack (6) - #2
128 // log.Println("Circuit Pack")
129 pkt = []byte{
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
131 0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52,
132 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
136 case 3:
137 // Circuit Pack (6) - #3
138 // log.Println("Circuit Pack")
139 pkt = []byte{
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
141 0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20,
142 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
143 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
144 0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
146 case 4:
147 // Circuit Pack (6) - #4
148 // log.Println("Circuit Pack")
149 pkt = []byte{
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
151 0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
156 case 5:
157 // Circuit Pack (6) - #5
158 // log.Println("Circuit Pack")
159 pkt = []byte{
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
161 0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01,
162 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
166 case 6:
167 // Circuit Pack (6) - #6
168 // log.Println("Circuit Pack")
169 pkt = []byte{
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
171 0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52,
172 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
176 case 7:
177 // Circuit Pack (6) - #7
178 // log.Println("Circuit Pack")
179 pkt = []byte{
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
181 0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20,
182 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
183 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
184 0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00,
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
186 case 8:
187 // Circuit Pack (6) - #8
188 // log.Println("Circuit Pack")
189 pkt = []byte{
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
191 0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00,
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
196 case 9, 10, 11, 12:
197 // PPTP (11)
198 // log.Println("PPTP")
199 pkt = []byte{
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
201 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f,
202 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00,
203 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
206 pkt[11] = state.pptpInstance // ME Instance
207 state.pptpInstance++
208 case 13, 14, 15, 16, 17, 18, 19, 20:
209 // T-CONT (262)
210 // log.Println("T-CONT")
211 pkt = []byte{
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
213 0x01, 0x06, 0x80, 0x00, 0xe0, 0x00, 0xff, 0xff,
214 0x01, 0x01, 0x00, 0x00, 0x00, 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
219 state.tcontInstance++
220 pkt[11] = state.tcontInstance // TCONT ME Instance
221
222 case 21:
223 // ANI-G (263)
224 // log.Println("ANI-G")
225 pkt = []byte{
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
227 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00,
228 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00,
229 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c,
230 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
232 case 22, 23, 24, 25:
233 // UNI-G (264)
234 // log.Println("UNI-G")
235 pkt = []byte{
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
237 0x01, 0x08, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
242 pkt[11] = state.uniGInstance // UNI-G ME Instance
243 state.uniGInstance++
244
245 case 26, 30, 34, 38, 42, 46, 50, 54,
246 58, 62, 66, 70, 74, 78, 82, 86,
247 90, 94, 98, 102, 106, 110, 114, 118,
248 122, 126, 130, 134, 138, 142, 146, 150,
249 154, 158, 162, 166, 170, 174, 178, 182,
250 186, 190, 194, 198, 202, 206, 210, 214,
251 218, 222, 226, 230, 234, 238, 242, 246,
252 250, 254, 258, 262, 266, 270, 274, 278:
253 // Prior-Q with mask downstream
254 log.Tracef("Mib-upload for prior-q with mask")
255 // For downstream PQ, pkt[10] is 0x00
256 // So the instanceId will be like 0x0001, 0x0002,... etc
257 pkt = []byte{
258 0x00, 0x42, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
259 0x01, 0x15, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff,
260 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
261 0x09, 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 }
265 state.priorQInstance++
266 pkt[11] = state.priorQInstance
267
268 case 27, 31, 35, 39, 43, 47, 51, 55,
269 59, 63, 67, 71, 75, 79, 83, 87,
270 91, 95, 99, 103, 107, 111, 115, 119,
271 123, 127, 131, 135, 139, 143, 147, 151,
272 155, 159, 163, 167, 171, 175, 179, 183,
273 187, 191, 195, 199, 203, 207, 211, 215,
274 219, 223, 227, 231, 235, 239, 243, 247,
275 251, 255, 259, 263, 267, 271, 275, 279:
276 // Prior-Q with attribute list downstream
277 // log.Println("Mib-upload for prior-q with attribute list")
278 pkt = []byte{
279 0x00, 0x43, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
280 0x01, 0x15, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x01,
281 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
282 0x20, 0x00, 0x00, 0x01, 0x20, 0x01, 0x00, 0x01,
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 }
286
287 pkt[11] = state.priorQInstance
288
289 // Group 8 PriorQ to point to a particular TCONT
290 // Priority for each group of PriorQ is 0 - 7
291 if state.priorQPriority % NumPriorQPerTcont == 0 {
292 state.tcontPointer++
293 }
294
295 // Only for verification. To be removed
296 if state.tcontPointer > state.tcontInstance {
297 log.Tracef("Error: Invalid TcontPointer")
298 break
299 }
300
301 pkt[24] = state.tcontPointer
302 pkt[26] = state.priorQPriority % NumPriorQPerTcont
303 pkt[28] = state.tcontInstance
304
305 case 28, 32, 36, 40, 44, 48, 52, 56,
306 60, 64, 68, 72, 76, 80, 84, 88,
307 92, 96, 100, 104, 108, 112, 116, 120,
308 124, 128, 132, 136, 140, 144, 148, 152,
309 156, 160, 164, 168, 172, 176, 180, 184,
310 188, 192, 196, 200, 204, 208, 212, 216,
311 220, 224, 228, 232, 236, 240, 244, 248,
312 252, 256, 260, 264, 268, 272, 276, 280:
313 // Prior-Q with mask upstream
314 // log.Println("Mib-upload for prior-q with mask")
315 pkt = []byte{
316 0x00, 0x42, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
317 0x01, 0x15, 0x80, 0x00, 0x00, 0x0f, 0xff, 0xff,
318 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
319 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 }
323 pkt[11] = state.priorQInstance
324
325 case 29, 33, 37, 41, 45, 49, 53, 57,
326 61, 65, 69, 73, 77, 81, 85, 89,
327 93, 97, 101, 105, 109, 113, 117, 121,
328 125, 129, 133, 137, 141, 145, 149, 153,
329 157, 161, 165, 169, 173, 177, 181, 185,
330 189, 193, 197, 201, 205, 209, 213, 217,
331 221, 225, 229, 233, 237, 241, 245, 249,
332 253, 257, 261, 265, 269, 273, 277, 281:
333 // Prior-Q with attribute list upstream
334 // log.Println("Mib-upload for prior-q with attribute list")
335 // For upstream pkt[10] is fixed as 80
336 // So for upstream PQ, instanceId will be like 0x8001, 0x8002 ... etc
337 pkt = []byte{
338 0x00, 0x43, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
339 0x01, 0x15, 0x80, 0x00, 0xff, 0xf0, 0x00, 0x01,
340 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
341 0x20, 0x00, 0x00, 0x80, 0x20, 0x01, 0x00, 0x01,
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344 }
345
346 pkt[11] = state.priorQInstance
347 pkt[24] = state.tcontPointer
348 pkt[26] = state.priorQPriority % NumPriorQPerTcont // Priority of this PriorQ
349 pkt[28] = state.tcontInstance
350 state.priorQPriority++
351
352
353 case 282, 283, 284, 285, 286, 287, 288, 289:
354 // Traffic Scheduler
355 // log.Println("Traffic Scheduler")
356 pkt = []byte{
357 0x02, 0xa4, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
358 0x01, 0x16, 0x80, 0x00, 0xf0, 0x00, 0x80, 0x00,
359 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
363 }
364
365 pkt[15] = state.tcontInstance
366 state.tcontInstance++
367
368 case 290:
369 // ONT-2G
370 // log.Println("ONT-2G")
371 pkt = []byte{
372 0x00, 0x16, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
373 0x01, 0x01, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x40,
374 0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
375 0x00, 0x7f, 0x00, 0x00, 0x3f, 0x00, 0x01, 0x00,
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
378 }
379
380 default:
381 state.extraMibUploadCtr++
382 errstr := fmt.Sprintf("%v - Invalid MibUpload request: %d, extras: %d", key, state.mibUploadCtr, state)
383 return nil, errors.New(errstr)
384 }
385
386 state.mibUploadCtr++
387 return pkt, nil
388}
389
390func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
391 var pkt []byte
392
393 pkt = []byte{
394 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
400
401 log.WithFields(log.Fields{
402 "IntfId": key.IntfId,
403 "OnuId": key.OnuId,
404 }).Tracef("Omci Set")
405
406 return pkt, nil
407}
408
409func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
410 var pkt []byte
411
412 if class == GEMPortNetworkCTP {
413 OnuOmciStateMapLock.RLock()
414 defer OnuOmciStateMapLock.RUnlock()
415 if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
416 log.WithFields(log.Fields{
417 "IntfId": key.IntfId,
418 "OnuId": key.OnuId,
419 }).Tracef("ONU Key Error")
420 return nil, errors.New("ONU Key Error")
421 } else {
422 onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
423 log.WithFields(log.Fields{
424 "IntfId": key.IntfId,
425 "OnuId": key.OnuId,
426 }).Tracef("Gem Port Id %d", key, onuOmciState)
427 // FIXME
428 OnuOmciStateMap[key].state = DONE
429 omciCh <- OmciChMessage{
430 Type: GemPortAdded,
431 Data: OmciChMessageData{
432 OnuId: key.OnuId,
433 IntfId: key.IntfId,
434 },
435 }
436 }
437 }
438
439 pkt = []byte{
440 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01,
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
446
447 log.WithFields(log.Fields{
448 "IntfId": key.IntfId,
449 "OnuId": key.OnuId,
450 }).Tracef("Omci Create")
451
452 return pkt, nil
453}
454
455func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
456 var pkt []byte
457
458 pkt = []byte{
459 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01,
460 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
461 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
463 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
464 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
465
466 pkt = GetAttributes(class, content, key, pkt)
467
468 log.WithFields(log.Fields{
469 "IntfId": key.IntfId,
470 "OnuId": key.OnuId,
471 }).Tracef("Omci Get")
472 return pkt, nil
473}
474
475func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
476 var pkt []byte
477
Matteo Scandolo732c0752020-01-28 07:24:13 -0800478 // Report number of commands as 1, basically there is always one alarm to get, the ONU/PPTP locked, link down or up
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700479 pkt = []byte{
480 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Matteo Scandolo732c0752020-01-28 07:24:13 -0800481 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700482 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
483 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
484 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
485 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
486
487 log.WithFields(log.Fields{
488 "IntfId": key.IntfId,
489 "OnuId": key.OnuId,
490 }).Tracef("Omci GetAllAlarms")
491
492 return pkt, nil
493}
494
495func syncTime(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
496 var pkt []byte
497
498 pkt = []byte{
499 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
500 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
501 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
502 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
503 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
504 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
505
506 log.WithFields(log.Fields{
507 "IntfId": key.IntfId,
508 "OnuId": key.OnuId,
509 }).Tracef("Omci syncTime")
510
511 return pkt, nil
512}
513
514func getAllAlarmsNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
515 var pkt []byte
516
Matteo Scandolo732c0752020-01-28 07:24:13 -0800517 OnuOmciStateMapLock.Lock()
518 if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
519 // if we are locked then admin down was sent and PPTP 257 is in alarm/locked state, this ensures get alarm
520 // shows that
521 if OnuOmciState.state == LOCKED {
522 // alarm set, alarm spot 0, LAN LOS
523 pkt = []byte{
524 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
525 0x00, 0x0b, 0x01, 0x01, 0x80, 0x00, 0x00, 0x00,
526 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
527 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
528 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
529 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
530 } else {
531 // alarm clear
532 pkt = []byte{
533 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
534 0x00, 0x0b, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
535 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
536 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
537 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
538 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
539 }
540 }
541 OnuOmciStateMapLock.Unlock()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700542
543 log.WithFields(log.Fields{
544 "IntfId": key.IntfId,
545 "OnuId": key.OnuId,
546 }).Tracef("Omci GetAllAlarmsNext")
547
548 return pkt, nil
549}
550
551func delete(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
552 var pkt []byte
553
554 pkt = []byte{
555 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
556 0x00, 0x0b, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
557 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
558 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
559 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
560 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
561
562 log.WithFields(log.Fields{
563 "IntfId": key.IntfId,
564 "OnuId": key.OnuId,
565 }).Tracef("Omci Delete")
566
567 return pkt, nil
568}
569
570func reboot(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
571 var pkt []byte
572 pkt = []byte{
573 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
574 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
575 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
576 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
579
580 log.WithFields(log.Fields{
581 "IntfId": key.IntfId,
582 "OnuId": key.OnuId,
583 }).Tracef("Omci Reboot")
584 return pkt, nil
585}
586
Matteo Scandoloca08fc72019-12-04 14:17:39 -0800587func testHandler(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
588 var pkt []byte
589 pkt = []byte{
590 0x20, 0x52, 0x45, 0x43, 0x56, 0x00, 0x20, 0x53,
591 0x45, 0x4e, 0x44, 0x00, 0x88, 0xb5, 0x02, 0x3f,
592 0x1b, 0x0a, 0x01, 0x07, 0x80, 0x01, 0x01, 0x00,
593 0xa5, 0x03, 0xe0, 0x0b, 0x05, 0x0b, 0x2b, 0x09,
594 0x1c, 0xd0, 0x0c, 0x32, 0x80, 0x00, 0x00, 0x00,
595 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
596 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
597 0x00, 0x28, 0xf8, 0x13, 0x1b, 0x36,}
598
599 log.WithFields(log.Fields{
600 "IntfId": key.IntfId,
601 "OnuId": key.OnuId,
602 }).Trace("Omci Test")
603 return pkt, nil
604}
605