NetSim Source Code Help
Loading...
Searching...
No Matches
FIFOBuffer.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
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*/
22 AODV_FIFO** fifoBuffer,
23 double time)
24{
25 AODV_FIFO* fifo = *fifoBuffer;
26 while(fifo)
27 {
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();
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*/
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;
67 //Update the metrics
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*/
83{
85 AODV_FIFO* fifo = devVar->fifo;
86 memcpy(&pevent,pstruEventDetails,sizeof pevent);
87 while(fifo)
88 {
90 {
91 while(fifo->packetList)
92 {
93 NetSim_PACKET* packet = fifo->packetList;
95 packet->pstruNextPacket = NULL;
96 pevent.dPacketSize = fnGetPacketSize(packet);
97 if(packet->pstruAppData)
98 {
100 pevent.nSegmentId = packet->pstruAppData->nSegmentId;
101 }
102 pevent.nInterfaceId = 0;
104 pevent.nPacketId = packet->nPacketId;
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}
#define AODV_METRICS_VAR(devId)
Definition: AODV.h:414
#define AODV_CHECK_ROUTE_FOUND(destIP)
Definition: AODV.h:392
#define FIFO_ALLOC()
Definition: AODV.h:415
int fn_NetSim_AODV_TransmitFIFOBuffer(AODV_DEVICE_VAR *devVar, NetSim_EVENTDETAILS *pstruEventDetails)
Definition: FIFOBuffer.c:81
bool fn_NetSim_AODV_AddToFIFOBuffer(NetSim_PACKET *packet, AODV_FIFO **fifoBuffer, double time)
Definition: FIFOBuffer.c:21
int fnEmptyFIFOBuffer(AODV_DEVICE_VAR *devVar, NETSIM_IPAddress dest)
Definition: FIFOBuffer.c:54
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
void IP_FREE(NETSIM_IPAddress ip)
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define LIST_ADD_LAST(ls, mem)
Definition: List.h:30
#define LIST_NEXT(ls)
Definition: List.h:29
#define LIST_FREE(ls, mem)
Definition: List.h:32
double fnGetPacketSize(NetSim_PACKET *pstruData)
NETWORK_LAYER_PROTOCOL fn_NetSim_Stack_GetNWProtocol(NETSIM_ID nDeviceId)
@ NETWORK_OUT_EVENT
Definition: Stack.h:108
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
AODV_FIFO * fifo
Definition: AODV.h:380
NetSim_PACKET * packetList
PacketList - List of packets added to the FIFO buffer.
Definition: AODV.h:335
NETSIM_IPAddress destination
Destination - destination ip address.
Definition: AODV.h:334
double time
Definition: AODV.h:336
NETSIM_ID nApplicationId
Definition: Stack.h:752
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
NETSIM_ID nInterfaceId
Definition: Stack.h:751
NETSIM_IPAddress szDestIP
Definition: Packet.h:199
long long int nPacketId
Definition: Packet.h:256
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition: Packet.h:273
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278