NetSim Source Code Help
Loading...
Searching...
No Matches
Network_Layer_Ack.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#include "main.h"
15#include "DSR.h"
16#include "List.h"
17/**
18This function adds the Acknowledge request option to the packet.
19*/
22{
24 static unsigned int nIdentification=1;
25 if(DSR_DEV_VAR(pstruEventDetails->nDeviceId)->AckType == NETWORK_LAYER_ACK)
26 {
27 if(!option->ackRequestOption)
28 option->ackRequestOption = (DSR_ACK_REQ_OPTION*)calloc(1,sizeof* option->ackRequestOption);
30 option->ackRequestOption->nIdentification = nIdentification++;
33 }
34 else
35 {
36 if(option->ackRequestOption)
37 {
38 option->ackRequestOption = NULL;
41 }
42 }
43 return 1;
44}
45/**
46If a packet has an acknowledge request option, this function generates the acknowledge
47and transmits it.
48*/
50{
52 if(option->ackRequestOption)
53 {
55 DSR_ACK_REQ_OPTION* ackRequest = option->ackRequestOption;
57 packet->nTransmitterId,
58 packet->nTransmitterId,
61 option = (DSR_OPTION_HEADER*)calloc(1,sizeof* option);
62 DSR_ACK_OPTION* ack = (DSR_ACK_OPTION*)calloc(1,sizeof* ack);
64 option->options = ack;
66 option->optType = optType_Ack;
68
70 ack->nIdentification = ackRequest->nIdentification;
76 ppacket->pstruNetworkData->nTTL = 2;
77 //Transmit ack
78 memcpy(&pevent,pstruEventDetails,sizeof* pstruEventDetails);
80 pevent.nApplicationId = 0;
82 pevent.nPacketId = 0;
84 pevent.nSegmentId = 0;
85 pevent.nSubEventType = 0;
86 pevent.pPacket = ppacket;
87 fnpAddEvent(&pevent);
88 }
89 return 1;
90}
91/**
92Whenever an acknowlegement is received, the DSR Maintenance Buffer is Emptied.
93*/
95{
97 NETSIM_ID nSource = packet->nSourceId;
101 return 1;
102}
103
104
unsigned int NETSIM_ID
Definition: Animation.h:45
NETSIM_IPAddress dsr_get_dev_ip(NETSIM_ID d)
#define DSR_EMPTY_MAINT_BUFFER(nDeviceId, nextHop)
Definition: DSR.h:723
#define DSR_DEV_VAR(dev)
Definition: DSR.h:772
#define DSR_ACK_REQUEST_LEN
Definition: DSR.h:37
@ ctrlPacket_ACK
Definition: DSR.h:90
#define DSR_OPTION_HEADER_SIZE
Definition: DSR.h:30
NetSim_PACKET * fn_NetSim_DSR_GenerateCtrlPacket(NETSIM_ID src, NETSIM_ID dest, NETSIM_ID recv, double dTime, DSR_CONTROL_PACKET type)
#define NO_NEXT_HEADER
Definition: DSR.h:45
NETSIM_IPAddress dsr_get_curr_ip()
@ optType_Ack
Definition: DSR.h:99
@ optType_AckRequest
Definition: DSR.h:101
#define DSR_ACK_OPTION_LEN
Definition: DSR.h:36
#define calloc(c, s)
Definition: Memory.h:29
int fn_NetSim_DSR_Add_Ack_request_Option(NetSim_PACKET *packet, NetSim_EVENTDETAILS *pstruEventDetails)
int fn_NetSim_DSR_Process_AckRequestOption(NetSim_PACKET *packet, NetSim_EVENTDETAILS *pstruEventDetails)
int fn_NetSim_DSR_ProcessAckOption(NetSim_EVENTDETAILS *pstruEventDetails)
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
unsigned int nIdentification
Definition: DSR.h:502
NETSIM_IPAddress DestAddress
Definition: DSR.h:509
NETSIM_IPAddress sourceAddress
Definition: DSR.h:506
unsigned int nOptionDataLen
Definition: DSR.h:498
DSR_OPTION_TYPE nOptionType
Definition: DSR.h:494
unsigned int nIdentification
Definition: DSR.h:464
DSR_OPTION_TYPE nOptionType
Definition: DSR.h:454
unsigned int nPayloadLength
Definition: DSR.h:557
DSR_ACK_REQ_OPTION * ackRequestOption
Definition: DSR.h:566
void * options
Definition: DSR.h:565
unsigned int nNextHeader
Definition: DSR.h:536
DSR_OPTION_TYPE optType
Definition: DSR.h:558
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
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
NETSIM_ID nTransmitterId
Definition: Packet.h:265
NETSIM_ID nSourceId
Definition: Packet.h:263