Skip to content

Commit

Permalink
Merge pull request sonic-net#70 from kcudnik/metadata
Browse files Browse the repository at this point in the history
Add static metadata
  • Loading branch information
Shuotian Cheng authored Sep 30, 2016
2 parents 03817ac + 867ced0 commit d286bcd
Show file tree
Hide file tree
Showing 96 changed files with 22,549 additions and 1,605 deletions.
48 changes: 24 additions & 24 deletions common/redisclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ int64_t RedisClient::del(std::string key)
{
char *temp;
int len = redisFormatCommand(&temp, "DEL %s", key.c_str());
std::string del(temp, len);
std::string sdel(temp, len);
free(temp);

RedisReply r(m_db, del, REDIS_REPLY_INTEGER, true);
RedisReply r(m_db, sdel, REDIS_REPLY_INTEGER, true);

if (r.getContext()->type != REDIS_REPLY_INTEGER)
throw std::runtime_error("DEL operation failed");
Expand All @@ -28,10 +28,10 @@ int64_t RedisClient::hdel(std::string key, std::string field)
{
char *temp;
int len = redisFormatCommand(&temp, "HDEL %s %s", key.c_str(), field.c_str());
std::string hdel(temp, len);
std::string shdel(temp, len);
free(temp);

RedisReply r(m_db, hdel, REDIS_REPLY_INTEGER, true);
RedisReply r(m_db, shdel, REDIS_REPLY_INTEGER, true);

if (r.getContext()->type != REDIS_REPLY_INTEGER)
throw std::runtime_error("HDEL operation failed");
Expand All @@ -43,10 +43,10 @@ void RedisClient::hset(std::string key, std::string field, std::string value)
{
char *temp;
int len = redisFormatCommand(&temp, "HSET %s %s %s", key.c_str(), field.c_str(), value.c_str());
std::string hset(temp, len);
std::string shset(temp, len);
free(temp);

RedisReply r(m_db, hset, REDIS_REPLY_INTEGER, true);
RedisReply r(m_db, shset, REDIS_REPLY_INTEGER, true);

if (r.getContext()->type != REDIS_REPLY_INTEGER)
throw std::runtime_error("HSET operation failed");
Expand All @@ -56,10 +56,10 @@ void RedisClient::set(std::string key, std::string value)
{
char *temp;
int len = redisFormatCommand(&temp, "SET %s %s", key.c_str(), value.c_str());
std::string set(temp, len);
std::string sset(temp, len);
free(temp);

RedisReply r(m_db, set, REDIS_REPLY_STATUS, true);
RedisReply r(m_db, sset, REDIS_REPLY_STATUS, true);

if (r.getContext()->type != REDIS_REPLY_STATUS)
throw std::runtime_error("SET operation failed");
Expand All @@ -72,10 +72,10 @@ std::unordered_map<std::string, std::string> RedisClient::hgetall(std::string ke
char *temp;
int len = redisFormatCommand(&temp, "HGETALL %s", key.c_str());

std::string incr(temp, len);
std::string sincr(temp, len);
free(temp);

RedisReply r(m_db, incr, REDIS_REPLY_ARRAY, true);
RedisReply r(m_db, sincr, REDIS_REPLY_ARRAY, true);

if (r.getContext()->type != REDIS_REPLY_ARRAY)
throw std::runtime_error("HGETALL operation failed");
Expand All @@ -95,10 +95,10 @@ std::vector<std::string> RedisClient::keys(std::string key)
char *temp;
int len = redisFormatCommand(&temp, "KEYS %s", key.c_str());

std::string keys(temp, len);
std::string skeys(temp, len);
free(temp);

RedisReply r(m_db, keys, REDIS_REPLY_ARRAY, true);
RedisReply r(m_db, skeys, REDIS_REPLY_ARRAY, true);

if (r.getContext()->type != REDIS_REPLY_ARRAY)
throw std::runtime_error("KEYS operation failed");
Expand All @@ -116,10 +116,10 @@ int64_t RedisClient::incr(std::string key)
char *temp;
int len = redisFormatCommand(&temp, "INCR %s", key.c_str());

std::string incr(temp, len);
std::string sincr(temp, len);
free(temp);

RedisReply r(m_db, incr, REDIS_REPLY_INTEGER, true);
RedisReply r(m_db, sincr, REDIS_REPLY_INTEGER, true);

if (r.getContext()->type != REDIS_REPLY_INTEGER)
throw std::runtime_error("INCR command failed");
Expand All @@ -132,10 +132,10 @@ int64_t RedisClient::decr(std::string key)
char *temp;
int len = redisFormatCommand(&temp, "DECR %s", key.c_str());

std::string decr(temp, len);
std::string sdecr(temp, len);
free(temp);

RedisReply r(m_db, decr, REDIS_REPLY_INTEGER, true);
RedisReply r(m_db, sdecr, REDIS_REPLY_INTEGER, true);

if (r.getContext()->type != REDIS_REPLY_INTEGER)
throw std::runtime_error("DECR command failed");
Expand All @@ -148,12 +148,12 @@ std::shared_ptr<std::string> RedisClient::get(std::string key)
char *temp;
int len = redisFormatCommand(&temp, "GET %s", key.c_str());

std::string get(temp, len);
std::string sget(temp, len);
free(temp);

redisReply *reply;

redisAppendFormattedCommand(m_db->getContext(), get.c_str(), get.length());
redisAppendFormattedCommand(m_db->getContext(), sget.c_str(), sget.length());
redisGetReply(m_db->getContext(), (void**)&reply);

if (!reply)
Expand Down Expand Up @@ -182,12 +182,12 @@ std::shared_ptr<std::string> RedisClient::hget(std::string key, std::string fiel
char *temp;
int len = redisFormatCommand(&temp, "HGET %s %s", key.c_str(), field.c_str());

std::string hget(temp, len);
std::string shget(temp, len);
free(temp);

redisReply *reply;

redisAppendFormattedCommand(m_db->getContext(), hget.c_str(), hget.length());
redisAppendFormattedCommand(m_db->getContext(), shget.c_str(), shget.length());
redisGetReply(m_db->getContext(), (void**)&reply);

if (!reply)
Expand Down Expand Up @@ -222,10 +222,10 @@ int64_t RedisClient::rpush(std::string list, std::string item)
char *temp;
int len = redisFormatCommand(&temp, "RPUSH %s %s", list.c_str(), item.c_str());

std::string rpush(temp, len);
std::string srpush(temp, len);
free(temp);

RedisReply r(m_db, rpush, REDIS_REPLY_INTEGER, true);
RedisReply r(m_db, srpush, REDIS_REPLY_INTEGER, true);

if (r.getContext()->type != REDIS_REPLY_INTEGER)
throw std::runtime_error("RPUSH command failed");
Expand All @@ -238,12 +238,12 @@ std::shared_ptr<std::string> RedisClient::blpop(std::string list, int timeout)
char *temp;
int len = redisFormatCommand(&temp, "BLPOP %s %d", list.c_str(), timeout);

std::string blpop(temp, len);
std::string sblpop(temp, len);
free(temp);

redisReply *reply;

redisAppendFormattedCommand(m_db->getContext(), blpop.c_str(), blpop.length());
redisAppendFormattedCommand(m_db->getContext(), sblpop.c_str(), sblpop.length());
redisGetReply(m_db->getContext(), (void**)&reply);

if (!reply)
Expand Down
10 changes: 5 additions & 5 deletions common/saiattributelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SaiAttributeList::SaiAttributeList(
_In_ const std::vector<swss::FieldValueTuple> &values,
_In_ bool onlyCount)
{
uint32_t attr_count = values.size();
size_t attr_count = values.size();

for (uint32_t i = 0; i < attr_count; ++i)
for (size_t i = 0; i < attr_count; ++i)
{
const std::string &str_attr_id = fvField(values[i]);
const std::string &str_attr_value = fvValue(values[i]);
Expand Down Expand Up @@ -44,9 +44,9 @@ SaiAttributeList::SaiAttributeList(

SaiAttributeList::~SaiAttributeList()
{
uint32_t attr_count = m_attr_list.size();
size_t attr_count = m_attr_list.size();

for (uint32_t i = 0; i < attr_count; ++i)
for (size_t i = 0; i < attr_count; ++i)
{
sai_attribute_t &attr = m_attr_list[i];

Expand Down Expand Up @@ -118,5 +118,5 @@ sai_attribute_t* SaiAttributeList::get_attr_list()

uint32_t SaiAttributeList::get_attr_count()
{
return m_attr_list.size();
return (uint32_t)m_attr_list.size();
}
67 changes: 64 additions & 3 deletions common/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@ sai_serialization_map_t sai_get_serialization_map()
map[SAI_OBJECT_TYPE_TRAP_GROUP][SAI_HOSTIF_TRAP_GROUP_ATTR_ADMIN_STATE] = SAI_SERIALIZATION_TYPE_BOOL;
map[SAI_OBJECT_TYPE_TRAP_GROUP][SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE] = SAI_SERIALIZATION_TYPE_UINT32;
map[SAI_OBJECT_TYPE_TRAP_GROUP][SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER] = SAI_SERIALIZATION_TYPE_OBJECT_ID;

map[SAI_OBJECT_TYPE_TUNNEL_MAP][SAI_TUNNEL_MAP_ATTR_TYPE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL_MAP][SAI_TUNNEL_MAP_ATTR_MAP_TO_VALUE_LIST] = SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST;

map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_TYPE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE] = SAI_SERIALIZATION_TYPE_OBJECT_ID;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_OVERLAY_INTERFACE] = SAI_SERIALIZATION_TYPE_OBJECT_ID;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_SRC_IP] = SAI_SERIALIZATION_TYPE_IP_ADDRESS;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_TTL_MODE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_TTL_VAL] = SAI_SERIALIZATION_TYPE_UINT8;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_DSCP_VAL] = SAI_SERIALIZATION_TYPE_UINT8;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_GRE_KEY_VALID] = SAI_SERIALIZATION_TYPE_BOOL;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_GRE_KEY] = SAI_SERIALIZATION_TYPE_UINT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_ECN_MODE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_ENCAP_MAPPERS] = SAI_SERIALIZATION_TYPE_OBJECT_LIST;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_DECAP_ECN_MODE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_DECAP_MAPPERS] = SAI_SERIALIZATION_TYPE_OBJECT_LIST;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_DECAP_TTL_MODE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL][SAI_TUNNEL_ATTR_DECAP_DSCP_MODE] = SAI_SERIALIZATION_TYPE_INT32;

map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY][SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID] = SAI_SERIALIZATION_TYPE_OBJECT_ID;
map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY][SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY][SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP] = SAI_SERIALIZATION_TYPE_IP_ADDRESS;
map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY][SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP] = SAI_SERIALIZATION_TYPE_IP_ADDRESS;
map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY][SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY][SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID] = SAI_SERIALIZATION_TYPE_OBJECT_ID;
return map;
}

Expand Down Expand Up @@ -398,12 +425,12 @@ void sai_deserialize_buffer(
int u = char_to_int(ptr[2 * i]);
int l = char_to_int(ptr[2 * i + 1]);

unsigned char c = (u << 4) | l;
int c = (u << 4) | l;

mem[i] = c;
mem[i] = (unsigned char) c;
}

index += buffer_size * 2;
index += (int)(buffer_size * 2);
}

void sai_free_buffer(void *buffer)
Expand Down Expand Up @@ -554,8 +581,17 @@ sai_status_t sai_serialize_attr_value(
sai_serialize_list(attr.value.qosmap, s, countOnly);
break;

case SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST:
sai_serialize_list(attr.value.tunnelmap, s, countOnly);
break;

/* ACL FIELD DATA */

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_BOOL:
sai_serialize_primitive(attr.value.aclfield.enable, s);
sai_serialize_primitive(attr.value.aclfield.data.booldata, s);
break;

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8:
sai_serialize_primitive(attr.value.aclfield.enable, s);
sai_serialize_primitive(attr.value.aclfield.mask.u8, s);
Expand Down Expand Up @@ -836,8 +872,17 @@ sai_status_t sai_deserialize_attr_value(
sai_deserialize_list(s, index, attr.value.qosmap, countOnly);
break;

case SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST:
sai_deserialize_list(s, index, attr.value.tunnelmap, countOnly);
break;

/* ACL FIELD DATA */

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_BOOL:
sai_deserialize_primitive(s, index, attr.value.aclfield.enable);
sai_deserialize_primitive(s, index, attr.value.aclfield.data.booldata);
break;

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8:
sai_deserialize_primitive(s, index, attr.value.aclfield.enable);
sai_deserialize_primitive(s, index, attr.value.aclfield.mask.u8);
Expand Down Expand Up @@ -1071,8 +1116,15 @@ sai_status_t sai_deserialize_free_attribute_value(
sai_free_list(attr.value.qosmap);
break;

case SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST:
sai_free_list(attr.value.tunnelmap);
break;

/* ACL FIELD DATA */

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_BOOL:
break;

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8:
break;

Expand Down Expand Up @@ -1409,8 +1461,17 @@ sai_status_t transfer_attribute(
transfer_list(src_attr.value.qosmap, dst_attr.value.qosmap, countOnly);
break;

case SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST:
transfer_list(src_attr.value.tunnelmap, dst_attr.value.tunnelmap, countOnly);
break;

/* ACL FIELD DATA */

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_BOOL:
transfer_primitive(src_attr.value.aclfield.enable, dst_attr.value.aclfield.enable);
transfer_primitive(src_attr.value.aclfield.data.booldata, dst_attr.value.aclfield.data.booldata);
break;

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8:
transfer_primitive(src_attr.value.aclfield.enable, dst_attr.value.aclfield.enable);
transfer_primitive(src_attr.value.aclfield.mask.u8, dst_attr.value.aclfield.mask.u8);
Expand Down
13 changes: 8 additions & 5 deletions common/saiserialize.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef __SAI_SERIALIZE__
#define __SAI_SERIALIZE__

extern "C" {
#include "sai.h"
}

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -43,8 +45,8 @@ typedef enum _sai_attr_serialization_type_t
SAI_SERIALIZATION_TYPE_UINT32_RANGE,
SAI_SERIALIZATION_TYPE_INT32_RANGE,
SAI_SERIALIZATION_TYPE_VLAN_LIST,
SAI_SERIALIZATION_TYPE_VLAN_PORT_LIST,

SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_BOOL,
SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8,
SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_INT8,
SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT16,
Expand All @@ -71,7 +73,8 @@ typedef enum _sai_attr_serialization_type_t
SAI_SERIALIZATION_TYPE_ACL_ACTION_DATA_OBJECT_LIST,

SAI_SERIALIZATION_TYPE_PORT_BREAKOUT,
SAI_SERIALIZATION_TYPE_QOS_MAP_LIST
SAI_SERIALIZATION_TYPE_QOS_MAP_LIST,
SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST

} sai_attr_serialization_type_t;

Expand Down Expand Up @@ -184,12 +187,12 @@ void sai_deserialize_primitive(
int u = char_to_int(ptr[2 * i]);
int l = char_to_int(ptr[2 * i + 1]);

unsigned char c = (u << 4) | l;
int c = (u << 4) | l;

mem[i] = c;
mem[i] = (unsigned char)c;
}

index += count * 2;
index += (int)(count * 2);
}

template<typename T>
Expand Down
Loading

0 comments on commit d286bcd

Please sign in to comment.