18int fn_NetSim_OLSR_ScheduleTCTransmission(NETSIM_ID nNodeId,
double dTime)
21 NODE_OLSR* olsr=GetOLSRData(nNodeId);
22 jitter = (int)((fn_NetSim_Utilities_GenerateRandomNo(&NETWORK->ppstruDeviceList[nNodeId-1]->ulSeed[0],
23 &NETWORK->ppstruDeviceList[nNodeId-1]->ulSeed[1])/NETSIM_RAND_MAX)*MAXJITTER);
24 pstruEventDetails->dEventTime = dTime+olsr->dTCInterval-jitter;
25 pstruEventDetails->dPacketSize=0;
26 pstruEventDetails->nApplicationId=0;
27 pstruEventDetails->nDeviceId=nNodeId;
28 pstruEventDetails->nDeviceType=DEVICE_TYPE(nNodeId);
29 pstruEventDetails->nEventType=TIMER_EVENT;
30 pstruEventDetails->nInterfaceId=1;
31 pstruEventDetails->nPacketId=0;
32 pstruEventDetails->nProtocolId=NW_PROTOCOL_OLSR;
33 pstruEventDetails->nSegmentId=0;
34 pstruEventDetails->nSubEventType=OLSR_ScheduleTCTransmission;
35 pstruEventDetails->pPacket=NULL;
36 pstruEventDetails->szOtherDetails=NULL;
37 fnpAddEvent(pstruEventDetails);
40int fn_NetSim_OLSR_TransmitTCMessage()
42 NetSim_EVENTDETAILS pevent;
43 NODE_OLSR* olsr=GetOLSRData(pstruEventDetails->nDeviceId);
44 NetSim_PACKET* packet;
45 OLSR_HEADER* header=(OLSR_HEADER*)calloc(1,
sizeof* header);
46 OLSR_TC_MESSAGE* tc=(OLSR_TC_MESSAGE*)calloc(1,
sizeof* tc);
47 OLSR_MPR_SELECTION_SET* set=olsr->mprSelectionSet;
48 olsr->bTCUpdateFlag=
false;
50 tc->ANSN = ++olsr->ANSN;
53 tc->AdvertisedNeighborCount++;
54 tc->AdvertisedNeighborMainAddress=(NETSIM_IPAddress*)realloc(tc->AdvertisedNeighborMainAddress,
55 tc->AdvertisedNeighborCount*
sizeof* tc->AdvertisedNeighborMainAddress);
56 tc->AdvertisedNeighborMainAddress[tc->AdvertisedNeighborCount-1]=IP_COPY(set->MS_main_addr);
57 set=(OLSR_MPR_SELECTION_SET*)LIST_NEXT(set);
61 header->message = (OLSR_HEADER_MESSAGE*)calloc(1,
sizeof* header->message);
62 header->message->HopCount=min(olsr->nZoneRadius,TC_MESSAGE_TTL)+1;
63 header->message->MESSAGE=tc;
64 header->message->MessageSequenceNumber=++olsr->nMessageSequenceNumber;
65 header->message->MessageType = TC_MESSAGE;
66 header->message->OriginatorAddress = IP_COPY(olsr->mainAddress);
67 header->message->TimeToLive = min(olsr->nZoneRadius,TC_MESSAGE_TTL);
68 header->message->Vtime = olsrConvertDoubleToME(TOP_HOLD_TIME);
69 header->message->MessageSize = TC_MESSAGE_SIZE_FIXED+tc->AdvertisedNeighborCount*4+MESSAGE_HEADER_SIZE;
71 header->PacketLength = header->message->MessageSize+OLSR_HEADER_SIZE;
72 header->PacketSequenceNumber = ++olsr->nPacketSequenceNumber;
75 packet=fn_NetSim_ZRP_GeneratePacket(pstruEventDetails->dEventTime,
76 OLSR_CONTROL_PACKET(TC_MESSAGE),
78 pstruEventDetails->nDeviceId,
80 header->PacketLength);
82 packet->pstruNetworkData->Packet_RoutingProtocol=header;
84 packet->pstruNetworkData->szNextHopIp = NULL;
85 packet->pstruNetworkData->nTTL = min(olsr->nZoneRadius,TC_MESSAGE_TTL);
87 pevent.dEventTime=pstruEventDetails->dEventTime;
88 pevent.dPacketSize = header->PacketLength;
89 pevent.nDeviceId=pstruEventDetails->nDeviceId;
90 pevent.nDeviceType=pstruEventDetails->nDeviceType;
91 pevent.nApplicationId = 0;
92 pevent.nEventType = NETWORK_OUT_EVENT;
93 pevent.nInterfaceId = 0;
95 pevent.nProtocolId = NW_PROTOCOL_IPV4;
96 pevent.nSegmentId = 0;
97 pevent.nSubEventType = 0;
98 pevent.pPacket = packet;
102int fn_NetSim_OLSR_CopyTCMessage(OLSR_HEADER_MESSAGE* dest,OLSR_HEADER_MESSAGE* src)
105 OLSR_TC_MESSAGE* srcTC=(OLSR_TC_MESSAGE*)src->MESSAGE;
106 OLSR_TC_MESSAGE* destTC = (OLSR_TC_MESSAGE*)calloc(1,
sizeof* destTC);
107 destTC->AdvertisedNeighborCount=srcTC->AdvertisedNeighborCount;
108 destTC->ANSN=srcTC->ANSN;
109 destTC->Reserved=srcTC->Reserved;
110 if(destTC->AdvertisedNeighborCount)
111 destTC->AdvertisedNeighborMainAddress=(NETSIM_IPAddress*)calloc(destTC->AdvertisedNeighborCount,
sizeof* destTC->AdvertisedNeighborMainAddress);
112 for(i=0;i<srcTC->AdvertisedNeighborCount;i++)
113 destTC->AdvertisedNeighborMainAddress[i]=IP_COPY(srcTC->AdvertisedNeighborMainAddress[i]);
114 dest->MESSAGE=destTC;
117int fn_NetSim_OLSR_FreeTCMessage(OLSR_HEADER_MESSAGE* message)
120 OLSR_TC_MESSAGE* tc = (OLSR_TC_MESSAGE*)message->MESSAGE;
121 for(i=0;i<tc->AdvertisedNeighborCount;i++)
122 IP_FREE(tc->AdvertisedNeighborMainAddress[i]);
123 free(tc->AdvertisedNeighborMainAddress);
125 message->MESSAGE=NULL;
129int fn_NetSim_OLSR_ReceiveTC()
132 NetSim_PACKET* packet=pstruEventDetails->pPacket;
133 NODE_OLSR* olsr=GetOLSRData(pstruEventDetails->nDeviceId);
134 OLSR_HEADER* header=(OLSR_HEADER*)pstruEventDetails->pPacket->pstruNetworkData->Packet_RoutingProtocol;
135 OLSR_TC_MESSAGE* tc = (OLSR_TC_MESSAGE*)header->message->MESSAGE;
137 OLSR_NEIGHBOR_SET* neighbor=olsrFindNeighborSet(olsr->neighborSet,pstruEventDetails->pPacket->pstruNetworkData->szGatewayIP);
138 if(IP_COMPARE(header->message->OriginatorAddress,pstruEventDetails->pPacket->pstruNetworkData->szGatewayIP) &&
139 neighbor && neighbor->N_status==SYM_NEIGH)
141 fn_NetSim_Packet_FreePacket(pstruEventDetails->pPacket);
142 pstruEventDetails->pPacket=NULL;
146 if(olsrValidateTopologyInfoOnCondition2(olsr->topologyInfoBase,header->message->OriginatorAddress,tc->ANSN))
148 fn_NetSim_Packet_FreePacket(pstruEventDetails->pPacket);
149 pstruEventDetails->pPacket=NULL;
154 olsrUpdateTopologySet(olsr,&olsr->topologyInfoBase,header->message);
157 fn_NetSim_OLSR_PacketForwarding();
158 fn_NetSim_Packet_FreePacket(packet);
159 pstruEventDetails->pPacket=NULL;
163OLSR_TOPOLOGY_INFORMATION_BASE* olsrFindTopologyInfo(OLSR_TOPOLOGY_INFORMATION_BASE* topology,NETSIM_IPAddress originator,NETSIM_IPAddress neighbor)
167 if(!IP_COMPARE(topology->T_last_addr,originator) &&
168 !IP_COMPARE(topology->T_dest_addr,neighbor))
170 topology=(OLSR_TOPOLOGY_INFORMATION_BASE*)LIST_NEXT(topology);
175bool olsrValidateTopologyInfoOnCondition2(OLSR_TOPOLOGY_INFORMATION_BASE* topology,NETSIM_IPAddress originator,
unsigned short int ANSN)
179 if(!IP_COMPARE(topology->T_last_addr,originator) &&
180 topology->T_seq > ANSN)
182 topology = (OLSR_TOPOLOGY_INFORMATION_BASE*)LIST_NEXT(topology);
186int olsrRemoveFromTopologySet(OLSR_TOPOLOGY_INFORMATION_BASE** topology,NETSIM_IPAddress originator,
unsigned short int ANSN)
188 OLSR_TOPOLOGY_INFORMATION_BASE* info=*topology;
191 if(!IP_COMPARE(info->T_last_addr,originator) &&
194 LIST_FREE((
void**)topology,info);
198 info=(OLSR_TOPOLOGY_INFORMATION_BASE*)LIST_NEXT(info);
202int olsrUpdateTopologySet(NODE_OLSR* olsr,OLSR_TOPOLOGY_INFORMATION_BASE** topology,OLSR_HEADER_MESSAGE* message)
206 OLSR_TC_MESSAGE* tc = (OLSR_TC_MESSAGE*)message->MESSAGE;
207 OLSR_TOPOLOGY_INFORMATION_BASE* info;
208 double validityTime=olsrConvertMEToDouble(message->Vtime);
209 for(i=0;i<tc->AdvertisedNeighborCount;i++)
211 info=olsrFindTopologyInfo(*topology,message->OriginatorAddress,tc->AdvertisedNeighborMainAddress[i]);
215 info->T_time=validityTime*SECOND+pstruEventDetails->dEventTime;
220 info=TOPOLOGY_INFO_BASE_ALLOC();
221 info->T_dest_addr=IP_COPY(tc->AdvertisedNeighborMainAddress[i]);
222 info->T_last_addr=IP_COPY(message->OriginatorAddress);
223 info->T_seq=tc->ANSN;
224 info->T_time=validityTime*SECOND+pstruEventDetails->dEventTime;
225 LIST_ADD_LAST((
void**)topology,info);
226 olsr->bRoutingTableUpdate=
true;
230 if(flag && !olsr->bTCUpdateFlag)
232 NetSim_EVENTDETAILS pevent;
233 pevent.nSubEventType = OLSR_ScheduleTCTransmission;
234 pevent.dEventTime =pstruEventDetails->dEventTime + (fn_NetSim_Utilities_GenerateRandomNo(
235 &NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->ulSeed[0],
236 &NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->ulSeed[1])/NETSIM_RAND_MAX)*SECOND;
237 pevent.dPacketSize=0;
238 pevent.nApplicationId=0;
239 pevent.nDeviceId=pstruEventDetails->nDeviceId;
240 pevent.nDeviceType=pstruEventDetails->nDeviceType;
241 pevent.nEventType=TIMER_EVENT;
242 pevent.nInterfaceId=1;
244 pevent.nProtocolId=NW_PROTOCOL_OLSR;
247 pevent.szOtherDetails=NULL;
248 fnpAddEvent(&pevent);
249 olsr->bTCUpdateFlag=
true;