Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
abdosi authored Oct 29, 2024
2 parents f609c8d + d76c34e commit a608553
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
49 changes: 40 additions & 9 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace swss;

extern Directory<Orch*> gDirectory;
extern std::unordered_map<std::string, sai_object_id_t> gVnetNameToId;
extern sai_dash_appliance_api_t* sai_dash_appliance_api;
extern sai_dash_vip_api_t* sai_dash_vip_api;
extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api;
extern sai_dash_eni_api_t* sai_dash_eni_api;
Expand Down Expand Up @@ -66,15 +67,31 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian
}

uint32_t attr_count = 1;
sai_attribute_t appliance_attr;
sai_status_t status;

// NOTE: DASH Appliance object should be the first object pushed to SAI
sai_object_id_t sai_appliance_id = 0UL;
appliance_attr.id = SAI_DASH_APPLIANCE_ATTR_LOCAL_REGION_ID;
appliance_attr.value.u32 = entry.local_region_id();
status = sai_dash_appliance_api->create_dash_appliance(&sai_appliance_id, gSwitchId,
attr_count, &appliance_attr);
if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED)
{
SWSS_LOG_ERROR("Failed to create dash appliance object in SAI for %s", appliance_id.c_str());
task_process_status handle_status = handleSaiCreateStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

sai_vip_entry_t vip_entry;
vip_entry.switch_id = gSwitchId;
if (!to_sai(entry.sip(), vip_entry.vip))
{
return false;
}
sai_attribute_t appliance_attr;
vector<sai_attribute_t> appliance_attrs;
sai_status_t status;
appliance_attr.id = SAI_VIP_ENTRY_ATTR_ACTION;
appliance_attr.value.u32 = SAI_VIP_ENTRY_ACTION_ACCEPT;
status = sai_dash_vip_api->create_vip_entry(&vip_entry, attr_count, &appliance_attr);
Expand Down Expand Up @@ -103,8 +120,8 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian
return parseHandleSaiStatusFailure(handle_status);
}
}
appliance_entries_[appliance_id] = entry;
SWSS_LOG_NOTICE("Created vip and direction lookup entries for %s", appliance_id.c_str());
appliance_entries_[appliance_id] = ApplianceEntry { sai_appliance_id, entry };
SWSS_LOG_NOTICE("Created appliance, vip and direction lookup entries for %s", appliance_id.c_str());

return true;
}
Expand All @@ -114,15 +131,14 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id)
SWSS_LOG_ENTER();

sai_status_t status;
dash::appliance::Appliance entry;

if (appliance_entries_.find(appliance_id) == appliance_entries_.end())
{
SWSS_LOG_WARN("Appliance id does not exist: %s", appliance_id.c_str());
return true;
}

entry = appliance_entries_[appliance_id];
const auto& entry = appliance_entries_[appliance_id].metadata;
sai_vip_entry_t vip_entry;
vip_entry.switch_id = gSwitchId;
if (!to_sai(entry.sip(), vip_entry.vip))
Expand Down Expand Up @@ -153,8 +169,23 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id)
return parseHandleSaiStatusFailure(handle_status);
}
}

auto sai_appliance_id = appliance_entries_[appliance_id].appliance_id;
if (sai_appliance_id != 0UL)
{
status = sai_dash_appliance_api->remove_dash_appliance(sai_appliance_id);
if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED)
{
SWSS_LOG_ERROR("Failed to remove dash appliance object in SAI for %s", appliance_id.c_str());
task_process_status handle_status = handleSaiRemoveStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
}
appliance_entries_.erase(appliance_id);
SWSS_LOG_NOTICE("Removed vip and direction lookup entries for %s", appliance_id.c_str());
SWSS_LOG_NOTICE("Removed appliance, vip and direction lookup entries for %s", appliance_id.c_str());

return true;
}
Expand Down Expand Up @@ -383,7 +414,7 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry)
eni_attrs.push_back(eni_attr);

eni_attr.id = SAI_ENI_ATTR_VM_VNI;
auto app_entry = appliance_entries_.begin()->second;
auto& app_entry = appliance_entries_.begin()->second.metadata;
eni_attr.value.u32 = app_entry.vm_vni();
eni_attrs.push_back(eni_attr);

Expand Down
8 changes: 7 additions & 1 deletion orchagent/dash/dashorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ struct EniEntry
dash::eni::Eni metadata;
};

typedef std::map<std::string, dash::appliance::Appliance> ApplianceTable;
struct ApplianceEntry
{
sai_object_id_t appliance_id;
dash::appliance::Appliance metadata;
};

typedef std::map<std::string, ApplianceEntry> ApplianceTable;
typedef std::map<dash::route_type::RoutingType, dash::route_type::RouteType> RoutingTypeTable;
typedef std::map<std::string, EniEntry> EniTable;
typedef std::map<std::string, dash::qos::Qos> QosTable;
Expand Down
8 changes: 8 additions & 0 deletions orchagent/rif_rates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ for i = 1, n do
local out_octets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS')
local out_pkts = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS')

if not in_octets or not in_pkts or not out_octets or not out_pkts then
return logtable
end

if initialized == "DONE" or initialized == "COUNTERS_LAST" then
-- Get old COUNTERS values
local in_octets_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_IN_OCTETS_last')
local in_pkts_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_IN_PACKETS_last')
local out_octets_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS_last')
local out_pkts_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS_last')

if not in_octets_last or not in_pkts_last or not out_octets_last or not out_pkts_last then
return logtable
end

-- Calculate new rates values
local rx_bps_new = (in_octets - in_octets_last) / delta * 1000
local tx_bps_new = (out_octets - out_octets_last) / delta * 1000
Expand Down
2 changes: 2 additions & 0 deletions orchagent/saihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ sai_counter_api_t* sai_counter_api;
sai_bfd_api_t* sai_bfd_api;
sai_my_mac_api_t* sai_my_mac_api;
sai_generic_programmable_api_t* sai_generic_programmable_api;
sai_dash_appliance_api_t* sai_dash_appliance_api;
sai_dash_acl_api_t* sai_dash_acl_api;
sai_dash_vnet_api_t sai_dash_vnet_api;
sai_dash_outbound_ca_to_pa_api_t* sai_dash_outbound_ca_to_pa_api;
Expand Down Expand Up @@ -221,6 +222,7 @@ void initSaiApi()
sai_api_query(SAI_API_BFD, (void **)&sai_bfd_api);
sai_api_query(SAI_API_MY_MAC, (void **)&sai_my_mac_api);
sai_api_query(SAI_API_GENERIC_PROGRAMMABLE, (void **)&sai_generic_programmable_api);
sai_api_query((sai_api_t)SAI_API_DASH_APPLIANCE, (void**)&sai_dash_appliance_api);
sai_api_query((sai_api_t)SAI_API_DASH_ACL, (void**)&sai_dash_acl_api);
sai_api_query((sai_api_t)SAI_API_DASH_VNET, (void**)&sai_dash_vnet_api);
sai_api_query((sai_api_t)SAI_API_DASH_OUTBOUND_CA_TO_PA, (void**)&sai_dash_outbound_ca_to_pa_api);
Expand Down
5 changes: 3 additions & 2 deletions tests/dash/dash_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"sip": {
"ipv4": socket.htonl(int(IP(SIP)))
},
"vm_vni": int(VM_VNI)
"vm_vni": int(VM_VNI),
"local_region_id": 10
}

VNET_CONFIG = {
Expand Down Expand Up @@ -168,4 +169,4 @@

ENI_ROUTE_GROUP2_CONFIG = {
"group_id": ROUTE_GROUP2,
}
}
1 change: 1 addition & 0 deletions tests/dash/test_dash_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_appliance(self, dash_db: DashDB):
self.appliance_id = "100"
self.sip = "10.0.0.1"
self.vm_vni = "4321"
self.local_region_id = "10"
pb = Appliance()
pb.sip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.sip)))
pb.vm_vni = int(self.vm_vni)
Expand Down
8 changes: 7 additions & 1 deletion tlm_teamd/values_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,13 @@ void ValuesStore::update(const std::vector<StringPair> & dumps)
{
const auto & storage = from_json(dumps);
const auto & old_keys = get_old_keys(storage);
remove_keys_db(old_keys);
// Do not delete te key from State Db. State DB LAB_TABLE entry is created/deleted
// from teamsyncd on detecting netlink of teamd dev as up/down. For some reason
// if we do not get state dump from teamdctl it might be transient issue. If it is
// persistent issue then teamsyncd might be able to catch it and delete state db entry
// or we can keep entry in it's current state as best effort. Similar to try_add_lag which is best effort
// to connect to teamdctl and if it fails we do not delete State Db entry.
//remove_keys_db(old_keys);
remove_keys_storage(old_keys);
const auto & keys_to_refresh = update_storage(storage);
update_db(storage, keys_to_refresh);
Expand Down

0 comments on commit a608553

Please sign in to comment.