blob: f05c34b14c3cff63052d6a9e9989faf2ea39c54c [file] [log] [blame]
Chip Boling6e27b352020-02-14 09:10:01 -06001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
Andrea Campanella7167ebb2020-02-24 09:56:38 +01003 * Copyright 2020-present Open Networking Foundation
4
Chip Boling6e27b352020-02-14 09:10:01 -06005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Andrea Campanella7167ebb2020-02-24 09:56:38 +01008
Chip Boling6e27b352020-02-14 09:10:01 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Andrea Campanella7167ebb2020-02-24 09:56:38 +010010
Chip Boling6e27b352020-02-14 09:10:01 -060011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Chip Boling6e27b352020-02-14 09:10:01 -060016 */
17
18package omci
19
20import (
21 "errors"
Andrea Campanella7167ebb2020-02-24 09:56:38 +010022 me "github.com/opencord/omci-lib-go/generated"
Chip Boling6e27b352020-02-14 09:10:01 -060023 "github.com/google/gopacket"
24)
25
26var nextLayerMapping map[MessageType]gopacket.LayerType
27
28var (
29 LayerTypeCreateRequest gopacket.LayerType
30 LayerTypeDeleteRequest gopacket.LayerType
31 LayerTypeSetRequest gopacket.LayerType
32 LayerTypeGetRequest gopacket.LayerType
33 LayerTypeGetAllAlarmsRequest gopacket.LayerType
34 LayerTypeGetAllAlarmsNextRequest gopacket.LayerType
35 LayerTypeMibUploadRequest gopacket.LayerType
36 LayerTypeMibUploadNextRequest gopacket.LayerType
37 LayerTypeMibResetRequest gopacket.LayerType
38 LayerTypeTestRequest gopacket.LayerType
39 LayerTypeStartSoftwareDownloadRequest gopacket.LayerType
40 LayerTypeDownloadSectionRequest gopacket.LayerType
41 LayerTypeDownloadSectionLastRequest gopacket.LayerType
42 LayerTypeEndSoftwareDownloadRequest gopacket.LayerType
43 LayerTypeActivateSoftwareRequest gopacket.LayerType
44 LayerTypeCommitSoftwareRequest gopacket.LayerType
45 LayerTypeSynchronizeTimeRequest gopacket.LayerType
46 LayerTypeRebootRequest gopacket.LayerType
47 LayerTypeGetNextRequest gopacket.LayerType
48 LayerTypeGetCurrentDataRequest gopacket.LayerType
49 LayerTypeSetTableRequest gopacket.LayerType
50)
51var (
52 LayerTypeCreateResponse gopacket.LayerType
53 LayerTypeDeleteResponse gopacket.LayerType
54 LayerTypeSetResponse gopacket.LayerType
55 LayerTypeGetResponse gopacket.LayerType
56 LayerTypeGetAllAlarmsResponse gopacket.LayerType
57 LayerTypeGetAllAlarmsNextResponse gopacket.LayerType
58 LayerTypeMibUploadResponse gopacket.LayerType
59 LayerTypeMibUploadNextResponse gopacket.LayerType
60 LayerTypeMibResetResponse gopacket.LayerType
61 LayerTypeAlarmNotification gopacket.LayerType
62 LayerTypeAttributeValueChange gopacket.LayerType
63 LayerTypeTestResponse gopacket.LayerType
64 LayerTypeStartSoftwareDownloadResponse gopacket.LayerType
65 LayerTypeDownloadSectionResponse gopacket.LayerType
66 LayerTypeEndSoftwareDownloadResponse gopacket.LayerType
67 LayerTypeActivateSoftwareResponse gopacket.LayerType
68 LayerTypeCommitSoftwareResponse gopacket.LayerType
69 LayerTypeSynchronizeTimeResponse gopacket.LayerType
70 LayerTypeRebootResponse gopacket.LayerType
71 LayerTypeGetNextResponse gopacket.LayerType
72 LayerTypeTestResult gopacket.LayerType
73 LayerTypeGetCurrentDataResponse gopacket.LayerType
74 LayerTypeSetTableResponse gopacket.LayerType
75)
76
77func mkReqLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
78 return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AR)),
79 gopacket.LayerTypeMetadata{Name: mts, Decoder: decode})
80}
81
82func mkRespLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
83 return gopacket.RegisterLayerType(1000+(int(mt)|int(me.AK)),
84 gopacket.LayerTypeMetadata{Name: mts, Decoder: decode})
85}
86
87func mkLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
88 return gopacket.RegisterLayerType(1000+(int(mt)),
89 gopacket.LayerTypeMetadata{Name: mts, Decoder: decode})
90}
91
92func init() {
93 // Create layers for message_type & action
94 LayerTypeCreateRequest = mkReqLayer(me.Create, "CreateRequest", gopacket.DecodeFunc(decodeCreateRequest))
95 LayerTypeDeleteRequest = mkReqLayer(me.Delete, "DeleteRequest", gopacket.DecodeFunc(decodeDeleteRequest))
96 LayerTypeSetRequest = mkReqLayer(me.Set, "SetRequest", gopacket.DecodeFunc(decodeSetRequest))
97 LayerTypeGetRequest = mkReqLayer(me.Get, "GetRequest", gopacket.DecodeFunc(decodeGetRequest))
98 LayerTypeGetAllAlarmsRequest = mkReqLayer(me.GetAllAlarms, "GetAllAlarmsRequest", gopacket.DecodeFunc(decodeGetAllAlarmsRequest))
99 LayerTypeGetAllAlarmsNextRequest = mkReqLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextRequest", gopacket.DecodeFunc(decodeGetAllAlarmsNextRequest))
100 LayerTypeMibUploadRequest = mkReqLayer(me.MibUpload, "MibUploadRequest", gopacket.DecodeFunc(decodeMibUploadRequest))
101 LayerTypeMibUploadNextRequest = mkReqLayer(me.MibUploadNext, "MibUploadNextRequest", gopacket.DecodeFunc(decodeMibUploadNextRequest))
102 LayerTypeMibResetRequest = mkReqLayer(me.MibReset, "MibResetRequest", gopacket.DecodeFunc(decodeMibResetRequest))
103 LayerTypeTestRequest = mkReqLayer(me.Test, "TestRequest", gopacket.DecodeFunc(decodeTestRequest))
104 LayerTypeStartSoftwareDownloadRequest = mkReqLayer(me.StartSoftwareDownload, "StartSoftwareDownloadRequest", gopacket.DecodeFunc(decodeStartSoftwareDownloadRequest))
105
106 // For Download section, AR=0 if not response expected, AR=1 if response expected (last section of a window)
107 LayerTypeDownloadSectionRequest = mkLayer(me.DownloadSection, "DownloadSectionRequest", gopacket.DecodeFunc(decodeDownloadSectionRequest))
108 LayerTypeDownloadSectionLastRequest = mkReqLayer(me.DownloadSection, "DownloadLastSectionRequest", gopacket.DecodeFunc(decodeDownloadSectionRequest))
109 LayerTypeEndSoftwareDownloadRequest = mkReqLayer(me.EndSoftwareDownload, "EndSoftwareDownloadRequest", gopacket.DecodeFunc(decodeEndSoftwareDownloadRequest))
110 LayerTypeActivateSoftwareRequest = mkReqLayer(me.ActivateSoftware, "ActivateSoftwareRequest", gopacket.DecodeFunc(decodeActivateSoftwareRequest))
111 LayerTypeCommitSoftwareRequest = mkReqLayer(me.CommitSoftware, "CommitSoftwareRequest", gopacket.DecodeFunc(decodeCommitSoftwareRequest))
112 LayerTypeSynchronizeTimeRequest = mkReqLayer(me.SynchronizeTime, "SynchronizeTimeRequest", gopacket.DecodeFunc(decodeSynchronizeTimeRequest))
113 LayerTypeRebootRequest = mkReqLayer(me.Reboot, "RebootRequest", gopacket.DecodeFunc(decodeRebootRequest))
114 LayerTypeGetNextRequest = mkReqLayer(me.GetNext, "GetNextRequest", gopacket.DecodeFunc(decodeGetNextRequest))
115 LayerTypeGetCurrentDataRequest = mkReqLayer(me.GetCurrentData, "GetCurrentDataRequest", gopacket.DecodeFunc(decodeGetCurrentDataRequest))
116 LayerTypeSetTableRequest = mkReqLayer(me.SetTable, "SetTableRequest", gopacket.DecodeFunc(decodeSetTableRequest))
117
118 LayerTypeCreateResponse = mkRespLayer(me.Create, "CreateResponse", gopacket.DecodeFunc(decodeCreateResponse))
119 LayerTypeDeleteResponse = mkRespLayer(me.Delete, "DeleteResponse", gopacket.DecodeFunc(decodeDeleteResponse))
120 LayerTypeSetResponse = mkRespLayer(me.Set, "SetResponse", gopacket.DecodeFunc(decodeSetResponse))
121 LayerTypeGetResponse = mkRespLayer(me.Get, "GetResponse", gopacket.DecodeFunc(decodeGetResponse))
122 LayerTypeGetAllAlarmsResponse = mkRespLayer(me.GetAllAlarms, "GetAllAlarmsResponse", gopacket.DecodeFunc(decodeGetAllAlarmsResponse))
123 LayerTypeGetAllAlarmsNextResponse = mkRespLayer(me.GetAllAlarmsNext, "GetAllAlarmsNextResponse", gopacket.DecodeFunc(decodeGetAllAlarmsNextResponse))
124 LayerTypeMibUploadResponse = mkRespLayer(me.MibUpload, "MibUploadResponse", gopacket.DecodeFunc(decodeMibUploadResponse))
125 LayerTypeMibUploadNextResponse = mkRespLayer(me.MibUploadNext, "MibUploadNextResponse", gopacket.DecodeFunc(decodeMibUploadNextResponse))
126 LayerTypeMibResetResponse = mkRespLayer(me.MibReset, "MibResetResponse", gopacket.DecodeFunc(decodeMibResetResponse))
127 LayerTypeAlarmNotification = mkLayer(me.AlarmNotification, "AlarmNotification", gopacket.DecodeFunc(decodeAlarmNotification))
128 LayerTypeAttributeValueChange = mkLayer(me.AttributeValueChange, "AttributeValueChange", gopacket.DecodeFunc(decodeAttributeValueChange))
129 LayerTypeTestResponse = mkRespLayer(me.Test, "TestResponse", gopacket.DecodeFunc(decodeTestResponse))
130 LayerTypeStartSoftwareDownloadResponse = mkRespLayer(me.StartSoftwareDownload, "StartSoftwareDownloadResponse", gopacket.DecodeFunc(decodeStartSoftwareDownloadResponse))
131 LayerTypeDownloadSectionResponse = mkRespLayer(me.DownloadSection, "DownloadSectionResponse", gopacket.DecodeFunc(decodeDownloadSectionResponse))
132 LayerTypeEndSoftwareDownloadResponse = mkRespLayer(me.EndSoftwareDownload, "EndSoftwareDownloadResponse", gopacket.DecodeFunc(decodeEndSoftwareDownloadResponse))
133 LayerTypeActivateSoftwareResponse = mkRespLayer(me.ActivateSoftware, "ActivateSoftwareResponse", gopacket.DecodeFunc(decodeActivateSoftwareResponse))
134 LayerTypeCommitSoftwareResponse = mkRespLayer(me.CommitSoftware, "CommitSoftwareResponse", gopacket.DecodeFunc(decodeCommitSoftwareResponse))
135 LayerTypeSynchronizeTimeResponse = mkRespLayer(me.SynchronizeTime, "SynchronizeTimeResponse", gopacket.DecodeFunc(decodeSynchronizeTimeResponse))
136 LayerTypeRebootResponse = mkRespLayer(me.Reboot, "RebootResponse", gopacket.DecodeFunc(decodeRebootResponse))
137 LayerTypeGetNextResponse = mkRespLayer(me.GetNext, "GetNextResponse", gopacket.DecodeFunc(decodeGetNextResponse))
138 LayerTypeTestResult = mkRespLayer(me.TestResult, "TestResult", gopacket.DecodeFunc(decodeTestResult))
139 LayerTypeGetCurrentDataResponse = mkRespLayer(me.GetCurrentData, "GetCurrentDataResponse", gopacket.DecodeFunc(decodeGetCurrentDataResponse))
140 LayerTypeSetTableResponse = mkRespLayer(me.SetTable, "SetTableResponse", gopacket.DecodeFunc(decodeSetTableResponse))
141
142 // Map message_type and action to layer
143 nextLayerMapping = make(map[MessageType]gopacket.LayerType)
144
145 nextLayerMapping[CreateRequestType] = LayerTypeCreateRequest
146 nextLayerMapping[DeleteRequestType] = LayerTypeDeleteRequest
147 nextLayerMapping[SetRequestType] = LayerTypeSetRequest
148 nextLayerMapping[GetRequestType] = LayerTypeGetRequest
149 nextLayerMapping[GetAllAlarmsRequestType] = LayerTypeGetAllAlarmsRequest
150 nextLayerMapping[GetAllAlarmsNextRequestType] = LayerTypeGetAllAlarmsNextRequest
151 nextLayerMapping[MibUploadRequestType] = LayerTypeMibUploadRequest
152 nextLayerMapping[MibUploadNextRequestType] = LayerTypeMibUploadNextRequest
153 nextLayerMapping[MibResetRequestType] = LayerTypeMibResetRequest
154 nextLayerMapping[TestRequestType] = LayerTypeTestRequest
155 nextLayerMapping[StartSoftwareDownloadRequestType] = LayerTypeStartSoftwareDownloadRequest
156 nextLayerMapping[DownloadSectionRequestType] = LayerTypeDownloadSectionRequest
157 nextLayerMapping[EndSoftwareDownloadRequestType] = LayerTypeEndSoftwareDownloadRequest
158 nextLayerMapping[ActivateSoftwareRequestType] = LayerTypeActivateSoftwareRequest
159 nextLayerMapping[CommitSoftwareRequestType] = LayerTypeCommitSoftwareRequest
160 nextLayerMapping[SynchronizeTimeRequestType] = LayerTypeSynchronizeTimeRequest
161 nextLayerMapping[RebootRequestType] = LayerTypeRebootRequest
162 nextLayerMapping[GetNextRequestType] = LayerTypeGetNextRequest
163 nextLayerMapping[GetCurrentDataRequestType] = LayerTypeGetCurrentDataRequest
164 nextLayerMapping[SetTableRequestType] = LayerTypeSetTableRequest
165
166 nextLayerMapping[CreateResponseType] = LayerTypeCreateResponse
167 nextLayerMapping[DeleteResponseType] = LayerTypeDeleteResponse
168 nextLayerMapping[SetResponseType] = LayerTypeSetResponse
169 nextLayerMapping[GetResponseType] = LayerTypeGetResponse
170 nextLayerMapping[GetAllAlarmsResponseType] = LayerTypeGetAllAlarmsResponse
171 nextLayerMapping[GetAllAlarmsNextResponseType] = LayerTypeGetAllAlarmsNextResponse
172 nextLayerMapping[MibUploadResponseType] = LayerTypeMibUploadResponse
173 nextLayerMapping[MibUploadNextResponseType] = LayerTypeMibUploadNextResponse
174 nextLayerMapping[MibResetResponseType] = LayerTypeMibResetResponse
175 nextLayerMapping[TestResponseType] = LayerTypeTestResponse
176 nextLayerMapping[StartSoftwareDownloadResponseType] = LayerTypeStartSoftwareDownloadResponse
177 nextLayerMapping[DownloadSectionResponseType] = LayerTypeDownloadSectionResponse
178 nextLayerMapping[EndSoftwareDownloadResponseType] = LayerTypeEndSoftwareDownloadResponse
179 nextLayerMapping[ActivateSoftwareResponseType] = LayerTypeActivateSoftwareResponse
180 nextLayerMapping[CommitSoftwareResponseType] = LayerTypeCommitSoftwareResponse
181 nextLayerMapping[SynchronizeTimeResponseType] = LayerTypeSynchronizeTimeResponse
182 nextLayerMapping[RebootResponseType] = LayerTypeRebootResponse
183 nextLayerMapping[GetNextResponseType] = LayerTypeGetNextResponse
184 nextLayerMapping[GetCurrentDataResponseType] = LayerTypeGetCurrentDataResponse
185 nextLayerMapping[SetTableResponseType] = LayerTypeSetTableResponse
186
187 nextLayerMapping[AttributeValueChangeType] = LayerTypeAttributeValueChange
188 nextLayerMapping[AlarmNotificationType] = LayerTypeAlarmNotification
189 nextLayerMapping[TestResultType] = LayerTypeTestResult
190}
191
192func MsgTypeToNextLayer(mt MessageType) (gopacket.LayerType, error) {
193 nextLayer, ok := nextLayerMapping[mt]
194 if ok {
195 return nextLayer, nil
196 }
197 return gopacket.LayerTypeZero, errors.New("unknown message type")
198}