Skip to content

Commit

Permalink
Fix serialize bug for route and neighbor
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Apr 12, 2016
1 parent a34a341 commit 1a6b05b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 14 deletions.
108 changes: 106 additions & 2 deletions common/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ sai_status_t sai_serialize_attr_value(
break;

case SAI_SERIALIZATION_TYPE_IP_ADDRESS:
sai_serialize_primitive(attr.value.ipaddr, s);
sai_serialize_ip_address(attr.value.ipaddr, s);
break;

case SAI_SERIALIZATION_TYPE_OBJECT_ID:
Expand Down Expand Up @@ -557,7 +557,7 @@ sai_status_t sai_deserialize_attr_value(
break;

case SAI_SERIALIZATION_TYPE_IP_ADDRESS:
sai_deserialize_primitive(s, index, attr.value.ipaddr);
sai_deserialize_ip_address(s, index, attr.value.ipaddr);
break;

case SAI_SERIALIZATION_TYPE_OBJECT_ID:
Expand Down Expand Up @@ -1362,3 +1362,107 @@ void transfer_attributes(
transfer_attribute(serialization_type, src_attr, dst_attr, countOnly);
}
}

void sai_serialize_ip_address(
_In_ const sai_ip_address_t &ip_address,
_Out_ std::string &s)
{
sai_serialize_primitive(ip_address.addr_family, s);

if (ip_address.addr_family == SAI_IP_ADDR_FAMILY_IPV4)
sai_serialize_primitive(ip_address.addr.ip4, s);

if (ip_address.addr_family == SAI_IP_ADDR_FAMILY_IPV6)
sai_serialize_primitive(ip_address.addr.ip6, s);
}

void sai_serialize_neighbor_entry(
_In_ const sai_neighbor_entry_t &ne,
_Out_ std::string &s)
{
sai_serialize_primitive(ne.rif_id, s);

sai_serialize_ip_address(ne.ip_address, s);
}

void sai_deserialize_ip_address(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_ip_address_t &ip_address)
{
sai_deserialize_primitive(s, index, ip_address.addr_family);

if (ip_address.addr_family == SAI_IP_ADDR_FAMILY_IPV4)
sai_deserialize_primitive(s, index, ip_address.addr.ip4);

if (ip_address.addr_family == SAI_IP_ADDR_FAMILY_IPV6)
sai_deserialize_primitive(s, index, ip_address.addr.ip6);
}

void sai_deserialize_neighbor_entry(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_neighbor_entry_t &ne)
{
sai_deserialize_primitive(s, index, ne.rif_id);

sai_deserialize_ip_address(s, index, ne.ip_address);
}

void sai_serialize_ip_prefix(
_In_ const sai_ip_prefix_t &ip_prefix,
_Out_ std::string &s)
{
sai_serialize_primitive(ip_prefix.addr_family, s);

if (ip_prefix.addr_family == SAI_IP_ADDR_FAMILY_IPV4)
{
sai_serialize_primitive(ip_prefix.addr.ip4, s);
sai_serialize_primitive(ip_prefix.mask.ip4, s);
}

if (ip_prefix.addr_family == SAI_IP_ADDR_FAMILY_IPV6)
{
sai_serialize_primitive(ip_prefix.addr.ip6, s);
sai_serialize_primitive(ip_prefix.mask.ip6, s);
}
}

void sai_serialize_route_entry(
_In_ const sai_unicast_route_entry_t &re,
_Out_ std::string &s)
{
sai_serialize_primitive(re.vr_id, s);

sai_serialize_ip_prefix(re.destination, s);
}

void sai_deserialize_ip_prefix(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_ip_prefix_t &ip_prefix)
{
sai_deserialize_primitive(s, index, ip_prefix.addr_family);

if (ip_prefix.addr_family == SAI_IP_ADDR_FAMILY_IPV4)
{
sai_deserialize_primitive(s, index, ip_prefix.addr.ip4);
sai_deserialize_primitive(s, index, ip_prefix.mask.ip4);
}

if (ip_prefix.addr_family == SAI_IP_ADDR_FAMILY_IPV6)
{
sai_deserialize_primitive(s, index, ip_prefix.addr.ip6);
sai_deserialize_primitive(s, index, ip_prefix.mask.ip6);
}
}

void sai_deserialize_route_entry(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_unicast_route_entry_t &re)
{
sai_deserialize_primitive(s, index, re.vr_id);

sai_deserialize_ip_prefix(s, index, re.destination);
}
36 changes: 36 additions & 0 deletions common/saiserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,42 @@ void transfer_list(
}
}

void sai_serialize_ip_address(
_In_ const sai_ip_address_t &ip_address,
_Out_ std::string &s);

void sai_deserialize_ip_address(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_ip_address_t &ip_address);

void sai_serialize_ip_prefix(
_In_ const sai_ip_prefix_t &ip_prefix,
_Out_ std::string &s);

void sai_deserialize_ip_prefix(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_ip_prefix_t &ip_prefix);

void sai_serialize_neighbor_entry(
_In_ const sai_neighbor_entry_t &ne,
_Out_ std::string &s);

void sai_deserialize_neighbor_entry(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_neighbor_entry_t &ne);

void sai_serialize_route_entry(
_In_ const sai_unicast_route_entry_t &ne,
_Out_ std::string &s);

void sai_deserialize_route_entry(
_In_ const std::string & s,
_In_ int &index,
_Out_ sai_unicast_route_entry_t &ne);

sai_status_t sai_deserialize_attr_value(
_In_ const std::string &s,
_In_ int &index,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sai_redis_generic_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ sai_status_t redis_generic_create(

// rif_id must be valid virtual id
std::string str_neighbor_entry;
sai_serialize_primitive(*neighbor_entry, str_neighbor_entry);
sai_serialize_neighbor_entry(*neighbor_entry, str_neighbor_entry);

sai_status_t status = internal_redis_generic_create(
object_type,
Expand All @@ -164,7 +164,7 @@ sai_status_t redis_generic_create(

// vr_id must be valid virtual router id
std::string str_route_entry;
sai_serialize_primitive(*unicast_route_entry, str_route_entry);
sai_serialize_route_entry(*unicast_route_entry, str_route_entry);

sai_status_t status = internal_redis_generic_create(
object_type,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sai_redis_generic_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ sai_status_t redis_generic_get(
SWSS_LOG_ENTER();

std::string str_neighbor_entry;
sai_serialize_primitive(*neighbor_entry, str_neighbor_entry);
sai_serialize_neighbor_entry(*neighbor_entry, str_neighbor_entry);

sai_status_t status = internal_redis_generic_get(
object_type,
Expand All @@ -209,7 +209,7 @@ sai_status_t redis_generic_get(
SWSS_LOG_ENTER();

std::string str_route_entry;
sai_serialize_primitive(*unicast_route_entry, str_route_entry);
sai_serialize_route_entry(*unicast_route_entry, str_route_entry);

sai_status_t status = internal_redis_generic_get(
object_type,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sai_redis_generic_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sai_status_t redis_generic_remove(

// rif_id must be valid virtual id
std::string str_neighbor_entry;
sai_serialize_primitive(*neighbor_entry, str_neighbor_entry);
sai_serialize_neighbor_entry(*neighbor_entry, str_neighbor_entry);

sai_status_t status = internal_redis_generic_remove(
object_type,
Expand All @@ -88,7 +88,7 @@ sai_status_t redis_generic_remove(

// vr_id must be valid virtual router id
std::string str_route_entry;
sai_serialize_primitive(*unicast_route_entry, str_route_entry);
sai_serialize_route_entry(*unicast_route_entry, str_route_entry);

sai_status_t status = internal_redis_generic_remove(
object_type,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sai_redis_generic_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sai_status_t redis_generic_set(
SWSS_LOG_ENTER();

std::string str_neighbor_entry;
sai_serialize_primitive(*neighbor_entry, str_neighbor_entry);
sai_serialize_neighbor_entry(*neighbor_entry, str_neighbor_entry);

sai_status_t status = internal_redis_generic_set(
object_type,
Expand All @@ -101,7 +101,7 @@ sai_status_t redis_generic_set(
SWSS_LOG_ENTER();

std::string str_route_entry;
sai_serialize_primitive(*unicast_route_entry, str_route_entry);
sai_serialize_route_entry(*unicast_route_entry, str_route_entry);

sai_status_t status = internal_redis_generic_set(
object_type,
Expand Down
4 changes: 2 additions & 2 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ sai_status_t handle_neighbor(

int index = 0;
sai_neighbor_entry_t neighbor_entry;
sai_deserialize_primitive(str_object_id, index, neighbor_entry);
sai_deserialize_neighbor_entry(str_object_id, index, neighbor_entry);

neighbor_entry.rif_id = translate_vid_to_rid(neighbor_entry.rif_id);

Expand Down Expand Up @@ -573,7 +573,7 @@ sai_status_t handle_route(

int index = 0;
sai_unicast_route_entry_t route_entry;
sai_deserialize_primitive(str_object_id, index, route_entry);
sai_deserialize_route_entry(str_object_id, index, route_entry);

route_entry.vr_id = translate_vid_to_rid(route_entry.vr_id);

Expand Down
4 changes: 2 additions & 2 deletions syncd/syncd_hard_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ sai_neighbor_entry_t getNeighborEntryFromString(const std::string &strNeighborEn

int index = 0;
sai_neighbor_entry_t neighborEntry;
sai_deserialize_primitive(strNeighborEntry, index, neighborEntry);
sai_deserialize_neighbor_entry(strNeighborEntry, index, neighborEntry);

return neighborEntry;
}
Expand Down Expand Up @@ -660,7 +660,7 @@ sai_unicast_route_entry_t getRouteEntryFromString(const std::string &strRouteEnt

int index = 0;
sai_unicast_route_entry_t routeEntry;
sai_deserialize_primitive(strRouteEntry, index, routeEntry);
sai_deserialize_route_entry(strRouteEntry, index, routeEntry);

return routeEntry;
}
Expand Down

0 comments on commit 1a6b05b

Please sign in to comment.