|
| 1 | +#include "Switch.h" |
| 2 | + |
| 3 | +#include "swss/logger.h" |
| 4 | + |
| 5 | +#include <cstring> |
| 6 | + |
| 7 | +using namespace sairedis; |
| 8 | + |
| 9 | +Switch::Switch( |
| 10 | + _In_ sai_object_id_t switchId): |
| 11 | + m_switchId(switchId) |
| 12 | +{ |
| 13 | + SWSS_LOG_ENTER(); |
| 14 | + |
| 15 | + if (switchId == SAI_NULL_OBJECT_ID) |
| 16 | + { |
| 17 | + SWSS_LOG_THROW("switch id can't be NULL"); |
| 18 | + } |
| 19 | + |
| 20 | + clearNotificationsPointers(); |
| 21 | +} |
| 22 | + |
| 23 | +Switch::Switch( |
| 24 | + _In_ sai_object_id_t switchId, |
| 25 | + _In_ uint32_t attrCount, |
| 26 | + _In_ const sai_attribute_t *attrList): |
| 27 | + Switch(switchId) |
| 28 | +{ |
| 29 | + SWSS_LOG_ENTER(); |
| 30 | + |
| 31 | + updateNotifications(attrCount, attrList); |
| 32 | +} |
| 33 | + |
| 34 | +void Switch::clearNotificationsPointers() |
| 35 | +{ |
| 36 | + SWSS_LOG_ENTER(); |
| 37 | + |
| 38 | + memset(&m_switchNotifications, 0, sizeof(m_switchNotifications)); |
| 39 | +} |
| 40 | + |
| 41 | +sai_object_id_t Switch::getSwitchId() const |
| 42 | +{ |
| 43 | + SWSS_LOG_ENTER(); |
| 44 | + |
| 45 | + return m_switchId; |
| 46 | +} |
| 47 | + |
| 48 | +void Switch::updateNotifications( |
| 49 | + _In_ uint32_t attrCount, |
| 50 | + _In_ const sai_attribute_t *attrList) |
| 51 | +{ |
| 52 | + SWSS_LOG_ENTER(); |
| 53 | + |
| 54 | + /* |
| 55 | + * This function should only be called on CREATE/SET |
| 56 | + * api when object is SWITCH. |
| 57 | + */ |
| 58 | + |
| 59 | + for (uint32_t index = 0; index < attrCount; ++index) |
| 60 | + { |
| 61 | + auto &attr = attrList[index]; |
| 62 | + |
| 63 | + auto meta = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_SWITCH, attr.id); |
| 64 | + |
| 65 | + if (meta == NULL) |
| 66 | + SWSS_LOG_THROW("failed to find metadata for switch attr %d", attr.id); |
| 67 | + |
| 68 | + if (meta->attrvaluetype != SAI_ATTR_VALUE_TYPE_POINTER) |
| 69 | + continue; |
| 70 | + |
| 71 | + switch (attr.id) |
| 72 | + { |
| 73 | + case SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY: |
| 74 | + m_switchNotifications.on_switch_state_change = |
| 75 | + (sai_switch_state_change_notification_fn)attr.value.ptr; |
| 76 | + break; |
| 77 | + |
| 78 | + case SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY: |
| 79 | + m_switchNotifications.on_switch_shutdown_request = |
| 80 | + (sai_switch_shutdown_request_notification_fn)attr.value.ptr; |
| 81 | + break; |
| 82 | + |
| 83 | + case SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY: |
| 84 | + m_switchNotifications.on_fdb_event = |
| 85 | + (sai_fdb_event_notification_fn)attr.value.ptr; |
| 86 | + break; |
| 87 | + |
| 88 | + case SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY: |
| 89 | + m_switchNotifications.on_port_state_change = |
| 90 | + (sai_port_state_change_notification_fn)attr.value.ptr; |
| 91 | + break; |
| 92 | + |
| 93 | + case SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY: |
| 94 | + m_switchNotifications.on_packet_event = |
| 95 | + (sai_packet_event_notification_fn)attr.value.ptr; |
| 96 | + break; |
| 97 | + |
| 98 | + case SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY: |
| 99 | + m_switchNotifications.on_queue_pfc_deadlock = |
| 100 | + (sai_queue_pfc_deadlock_notification_fn)attr.value.ptr; |
| 101 | + break; |
| 102 | + |
| 103 | + default: |
| 104 | + SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname); |
| 105 | + break; |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +const sai_switch_notifications_t& Switch::getSwitchNotifications() const |
| 111 | +{ |
| 112 | + SWSS_LOG_ENTER(); |
| 113 | + |
| 114 | + return m_switchNotifications; |
| 115 | +} |
| 116 | + |
0 commit comments