NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
FIFOBuffer.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
15#include "main.h"
16#include "AODV.h"
17#include "List.h"
18/**
19This function adds a packet to the FIFO Buffer
20*/
21bool fn_NetSim_AODV_AddToFIFOBuffer(NetSim_PACKET* packet,
22 AODV_FIFO** fifoBuffer,
23 double time)
24{
25 AODV_FIFO* fifo = *fifoBuffer;
26 while(fifo)
27 {
28 if(!IP_COMPARE(fifo->destination,packet->pstruNetworkData->szDestIP))
29 {
30 NetSim_PACKET* packetList = fifo->packetList;
31 if(!fifo->packetList)
32 {
33 fifo->packetList = packet;
34 fifo->time = time;
35 return false;
36 }
37 while(packetList->pstruNextPacket)
38 packetList = packetList->pstruNextPacket;
39 packetList->pstruNextPacket = packet;
40 return true;
41 }
42 fifo = LIST_NEXT(fifo);
43 }
44 fifo = FIFO_ALLOC();
45 fifo->destination = IP_COPY(packet->pstruNetworkData->szDestIP);
46 fifo->packetList = packet;
47 fifo->time = time;
48 LIST_ADD_LAST(fifoBuffer,fifo);
49 return false;
50}
51/**
52This function empties the FIFO buffer
53*/
54int fnEmptyFIFOBuffer(AODV_DEVICE_VAR* devVar,NETSIM_IPAddress dest)
55{
56 AODV_FIFO* fifo = devVar->fifo;
57 while(fifo)
58 {
59 if(!IP_COMPARE(fifo->destination,dest))
60 {
61 while(fifo->packetList)
62 {
63 NetSim_PACKET* packet = fifo->packetList;
64 fifo->packetList = packet->pstruNextPacket;
65 packet->pstruNextPacket = NULL;
66 fn_NetSim_Packet_FreePacket(packet);
67 //Update the metrics
68 AODV_METRICS_VAR(pstruEventDetails->nDeviceId).packetDropped++;
69 }
70 IP_FREE(fifo->destination);
71 LIST_FREE(&devVar->fifo,fifo);
72 break;
73 }
74 fifo=LIST_NEXT(fifo);
75 }
76 return 1;
77}
78/**
79This function Transmits the FIFO Buffer
80*/
81int fn_NetSim_AODV_TransmitFIFOBuffer(AODV_DEVICE_VAR* devVar,
82 NetSim_EVENTDETAILS* pstruEventDetails)
83{
84 NetSim_EVENTDETAILS pevent;
85 AODV_FIFO* fifo = devVar->fifo;
86 memcpy(&pevent,pstruEventDetails,sizeof pevent);
87 while(fifo)
88 {
89 if(AODV_CHECK_ROUTE_FOUND(fifo->destination))
90 {
91 while(fifo->packetList)
92 {
93 NetSim_PACKET* packet = fifo->packetList;
94 fifo->packetList = fifo->packetList->pstruNextPacket;
95 packet->pstruNextPacket = NULL;
96 pevent.dPacketSize = fnGetPacketSize(packet);
97 if(packet->pstruAppData)
98 {
99 pevent.nApplicationId = packet->pstruAppData->nApplicationId;
100 pevent.nSegmentId = packet->pstruAppData->nSegmentId;
101 }
102 pevent.nInterfaceId = 0;
103 pevent.nEventType = NETWORK_OUT_EVENT;
104 pevent.nPacketId = packet->nPacketId;
105 pevent.nProtocolId = fn_NetSim_Stack_GetNWProtocol(pstruEventDetails->nDeviceId);
106 pevent.nSubEventType = 0;
107 pevent.pPacket = packet;
108 pevent.szOtherDetails = NULL;
109 fnpAddEvent(&pevent);
110 }
111 }
112 fifo = (AODV_FIFO*)LIST_NEXT(fifo);
113 }
114 return 1;
115}
NetSim_PACKET * packetList
PacketList - List of packets added to the FIFO buffer.
Definition AODV.h:336
NETSIM_IPAddress destination
Destination - destination ip address.
Definition AODV.h:335