Commit d0262ace authored by vimala.v's avatar vimala.v Committed by Ashok Babu Channa

Optimization in the length of the RM Header option

Change-Id: I13caa257aede8e812e1ea1c2807668572e327f33
Signed-off-by: default avatarvimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5683Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarAbhishek Sharma <ce.abhishek@samsung.com>
Reviewed-by: default avatarAshok Babu Channa <ashok.channa@samsung.com>
parent cf70ee57
......@@ -91,8 +91,7 @@ typedef enum
{
NOR = 0, /**< Normal Message. */
ACK, /**< Empty Acknowledgement message. */
RST, /**< Empty Reset message. */
UNDEFINED /**< Message type not defined. */
RST /**< Empty Reset message. */
}MSGType;
/**
......
......@@ -35,13 +35,37 @@
*/
#define RM_TAG "OIC_RM_RAP"
/**
* Default routing option data length is 1 byte with any of the following values.
* 00 - source and destination address is not present.
* 01 - source and destination address is present with message type as ACK.
* 10 - source and destination address is present with message type as RESET.
* 11 - source and destination address is present with message type as NORMAL.
*/
#define DEFAULT_ROUTE_OPTION_LEN 1
/**
* Minimum routing option data length is
* length of src address(1byte) + length of destination address(1byte) +
* Seq Num(2bytes) + Msg Type(1 bytes)
* Msg Type(1 bytes) + length of src address(1byte) + length of destination address(1byte) +
* Seq Num(2bytes)
*/
#define MIN_ROUTE_OPTION_LEN 5
/**
* Acknowledge message type is denoted as 01000000
*/
#define ACK_MESSAGE_TYPE (1 << 6)
/**
* Reset message type is denoted as 10000000
*/
#define RST_MESSAGE_TYPE (1 << 7)
/**
* Normal message type is denoted as 11000000
*/
#define NORMAL_MESSAGE_TYPE (3 << 6)
/**
* Stack mode.
*/
......@@ -219,11 +243,11 @@ OCStackResult RMUpdateInfo(CAHeaderOption_t **options, uint8_t *numOptions,
}
// Update Endpoint with source address from RM header option.
if (0 != (*options + routeIndex)->optionLength)
if (DEFAULT_ROUTE_OPTION_LEN < (*options + routeIndex)->optionLength )
{
uint8_t dLen = 0;
uint16_t count = sizeof(dLen);
memcpy(&dLen, (*options + routeIndex)->optionData, sizeof(dLen));
uint16_t count = sizeof(dLen) + DEFAULT_ROUTE_OPTION_LEN;
memcpy(&dLen, (*options + routeIndex)->optionData + DEFAULT_ROUTE_OPTION_LEN, sizeof(dLen));
count += dLen;
uint8_t sLen = 0;
memcpy(&sLen, (*options + routeIndex)->optionData + count, sizeof(sLen));
......@@ -294,50 +318,99 @@ OCStackResult RMCreateRouteOption(const RMRouteOption_t *optValue, CAHeaderOptio
(optValue->srcEp ? ENDPOINT_ID_LENGTH:0);
OIC_LOG_V(DEBUG, RM_TAG, "createoption dlen %u slen [%u]", dLen, sLen);
unsigned int totalLength = MIN_ROUTE_OPTION_LEN + dLen + sLen;
void *tempData = OICCalloc(totalLength, sizeof(char));
if (NULL == tempData)
unsigned int totalLength = 0;
void *tempData = NULL;
if (0 == dLen && 0 == sLen)
{
OIC_LOG(ERROR, RM_TAG, "Calloc failed");
return OC_STACK_NO_MEMORY;
OIC_LOG(DEBUG, RM_TAG, "Source and destination is not present");
totalLength = DEFAULT_ROUTE_OPTION_LEN;
tempData = OICCalloc(totalLength, sizeof(char));
if (NULL == tempData)
{
OIC_LOG(ERROR, RM_TAG, "Calloc failed");
return OC_STACK_NO_MEMORY;
}
if (ACK == optValue->msgType)
{
OIC_LOG(DEBUG, RM_TAG, "OptValue ACK Message Type");
memset(tempData, ACK_MESSAGE_TYPE, DEFAULT_ROUTE_OPTION_LEN);
}
else if (RST == optValue->msgType)
{
OIC_LOG(DEBUG, RM_TAG, "OptValue RST Message Type");
memset(tempData, RST_MESSAGE_TYPE, DEFAULT_ROUTE_OPTION_LEN);
}
else
{
OIC_LOG(DEBUG, RM_TAG, "OptValue NOR Message Type");
memset(tempData, NORMAL_MESSAGE_TYPE, DEFAULT_ROUTE_OPTION_LEN);
}
}
memcpy(tempData, &dLen, sizeof(dLen));
unsigned int count = sizeof(dLen);
if (0 < dLen)
else
{
if (optValue->destGw)
totalLength = MIN_ROUTE_OPTION_LEN + dLen + sLen;
tempData = OICCalloc(totalLength, sizeof(char));
if (NULL == tempData)
{
memcpy(tempData + count, &(optValue->destGw), GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
OIC_LOG(ERROR, RM_TAG, "Calloc failed");
return OC_STACK_NO_MEMORY;
}
if (optValue->destEp)
if (ACK == optValue->msgType)
{
memcpy(tempData + count, &(optValue->destEp), ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
OIC_LOG(DEBUG, RM_TAG, "OptValue ACK Message Type");
memset(tempData, ACK_MESSAGE_TYPE, DEFAULT_ROUTE_OPTION_LEN);
}
else if (RST == optValue->msgType)
{
OIC_LOG(DEBUG, RM_TAG, "OptValue RST Message Type");
memset(tempData, RST_MESSAGE_TYPE, DEFAULT_ROUTE_OPTION_LEN);
}
else
{
OIC_LOG(DEBUG, RM_TAG, "OptValue NOR Message Type");
memset(tempData, NORMAL_MESSAGE_TYPE, DEFAULT_ROUTE_OPTION_LEN);
}
}
memcpy(tempData + count, &sLen, sizeof(sLen));
count += sizeof(sLen);
if (0 < sLen)
{
if (optValue->srcGw)
memcpy(tempData + DEFAULT_ROUTE_OPTION_LEN, &dLen, sizeof(dLen));
unsigned int count = sizeof(dLen) + DEFAULT_ROUTE_OPTION_LEN;
if (0 < dLen)
{
memcpy(tempData + count, &(optValue->srcGw), GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
if (optValue->destGw)
{
memcpy(tempData + count, &(optValue->destGw), GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
}
if (optValue->destEp)
{
memcpy(tempData + count, &(optValue->destEp), ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
}
}
if (optValue->srcEp)
memcpy(tempData + count, &sLen, sizeof(sLen));
count += sizeof(sLen);
if (0 < sLen)
{
memcpy(tempData + count, &(optValue->srcEp), ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
if (optValue->srcGw)
{
memcpy(tempData + count, &(optValue->srcGw), GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
}
if (optValue->srcEp)
{
memcpy(tempData + count, &(optValue->srcEp), ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
}
}
memcpy(tempData + count, &optValue->mSeqNum, sizeof(optValue->mSeqNum));
}
memcpy(tempData + count, &optValue->mSeqNum, sizeof(optValue->mSeqNum));
count += sizeof(optValue->mSeqNum);
memcpy(tempData + count, &optValue->msgType, sizeof(optValue->msgType));
memcpy(options->optionData, tempData, totalLength);
options->optionID = RM_OPTION_MESSAGE_SWITCHING;
......@@ -361,38 +434,64 @@ OCStackResult RMParseRouteOption(const CAHeaderOption_t *options, RMRouteOption_
return OC_STACK_ERROR;
}
uint8_t dLen = 0 ;
uint16_t count = sizeof(dLen);
memcpy(&dLen, options->optionData, sizeof(dLen));
if (0 < dLen)
{
memcpy(&(optValue->destGw), options->optionData + count, GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
OIC_LOG_V(DEBUG, RM_TAG, "Option Length is %d", options->optionLength);
uint8_t mType = 0;
memcpy(&mType, options->optionData, sizeof(mType));
if (GATEWAY_ID_LENGTH < dLen)
{
memcpy(&(optValue->destEp), options->optionData + count, ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
}
if (ACK_MESSAGE_TYPE == mType)
{
OIC_LOG(INFO, RM_TAG, "ACK_MESSAGE_TYPE");
optValue->msgType = ACK;
}
else if (RST_MESSAGE_TYPE == mType)
{
OIC_LOG(INFO, RM_TAG, "RST_MESSAGE_TYPE");
optValue->msgType = RST;
}
else if (NORMAL_MESSAGE_TYPE == mType)
{
OIC_LOG(INFO, RM_TAG, "NOR_MESSAGE_TYPE");
optValue->msgType = NOR;
}
uint8_t sLen = 0;
memcpy(&sLen, options->optionData + count, sizeof(sLen));
count += sizeof(sLen);
if (0 < sLen)
if (DEFAULT_ROUTE_OPTION_LEN == options->optionLength)
{
memcpy(&(optValue->srcGw), options->optionData + count, GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
OIC_LOG(INFO, RM_TAG, "No source and destination are present");
}
else
{
uint8_t dLen = 0 ;
uint16_t count = DEFAULT_ROUTE_OPTION_LEN;
memcpy(&dLen, options->optionData + count, sizeof(dLen));
count += sizeof(dLen);
if (0 < dLen)
{
memcpy(&(optValue->destGw), options->optionData + count, GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
if (GATEWAY_ID_LENGTH < dLen)
{
memcpy(&(optValue->destEp), options->optionData + count, ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
}
}
if (GATEWAY_ID_LENGTH < sLen)
uint8_t sLen = 0;
memcpy(&sLen, options->optionData + count, sizeof(sLen));
count += sizeof(sLen);
if (0 < sLen)
{
memcpy(&(optValue->srcEp), options->optionData + count, ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
memcpy(&(optValue->srcGw), options->optionData + count, GATEWAY_ID_LENGTH);
count += GATEWAY_ID_LENGTH;
if (GATEWAY_ID_LENGTH < sLen)
{
memcpy(&(optValue->srcEp), options->optionData + count, ENDPOINT_ID_LENGTH);
count += ENDPOINT_ID_LENGTH;
}
}
memcpy(&optValue->mSeqNum, options->optionData + count, sizeof(optValue->mSeqNum));
}
memcpy(&optValue->mSeqNum, options->optionData + count, sizeof(optValue->mSeqNum));
count += sizeof(optValue->mSeqNum);
memcpy(&optValue->msgType, options->optionData + count, sizeof(optValue->msgType));
OIC_LOG_V(INFO, RM_TAG, "Option hopcount is %d", optValue->mSeqNum);
OIC_LOG_V(INFO, RM_TAG, "Option Sender Addr is [%u][%u]", optValue->srcGw, optValue->srcEp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment