MCPcopy Create free account
hub / github.com/SNAS/openbmp / decodeType_common

Method decodeType_common

Server/src/bgp/ExtCommunity.cpp:136–291  ·  view source on GitHub ↗

* Decode common Type/Subtypes * * \details * Decodes the common 2-octet, 4-octet, and IPv4 specific common subtypes. * Converts to human readable form. * * \param [in] ec_hdr Reference to the extended community header * \param [in] isGlobal4Bytes True if the global admin field is 4 bytes, false if 2 * \param [in] isGlobalIPv4 Tru

Source from the content-addressed store, hash-verified

134 * \return Decoded string value
135 */
136 std::string ExtCommunity::decodeType_common(const extcomm_hdr &ec_hdr, bool isGlobal4Bytes, bool isGlobalIPv4) {
137 std::stringstream val_ss;
138 uint16_t val_16b;
139 uint32_t val_32b;
140 char ipv4_char[16] = {0};
141
142 /*
143 * Decode values based on bit size
144 */
145 if (isGlobal4Bytes) {
146 // Four-byte global field
147 memcpy(&val_32b, ec_hdr.value, 4);
148 memcpy(&val_16b, ec_hdr.value + 4, 2);
149
150 bgp::SWAP_BYTES(&val_16b);
151
152 if (isGlobalIPv4) {
153 inet_ntop(AF_INET, &val_32b, ipv4_char, sizeof(ipv4_char));
154 } else
155 bgp::SWAP_BYTES(&val_32b);
156
157 } else {
158 // Two-byte global field
159 memcpy(&val_16b, ec_hdr.value, 2);
160 memcpy(&val_32b, ec_hdr.value + 2, 4);
161
162 // Chagne to host order
163 bgp::SWAP_BYTES(&val_16b);
164 bgp::SWAP_BYTES(&val_32b);
165 }
166
167 /*
168 * Decode by subtype
169 */
170 switch (ec_hdr.low_type) {
171
172 case EXT_COMMON_BGP_DATA_COL :
173 if (isGlobal4Bytes)
174 val_ss << "colc=" << val_32b << ":" << val_16b;
175
176 else
177 val_ss << "colc=" << val_16b << ":" << val_32b;
178
179 break;
180
181 case EXT_COMMON_ROUTE_ORIGIN :
182 if (isGlobalIPv4)
183 val_ss << "soo=" << ipv4_char << ":" << val_16b;
184
185 else if (isGlobal4Bytes)
186 val_ss << "soo=" << val_32b << ":" << val_16b;
187
188 else
189 val_ss << "soo=" << val_16b << ":" << val_32b;
190 break;
191
192 case EXT_COMMON_ROUTE_TARGET :
193 if (isGlobalIPv4)

Callers

nothing calls this directly

Calls 1

SWAP_BYTESFunction · 0.85

Tested by

no test coverage detected