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 * Frees the endpoint table memory with nodes containing structute RTMEndpointEntry_t.
146 * @param[in/out] endpointTable Endpoint Routing Table.
147 * @return ::OC_STACK_OK or Appropriate error code.
149 OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable);
152 * Adds the entry to the routing table if the entry for Gateway id is
153 * not preset in Routing table, Updates the Old entry if Entry for
154 * Gateway Id is already present in Routing table i.e routeCost and NextHop
155 * will be updated for efficient hop result.
157 * @param[in] gatewayId Gateway Id.
158 * @param[in] nextHop Next Hop address.
159 * @param[in] routeCost Shortest Path to Destination - Hopcount.
160 * @param[in] destInterfaces Destination Interface Information.
161 * @param[in/out] gatewayTable Gateway Routing Table.
162 * @return ::OC_STACK_OK or Appropriate error code.
164 OCStackResult RTMAddGatewayEntry(uint32_t gatewayId, uint32_t nextHop, uint32_t routeCost,
165 const RTMDestIntfInfo_t *destInterfaces, u_linklist_t **gatewayTable);
168 * Adds the endpoint entry to the routing table.
169 * @param[in/out] endpointId Endpoint Id.
170 * @param[in] destAddr Destination Address.
171 * @param[in/out] endpointTable Endpoint Routing Table.
172 * @return ::OC_STACK_OK or Appropriate error code.
174 OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
175 u_linklist_t **endpointTable);
178 * Removes the gateway entry from the routing table and also removes
179 * corresponding entries having nexthop as removed gateway.
180 * @param[in] gatewayId Gateway id of node need to be removed.
181 * @param[in/out] removedGatewayNodes Linklist containing removed gateway nodes
182 * list need to be freed by caller.
183 * @param[in/out] gatewayTable Gateway Routing Table.
184 * @return ::OC_STACK_OK or Appropriate error code.
186 OCStackResult RTMRemoveGatewayEntry(uint32_t gatewayId, u_linklist_t **removedGatewayNodes,
187 u_linklist_t **gatewayTable);
190 * Removes the endpoint entry from the routing table.
191 * @param[in] endpointId Endpoint id of node need to be removed.
192 * @param[in/out] endpointTable Endpoint Routing Table.
193 * @return ::OC_STACK_OK or Appropriate error code.
195 OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable);
198 * Removes the gateway entry from the routing table which has gateway id and nexthop as given.
199 * @param[in] gatewayId Gateway Id.
200 * @param[in] nextHop Next Hop address.
201 * @param[in] destInfAdr Destination Address of Next Hop to update time.
202 * @param[in/out] existEntry Entry which has different Next Hop.
203 * @param[in/out] gatewayTable Gateway Routing Table.
204 * @return ::OC_STACK_OK or Appropriate error code.
206 OCStackResult RTMRemoveGatewayDestEntry(uint32_t gatewayId, uint32_t nextHop,
207 const RTMDestIntfInfo_t *destInfAdr,
208 RTMGatewayEntry_t **existEntry, u_linklist_t **gatewayTable);
210 * Removes the gateway nodes.
211 * @param[in/out] gatewayTable Gateway Routing Table.
212 * @return ::OC_STACK_OK or Appropriate error code.
214 OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable);
217 * Removes the endpoint nodes.
218 * @param[in/out] endpointTable Endpoint Routing Table.
219 * @return ::OC_STACK_OK or Appropriate error code.
221 OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable);
224 * Gets the neighbour nodes i.e nodes with routecost 1.
225 * @param[in/out] neighbourNodes link list containing neighbouring nodes.
226 this list will be pointer to GatewayIds
227 and must be freed by caller.
228 * @param[in] gatewayTable Gateway Routing Table.
231 void RTMGetNeighbours(u_linklist_t **neighbourNodes, const u_linklist_t *gatewayTable);
234 * Gets next hop from the routing table.
235 * @param[in] gatewayId Gateway Id.
236 * @param[in] gatewayTable Gateway Routing Table.
237 * @return Next Hop address - returns NULL if it is End Device.
239 RTMGatewayId_t *RTMGetNextHop(uint32_t gatewayId, const u_linklist_t *gatewayTable);
242 * Gets endpoint entry
243 * @param[in] endpointId Endpoint id of node need to be removed.
244 * @param[in] endpointTable Endpoint Routing Table.
245 * @return Endpoint Destination inteface address.
247 CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable);
250 * Updates destination interface address of an entry with provided gateway id
252 * @param[in] gatewayId Gateway Id of Hop need to be updated.
253 * @param[in] destInterfaces Destination Interface Information.
254 * @param[in] addAdr Add/Remove Dest intf addr.
255 * @param[in/out] gatewayTable Gateway Routing Table.
256 * @return ::OC_STACK_OK or Appropriate error code.
258 OCStackResult RTMUpdateDestinationIntfAdr(uint32_t gatewayId, RTMDestIntfInfo_t destInterfaces,
259 bool addAdr, u_linklist_t **gatewayTable);
262 * Updates Multicast sequence number for gatewayID
263 * @param[in] gatewayId Gateway Id of Hop need to be updated.
264 * @param[in] seqNum sequence number for last cast packet from gateway.
265 * @param[in/out] gatewayTable Gateway Routing Table.
266 * @return ::OC_STACK_OK or Appropriate error code.
268 OCStackResult RTMUpdateMcastSeqNumber(uint32_t gatewayId, uint16_t seqNum,
269 u_linklist_t **gatewayTable);
272 * Prints the routing table
273 * @param[in] gatewayTable Gateway Routing Table.
274 * @param[in] endpointTable Endpoint Routing Table.
277 void RTMPrintTable(const u_linklist_t *gatewayTable, const u_linklist_t *endpointTable);
280 * Frees the GatewayId
281 * @param[in] gateway Gateway Structure pointer.
282 * @param[in/out] gatewayTable Gateway Routing Table.
285 void RTMFreeGateway(RTMGatewayId_t *gateway, u_linklist_t **gatewayTable);
288 * Gets the list of observer IDs.
289 * @param[in/out] obsList List of Observation IDs.
290 * @param[in/out] obsListLen Length if Observation ID list.
291 * @param[in] gatewayTable Gateway Routing Table.
294 void RTMGetObserverList(OCObservationId **obsList, uint8_t *obsListLen,
295 const u_linklist_t *gatewayTable);
298 * Adds a observer address and obsID to the list.
299 * @param[in] obsID Observation ID.
300 * @param[in] devAddr Address of Gateway.
301 * @param[in/out] gatewayTable Gateway Routing Table.
304 OCStackResult RTMAddObserver(uint32_t obsID, CAEndpoint_t devAddr, u_linklist_t **gatewayTable);
307 * Check if a particular observer address is already registerd and returns
308 * its obsID if present.
309 * @param[in] devAddr Address of Gateway.
310 * @param[in/out] obsID Observation ID.
311 * @param[in] gatewayTable Gateway Routing Table.
314 bool RTMIsObserverPresent(CAEndpoint_t devAddr, OCObservationId *obsID,
315 const u_linklist_t *gatewayTable);
318 * Gets Current Time in Micro Seconds.
319 * @return Current Time.
321 uint64_t RTMGetCurrentTime();
324 * Update Gateway Address Validity.
325 * @param[in/out] invalidTable Removed entries Table.
326 * @param[in/out] gatewayTable Gateway Routing Table.
327 * @return ::OC_STACK_OK or Appropriate error code.
329 OCStackResult RTMUpdateDestAddrValidity(u_linklist_t **invalidTable, u_linklist_t **gatewayTable);
332 * Removes invalid gateways.
333 * @param[in/out] invalidTable Removed entries Table.
334 * @param[in/out] gatewayTable Gateway Routing Table.
335 * @return ::OC_STACK_OK or Appropriate error code.
337 OCStackResult RTMRemoveInvalidGateways(u_linklist_t **invalidTable, u_linklist_t **gatewayTable);
340 * Update Sequence number of Gateway Entry.
341 * @param[in] gatewayId Gateway Id.
342 * @param[in] seqNum Sequence Number of Entry.
343 * @param[in] destInterfaces Destination Interface Information.
344 * @param[out] gatewayTable Gateway Routing Table.
345 * @param[in] forceUpdate To Update parameters forcefully.
346 * @return ::OC_STACK_OK or Appropriate error code.
348 OCStackResult RTMUpdateEntryParameters(uint32_t gatewayId, uint32_t seqNum,
349 const RTMDestIntfInfo_t *destAdr, u_linklist_t **gatewayTable,
356 #endif /* ROUTING_TABLE_MANAGER_H_ */