Skip to content

Commit

Permalink
Add more static metadata (sonic-net#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Oct 25, 2016
1 parent 3f61a44 commit 23df60b
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 28 deletions.
2 changes: 1 addition & 1 deletion meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ OBJ = \
sai_extra_udf.o \
sai_extra_vlan.o \
sai_extra_wred.o \
../common/saiserialize.o \
saiserialize.o \
sai_meta.o \
sai_meta_sanity.o \
sai_meta_acl.o \
Expand Down
29 changes: 11 additions & 18 deletions meta/sai_meta.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "sai_meta.h"
#include "sai_extra.h"
#include <string.h>
#include "saiserialize.h"

#include <string.h>
#include <arpa/inet.h>

#include <map>
Expand Down Expand Up @@ -310,44 +311,36 @@ class SaiAttrWrapper
public:

SaiAttrWrapper(
_In_ sai_object_type_t objecttype,
_In_ sai_attr_serialization_type_t st,
_In_ const sai_attr_metadata_t* meta,
_In_ const sai_attribute_t& attr):
m_objecttype(objecttype),
m_serializationtype(st),
m_meta(meta),
m_attr(attr)
{
SWSS_LOG_ENTER();

m_attr.id = attr.id;

std::string s;
sai_serialize_attr_value(st, attr, s, false);
std::string s = sai_serialize_attr_value(*meta, attr, false);

int index = 0;
sai_deserialize_attr_value(s, index, st, m_attr, false);
sai_deserialize_attr_value(s, *meta, m_attr, false);
}

~SaiAttrWrapper()
{
sai_deserialize_free_attribute_value(m_serializationtype, m_attr);
sai_deserialize_free_attribute_value(m_meta->serializationtype, m_attr);
}

const sai_attribute_t* getattr() const
{
return &m_attr;
}

sai_attr_serialization_type_t getserializationtype() const
{
return m_serializationtype;
}

private:

SaiAttrWrapper(const SaiAttrWrapper&);
SaiAttrWrapper& operator=(const SaiAttrWrapper&);

sai_object_type_t m_objecttype;
sai_attr_serialization_type_t m_serializationtype;
const sai_attr_metadata_t* m_meta;
sai_attribute_t m_attr;
};

Expand Down Expand Up @@ -746,7 +739,7 @@ void set_object(

META_LOG_DEBUG(md, "set attribute %d on %s", attr->id, key.c_str());

auto p = new SaiAttrWrapper(meta_key.object_type, md.serializationtype, *attr);
auto p = new SaiAttrWrapper(&md,*attr);

ObjectAttrHash[key][attr->id] = std::shared_ptr<SaiAttrWrapper>(p);
}
Expand Down
8 changes: 5 additions & 3 deletions meta/sai_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern "C" {
}

#include "swss/logger.h"
#include "saiserialize.h"

#define MAX_LIST_COUNT 128

Expand All @@ -37,7 +36,6 @@ extern "C" {

#define StringifyEnum(x) ((std::is_enum<x>::value) ? #x : 0)

/*
typedef enum _sai_attr_serialization_type_t
{
SAI_SERIALIZATION_TYPE_BOOL,
Expand Down Expand Up @@ -98,7 +96,6 @@ typedef enum _sai_attr_serialization_type_t
SAI_SERIALIZATION_TYPE_ACL_CAPABILITY

} sai_attr_serialization_type_t;
*/

typedef struct _sai_object_meta_key_t
{
Expand Down Expand Up @@ -711,6 +708,7 @@ const sai_enum_metadata_t metadata_enum_ ## x = {\
};


extern const sai_enum_metadata_t metadata_enum_sai_switch_oper_status_t;
extern const sai_enum_metadata_t metadata_enum_sai_port_oper_status_t;
extern const sai_enum_metadata_t metadata_enum_sai_status_t;
extern const sai_enum_metadata_t metadata_enum_sai_fdb_event_t;
Expand All @@ -720,6 +718,8 @@ extern const sai_enum_metadata_t metadata_enum_sai_packet_color_t;
extern const sai_enum_metadata_t metadata_enum_sai_packet_action_t;
extern const sai_enum_metadata_t metadata_enum_sai_next_hop_group_type_t;
extern const sai_enum_metadata_t metadata_enum_sai_meter_type_t;
extern const sai_enum_metadata_t metadata_enum_sai_hostif_trap_type_t;
extern const sai_enum_metadata_t metadata_enum_sai_port_stat_t;

struct HashForEnum
{
Expand All @@ -729,7 +729,9 @@ struct HashForEnum
}
};

// TODO those should be internal only
extern std::unordered_map<sai_object_type_t,std::unordered_map<sai_attr_id_t, const sai_attr_metadata_t*>, HashForEnum> AttributesMetadata;
extern std::unordered_map<std::string,const sai_attr_metadata_t*> AttributesIdMetadata;

extern std::string get_attr_info(const sai_attr_metadata_t& md);
extern const char* get_object_type_name(sai_object_type_t o);
Expand Down
2 changes: 1 addition & 1 deletion meta/sai_meta_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const sai_attr_metadata_t sai_buffer_profile_attr_metadata[] = {

// TODO condition here is complex, since if TH is inherited from pool then this is hard to determine
// and it should be SAI_BUFFER_POOL_TH_MODE = SAI_BUFFER_THRESHOLD_MODE_DYNAMIC, so this attribute depends on other attribute
// FIXME: SAI_ATTR_FLAGS_MANDATORY_ON_CREATE was temporary comment out until SAI has better support for it
// FIXME: SAI_ATTR_FLAGS_MANDATORY_ON_CREATE was temporary comment out until SAI has better support for it
},

{
Expand Down
111 changes: 111 additions & 0 deletions meta/sai_meta_hostintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,117 @@ const char* metadata_sai_hostif_type_t_enum_values_short_names[] = {
const size_t metadata_sai_hostif_type_t_enum_values_count = 2;
DEFINE_ENUM_METADATA(sai_hostif_type_t, 2);

const char metadata_sai_hostif_trap_type_t_enum_name[] = "sai_hostif_trap_type_t";
const sai_hostif_trap_id_t metadata_sai_hostif_trap_type_t_enum_values[] = {
SAI_HOSTIF_TRAP_ID_STP,
SAI_HOSTIF_TRAP_ID_LACP,
SAI_HOSTIF_TRAP_ID_EAPOL,
SAI_HOSTIF_TRAP_ID_LLDP,
SAI_HOSTIF_TRAP_ID_PVRST,
SAI_HOSTIF_TRAP_ID_IGMP_TYPE_QUERY,
SAI_HOSTIF_TRAP_ID_IGMP_TYPE_LEAVE,
SAI_HOSTIF_TRAP_ID_IGMP_TYPE_V1_REPORT,
SAI_HOSTIF_TRAP_ID_IGMP_TYPE_V2_REPORT,
SAI_HOSTIF_TRAP_ID_IGMP_TYPE_V3_REPORT,
SAI_HOSTIF_TRAP_ID_SAMP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V3_REPORT",
"SAI_HOSTIF_TRAP_TYPE_SAMPLEPACKET",
"SAI_HOSTIF_TRAP_TYPE_ARP_REQUEST",
"SAI_HOSTIF_TRAP_TYPE_ARP_RESPONSE",
"SAI_HOSTIF_TRAP_TYPE_DHCP",
"SAI_HOSTIF_TRAP_TYPE_OSPF",
"SAI_HOSTIF_TRAP_TYPE_PIM",
"SAI_HOSTIF_TRAP_TYPE_VRRP",
"SAI_HOSTIF_TRAP_TYPE_BGP",
"SAI_HOSTIF_TRAP_TYPE_DHCPV6",
"SAI_HOSTIF_TRAP_TYPE_OSPFV6",
"SAI_HOSTIF_TRAP_TYPE_VRRPV6",
"SAI_HOSTIF_TRAP_TYPE_BGPV6",
"SAI_HOSTIF_TRAP_TYPE_IPV6_NEIGHBOR_DISCOVERY",
"SAI_HOSTIF_TRAP_TYPE_IPV6_MLD_V1_V2",
"SAI_HOSTIF_TRAP_TYPE_IPV6_MLD_V1_REPORT",
"SAI_HOSTIF_TRAP_TYPE_IPV6_MLD_V1_DONE",
"SAI_HOSTIF_TRAP_TYPE_MLD_V2_REPORT",
"SAI_HOSTIF_TRAP_TYPE_IP2ME",
"SAI_HOSTIF_TRAP_TYPE_SSH",
"SAI_HOSTIF_TRAP_TYPE_SNMP",
"SAI_HOSTIF_TRAP_TYPE_L3_MTU_ERROR",
"SAI_HOSTIF_TRAP_TYPE_TTL_ERROR",
"SAI_HOSTIF_TRAP_TYPE_CUSTOM_EXCEPTION_RANGE_BASE",
NULL
};
const char* metadata_sai_hostif_trap_type_t_enum_values_short_names[] = {
"STP",
"LACP",
"EAPOL",
"LLDP",
"PVRST",
"IGMP_TYPE_QUERY",
"IGMP_TYPE_LEAVE",
"IGMP_TYPE_V1_REPORT",
"IGMP_TYPE_V2_REPORT",
"IGMP_TYPE_V3_REPORT",
"SAMPLEPACKET",
"ARP_REQUEST",
"ARP_RESPONSE",
"DHCP",
"OSPF",
"PIM",
"VRRP",
"BGP",
"DHCPV6",
"OSPFV6",
"VRRPV6",
"BGPV6",
"IPV6_NEIGHBOR_DISCOVERY",
"IPV6_MLD_V1_V2",
"IPV6_MLD_V1_REPORT",
"IPV6_MLD_V1_DONE",
"MLD_V2_REPORT",
"IP2ME",
"SSH",
"SNMP",
"L3_MTU_ERROR",
"TTL_ERROR",
"CUSTOM_EXCEPTION_RANGE_BASE",
NULL
};
const size_t metadata_sai_hostif_trap_type_t_enum_values_count = 33;
DEFINE_ENUM_METADATA(sai_hostif_trap_type_t, 33);

const sai_attr_metadata_t sai_hostintf_attr_metadata[] = {

{
Expand Down
Loading

0 comments on commit 23df60b

Please sign in to comment.