anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 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 "sgwsNodeLevelLoadControlInformationInDownlinkDataNotification.h" |
| 16 | #include "manual/gtpV2Ie.h" |
| 17 | #include "gtpV2IeFactory.h" |
| 18 | #include "sequenceNumberIe.h" |
| 19 | #include "metricIe.h" |
| 20 | |
| 21 | SgwsNodeLevelLoadControlInformationInDownlinkDataNotification:: |
| 22 | SgwsNodeLevelLoadControlInformationInDownlinkDataNotification() |
| 23 | { |
| 24 | Uint16 mandIe; |
| 25 | mandIe = SequenceNumberIeType; |
| 26 | mandIe = (mandIe << 8) | 0; // loadControlSequenceNumber |
| 27 | mandatoryIeSet.insert(mandIe); |
| 28 | mandIe = MetricIeType; |
| 29 | mandIe = (mandIe << 8) | 0; // loadMetric |
| 30 | mandatoryIeSet.insert(mandIe); |
| 31 | |
| 32 | } |
| 33 | |
| 34 | SgwsNodeLevelLoadControlInformationInDownlinkDataNotification:: |
| 35 | ~SgwsNodeLevelLoadControlInformationInDownlinkDataNotification() |
| 36 | { |
| 37 | |
| 38 | } |
| 39 | bool SgwsNodeLevelLoadControlInformationInDownlinkDataNotification:: |
| 40 | encodeSgwsNodeLevelLoadControlInformationInDownlinkDataNotification(MsgBuffer &buffer, |
| 41 | SgwsNodeLevelLoadControlInformationInDownlinkDataNotificationData |
| 42 | const &data) |
| 43 | { |
| 44 | bool rc = false; |
| 45 | GtpV2IeHeader header; |
| 46 | Uint16 startIndex = 0; |
| 47 | Uint16 endIndex = 0; |
| 48 | Uint16 length = 0; |
| 49 | |
| 50 | |
| 51 | |
| 52 | // Encode the Ie Header |
| 53 | header.ieType = SequenceNumberIeType; |
| 54 | header.instance = 0; |
| 55 | header.length = 0; // We will encode the IE first and then update the length |
| 56 | GtpV2Ie::encodeGtpV2IeHeader(buffer, header); |
| 57 | startIndex = buffer.getCurrentIndex(); |
| 58 | SequenceNumberIe sequenceNumber= |
| 59 | dynamic_cast< |
| 60 | SequenceNumberIe&>(GtpV2IeFactory::getInstance().getIeObject(SequenceNumberIeType)); |
| 61 | rc = sequenceNumber.encodeSequenceNumberIe(buffer, data.loadControlSequenceNumber); |
| 62 | endIndex = buffer.getCurrentIndex(); |
| 63 | length = endIndex - startIndex; |
| 64 | |
| 65 | // encode the length value now |
| 66 | buffer.goToIndex(startIndex - 3); |
| 67 | buffer.writeUint16(length, false); |
| 68 | buffer.goToIndex(endIndex); |
| 69 | if (!(rc)) |
| 70 | { |
| 71 | errorStream.add((char *)"Failed to encode IE: loadControlSequenceNumber\n"); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | |
| 77 | // Encode the Ie Header |
| 78 | header.ieType = MetricIeType; |
| 79 | header.instance = 0; |
| 80 | header.length = 0; // We will encode the IE first and then update the length |
| 81 | GtpV2Ie::encodeGtpV2IeHeader(buffer, header); |
| 82 | startIndex = buffer.getCurrentIndex(); |
| 83 | MetricIe metric= |
| 84 | dynamic_cast< |
| 85 | MetricIe&>(GtpV2IeFactory::getInstance().getIeObject(MetricIeType)); |
| 86 | rc = metric.encodeMetricIe(buffer, data.loadMetric); |
| 87 | endIndex = buffer.getCurrentIndex(); |
| 88 | length = endIndex - startIndex; |
| 89 | |
| 90 | // encode the length value now |
| 91 | buffer.goToIndex(startIndex - 3); |
| 92 | buffer.writeUint16(length, false); |
| 93 | buffer.goToIndex(endIndex); |
| 94 | if (!(rc)) |
| 95 | { |
| 96 | errorStream.add((char *)"Failed to encode IE: loadMetric\n"); |
| 97 | return false; |
| 98 | } |
| 99 | return rc; |
| 100 | } |
| 101 | |
| 102 | bool SgwsNodeLevelLoadControlInformationInDownlinkDataNotification:: |
| 103 | decodeSgwsNodeLevelLoadControlInformationInDownlinkDataNotification(MsgBuffer &buffer, |
| 104 | SgwsNodeLevelLoadControlInformationInDownlinkDataNotificationData |
| 105 | &data, Uint16 length) |
| 106 | { |
| 107 | |
| 108 | bool rc = false; |
| 109 | GtpV2IeHeader ieHeader; |
| 110 | set<Uint16> mandatoryIeLocalList = mandatoryIeSet; |
| 111 | while (buffer.lengthLeft() > IE_HEADER_SIZE) |
| 112 | { |
| 113 | GtpV2Ie::decodeGtpV2IeHeader(buffer, ieHeader); |
| 114 | if (ieHeader.length > buffer.lengthLeft()) |
| 115 | { |
| 116 | // We do not have enough bytes left in the message for this IE |
| 117 | errorStream.add((char *)"IE Length exceeds beyond message boundary\n"); |
| 118 | errorStream.add((char *)" Offending IE Type: "); |
| 119 | errorStream.add(ieHeader.ieType); |
| 120 | errorStream.add((char *)"\n Ie Length in Header: "); |
| 121 | errorStream.add(ieHeader.length); |
| 122 | errorStream.add((char *)"\n Bytes left in message: "); |
| 123 | errorStream.add(buffer.lengthLeft()); |
| 124 | errorStream.endOfLine(); |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | switch (ieHeader.ieType){ |
| 129 | case SequenceNumberIeType: |
| 130 | { |
| 131 | SequenceNumberIe ieObject = |
| 132 | dynamic_cast< |
| 133 | SequenceNumberIe&>(GtpV2IeFactory::getInstance(). |
| 134 | getIeObject(SequenceNumberIeType)); |
| 135 | |
| 136 | |
| 137 | if(ieHeader.instance == 0) |
| 138 | { |
| 139 | |
| 140 | rc = ieObject.decodeSequenceNumberIe(buffer, data.loadControlSequenceNumber, ieHeader.length); |
| 141 | |
| 142 | if (!(rc)) |
| 143 | { |
| 144 | errorStream.add((char *)"Failed to decode IE: loadControlSequenceNumber\n"); |
| 145 | return false; |
| 146 | } |
| 147 | Uint16 mandIe = SequenceNumberIeType; |
| 148 | mandIe = (mandIe << 8) | 0; |
| 149 | mandatoryIeLocalList.erase(mandIe); |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | // Unknown IE instance print error TODO |
| 154 | errorStream.add((char *)"Unknown IE Type: "); |
| 155 | errorStream.add(ieHeader.ieType); |
| 156 | errorStream.endOfLine(); |
| 157 | buffer.skipBytes(ieHeader.length); |
| 158 | } |
| 159 | break; |
| 160 | } |
| 161 | case MetricIeType: |
| 162 | { |
| 163 | MetricIe ieObject = |
| 164 | dynamic_cast< |
| 165 | MetricIe&>(GtpV2IeFactory::getInstance(). |
| 166 | getIeObject(MetricIeType)); |
| 167 | |
| 168 | |
| 169 | if(ieHeader.instance == 0) |
| 170 | { |
| 171 | |
| 172 | rc = ieObject.decodeMetricIe(buffer, data.loadMetric, ieHeader.length); |
| 173 | |
| 174 | if (!(rc)) |
| 175 | { |
| 176 | errorStream.add((char *)"Failed to decode IE: loadMetric\n"); |
| 177 | return false; |
| 178 | } |
| 179 | Uint16 mandIe = MetricIeType; |
| 180 | mandIe = (mandIe << 8) | 0; |
| 181 | mandatoryIeLocalList.erase(mandIe); |
| 182 | } |
| 183 | else |
| 184 | { |
| 185 | // Unknown IE instance print error TODO |
| 186 | errorStream.add((char *)"Unknown IE Type: "); |
| 187 | errorStream.add(ieHeader.ieType); |
| 188 | errorStream.endOfLine(); |
| 189 | buffer.skipBytes(ieHeader.length); |
| 190 | } |
| 191 | break; |
| 192 | } |
| 193 | default: |
| 194 | { |
| 195 | // Unknown IE print error |
| 196 | errorStream.add((char *)"Unknown IE Type: "); |
| 197 | errorStream.add(ieHeader.ieType); |
| 198 | errorStream.endOfLine(); |
| 199 | buffer.skipBytes(ieHeader.length); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | if (!mandatoryIeLocalList.empty()) |
| 204 | { |
| 205 | // some mandatory IEs are missing |
| 206 | errorStream.add((char *)"Missing Mandatory IEs:"); |
| 207 | errorStream.endOfLine(); |
| 208 | while (!mandatoryIeLocalList.empty()) |
| 209 | { |
| 210 | Uint16 missingMandIe = *mandatoryIeLocalList.begin (); |
| 211 | mandatoryIeLocalList.erase (mandatoryIeLocalList.begin ()); |
| 212 | Uint16 missingInstance = missingMandIe & 0x00FF; |
| 213 | Uint16 missingIeType = (missingMandIe >> 8); |
| 214 | errorStream.add ((char *)"Missing Ie type: "); |
| 215 | errorStream.add (missingIeType); |
| 216 | errorStream.add ((char *)" Instance: "); |
| 217 | errorStream.add (missingInstance); |
| 218 | errorStream.endOfLine(); |
| 219 | } |
| 220 | rc = false; |
| 221 | |
| 222 | } |
| 223 | return rc; |
| 224 | } |
| 225 | |
| 226 | void SgwsNodeLevelLoadControlInformationInDownlinkDataNotification:: |
| 227 | displaySgwsNodeLevelLoadControlInformationInDownlinkDataNotificationData_v |
| 228 | (SgwsNodeLevelLoadControlInformationInDownlinkDataNotificationData const &data, Debug &stream) |
| 229 | { |
| 230 | stream.incrIndent(); |
| 231 | stream.add((char *)"SgwsNodeLevelLoadControlInformationInDownlinkDataNotification:"); |
| 232 | stream.endOfLine(); |
| 233 | stream.incrIndent(); |
| 234 | |
| 235 | |
| 236 | |
| 237 | stream.decrIndent(); |
| 238 | stream.decrIndent(); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |