|
2 | 2 | #include "sairedis.h"
|
3 | 3 |
|
4 | 4 | #include "meta/sai_serialize.h"
|
| 5 | +#include "meta/saiattributelist.h" |
5 | 6 |
|
6 | 7 | #include "swss/selectableevent.h"
|
7 | 8 | #include <string.h>
|
@@ -410,3 +411,119 @@ sai_status_t sai_query_attribute_enum_values_capability(
|
410 | 411 | SWSS_LOG_ERROR("Failed to receive a response from syncd");
|
411 | 412 | return SAI_STATUS_FAILURE;
|
412 | 413 | }
|
| 414 | + |
| 415 | +sai_status_t sai_object_type_get_availability( |
| 416 | + _In_ sai_object_id_t switch_id, |
| 417 | + _In_ sai_object_type_t object_type, |
| 418 | + _In_ uint32_t attr_count, |
| 419 | + _In_ const sai_attribute_t *attr_list, |
| 420 | + _Out_ uint64_t *count) |
| 421 | +{ |
| 422 | + MUTEX(); |
| 423 | + |
| 424 | + SWSS_LOG_ENTER(); |
| 425 | + |
| 426 | + const std::string switch_id_str = sai_serialize_object_id(switch_id); |
| 427 | + const std::string object_type_str = sai_serialize_object_type(object_type); |
| 428 | + std::vector<swss::FieldValueTuple> query_arguments = SaiAttributeList::serialize_attr_list( |
| 429 | + object_type, |
| 430 | + attr_count, |
| 431 | + attr_list, |
| 432 | + false); |
| 433 | + |
| 434 | + SWSS_LOG_DEBUG( |
| 435 | + "Query arguments: switch: %s, object type: %s, attributes: %s", |
| 436 | + switch_id_str.c_str(), |
| 437 | + object_type_str.c_str(), |
| 438 | + joinFieldValues(query_arguments).c_str() |
| 439 | + ); |
| 440 | + |
| 441 | + // Syncd will pop this argument off before trying to deserialize the attribute list |
| 442 | + query_arguments.push_back(swss::FieldValueTuple("OBJECT_TYPE", object_type_str)); |
| 443 | + |
| 444 | + if (g_record) |
| 445 | + { |
| 446 | + recordLine("q|object_type_get_availability|" + switch_id_str + "|" + joinFieldValues(query_arguments)); |
| 447 | + } |
| 448 | + |
| 449 | + // This query will not put any data into the ASIC view, just into the |
| 450 | + // message queue |
| 451 | + g_asicState->set(switch_id_str, query_arguments, objectTypeGetAvailabilityQuery); |
| 452 | + |
| 453 | + swss::Select callback; |
| 454 | + callback.addSelectable(g_redisGetConsumer.get()); |
| 455 | + |
| 456 | + while (true) |
| 457 | + { |
| 458 | + SWSS_LOG_DEBUG("Waiting for a response"); |
| 459 | + |
| 460 | + swss::Selectable *sel; |
| 461 | + |
| 462 | + auto result = callback.select(&sel, GET_RESPONSE_TIMEOUT); |
| 463 | + |
| 464 | + if (result == swss::Select::OBJECT) |
| 465 | + { |
| 466 | + swss::KeyOpFieldsValuesTuple kco; |
| 467 | + |
| 468 | + g_redisGetConsumer->pop(kco); |
| 469 | + |
| 470 | + const std::string &message_type = kfvOp(kco); |
| 471 | + const std::string &status_str = kfvKey(kco); |
| 472 | + |
| 473 | + SWSS_LOG_DEBUG("Received response: op = %s, key = %s", message_type.c_str(), status_str.c_str()); |
| 474 | + |
| 475 | + // Ignore messages that are not in response to our query |
| 476 | + if (message_type != objectTypeGetAvailabilityResponse) |
| 477 | + { |
| 478 | + continue; |
| 479 | + } |
| 480 | + |
| 481 | + sai_status_t status; |
| 482 | + sai_deserialize_status(status_str, status); |
| 483 | + |
| 484 | + if (status == SAI_STATUS_SUCCESS) |
| 485 | + { |
| 486 | + const std::vector<swss::FieldValueTuple> &values = kfvFieldsValues(kco); |
| 487 | + |
| 488 | + if (values.size() != 1) |
| 489 | + { |
| 490 | + if (g_record) |
| 491 | + { |
| 492 | + recordLine("Q|object_type_get_availability|SAI_STATUS_FAILURE"); |
| 493 | + } |
| 494 | + |
| 495 | + SWSS_LOG_ERROR("Invalid response from syncd: expected 1 value, received %d", values.size()); |
| 496 | + return SAI_STATUS_FAILURE; |
| 497 | + } |
| 498 | + |
| 499 | + const std::string &availability_str = fvValue(values[0]); |
| 500 | + *count = std::stol(availability_str); |
| 501 | + |
| 502 | + SWSS_LOG_DEBUG("Received payload: count = %lu", *count); |
| 503 | + |
| 504 | + if (g_record) |
| 505 | + { |
| 506 | + recordLine("Q|object_type_get_availability|" + status_str + "|" + joinFieldValues(values)); |
| 507 | + } |
| 508 | + } |
| 509 | + else |
| 510 | + { |
| 511 | + if (g_record) |
| 512 | + { |
| 513 | + recordLine("Q|object_type_get_availability|" + status_str); |
| 514 | + } |
| 515 | + } |
| 516 | + |
| 517 | + SWSS_LOG_DEBUG("Status: %s", status_str.c_str()); |
| 518 | + return status; |
| 519 | + } |
| 520 | + } |
| 521 | + |
| 522 | + if (g_record) |
| 523 | + { |
| 524 | + recordLine("Q|object_type_get_availability|SAI_STATUS_FAILURE"); |
| 525 | + } |
| 526 | + |
| 527 | + SWSS_LOG_ERROR("Failed to receive a response from syncd"); |
| 528 | + return SAI_STATUS_FAILURE; |
| 529 | +} |
0 commit comments