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

Method parseAttrData

Server/src/bgp/UpdateMsg.cpp:322–525  ·  view source on GitHub ↗

* Parse attribute data based on attribute type * * \details * Parses the attribute data based on the passed attribute type. * Parsed_data will be updated based on the attribute data parsed. * * \param [in] attr_type Attribute type * \param [in] attr_len Length of the attribute data * \param [in] data Pointer to the attribute data * \param [out] parsed

Source from the content-addressed store, hash-verified

320 * \param [out] parsed_data Reference to parsed_update_data; will be updated with all parsed data
321 */
322void UpdateMsg::parseAttrData(u_char attr_type, uint16_t attr_len, u_char *data, parsed_update_data &parsed_data) {
323 std::string decodeStr = "";
324 u_char ipv4_raw[4];
325 char ipv4_char[16];
326 uint32_t value32bit;
327 uint16_t value16bit;
328
329 /*
330 * Parse based on attribute type
331 */
332 switch (attr_type) {
333
334 case ATTR_TYPE_ORIGIN : // Origin
335 switch (data[0]) {
336 case 0 : decodeStr.assign("igp"); break;
337 case 1 : decodeStr.assign("egp"); break;
338 case 2 : decodeStr.assign("incomplete"); break;
339 }
340
341 parsed_data.attrs[ATTR_TYPE_ORIGIN] = decodeStr;
342 break;
343
344 case ATTR_TYPE_AS_PATH : // AS_PATH
345 parseAttr_AsPath(attr_len, data, parsed_data.attrs);
346 break;
347
348 case ATTR_TYPE_NEXT_HOP : // Next hop v4
349 memcpy(ipv4_raw, data, 4);
350 inet_ntop(AF_INET, ipv4_raw, ipv4_char, sizeof(ipv4_char));
351 parsed_data.attrs[ATTR_TYPE_NEXT_HOP] = std::string(ipv4_char);
352 break;
353
354 case ATTR_TYPE_MED : // MED value
355 {
356 memcpy(&value32bit, data, 4);
357 bgp::SWAP_BYTES(&value32bit);
358 std::ostringstream numString;
359 numString << value32bit;
360 parsed_data.attrs[ATTR_TYPE_MED] = numString.str();
361 break;
362 }
363 case ATTR_TYPE_LOCAL_PREF : // local pref value
364 {
365 memcpy(&value32bit, data, 4);
366 bgp::SWAP_BYTES(&value32bit);
367 std::ostringstream numString;
368 numString << value32bit;
369 parsed_data.attrs[ATTR_TYPE_LOCAL_PREF] = numString.str();
370 break;
371 }
372 case ATTR_TYPE_ATOMIC_AGGREGATE : // Atomic aggregate
373 parsed_data.attrs[ATTR_TYPE_ATOMIC_AGGREGATE] = std::string("1");
374 break;
375
376 case ATTR_TYPE_AGGEGATOR : // Aggregator
377 parseAttr_Aggegator(attr_len, data, parsed_data.attrs);
378 break;
379

Callers

nothing calls this directly

Calls 6

SWAP_BYTESFunction · 0.85
parseExtCommunitiesMethod · 0.80
parsev6ExtCommunitiesMethod · 0.80
parseReachNlriAttrMethod · 0.80
parseUnReachNlriAttrMethod · 0.80
parseAttrLinkStateMethod · 0.80

Tested by

no test coverage detected