1 /* ****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
23 * This file contains the APIs for routing table manager.
25 #ifndef ROUTING_TABLE_MANAGER_H_
26 #define ROUTING_TABLE_MANAGER_H_
34 #if defined(__ANDROID__)
35 #include <linux/time.h>
37 #include "ulinklist.h"
38 #include "uarraylist.h"
48 * Maximum hop/destination address length.
50 #define MAX_DEST_ADDR_LEN 40
53 * Maximum number of observers for the gateway resource.
55 #define MAX_NUM_OBSERVERS 10
58 * Maximum time after which gateway should send a notification for its existence.
59 * Every 30s gateway will send its existence notification.
61 #define GATEWAY_ALIVE_TIMEOUT 30
64 * The routing table entries are validated for every 40 seconds for its existence.
66 #define ROUTINGTABLE_REFRESH_TIMEOUT 40
69 * The routing table entries are removed if entries are invalid every 45 seconds.
71 #define ROUTINGTABLE_VALIDATION_TIMEOUT 45
74 * Destination Interface Address entries.
78 uint32_t observerId; /**< Observer Id. */
79 CAEndpoint_t destIntfAddr; /**< Destination Interface Address. */
80 uint32_t timeElapsed; /**< Time elapsed. */
81 bool isValid; /**< Valid check for Gateway. */
85 * Endpoint Address entries.
89 uint16_t endpointId; /**< Endpoint Id. */
90 CAEndpoint_t destIntfAddr; /**< Destination Interface Address. */
94 * Gateway Address entries.
96 typedef struct gatewayAddress
98 uint32_t gatewayId; /**< Gateway Id. */
99 u_arraylist_t *destIntfAddr; /**< Destination Interface Addresses. */
103 * Routing table entries at Gateway.
107 RTMGatewayId_t *destination; /**< destination Address. */
108 RTMGatewayId_t *nextHop; /**< Next Hop Information. */
109 uint32_t routeCost; /**< routeCost. */
110 uint16_t mcastMessageSeqNum; /**< sequence number for last mcast packet. */
111 uint32_t seqNum; /**< sequence number for notification. */
115 * Initialize the Routing Table Manager.
116 * @param[in/out] gatewayTable Gateway Routing Table.
117 * @param[in/out] endpointTable Endpoint Routing Table.
118 * @return ::OC_STACK_OK or Appropriate error code.
120 OCStackResult RTMInitialize(u_linklist_t **gatewayTable, u_linklist_t **endpointTable);
123 * Terminates the Routing Table Manager.
124 * @param[in/out] gatewayTable Gateway Routing Table.
125 * @param[in/out] endpointTable Endpoint Routing Table.
126 * @return ::OC_STACK_OK or Appropriate error code.
128 OCStackResult RTMTerminate(u_linklist_t **gatewayTable, u_linklist_t **endpointTable);
131 * Frees the gateway table memory with nodes containing structure RTMGatewayEntry_t.
132 * @param[in/out] gatewayTable Gateway Routing Table.
133 * @return ::OC_STACK_OK or Appropriate error code.
135 OCStackResult RTMFreeGatewayRouteTable(u_linklist_t **gatewayTable);
138 * Frees the gateway ID list memory with nodes containing structute RTMGatewayId_t.
139 * @param[in/out] gatewayIdTable Gateway ID list.
140 * @return ::OC_STACK_OK or Appropriate error code.
142 OCStackResult RTMFreeGatewayIdList(u_linklist_t **gatewayIdTable);
145 * Adds the entry to the routing table if the entry for Gateway id is
146 * not preset in Routing table, Updates the Old entry if Entry for
147 * Gateway Id is already present in Routing table i.e routeCost and NextHop
148 * will be updated for efficient hop result.
150 * @param[in] gatewayId Gateway Id.
151 * @param[in] nextHop Next Hop address.
152 * @param[in] routeCost Shortest Path to Destination - Hopcount.
153 * @param[in] destInterfaces Destination Interface Information.
154 * @param[in/out] gatewayTable Gateway Routing Table.
155 * @return ::OC_STACK_OK or Appropriate error code.
157 OCStackResult RTMAddGatewayEntry(uint32_t gatewayId, uint32_t nextHop, uint32_t routeCost,
158 const RTMDestIntfInfo_t *destInterfaces, u_linklist_t **gatewayTable);
161 * Removes the gateway entry from the routing table and also removes
162 * corresponding entries having nexthop as removed gateway.
163 * @param[in] gatewayId Gateway id of node need to be removed.
164 * @param[in/out] removedGatewayNodes Linklist containing removed gateway nodes
165 * list need to be freed by caller.
166 * @param[in/out] gatewayTable Gateway Routing Table.
167 * @return ::OC_STACK_OK or Appropriate error code.
169 OCStackResult RTMRemoveGatewayEntry(uint32_t gatewayId, u_linklist_t **removedGatewayNodes,
170 u_linklist_t **gatewayTable);
173 * Removes the gateway entry from the routing table which has gateway id and nexthop as given.
174 * @param[in] gatewayId Gateway Id.
175 * @param[in] nextHop Next Hop address.
176 * @param[in] destInfAdr Destination Address of Next Hop to update time.
177 * @param[in/out] existEntry Entry which has different Next Hop.
178 * @param[in/out] gatewayTable Gateway Routing Table.
179 * @return ::OC_STACK_OK or Appropriate error code.
181 OCStackResult RTMRemoveGatewayDestEntry(uint32_t gatewayId, uint32_t nextHop,
182 const RTMDestIntfInfo_t *destInfAdr,
183 RTMGatewayEntry_t **existEntry, u_linklist_t **gatewayTable);
185 * Removes the gateway nodes.
186 * @param[in/out] gatewayTable Gateway Routing Table.
187 * @return ::OC_STACK_OK or Appropriate error code.
189 OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable);
192 * Gets the neighbor nodes i.e nodes with routecost 1.
193 * @param[in/out] neighbourNodes link list containing neighbor nodes.
194 this list will be pointer to GatewayIds
195 and must be freed by caller.
196 * @param[in] gatewayTable Gateway Routing Table.
198 void RTMGetNeighbours(u_linklist_t **neighbourNodes, const u_linklist_t *gatewayTable);
201 * Gets next hop from the routing table.
202 * @param[in] gatewayId Gateway Id.
203 * @param[in] gatewayTable Gateway Routing Table.
204 * @return Next Hop address - returns NULL if it is End Device.
206 RTMGatewayId_t *RTMGetNextHop(uint32_t gatewayId, const u_linklist_t *gatewayTable);
209 * Updates destination interface address of an entry with provided gateway id
211 * @param[in] gatewayId Gateway Id of Hop need to be updated.
212 * @param[in] destInterfaces Destination Interface Information.
213 * @param[in] addAdr Add/Remove destination address.
214 * @param[in/out] gatewayTable Gateway Routing Table.
215 * @return ::OC_STACK_OK or Appropriate error code.
217 OCStackResult RTMUpdateDestinationIntfAdr(uint32_t gatewayId, RTMDestIntfInfo_t destInterfaces,
218 bool addAdr, u_linklist_t **gatewayTable);
221 * Updates Multicast sequence number for gatewayID
222 * @param[in] gatewayId Gateway Id of Hop need to be updated.
223 * @param[in] seqNum Sequence number for last cast packet from gateway.
224 * @param[in/out] gatewayTable Gateway Routing Table.
225 * @return ::OC_STACK_OK or Appropriate error code.
227 OCStackResult RTMUpdateMcastSeqNumber(uint32_t gatewayId, uint16_t seqNum,
228 u_linklist_t **gatewayTable);
231 * Prints the routing table
232 * @param[in] gatewayTable Gateway Routing Table.
233 * @param[in] endpointTable Endpoint Routing Table.
235 void RTMPrintTable(const u_linklist_t *gatewayTable, const u_linklist_t *endpointTable);
238 * Frees the GatewayId
239 * @param[in] gateway Gateway Structure pointer.
240 * @param[in/out] gatewayTable Gateway Routing Table.
242 void RTMFreeGateway(RTMGatewayId_t *gateway, u_linklist_t **gatewayTable);
245 * Gets the list of observer IDs.
246 * @param[in/out] obsList List of Observation IDs.
247 * @param[in/out] obsListLen Length if Observation ID list.
248 * @param[in] gatewayTable Gateway Routing Table.
250 void RTMGetObserverList(OCObservationId **obsList, uint8_t *obsListLen,
251 const u_linklist_t *gatewayTable);
254 * Adds a observer address and obsID to the list.
255 * @param[in] obsID Observation ID.
256 * @param[in] devAddr Address of Gateway.
257 * @param[in/out] gatewayTable Gateway Routing Table.
258 * @return ::OC_STACK_OK or Appropriate error code.
260 OCStackResult RTMAddObserver(uint32_t obsID, CAEndpoint_t devAddr, u_linklist_t **gatewayTable);
263 * Check if a particular observer address is already registerd and returns
264 * its obsID if present.
265 * @param[in] devAddr Address of Gateway.
266 * @param[in/out] obsID Observation ID.
267 * @param[in] gatewayTable Gateway Routing Table.
268 * @return true or false.
270 bool RTMIsObserverPresent(CAEndpoint_t devAddr, OCObservationId *obsID,
271 const u_linklist_t *gatewayTable);
274 * Gets Current Time in Micro Seconds.
275 * @return Current Time.
277 uint64_t RTMGetCurrentTime();
280 * Update Gateway Address Validity.
281 * @param[in/out] invalidTable Removed entries Table.
282 * @param[in/out] gatewayTable Gateway Routing Table.
283 * @return ::OC_STACK_OK or Appropriate error code.
285 OCStackResult RTMUpdateDestAddrValidity(u_linklist_t **invalidTable, u_linklist_t **gatewayTable);
288 * Removes invalid gateways.
289 * @param[in/out] invalidTable Removed entries Table.
290 * @param[in/out] gatewayTable Gateway Routing Table.
291 * @return ::OC_STACK_OK or Appropriate error code.
293 OCStackResult RTMRemoveInvalidGateways(u_linklist_t **invalidTable, u_linklist_t **gatewayTable);
296 * Update Sequence number of Gateway Entry.
297 * @param[in] gatewayId Gateway Id.
298 * @param[in] seqNum Sequence Number of Entry.
299 * @param[in] destInterfaces Destination Interface Information.
300 * @param[out] gatewayTable Gateway Routing Table.
301 * @param[in] forceUpdate To Update parameters forcefully.
302 * @return ::OC_STACK_OK or Appropriate error code.
304 OCStackResult RTMUpdateEntryParameters(uint32_t gatewayId, uint32_t seqNum,
305 const RTMDestIntfInfo_t *destAdr, u_linklist_t **gatewayTable,
312 #endif /* ROUTING_TABLE_MANAGER_H_ */