Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JunhongMao committed Dec 26, 2023
2 parents 43d2675 + c774f13 commit 9995136
Show file tree
Hide file tree
Showing 59 changed files with 2,125 additions and 57 deletions.
15 changes: 15 additions & 0 deletions .azure-pipelines/build-docker-sonic-vs-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ jobs:
path: $(Build.ArtifactStagingDirectory)/download
patterns: '**/target/${{ parameters.artifact_name }}.gz'
displayName: "Download sonic-buildimage ${{ parameters.artifact_name }}"
- task: DownloadPipelineArtifact@2
inputs:
source: specific
project: build
pipeline: sonic-net.sonic-dash-api
${{ if eq(parameters.arch, 'amd64') }}:
artifact: sonic-dash-api
${{ else }}:
artifact: sonic-dash-api.${{ parameters.arch }}
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/$(BUILD_BRANCH)'
path: $(Build.ArtifactStagingDirectory)/download
patterns: |
libdashapi*.deb
displayName: "Download dash api"
- script: |
set -ex
echo $(Build.DefinitionName).$(Build.BuildNumber)
Expand Down
16 changes: 15 additions & 1 deletion .azure-pipelines/build-swss-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,22 @@ jobs:
target/debs/${{ parameters.debian_version }}/libprotobuf*.deb
target/debs/${{ parameters.debian_version }}/libprotoc*.deb
target/debs/${{ parameters.debian_version }}/protobuf-compiler*.deb
target/debs/${{ parameters.debian_version }}/libdashapi*.deb
displayName: "Download common libs"
- task: DownloadPipelineArtifact@2
inputs:
source: specific
project: build
pipeline: sonic-net.sonic-dash-api
${{ if eq(parameters.arch, 'amd64') }}:
artifact: sonic-dash-api
${{ else }}:
artifact: sonic-dash-api.${{ parameters.arch }}
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/$(BUILD_BRANCH)'
path: $(Build.ArtifactStagingDirectory)/download
patterns: |
libdashapi*.deb
displayName: "Download dash api"

- script: |
set -ex
Expand Down
5 changes: 3 additions & 2 deletions .azure-pipelines/docker-sonic-vs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ COPY ["debs", "/debs"]
# Remove existing packages first before installing the new/current packages. This is to overcome limitations with
# Docker's diff detection mechanism, where only the file size and the modification timestamp (which will remain the
# same, even though contents have changed) are checked between the previous and current layer.
RUN dpkg --purge libswsscommon python3-swsscommon sonic-db-cli libsaimetadata libsairedis libsaivs syncd-vs swss sonic-eventd
RUN dpkg -i /debs/libswsscommon_1.0.0_amd64.deb \
RUN dpkg --purge libswsscommon python3-swsscommon sonic-db-cli libsaimetadata libsairedis libsaivs syncd-vs swss sonic-eventd libdashapi
RUN dpkg -i /debs/libdashapi_1.0.0_amd64.deb \
/debs/libswsscommon_1.0.0_amd64.deb \
/debs/python3-swsscommon_1.0.0_amd64.deb \
/debs/sonic-db-cli_1.0.0_amd64.deb \
/debs/libsaimetadata_1.0.0_amd64.deb \
Expand Down
10 changes: 10 additions & 0 deletions lib/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ void Switch::updateNotifications(
(sai_bfd_session_state_change_notification_fn)attr.value.ptr;
break;

case SAI_SWITCH_ATTR_PORT_HOST_TX_READY_NOTIFY:
m_switchNotifications.on_port_host_tx_ready =
(sai_port_host_tx_ready_notification_fn)attr.value.ptr;
break;

case SAI_SWITCH_ATTR_TWAMP_SESSION_EVENT_NOTIFY:
m_switchNotifications.on_twamp_session_event =
(sai_twamp_session_event_notification_fn)attr.value.ptr;
break;

default:
SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname);
break;
Expand Down
39 changes: 39 additions & 0 deletions lib/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extern "C" {
#include "meta/sai_serialize.h"
#include "swss/logger.h"

#include <cmath>

using namespace sairedis;

void Utils::clearOidList(
Expand Down Expand Up @@ -80,3 +82,40 @@ void Utils::clearOidValues(

}
}

uint64_t Utils::timeToReachTargetValueUsingHalfLife(
_In_ uint64_t halfLifeUsec,
_In_ uint32_t initialValue,
_In_ uint32_t targetValue)
{
SWSS_LOG_ENTER();

// Check if all the input fields have positive values and targeted value is
// smaller than initial value.
if ((initialValue == 0) || (targetValue == 0) ||
(targetValue >= initialValue) || (halfLifeUsec == 0))
{
return 0;
}

// t = -half_life * log2[N(t)/N(0)] from half-life formula "N(t) = N(0) * 2 ^ (-t / half_life)"
return uint64_t(-double(halfLifeUsec) * (log(double(targetValue)/double(initialValue))/log(2.0)));
}

uint32_t Utils::valueAfterDecay(
_In_ uint64_t timeToDecayUsec,
_In_ uint64_t halfLifeUsec,
_In_ uint32_t initialValue)
{
SWSS_LOG_ENTER();

if ((initialValue == 0) || (timeToDecayUsec == 0) || (halfLifeUsec == 0))
{
return initialValue;
}

// Using half-life formula: N(t) = N(0) * 2 ^ (-t / half_life)
double ratio = double(timeToDecayUsec)/double(halfLifeUsec);

return uint32_t(double(initialValue) * pow(0.5, ratio));
}
11 changes: 11 additions & 0 deletions lib/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,16 @@ namespace sairedis

static void clearOidList(
_Out_ sai_object_list_t& list);

static uint64_t timeToReachTargetValueUsingHalfLife(
_In_ uint64_t halfLifeUsec,
_In_ uint32_t initialValue,
_In_ uint32_t targetValue);

static uint32_t valueAfterDecay(
_In_ uint64_t timeToDecayUsec,
_In_ uint64_t halfLifeUsec,
_In_ uint32_t initialValue);

};
}
55 changes: 55 additions & 0 deletions lib/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,58 @@ typedef enum _sai_redis_switch_attr_t
*/
SAI_REDIS_SWITCH_ATTR_SYNC_OPERATION_RESPONSE_TIMEOUT,
} sai_redis_switch_attr_t;

/**
* @brief Link event damping algorithms.
*/
typedef enum _sai_redis_link_event_damping_algorithm_t
{
/** Link event damping algorithm disabled. */
SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_DISABLED = 0,

/** Additive increase exponential decrease based link event damping algorithm. */
SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_AIED = 1,

} sai_redis_link_event_damping_algorithm_t;

typedef struct _sai_redis_link_event_damping_algo_aied_config_t
{
/** Max link event damping suppression time (in milliseconds). */
sai_uint32_t max_suppress_time;

/** Link event damping suppress threshold. */
sai_uint32_t suppress_threshold;

/** Link event damping reuse threshold. */
sai_uint32_t reuse_threshold;

/** Link event damping decay half time duration (in milliseconds). */
sai_uint32_t decay_half_life;

/** Link event flap penalty. */
sai_uint32_t flap_penalty;

} sai_redis_link_event_damping_algo_aied_config_t;

typedef enum _sai_redis_port_attr_t
{
/**
* @brief Link event damping algorithm.
*
* @type sai_redis_link_event_damping_algorithm_t
* @flags CREATE_AND_SET
* @default SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_DISABLED
*/
SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGORITHM = SAI_PORT_ATTR_CUSTOM_RANGE_START,

/**
* @brief Link event damping AIED configuration.
*
* @type sai_redis_link_event_damping_algo_aied_config_t
* @flags CREATE_AND_SET
* @validonly SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGORITHM = SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_AIED
* @default internal
*/
SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGO_AIED_CONFIG,

} sai_redis_port_attr_t;
2 changes: 2 additions & 0 deletions meta/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ libsaimeta_la_SOURCES = \
NotificationSwitchShutdownRequest.cpp \
NotificationSwitchStateChange.cpp \
NotificationBfdSessionStateChange.cpp \
NotificationTwampSessionEvent.cpp \
NotificationPortHostTxReadyEvent.cpp \
NumberOidIndexGenerator.cpp \
OidRefCounter.cpp \
PerformanceIntervalTimer.cpp \
Expand Down
121 changes: 121 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6434,6 +6434,49 @@ void Meta::meta_sai_on_nat_event(
}
}

void Meta::meta_sai_on_port_host_tx_ready_change(
_In_ sai_object_id_t port_id,
_In_ sai_object_id_t switch_id,
_In_ sai_port_host_tx_ready_status_t host_tx_ready_status)
{
SWSS_LOG_ENTER();

if (!sai_metadata_get_enum_value_name(
&sai_metadata_enum_sai_port_host_tx_ready_status_t,
host_tx_ready_status))
{
SWSS_LOG_WARN("port host_tx_ready value (%d) not found in sai_port_host_tx_ready_status_t. Dropping the notification",
host_tx_ready_status);

return;
}

auto ot = objectTypeQuery(port_id);

if (ot != SAI_OBJECT_TYPE_PORT)
{
SWSS_LOG_ERROR("port_id %s has unexpected type: %s, expected PORT",
sai_serialize_object_id(port_id).c_str(),
sai_serialize_object_type(ot).c_str());
return;
}

if (!m_oids.objectReferenceExists(port_id))
{
SWSS_LOG_NOTICE("port_id new object spotted %s not present in local DB (snoop!)",
sai_serialize_object_id(port_id).c_str());

sai_object_meta_key_t host_tx_ready_key = { .objecttype = ot, .objectkey = { .key = { .object_id = port_id } } };
m_oids.objectReferenceInsert(port_id);

if (!m_saiObjectCollection.objectExists(host_tx_ready_key))
{
m_saiObjectCollection.createObject(host_tx_ready_key);
}
}
}


void Meta::meta_sai_on_switch_state_change(
_In_ sai_object_id_t switch_id,
_In_ sai_switch_oper_status_t switch_oper_status)
Expand Down Expand Up @@ -6686,6 +6729,84 @@ void Meta::meta_sai_on_bfd_session_state_change(
}
}

void Meta::meta_sai_on_twamp_session_event_single(
_In_ const sai_twamp_session_event_notification_data_t& data)
{
SWSS_LOG_ENTER();

auto ot = objectTypeQuery(data.twamp_session_id);

bool valid = false;

switch (ot)
{
// TODO hardcoded types, must advance SAI repository commit to get metadata for this
case SAI_OBJECT_TYPE_TWAMP_SESSION:

valid = true;
break;

default:

SWSS_LOG_ERROR("data.twamp_session_id %s has unexpected type: %s, expected TWAMP_SESSION",
sai_serialize_object_id(data.twamp_session_id).c_str(),
sai_serialize_object_type(ot).c_str());
break;
}

// check if all counter ids are in enum range
for (uint32_t idx = 0; idx < data.session_stats.number_of_counters; idx++)
{
if (!sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_twamp_session_stat_t, data.session_stats.counters_ids[idx]))
{
SWSS_LOG_ERROR("value %d is not in range on sai_twamp_session_stat_t ", data.session_stats.counters_ids[idx]);

return;
}
}

if (valid && !m_oids.objectReferenceExists(data.twamp_session_id))
{
SWSS_LOG_NOTICE("data.twamp_session_id new object spotted %s not present in local DB (snoop!)",
sai_serialize_object_id(data.twamp_session_id).c_str());

sai_object_meta_key_t key = { .objecttype = (sai_object_type_t)ot, .objectkey = { .key = { .object_id = data.twamp_session_id } } };

m_oids.objectReferenceInsert(data.twamp_session_id);

if (!m_saiObjectCollection.objectExists(key))
{
m_saiObjectCollection.createObject(key);
}
}

if (!sai_metadata_get_enum_value_name(
&sai_metadata_enum_sai_twamp_session_state_t,
data.session_state))
{
SWSS_LOG_WARN("session_state value (%d) not found sai_twamp_session_state_t",
data.session_state);
}
}

void Meta::meta_sai_on_twamp_session_event(
_In_ uint32_t count,
_In_ const sai_twamp_session_event_notification_data_t *data)
{
SWSS_LOG_ENTER();

if (count && data == NULL)
{
SWSS_LOG_ERROR("sai_twamp_session_event_notification_data_t pointer is NULL but count is %u", count);
return;
}

for (uint32_t i = 0; i < count; ++i)
{
meta_sai_on_twamp_session_event_single(data[i]);
}
}

int32_t Meta::getObjectReferenceCount(
_In_ sai_object_id_t oid) const
{
Expand Down
12 changes: 12 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ namespace saimeta
_In_ uint32_t count,
_In_ const sai_bfd_session_state_notification_t *data);

void meta_sai_on_port_host_tx_ready_change(
_In_ sai_object_id_t port_id,
_In_ sai_object_id_t switch_id,
_In_ sai_port_host_tx_ready_status_t host_tx_ready_status);

void meta_sai_on_twamp_session_event(
_In_ uint32_t count,
_In_ const sai_twamp_session_event_notification_data_t *data);

private: // notifications helpers

void meta_sai_on_fdb_flush_event_consolidated(
Expand All @@ -243,6 +252,9 @@ namespace saimeta
void meta_sai_on_bfd_session_state_change_single(
_In_ const sai_bfd_session_state_notification_t& data);

void meta_sai_on_twamp_session_event_single(
_In_ const sai_twamp_session_event_notification_data_t& data);

private: // validation helpers

sai_status_t meta_generic_validation_objlist(
Expand Down
Loading

0 comments on commit 9995136

Please sign in to comment.