summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkush.agrawal@samsung.com <kush.agrawal@samsung.com>2019-11-22 12:50:23 +0530
committerDoHyun Pyun <dh79.pyun@samsung.com>2019-11-28 16:27:22 +0900
commitf343e7b72f04c84a63453ea5c5ff9db8d0293359 (patch)
treed8631589615b4b2a3bb8e7882c003ae14bf82d2c
parent2a48d33152759b69583c6503f8ea8eae30adde73 (diff)
downloadiotivity-f343e7b72f04c84a63453ea5c5ff9db8d0293359.tar.gz
iotivity-f343e7b72f04c84a63453ea5c5ff9db8d0293359.tar.bz2
iotivity-f343e7b72f04c84a63453ea5c5ff9db8d0293359.zip
Split Routing Table into Gateway and Endpoint (#617)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/617 (cherry-picked from 0ec246dda82834e64d27705d59bcd13a61e81b12) Change-Id: Ia81472992ef710fb6671e20d8d1480be0de7f4d3 Signed-off-by: Kush <kush.agrawal@samsung.com> Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
-rwxr-xr-x[-rw-r--r--]resource/csdk/routing/SConscript1
-rwxr-xr-x[-rw-r--r--]resource/csdk/routing/include/routingtablemanager.h40
-rwxr-xr-xresource/csdk/routing/include/routingtablemanager_endpoint.h111
-rwxr-xr-x[-rw-r--r--]resource/csdk/routing/src/routingtablemanager.c212
-rwxr-xr-xresource/csdk/routing/src/routingtablemanager_endpoint.c267
5 files changed, 387 insertions, 244 deletions
diff --git a/resource/csdk/routing/SConscript b/resource/csdk/routing/SConscript
index cf18ade3f..b84399bce 100644..100755
--- a/resource/csdk/routing/SConscript
+++ b/resource/csdk/routing/SConscript
@@ -51,6 +51,7 @@ if env.get('ROUTING') == 'GW':
'./src/routingutility.c',
'./src/routingmanager.c',
'./src/routingtablemanager.c',
+ './src/routingtablemanager_endpoint.c',
'./src/routingmanagerinterface.c',
'./src/routingmessageparser.c',
]
diff --git a/resource/csdk/routing/include/routingtablemanager.h b/resource/csdk/routing/include/routingtablemanager.h
index 9497b4832..0b241352f 100644..100755
--- a/resource/csdk/routing/include/routingtablemanager.h
+++ b/resource/csdk/routing/include/routingtablemanager.h
@@ -142,13 +142,6 @@ OCStackResult RTMFreeGatewayRouteTable(u_linklist_t **gatewayTable);
OCStackResult RTMFreeGatewayIdList(u_linklist_t **gatewayIdTable);
/**
- * Frees the endpoint table memory with nodes containing structute RTMEndpointEntry_t.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable);
-
-/**
* Adds the entry to the routing table if the entry for Gateway id is
* not preset in Routing table, Updates the Old entry if Entry for
* Gateway Id is already present in Routing table i.e routeCost and NextHop
@@ -165,16 +158,6 @@ OCStackResult RTMAddGatewayEntry(uint32_t gatewayId, uint32_t nextHop, uint32_t
const RTMDestIntfInfo_t *destInterfaces, u_linklist_t **gatewayTable);
/**
- * Adds the endpoint entry to the routing table.
- * @param[in/out] endpointId Endpoint Id.
- * @param[in] destAddr Destination Address.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
- u_linklist_t **endpointTable);
-
-/**
* Removes the gateway entry from the routing table and also removes
* corresponding entries having nexthop as removed gateway.
* @param[in] gatewayId Gateway id of node need to be removed.
@@ -187,14 +170,6 @@ OCStackResult RTMRemoveGatewayEntry(uint32_t gatewayId, u_linklist_t **removedGa
u_linklist_t **gatewayTable);
/**
- * Removes the endpoint entry from the routing table.
- * @param[in] endpointId Endpoint id of node need to be removed.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable);
-
-/**
* Removes the gateway entry from the routing table which has gateway id and nexthop as given.
* @param[in] gatewayId Gateway Id.
* @param[in] nextHop Next Hop address.
@@ -214,13 +189,6 @@ OCStackResult RTMRemoveGatewayDestEntry(uint32_t gatewayId, uint32_t nextHop,
OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable);
/**
- * Removes the endpoint nodes.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable);
-
-/**
* Gets the neighbor nodes i.e nodes with routecost 1.
* @param[in/out] neighbourNodes link list containing neighbor nodes.
this list will be pointer to GatewayIds
@@ -238,14 +206,6 @@ void RTMGetNeighbours(u_linklist_t **neighbourNodes, const u_linklist_t *gateway
RTMGatewayId_t *RTMGetNextHop(uint32_t gatewayId, const u_linklist_t *gatewayTable);
/**
- * Gets endpoint entry
- * @param[in] endpointId Endpoint id of node need to be removed.
- * @param[in] endpointTable Endpoint Routing Table.
- * @return Endpoint Destination inteface address.
- */
-CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable);
-
-/**
* Updates destination interface address of an entry with provided gateway id
* as destination.
* @param[in] gatewayId Gateway Id of Hop need to be updated.
diff --git a/resource/csdk/routing/include/routingtablemanager_endpoint.h b/resource/csdk/routing/include/routingtablemanager_endpoint.h
new file mode 100755
index 000000000..473045880
--- /dev/null
+++ b/resource/csdk/routing/include/routingtablemanager_endpoint.h
@@ -0,0 +1,111 @@
+/* ****************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+/**
+ * @file
+ * This file contains the APIs for routing table manager endpoint.
+ */
+#ifndef ROUTING_TABLE_MANAGER_ENDPOINT_H_
+#define ROUTING_TABLE_MANAGER_ENDPOINT_H_
+
+#ifndef SINGLE_THREAD
+#include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#endif
+
+#if defined(__ANDROID__)
+#include <linux/time.h>
+#endif
+#include "ulinklist.h"
+#include "uarraylist.h"
+#include "octypes.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Initialize the Routing Table Manager.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMEndpointInitialize(u_linklist_t **endpointTable);
+
+/**
+ * Terminates the Routing Table Manager..
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMEndpointTerminate(u_linklist_t **endpointTable);
+
+/**
+ * Frees the endpoint table memory with nodes containing structute RTMEndpointEntry_t.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable);
+
+/**
+ * Adds the endpoint entry to the routing table.
+ * @param[in/out] endpointId Endpoint Id.
+ * @param[in] destAddr Destination Address.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
+ u_linklist_t **endpointTable);
+
+/**
+ * Removes the endpoint entry from the routing table.
+ * @param[in] endpointId Endpoint id of node need to be removed.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable);
+
+/**
+ * Removes the endpoint nodes.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable);
+
+/**
+ * Gets endpoint entry
+ * @param[in] endpointId Endpoint id of node need to be removed.
+ * @param[in] endpointTable Endpoint Routing Table.
+ * @return Endpoint Destination inteface address.
+ */
+CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable);
+
+/**
+ * Prints the routing table
+ * @param[in] endpointTable Endpoint Routing Table.
+ */
+void RTMEndpointPrintTable(const u_linklist_t *endpointTable);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ROUTING_TABLE_MANAGER_ENDPOINT_H_ */
diff --git a/resource/csdk/routing/src/routingtablemanager.c b/resource/csdk/routing/src/routingtablemanager.c
index f949c6223..3a3cbb9c7 100644..100755
--- a/resource/csdk/routing/src/routingtablemanager.c
+++ b/resource/csdk/routing/src/routingtablemanager.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <string.h>
#include "routingtablemanager.h"
+#include "routingtablemanager_endpoint.h"
#include "routingutility.h"
#include "oic_malloc.h"
#include "oic_string.h"
@@ -60,16 +61,13 @@ OCStackResult RTMInitialize(u_linklist_t **gatewayTable, u_linklist_t **endpoint
}
}
- if (NULL == *endpointTable)
+ if (OC_STACK_ERROR == RTMEndpointInitialize(endpointTable))
{
- *endpointTable = u_linklist_create();
- if (NULL == *endpointTable)
- {
- OIC_LOG(ERROR, TAG, "Creating Routing Table failed");
- RTMTerminate(gatewayTable, endpointTable);
- return OC_STACK_ERROR;
- }
+ OIC_LOG(ERROR, TAG, "Creating EndPoint Routing Table failed");
+ RTMTerminate(gatewayTable, endpointTable);
+ return OC_STACK_ERROR;
}
+
OIC_LOG(DEBUG, TAG, "RTMInitialize OUT");
return OC_STACK_OK;
}
@@ -118,39 +116,6 @@ OCStackResult RTMFreeGatewayRouteTable(u_linklist_t **gatewayTable)
return OC_STACK_OK;
}
-/*
- * Freeing every char pointer of endpoint entry here frees the table.
- */
-OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- if (NULL == endpointTable || NULL == *endpointTable)
- {
- return OC_STACK_OK;
- }
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(*endpointTable, &iterTable);
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *hop = u_linklist_get_data(iterTable);
- if (NULL != hop)
- {
- OICFree(hop);
- }
-
- OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
- return OC_STACK_ERROR;
- }
- }
- u_linklist_free(endpointTable);
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
OCStackResult RTMFreeGatewayIdList(u_linklist_t **gatewayIdTable)
{
OIC_LOG(DEBUG, TAG, "IN");
@@ -212,15 +177,7 @@ OCStackResult RTMTerminate(u_linklist_t **gatewayTable, u_linklist_t **endpointT
*gatewayTable = NULL;
}
- ret = RTMFreeEndpointRouteTable(endpointTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Deleting Endpoint Routing Table failed");
- }
- if (NULL != *endpointTable)
- {
- *endpointTable = NULL;
- }
+ RTMEndpointTerminate(endpointTable);
OIC_LOG(DEBUG, TAG, "OUT");
return OC_STACK_OK;
}
@@ -499,65 +456,6 @@ OCStackResult RTMAddGatewayEntry(uint32_t gatewayId, uint32_t nextHop, uint32_t
return OC_STACK_OK;
}
-OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
- u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- RM_NULL_CHECK_WITH_RET(endpointId, TAG, "endpointId");
- RM_NULL_CHECK_WITH_RET(destAddr, TAG, "destAddr");
- RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
- if (NULL == *endpointTable)
- {
- *endpointTable = u_linklist_create();
- if (NULL == *endpointTable)
- {
- OIC_LOG(ERROR, TAG, "u_linklist_create failed");
- return OC_STACK_NO_MEMORY;
- }
- }
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(*endpointTable, &iterTable);
- // Iterate over gateway list to find if already entry with this gatewayid is present.
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *entry =
- (RTMEndpointEntry_t *) u_linklist_get_data(iterTable);
-
- if (NULL != entry && (0 == memcmp(destAddr->addr, entry->destIntfAddr.addr,
- strlen(entry->destIntfAddr.addr)))
- && destAddr->port == entry->destIntfAddr.port)
- {
- *endpointId = entry->endpointId;
- OIC_LOG(ERROR, TAG, "Adding failed as Enpoint Entry Already present in Table");
- return OC_STACK_DUPLICATE_REQUEST;
- }
- u_linklist_get_next(&iterTable);
- }
-
- // Filling Entry.
- RTMEndpointEntry_t *hopEntry = (RTMEndpointEntry_t *)OICCalloc(1, sizeof(RTMEndpointEntry_t));
-
- if (NULL == hopEntry)
- {
- OIC_LOG(ERROR, TAG, "Malloc failed for hop entry");
- return OC_STACK_ERROR;
- }
-
- hopEntry->endpointId = *endpointId;
- hopEntry->destIntfAddr = *destAddr;
-
- OCStackResult ret = u_linklist_add(*endpointTable, (void *)hopEntry);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Adding Enpoint Entry to Routing Table failed");
- OICFree(hopEntry);
- return OC_STACK_ERROR;
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
OCStackResult RTMAddObserver(uint32_t obsID, CAEndpoint_t devAddr, u_linklist_t **gatewayTable)
{
OIC_LOG(DEBUG, TAG, "IN");
@@ -756,36 +654,6 @@ OCStackResult RTMRemoveGatewayDestEntry(uint32_t gatewayId, uint32_t nextHop,
return OC_STACK_ERROR;
}
-OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
- RM_NULL_CHECK_WITH_RET(*endpointTable, TAG, "*endpointTable");
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(*endpointTable, &iterTable);
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
- if (NULL != entry && endpointId == entry->endpointId)
- {
- OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
- return OC_STACK_ERROR;
- }
- OICFree(entry);
- }
- else
- {
- u_linklist_get_next(&iterTable);
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable)
{
OIC_LOG(DEBUG, TAG, "IN");
@@ -806,25 +674,6 @@ OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable)
return OC_STACK_OK;
}
-OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- if (NULL == endpointTable || NULL == *endpointTable)
- {
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
- }
-
- OCStackResult ret = RTMFreeEndpointRouteTable(endpointTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Freeing Endpoints failed");
- return OC_STACK_ERROR;
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
void RTMFreeGateway(RTMGatewayId_t *gateway, u_linklist_t **gatewayTable)
{
OIC_LOG(DEBUG, TAG, "IN");
@@ -909,32 +758,6 @@ RTMGatewayId_t *RTMGetNextHop(uint32_t gatewayId, const u_linklist_t *gatewayTab
return NULL;
}
-CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- if (NULL == endpointTable)
- {
- OIC_LOG(ERROR, TAG, "endpointTable is null");
- return NULL;
- }
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(endpointTable, &iterTable);
-
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
- if (NULL != entry && (endpointId == entry->endpointId))
- {
- OIC_LOG(DEBUG, TAG, "OUT");
- return &(entry->destIntfAddr);
- }
- u_linklist_get_next(&iterTable);
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return NULL;
-}
-
void RTMGetObserverList(OCObservationId **obsList, uint8_t *obsListLen,
const u_linklist_t *gatewayTable)
{
@@ -1350,24 +1173,5 @@ void RTMPrintTable(const u_linklist_t *gatewayTable, const u_linklist_t *endpoin
u_linklist_get_next(&iterTable);
}
- OIC_LOG(DEBUG, RM_TAG, "=================Endpoint List table============================\n");
- u_linklist_iterator_t *iterEndpointTable = NULL;
- u_linklist_init_iterator(endpointTable, &iterEndpointTable);
-
- // Iterate over endpoint list to find if already entry for gatewayid is present.
- while (NULL != iterEndpointTable)
- {
- RTMEndpointEntry_t *hop =
- (RTMEndpointEntry_t *) u_linklist_get_data(iterEndpointTable);
- if (NULL == hop)
- {
- OIC_LOG(ERROR, RM_TAG, "Printing Table Failed");
- return;
- }
- OIC_LOG_V(DEBUG, RM_TAG, "EndpointId : %u\naddr : %s Port : %d",
- hop->endpointId, hop->destIntfAddr.addr, hop->destIntfAddr.port);
-
- OIC_LOG(DEBUG, RM_TAG, "********************************************\n");
- u_linklist_get_next(&iterEndpointTable);
- }
+ RTMEndpointPrintTable(endpointTable);
}
diff --git a/resource/csdk/routing/src/routingtablemanager_endpoint.c b/resource/csdk/routing/src/routingtablemanager_endpoint.c
new file mode 100755
index 000000000..9b68c3a40
--- /dev/null
+++ b/resource/csdk/routing/src/routingtablemanager_endpoint.c
@@ -0,0 +1,267 @@
+/* ****************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "routingtablemanager_endpoint.h"
+#include "routingtablemanager.h"
+#include "routingutility.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "include/logger.h"
+
+/**
+ * Logging tag for module name.
+ */
+#define TAG "OIC_RM_TM"
+
+/**
+ * Tag for printing the Routing table.
+ */
+#define RM_TAG "OIC_RM_RAP"
+
+OCStackResult RTMEndpointInitialize(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "RTMEndpointInitialize IN");
+ if (NULL == *endpointTable)
+ {
+ *endpointTable = u_linklist_create();
+ if (NULL == *endpointTable)
+ {
+ OIC_LOG(ERROR, TAG, "Creating Routing Table failed");
+ return OC_STACK_ERROR;
+ }
+ }
+ OIC_LOG(DEBUG, TAG, "RTMEndpointInitialize OUT");
+ return OC_STACK_OK;
+}
+
+/*
+ * Freeing every char pointer of endpoint entry here frees the table.
+ */
+OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == endpointTable || NULL == *endpointTable)
+ {
+ return OC_STACK_OK;
+ }
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(*endpointTable, &iterTable);
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *hop = u_linklist_get_data(iterTable);
+ if (NULL != hop)
+ {
+ OICFree(hop);
+ }
+
+ OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
+ return OC_STACK_ERROR;
+ }
+ }
+ u_linklist_free(endpointTable);
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+/*
+ * Freeing memory first and then Freeing linked list for gateway and endpoint.
+ */
+OCStackResult RTMEndpointTerminate(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ OCStackResult ret = RTMFreeEndpointRouteTable(endpointTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Deleting Endpoint Routing Table failed");
+ }
+ if (NULL != *endpointTable)
+ {
+ *endpointTable = NULL;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
+ u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ RM_NULL_CHECK_WITH_RET(endpointId, TAG, "endpointId");
+ RM_NULL_CHECK_WITH_RET(destAddr, TAG, "destAddr");
+ RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
+ if (NULL == *endpointTable)
+ {
+ *endpointTable = u_linklist_create();
+ if (NULL == *endpointTable)
+ {
+ OIC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(*endpointTable, &iterTable);
+ // Iterate over gateway list to find if already entry with this gatewayid is present.
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *entry =
+ (RTMEndpointEntry_t *) u_linklist_get_data(iterTable);
+
+ if (NULL != entry && (0 == memcmp(destAddr->addr, entry->destIntfAddr.addr,
+ strlen(entry->destIntfAddr.addr)))
+ && destAddr->port == entry->destIntfAddr.port)
+ {
+ *endpointId = entry->endpointId;
+ OIC_LOG(ERROR, TAG, "Adding failed as Enpoint Entry Already present in Table");
+ return OC_STACK_DUPLICATE_REQUEST;
+ }
+ u_linklist_get_next(&iterTable);
+ }
+
+ // Filling Entry.
+ RTMEndpointEntry_t *hopEntry = (RTMEndpointEntry_t *)OICCalloc(1, sizeof(RTMEndpointEntry_t));
+
+ if (NULL == hopEntry)
+ {
+ OIC_LOG(ERROR, TAG, "Malloc failed for hop entry");
+ return OC_STACK_ERROR;
+ }
+
+ hopEntry->endpointId = *endpointId;
+ hopEntry->destIntfAddr = *destAddr;
+
+ OCStackResult ret = u_linklist_add(*endpointTable, (void *)hopEntry);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Adding Enpoint Entry to Routing Table failed");
+ OICFree(hopEntry);
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
+ RM_NULL_CHECK_WITH_RET(*endpointTable, TAG, "*endpointTable");
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(*endpointTable, &iterTable);
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
+ if (NULL != entry && endpointId == entry->endpointId)
+ {
+ OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
+ return OC_STACK_ERROR;
+ }
+ OICFree(entry);
+ }
+ else
+ {
+ u_linklist_get_next(&iterTable);
+ }
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == endpointTable || NULL == *endpointTable)
+ {
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+ }
+
+ OCStackResult ret = RTMFreeEndpointRouteTable(endpointTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Freeing Endpoints failed");
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == endpointTable)
+ {
+ OIC_LOG(ERROR, TAG, "endpointTable is null");
+ return NULL;
+ }
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(endpointTable, &iterTable);
+
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
+ if (NULL != entry && (endpointId == entry->endpointId))
+ {
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return &(entry->destIntfAddr);
+ }
+ u_linklist_get_next(&iterTable);
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return NULL;
+}
+
+void RTMEndpointPrintTable(const u_linklist_t *endpointTable)
+{
+ RM_NULL_CHECK_VOID(endpointTable, TAG, "endpointTable");
+
+ OIC_LOG(DEBUG, RM_TAG, "=================Endpoint List table============================\n");
+ u_linklist_iterator_t *iterEndpointTable = NULL;
+ u_linklist_init_iterator(endpointTable, &iterEndpointTable);
+
+ // Iterate over endpoint list to find if already entry for gatewayid is present.
+ while (NULL != iterEndpointTable)
+ {
+ RTMEndpointEntry_t *hop =
+ (RTMEndpointEntry_t *) u_linklist_get_data(iterEndpointTable);
+ if (NULL == hop)
+ {
+ OIC_LOG(ERROR, RM_TAG, "Printing Table Failed");
+ return;
+ }
+ OIC_LOG_V(DEBUG, RM_TAG, "EndpointId : %u\naddr : %s Port : %d Flags : %d",
+ hop->endpointId, hop->destIntfAddr.addr, hop->destIntfAddr.port, hop->destIntfAddr.flags);
+
+ OIC_LOG(DEBUG, RM_TAG, "********************************************\n");
+ u_linklist_get_next(&iterEndpointTable);
+ }
+}