blob: 60935b4c3bafe8944b24bffff47b64639763e8a0 [file] [log] [blame]
/*
* Copyright 2019-present Infosys Limited  
*   
* SPDX-License-Identifier: Apache-2.0    
*/
/******************************************************************************
*
* This is an auto generated file.
* Please do not edit this file.
* All edits to be made through template source file
* <TOP-DIR/scripts/GtpV2StackCodeGen/tts/grpieinsttemplate.cpp.tt>
******************************************************************************/
#include "[% tempdata.fileName %].h"
#include "manual/gtpV2Ie.h"
#include "gtpV2IeFactory.h"
[% FOREACH ieData IN tempdata.ieList -%]
#include "[% ieData.ieFileName %].h"
[% END -%]
[% tempdata.msgClassName %]::
[% tempdata.msgClassName %]()
{
[% PROCESS MandIeList %]
}
[% tempdata.msgClassName %]::
~[% tempdata.msgClassName %]()
{
}
bool [% tempdata.msgClassName %]::
encode[% tempdata.msgClassName %](MsgBuffer &buffer,
[% tempdata.msgClassName %]Data
const &data)
{
bool rc = false;
GtpV2IeHeader header;
Uint16 startIndex = 0;
Uint16 endIndex = 0;
Uint16 length = 0;
[% FOREACH ieData IN tempdata.ieList -%]
[% IF ieData.iePresence != 'M' -%]
if (data.[% ieData.ieVarName %]IePresent)
{
[% INCLUDE tts/msgEncode.tt FILTER indent%]
if (!(rc))
{
errorStream.add((char *)"Failed to encode IE: [% ieData.ieVarName %]\n");
return false;
}
}
[% ELSE %]
[% INCLUDE tts/msgEncode.tt -%]
if (!(rc))
{
errorStream.add((char *)"Failed to encode IE: [% ieData.ieVarName %]\n");
return false;
}
[% END -%]
[% END -%]
return rc;
}
bool [% tempdata.msgClassName %]::
decode[% tempdata.msgClassName %](MsgBuffer &buffer,
[% tempdata.msgClassName %]Data
&data, Uint16 length)
{
bool rc = false;
GtpV2IeHeader ieHeader;
set<Uint16> mandatoryIeLocalList = mandatoryIeSet;
while (buffer.lengthLeft() > IE_HEADER_SIZE)
{
GtpV2Ie::decodeGtpV2IeHeader(buffer, ieHeader);
if (ieHeader.length > buffer.lengthLeft())
{
// We do not have enough bytes left in the message for this IE
errorStream.add((char *)"IE Length exceeds beyond message boundary\n");
errorStream.add((char *)" Offending IE Type: ");
errorStream.add(ieHeader.ieType);
errorStream.add((char *)"\n Ie Length in Header: ");
errorStream.add(ieHeader.length);
errorStream.add((char *)"\n Bytes left in message: ");
errorStream.add(buffer.lengthLeft());
errorStream.endOfLine();
return false;
}
switch (ieHeader.ieType){
[% FOREACH ieTypeEntry IN tempdata.ieTypeList -%]
case [% ieTypeEntry %]IeType:
{
[% ieTypeEntry %]Ie ieObject =
dynamic_cast<
[% ieTypeEntry %]Ie&>(GtpV2IeFactory::getInstance().
getIeObject([% ieTypeEntry %]IeType));
[% SET first = 1 -%]
[% FOREACH ieTypeData IN tempdata.ieList -%]
[% IF ieTypeData.ieType == ieTypeEntry -%]
[% IF first == 1 -%]
[% SET first = 0 %]
if(ieHeader.instance == [% ieTypeData.instance %])
[% ELSE -%]
else if(ieHeader.instance == [% ieTypeData.instance %])
[% END -%]
{
[% INCLUDE tts/msgDecode.tt %]
[% IF ieTypeData.ieCardinality == 1 %][% IF ieTypeData.iePresence != "M" -%]
data.[% ieTypeData.ieVarName %]IePresent = true;
[% END %][% END -%]
if (!(rc))
{
errorStream.add((char *)"Failed to decode IE: [% ieTypeData.ieVarName %]\n");
return false;
}
[% IF ieTypeData.iePresence == 'M' -%]
Uint16 mandIe = [% ieTypeEntry %]IeType;
mandIe = (mandIe << 8) | [% ieTypeData.instance %];
mandatoryIeLocalList.erase(mandIe);
[% END -%]
}
[% END -%]
[% END -%]
else
{
// Unknown IE instance print error TODO
errorStream.add((char *)"Unknown IE Type: ");
errorStream.add(ieHeader.ieType);
errorStream.endOfLine();
buffer.skipBytes(ieHeader.length);
}
break;
}
[% END -%]
default:
{
// Unknown IE print error
errorStream.add((char *)"Unknown IE Type: ");
errorStream.add(ieHeader.ieType);
errorStream.endOfLine();
buffer.skipBytes(ieHeader.length);
}
}
}
if (!mandatoryIeLocalList.empty())
{
// some mandatory IEs are missing
errorStream.add((char *)"Missing Mandatory IEs:");
errorStream.endOfLine();
while (!mandatoryIeLocalList.empty())
{
Uint16 missingMandIe = *mandatoryIeLocalList.begin ();
mandatoryIeLocalList.erase (mandatoryIeLocalList.begin ());
Uint16 missingInstance = missingMandIe & 0x00FF;
Uint16 missingIeType = (missingMandIe >> 8);
errorStream.add ((char *)"Missing Ie type: ");
errorStream.add (missingIeType);
errorStream.add ((char *)" Instance: ");
errorStream.add (missingInstance);
errorStream.endOfLine();
}
rc = false;
}
return rc;
}
void [% tempdata.msgClassName %]::
display[% tempdata.msgClassName %]Data_v
([% tempdata.msgClassName %]Data const &data, Debug &stream)
{
stream.incrIndent();
stream.add((char *)"[% tempdata.msgClassName %]:");
stream.endOfLine();
stream.incrIndent();
[% FOREACH ieData IN tempdata.ieList -%]
[% IF ieData.iePresence != 'M' -%][% IF ieData.ieCardinality == 1 -%]
if (data.[% ieData.ieVarName %]IePresent)
{
[% IF ieData.ieCardinality == 1 -%]
stream.add((char *)"[% ieData.ieVarName %]:");
stream.endOfLine();
[% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
dynamic_cast<
[% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
[% PROCESS ieDisplay_grp %]
[% ELSE -%]
for (Uint8 i = 0; i < data.[% ieData.ieVarName %]Count; i++)
{
stream.add((char *)"IE - [% ieData.ieVarName %]:");
stream.endOfLine();
[% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
dynamic_cast<[% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
[% PROCESS ieDisplay_grp %]
}
[% END -%]
}
[% ELSE -%]
[% IF ieData.ieCardinality == 1 -%]
stream.add((char *)"[% ieData.ieVarName %]:");
stream.endOfLine();
[% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
dynamic_cast<
[% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
[% PROCESS ieDisplay_grp -%]
[% ELSE -%]
for (Uint8 i = 0; i < data.[% ieData.ieVarName %]Count; i++)
{
stream.add((char *)"IE - [% ieData.ieVarName %]:");
stream.endOfLine();
[% ieData.ieType %]Ie [% ieData.ieLocalVar %]=
dynamic_cast<[% ieData.ieType %]Ie&>(GtpV2IeFactory::getInstance().getIeObject([% ieData.ieType %]IeType));
[% PROCESS ieDisplay_grp -%]
}
[% END -%]
[% END %][% END -%]
[% END -%]
stream.decrIndent();
stream.decrIndent();
}
[% BLOCK ieDisplay_grp -%]
[% IF ieData.grouped == "Yes" -%]
[% ieData.grpIeInstClassName %] groupedIeInstance =
dynamic_cast<
[% ieData.grpIeInstClassName %]&>([% ieData.ieLocalVar %].getGroupedIe(msgType, [% ieData.instance %]));
groupedIeInstance.display[% ieData.grpIeInstClassName %]Data_v(data.[% ieData.ieVarName %][% PROCESS cardinalIndex %], stream);
[% ELSE -%]
[% ieData.ieLocalVar %].display[% ieData.ieType %]Ie_v(data.[% ieData.ieVarName %][% PROCESS cardinalIndex %], stream);
[% END -%]
[% END -%]
[% BLOCK cardinalIndex -%]
[% IF ieData.ieCardinality != 1 %][i][% END -%]
[% END -%]
[% BLOCK MandIeList -%]
[% SET first = 1 -%]
[% FOREACH ieData IN tempdata.ieList -%]
[% IF ieData.iePresence == 'M' -%]
[% IF first == 1 -%]
Uint16 mandIe;
[% SET first = 0 -%]
[% END -%]
mandIe = [% ieData.ieType %]IeType;
mandIe = (mandIe << 8) | [% ieData.instance %]; // [% ieData.ieVarName %]
mandatoryIeSet.insert(mandIe);
[% END -%]
[% END -%]
[% END -%]