blob: 60935b4c3bafe8944b24bffff47b64639763e8a0 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright 2019-present Infosys Limited  
3 *   
4 * SPDX-License-Identifier: Apache-2.0    
5 */
6
7/******************************************************************************
8 *
9 * This is an auto generated file.
10 * Please do not edit this file.
11 * All edits to be made through template source file
12 * <TOP-DIR/scripts/GtpV2StackCodeGen/tts/grpieinsttemplate.cpp.tt>
13 ******************************************************************************/
14
15#include "[% tempdata.fileName %].h"
16#include "manual/gtpV2Ie.h"
17#include "gtpV2IeFactory.h"
18[% FOREACH ieData IN tempdata.ieList -%]
19#include "[% ieData.ieFileName %].h"
20[% END -%]
21
22[% tempdata.msgClassName %]::
23[% tempdata.msgClassName %]()
24{
25[% PROCESS MandIeList %]
26}
27
28[% tempdata.msgClassName %]::
29~[% tempdata.msgClassName %]()
30{
31
32}
33bool [% tempdata.msgClassName %]::
34encode[% tempdata.msgClassName %](MsgBuffer &buffer,
35 [% tempdata.msgClassName %]Data
36 const &data)
37{
38 bool rc = false;
39 GtpV2IeHeader header;
40 Uint16 startIndex = 0;
41 Uint16 endIndex = 0;
42 Uint16 length = 0;
43[% FOREACH ieData IN tempdata.ieList -%]
44
45[% IF ieData.iePresence != 'M' -%]
46 if (data.[% ieData.ieVarName %]IePresent)
47 {
48 [% INCLUDE tts/msgEncode.tt FILTER indent%]
49 if (!(rc))
50 {
51 errorStream.add((char *)"Failed to encode IE: [% ieData.ieVarName %]\n");
52 return false;
53 }
54 }
55[% ELSE %]
56 [% INCLUDE tts/msgEncode.tt -%]
57 if (!(rc))
58 {
59 errorStream.add((char *)"Failed to encode IE: [% ieData.ieVarName %]\n");
60 return false;
61 }
62[% END -%]
63[% END -%]
64 return rc;
65}
66
67bool [% tempdata.msgClassName %]::
68decode[% tempdata.msgClassName %](MsgBuffer &buffer,
69 [% tempdata.msgClassName %]Data
70 &data, Uint16 length)
71{
72
73 bool rc = false;
74 GtpV2IeHeader ieHeader;
75 set<Uint16> mandatoryIeLocalList = mandatoryIeSet;
76 while (buffer.lengthLeft() > IE_HEADER_SIZE)
77 {
78 GtpV2Ie::decodeGtpV2IeHeader(buffer, ieHeader);
79 if (ieHeader.length > buffer.lengthLeft())
80 {
81 // We do not have enough bytes left in the message for this IE
82 errorStream.add((char *)"IE Length exceeds beyond message boundary\n");
83 errorStream.add((char *)" Offending IE Type: ");
84 errorStream.add(ieHeader.ieType);
85 errorStream.add((char *)"\n Ie Length in Header: ");
86 errorStream.add(ieHeader.length);
87 errorStream.add((char *)"\n Bytes left in message: ");
88 errorStream.add(buffer.lengthLeft());
89 errorStream.endOfLine();
90 return false;
91 }
92
93 switch (ieHeader.ieType){
94[% FOREACH ieTypeEntry IN tempdata.ieTypeList -%]
95 case [% ieTypeEntry %]IeType:
96 {
97 [% ieTypeEntry %]Ie ieObject =
98 dynamic_cast<
99 [% ieTypeEntry %]Ie&>(GtpV2IeFactory::getInstance().
100 getIeObject([% ieTypeEntry %]IeType));
101[% SET first = 1 -%]
102[% FOREACH ieTypeData IN tempdata.ieList -%]
103[% IF ieTypeData.ieType == ieTypeEntry -%]
104
105[% IF first == 1 -%]
106[% SET first = 0 %]
107 if(ieHeader.instance == [% ieTypeData.instance %])
108[% ELSE -%]
109 else if(ieHeader.instance == [% ieTypeData.instance %])
110[% END -%]
111 {
112
113 [% INCLUDE tts/msgDecode.tt %]
114[% IF ieTypeData.ieCardinality == 1 %][% IF ieTypeData.iePresence != "M" -%]
115 data.[% ieTypeData.ieVarName %]IePresent = true;
116[% END %][% END -%]
117 if (!(rc))
118 {
119 errorStream.add((char *)"Failed to decode IE: [% ieTypeData.ieVarName %]\n");
120 return false;
121 }
122[% IF ieTypeData.iePresence == 'M' -%]
123 Uint16 mandIe = [% ieTypeEntry %]IeType;
124 mandIe = (mandIe << 8) | [% ieTypeData.instance %];
125 mandatoryIeLocalList.erase(mandIe);
126[% END -%]
127 }
128[% END -%]
129[% END -%]
130 else
131 {
132 // Unknown IE instance print error TODO
133 errorStream.add((char *)"Unknown IE Type: ");
134 errorStream.add(ieHeader.ieType);
135 errorStream.endOfLine();
136 buffer.skipBytes(ieHeader.length);
137 }
138 break;
139 }
140[% END -%]
141 default:
142 {
143 // Unknown IE print error
144 errorStream.add((char *)"Unknown IE Type: ");
145 errorStream.add(ieHeader.ieType);
146 errorStream.endOfLine();
147 buffer.skipBytes(ieHeader.length);
148 }
149 }
150 }
151 if (!mandatoryIeLocalList.empty())
152 {
153 // some mandatory IEs are missing
154 errorStream.add((char *)"Missing Mandatory IEs:");
155 errorStream.endOfLine();
156 while (!mandatoryIeLocalList.empty())
157 {
158 Uint16 missingMandIe = *mandatoryIeLocalList.begin ();
159 mandatoryIeLocalList.erase (mandatoryIeLocalList.begin ());
160 Uint16 missingInstance = missingMandIe & 0x00FF;
161 Uint16 missingIeType = (missingMandIe >> 8);
162 errorStream.add ((char *)"Missing Ie type: ");
163 errorStream.add (missingIeType);
164 errorStream.add ((char *)" Instance: ");
165 errorStream.add (missingInstance);
166 errorStream.endOfLine();
167 }
168 rc = false;
169
170 }
171 return rc;
172}
173
174void [% tempdata.msgClassName %]::
175display[% tempdata.msgClassName %]Data_v
176([% tempdata.msgClassName %]Data const &data, Debug &stream)
177{
178 stream.incrIndent();
179 stream.add((char *)"[% tempdata.msgClassName %]:");
180 stream.endOfLine();
181 stream.incrIndent();
182[% FOREACH ieData IN tempdata.ieList -%]
183
184[% IF ieData.iePresence != 'M' -%][% IF ieData.ieCardinality == 1 -%]
185 if (data.[% ieData.ieVarName %]IePresent)
186 {
187
188[% IF ieData.ieCardinality == 1 -%]
189 stream.add((char *)"[% ieData.ieVarName %]:");
190 stream.endOfLine();
191 [% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
192 dynamic_cast<
193 [% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
194 [% PROCESS ieDisplay_grp %]
195[% ELSE -%]
196 for (Uint8 i = 0; i < data.[% ieData.ieVarName %]Count; i++)
197 {
198 stream.add((char *)"IE - [% ieData.ieVarName %]:");
199 stream.endOfLine();
200 [% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
201 dynamic_cast<[% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
202 [% PROCESS ieDisplay_grp %]
203 }
204[% END -%]
205 }
206[% ELSE -%]
207[% IF ieData.ieCardinality == 1 -%]
208 stream.add((char *)"[% ieData.ieVarName %]:");
209 stream.endOfLine();
210 [% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
211 dynamic_cast<
212 [% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
213[% PROCESS ieDisplay_grp -%]
214[% ELSE -%]
215 for (Uint8 i = 0; i < data.[% ieData.ieVarName %]Count; i++)
216 {
217 stream.add((char *)"IE - [% ieData.ieVarName %]:");
218 stream.endOfLine();
219 [% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
220 dynamic_cast<[% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
221 [% PROCESS ieDisplay_grp -%]
222 }
223[% END -%]
224[% END %][% END -%]
225[% END -%]
226
227 stream.decrIndent();
228 stream.decrIndent();
229}
230
231
232[% BLOCK ieDisplay_grp -%]
233[% IF ieData.grouped == "Yes" -%]
234 [% ieData.grpIeInstClassName %] groupedIeInstance =
235 dynamic_cast<
236 [% ieData.grpIeInstClassName %]&>([% ieData.ieLocalVar %].getGroupedIe(msgType, [% ieData.instance %]));
237 groupedIeInstance.display[% ieData.grpIeInstClassName %]Data_v(data.[% ieData.ieVarName %][% PROCESS cardinalIndex %], stream);
238[% ELSE -%]
239 [% ieData.ieLocalVar %].display[% ieData.ieType %]Ie_v(data.[% ieData.ieVarName %][% PROCESS cardinalIndex %], stream);
240[% END -%]
241[% END -%]
242
243[% BLOCK cardinalIndex -%]
244[% IF ieData.ieCardinality != 1 %][i][% END -%]
245[% END -%]
246
247
248[% BLOCK MandIeList -%]
249[% SET first = 1 -%]
250[% FOREACH ieData IN tempdata.ieList -%]
251[% IF ieData.iePresence == 'M' -%]
252[% IF first == 1 -%]
253 Uint16 mandIe;
254[% SET first = 0 -%]
255[% END -%]
256 mandIe = [% ieData.ieType %]IeType;
257 mandIe = (mandIe << 8) | [% ieData.instance %]; // [% ieData.ieVarName %]
258 mandatoryIeSet.insert(mandIe);
259[% END -%]
260[% END -%]
261[% END -%]