Split Routing Table into Gateway and Endpoint (#617) 97/218797/1
authorkush.agrawal@samsung.com <kush.agrawal@samsung.com>
Fri, 22 Nov 2019 07:20:23 +0000 (12:50 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 28 Nov 2019 07:27:22 +0000 (16:27 +0900)
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>
resource/csdk/routing/SConscript [changed mode: 0644->0755]
resource/csdk/routing/include/routingtablemanager.h [changed mode: 0644->0755]
resource/csdk/routing/include/routingtablemanager_endpoint.h [new file with mode: 0755]
resource/csdk/routing/src/routingtablemanager.c [changed mode: 0644->0755]
resource/csdk/routing/src/routingtablemanager_endpoint.c [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index cf18ade..b84399b
@@ -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',
     ]
old mode 100644 (file)
new mode 100755 (executable)
index 9497b48..0b24135
@@ -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 (executable)
index 0000000..4730458
--- /dev/null
@@ -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_ */
old mode 100644 (file)
new mode 100755 (executable)
index f949c62..3a3cbb9
@@ -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 (executable)
index 0000000..9b68c3a
--- /dev/null
@@ -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);
+    }
+}