blob: aa43dbe5643c2a825eb86726d070e3f3bb9588d0 [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 * This is an auto generated file.
9 * Please do not edit this file.
10 * All edits to be made through template source file
11 * <TOP-DIR/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt>
12 ******************************************************************************/
13
14#include "fqCsidIe.h"
15#include "dataTypeCodecUtils.h"
16
17FqCsidIe::FqCsidIe()
18{
19 ieType = 132;
20 // TODO
21
22}
23
24FqCsidIe::~FqCsidIe() {
25 // TODO Auto-generated destructor stub
26}
27
28bool FqCsidIe::encodeFqCsidIe(MsgBuffer &buffer, FqCsidIeData const &data)
29{
30 if(!(buffer.writeBits(data.nodeIdType, 4)))
31 {
32 errorStream.add((char *)"Encoding of nodeIdType failed\n");
33 return false;
34 }
35 if(!(buffer.writeBits(data.numberOfCsids, 4)))
36 {
37 errorStream.add((char *)"Encoding of numberOfCsids failed\n");
38 return false;
39 }
40 if (data.nodeIdType == 0)
41 {
42 if (!(DataTypeCodecUtils::encodeIpAddressV4(buffer, data.nodeIdIpv4)))
43 {
44 errorStream.add((char *)"Encoding of nodeIdIpv4 failed\n");
45 return false;
46 }
47 }
48 if (data.nodeIdType == 1)
49 {
50 if (!(DataTypeCodecUtils::encodeIpAddressV6(buffer, data.nodeIdIpv6)))
51 {
52 errorStream.add((char *)"Encoding of nodeIdIpv6 failed\n");
53 return false;
54 }
55 }
56 if (data.nodeIdType == 2)
57 {
58 if (!(buffer.writeUint32(data.nodeIdUint32)))
59 {
60 errorStream.add((char *)"Encoding of nodeIdUint32 failed\n");
61 return false;
62 }
63 }
64 if (!(DataTypeCodecUtils::encodeUint16Array16(buffer, data.csidList)))
65 {
66 errorStream.add((char *)"Encoding of csidList failed\n");
67 return false;
68 }
69
70 return true;
71}
72
73bool FqCsidIe::decodeFqCsidIe(MsgBuffer &buffer, FqCsidIeData &data, Uint16 length)
74{
75 // TODO optimize the length checks
76
77 Uint16 ieBoundary = buffer.getCurrentIndex() + length;
78 data.nodeIdType = buffer.readBits(4);
79 // confirm that we are not reading beyond the IE boundary
80 if (buffer.getCurrentIndex() > ieBoundary)
81 {
82 errorStream.add((char *)"Attempt to read beyond IE boundary: nodeIdType\n");
83 return false;
84 }
85 data.numberOfCsids = buffer.readBits(4);
86 // confirm that we are not reading beyond the IE boundary
87 if (buffer.getCurrentIndex() > ieBoundary)
88 {
89 errorStream.add((char *)"Attempt to read beyond IE boundary: numberOfCsids\n");
90 return false;
91 }
92
93 Uint16 lengthLeft = length;
94
95 if (data.nodeIdType == 0)
96 {
97 lengthLeft = ieBoundary - buffer.getCurrentIndex();
98 if (!(DataTypeCodecUtils::decodeIpAddressV4(buffer, data.nodeIdIpv4, lengthLeft)))
99 {
100 errorStream.add((char *)"Failed to decode: nodeIdIpv4\n");
101 return false;
102 }
103 }
104
105 if (data.nodeIdType == 1)
106 {
107 lengthLeft = ieBoundary - buffer.getCurrentIndex();
108 if (!(DataTypeCodecUtils::decodeIpAddressV6(buffer, data.nodeIdIpv6, lengthLeft)))
109 {
110 errorStream.add((char *)"Failed to decode: nodeIdIpv6\n");
111 return false;
112 }
113 }
114
115 if (data.nodeIdType == 2)
116 {
117
118 buffer.readUint32(data.nodeIdUint32);
119 if (buffer.getCurrentIndex() > ieBoundary)
120 {
121 errorStream.add((char *)"Attempt to read beyond IE boundary: nodeIdUint32\n");
122 return false;
123 }
124 }
125 lengthLeft = ieBoundary - buffer.getCurrentIndex();
126 if (!(DataTypeCodecUtils::decodeUint16Array16(buffer, data.csidList, lengthLeft, data.numberOfCsids)))
127 {
128 errorStream.add((char *)"Failed to decode: csidList\n");
129 return false;
130 }
131
132 // The IE is decoded now. The buffer index should be pointing to the
133 // IE Boundary. If not, we have some more data left for the IE which we don't know
134 // how to decode
135 if (ieBoundary == buffer.getCurrentIndex())
136 {
137 return true;
138 }
139 else
140 {
141 errorStream.add((char *)"Unable to decode IE FqCsidIe\n");
142 return false;
143 }
144}
145void FqCsidIe::displayFqCsidIe_v(FqCsidIeData const &data, Debug &stream)
146{
147 stream.incrIndent();
148 stream.add((char *)"FqCsidIeData:");
149 stream.incrIndent();
150 stream.endOfLine();
151
152 stream.add( (char *)"nodeIdType: ");
153 stream.add((Uint8)data.nodeIdType);
154 stream.endOfLine();
155
156 stream.add( (char *)"numberOfCsids: ");
157 stream.add((Uint8)data.numberOfCsids);
158 stream.endOfLine();
159
160 if (data.nodeIdType == 0)
161 {
162 stream.add((char *)"nodeIdIpv4:");
163 stream.endOfLine();
164 DataTypeCodecUtils::displayIpAddressV4_v(data.nodeIdIpv4, stream);
165 }
166
167 if (data.nodeIdType == 1)
168 {
169 stream.add((char *)"nodeIdIpv6:");
170 stream.endOfLine();
171 DataTypeCodecUtils::displayIpAddressV6_v(data.nodeIdIpv6, stream);
172 }
173
174 if (data.nodeIdType == 2)
175 {
176 stream.add((char *)"nodeIdUint32: ");
177 stream.add(data.nodeIdUint32);
178 stream.endOfLine();
179 }
180
181 stream.add((char *)"csidList:");
182 stream.endOfLine();
183 DataTypeCodecUtils::displayUint16Array16_v(data.csidList, stream);
184 stream.decrIndent();
185 stream.decrIndent();
186}