NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
SequenceNumber.c
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "RPL.h"
16
17static seq_num_mapping_t ** seq_num_mapping_list = NULL;
18static UINT16 seq_num_mapping_count = 0;
19
20void seq_num_mapping_cleanup()
21{
22 UINT16 i;
23 for (i = 0; i < seq_num_mapping_count; i++)
24 {
25 seq_num_mapping_t *mapping = seq_num_mapping_list[i];
26
27 bool in_use = FALSE;
28
29 UINT16 j;
30 for (j = 0; j < NETWORK->nDeviceCount; j++)
31 {
32 PRPL_NODE rpl = GET_RPL_NODE(j + 1);
33 if(!rpl)
34 continue; // RPL is not configured for this device.
35 if (!rpl_node_is_root(rpl))
36 { /* only root nodes modify sequence numbers */
37 continue;
38 }
39 if (!rpl->root_info->dodag_id)
40 fnNetSimError("DODAG Id is NULL. This may occur because some RPL configuration is wrong. Don't know what?");
41
42 if (IP_COMPARE(rpl->root_info->dodag_id, mapping->dodag_id) == 0)
43 {
44 in_use = TRUE;
45 break;
46 }
47 }
48
49 if (in_use)
50 {
51 continue;
52 }
53
54 for (j = i; j < seq_num_mapping_count - 1; j++)
55 {
56 seq_num_mapping_list[j] = seq_num_mapping_list[j + 1];
57 }
58
59 free(mapping);
60
61 seq_num_mapping_count--;
62 }
63}
64
65seq_num_mapping_t *seq_num_mapping_get(NETSIM_IPAddress dodag_id)
66{
67 UINT16 i;
68 for (i = 0; i < seq_num_mapping_count; i++)
69 {
70 seq_num_mapping_t *mapping = seq_num_mapping_list[i];
71
72 if (IP_COMPARE(mapping->dodag_id, dodag_id) == 0)
73 return mapping;
74 }
75
76 seq_num_mapping_list = realloc(seq_num_mapping_list, (seq_num_mapping_count + 1) * sizeof(seq_num_mapping_t *));
77
78 seq_num_mapping_list[seq_num_mapping_count] = malloc(sizeof(seq_num_mapping_t));
79 seq_num_mapping_list[seq_num_mapping_count]->dodag_id = IP_COPY(dodag_id);
80 seq_num_mapping_list[seq_num_mapping_count]->seq_num = 1;
81
82 return seq_num_mapping_list[seq_num_mapping_count++];
83}