blob: 250d1681bb50fc5616d1c7a1cd01443af7fc6ce6 [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 "fTeidIe.h"
15#include "dataTypeCodecUtils.h"
16
17FTeidIe::FTeidIe()
18{
19 ieType = 87;
20 // TODO
21
22}
23
24FTeidIe::~FTeidIe() {
25 // TODO Auto-generated destructor stub
26}
27
28bool FTeidIe::encodeFTeidIe(MsgBuffer &buffer, FTeidIeData const &data)
29{
30 if(!(buffer.writeBits(data.ipv4present, 1)))
31 {
32 errorStream.add((char *)"Encoding of ipv4present failed\n");
33 return false;
34 }
35 if(!(buffer.writeBits(data.ipv6present, 1)))
36 {
37 errorStream.add((char *)"Encoding of ipv6present failed\n");
38 return false;
39 }
40 if(!(buffer.writeBits(data.interfaceType, 6)))
41 {
42 errorStream.add((char *)"Encoding of interfaceType failed\n");
43 return false;
44 }
45 if (!(buffer.writeUint32(data.teidGreKey)))
46 {
47 errorStream.add((char *)"Encoding of teidGreKey failed\n");
48 return false;
49 }
50 if (data.ipv4present)
51 {
52 if (!(DataTypeCodecUtils::encodeIpAddressV4(buffer, data.ipV4Address)))
53 {
54 errorStream.add((char *)"Encoding of ipV4Address failed\n");
55 return false;
56 }
57 }
58 if (data.ipv6present)
59 {
60 if (!(DataTypeCodecUtils::encodeIpAddressV6(buffer, data.ipV6Address)))
61 {
62 errorStream.add((char *)"Encoding of ipV6Address failed\n");
63 return false;
64 }
65 }
66
67 return true;
68}
69
70bool FTeidIe::decodeFTeidIe(MsgBuffer &buffer, FTeidIeData &data, Uint16 length)
71{
72 // TODO optimize the length checks
73
74 Uint16 ieBoundary = buffer.getCurrentIndex() + length;
75 data.ipv4present = buffer.readBits(1);
76 // confirm that we are not reading beyond the IE boundary
77 if (buffer.getCurrentIndex() > ieBoundary)
78 {
79 errorStream.add((char *)"Attempt to read beyond IE boundary: ipv4present\n");
80 return false;
81 }
82 data.ipv6present = buffer.readBits(1);
83 // confirm that we are not reading beyond the IE boundary
84 if (buffer.getCurrentIndex() > ieBoundary)
85 {
86 errorStream.add((char *)"Attempt to read beyond IE boundary: ipv6present\n");
87 return false;
88 }
89 data.interfaceType = buffer.readBits(6);
90 // confirm that we are not reading beyond the IE boundary
91 if (buffer.getCurrentIndex() > ieBoundary)
92 {
93 errorStream.add((char *)"Attempt to read beyond IE boundary: interfaceType\n");
94 return false;
95 }
96
97 buffer.readUint32(data.teidGreKey);
98 if (buffer.getCurrentIndex() > ieBoundary)
99 {
100 errorStream.add((char *)"Attempt to read beyond IE boundary: teidGreKey\n");
101 return false;
102 }
103
104 Uint16 lengthLeft = length;
105
106 if (data.ipv4present)
107 {
108 lengthLeft = ieBoundary - buffer.getCurrentIndex();
109 if (!(DataTypeCodecUtils::decodeIpAddressV4(buffer, data.ipV4Address, lengthLeft)))
110 {
111 errorStream.add((char *)"Failed to decode: ipV4Address\n");
112 return false;
113 }
114 }
115
116 if (data.ipv6present)
117 {
118 lengthLeft = ieBoundary - buffer.getCurrentIndex();
119 if (!(DataTypeCodecUtils::decodeIpAddressV6(buffer, data.ipV6Address, lengthLeft)))
120 {
121 errorStream.add((char *)"Failed to decode: ipV6Address\n");
122 return false;
123 }
124 }
125
126 // The IE is decoded now. The buffer index should be pointing to the
127 // IE Boundary. If not, we have some more data left for the IE which we don't know
128 // how to decode
129 if (ieBoundary == buffer.getCurrentIndex())
130 {
131 return true;
132 }
133 else
134 {
135 errorStream.add((char *)"Unable to decode IE FTeidIe\n");
136 return false;
137 }
138}
139void FTeidIe::displayFTeidIe_v(FTeidIeData const &data, Debug &stream)
140{
141 stream.incrIndent();
142 stream.add((char *)"FTeidIeData:");
143 stream.incrIndent();
144 stream.endOfLine();
145
146 stream.add( (char *)"ipv4present: ");
147 stream.add((Uint8)data.ipv4present);
148 stream.endOfLine();
149
150 stream.add( (char *)"ipv6present: ");
151 stream.add((Uint8)data.ipv6present);
152 stream.endOfLine();
153
154 stream.add( (char *)"interfaceType: ");
155 stream.add((Uint8)data.interfaceType);
156 stream.endOfLine();
157
158 stream.add((char *)"teidGreKey: ");
159 stream.add(data.teidGreKey);
160 stream.endOfLine();
161
162 if (data.ipv4present)
163 {
164 stream.add((char *)"ipV4Address:");
165 stream.endOfLine();
166 DataTypeCodecUtils::displayIpAddressV4_v(data.ipV4Address, stream);
167 }
168
169 if (data.ipv6present)
170 {
171 stream.add((char *)"ipV6Address:");
172 stream.endOfLine();
173 DataTypeCodecUtils::displayIpAddressV6_v(data.ipV6Address, stream);
174 }
175 stream.decrIndent();
176 stream.decrIndent();
177}