NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Network_Layer_Ack.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 "DSR.h"
16#include "List.h"
17/**
18This function adds the Acknowledge request option to the packet.
19*/
20int fn_NetSim_DSR_Add_Ack_request_Option(NetSim_PACKET* packet,
21 NetSim_EVENTDETAILS* pstruEventDetails)
22{
23 DSR_OPTION_HEADER* option = (DSR_OPTION_HEADER*)packet->pstruNetworkData->Packet_RoutingProtocol;
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);
29 option->ackRequestOption->nOptionType = optType_AckRequest;
30 option->ackRequestOption->nIdentification = nIdentification++;
31 packet->pstruNetworkData->dPacketSize+=DSR_ACK_REQUEST_LEN;
32 packet->pstruNetworkData->dOverhead+=DSR_ACK_REQUEST_LEN;
33 }
34 else
35 {
36 if(option->ackRequestOption)
37 {
38 option->ackRequestOption = NULL;
39 packet->pstruNetworkData->dPacketSize-=DSR_ACK_REQUEST_LEN;
40 packet->pstruNetworkData->dOverhead-=DSR_ACK_REQUEST_LEN;
41 }
42 }
43 return 1;
44}
45/**
46If a packet has an acknowledge request option, this function generates the acknowledge
47and transmits it.
48*/
49int fn_NetSim_DSR_Process_AckRequestOption(NetSim_PACKET* packet,NetSim_EVENTDETAILS* pstruEventDetails)
50{
51 DSR_OPTION_HEADER* option = (DSR_OPTION_HEADER*)packet->pstruNetworkData->Packet_RoutingProtocol;
52 if(option->ackRequestOption)
53 {
54 NetSim_EVENTDETAILS pevent;
55 DSR_ACK_REQ_OPTION* ackRequest = option->ackRequestOption;
56 NetSim_PACKET* ppacket = fn_NetSim_DSR_GenerateCtrlPacket(pstruEventDetails->nDeviceId,
57 packet->nTransmitterId,
58 packet->nTransmitterId,
59 pstruEventDetails->dEventTime,
60 ctrlPacket_ACK);
61 option = (DSR_OPTION_HEADER*)calloc(1,sizeof* option);
62 DSR_ACK_OPTION* ack = (DSR_ACK_OPTION*)calloc(1,sizeof* ack);
63 ppacket->pstruNetworkData->Packet_RoutingProtocol = option;
64 option->options = ack;
65 option->nNextHeader = NO_NEXT_HEADER;
66 option->optType = optType_Ack;
67 option->nPayloadLength = DSR_ACK_OPTION_LEN;
68
69 ack->DestAddress = dsr_get_dev_ip(packet->nTransmitterId);
70 ack->nIdentification = ackRequest->nIdentification;
71 ack->nOptionDataLen = DSR_ACK_OPTION_LEN;
72 ack->nOptionType = optType_Ack;
73 ack->sourceAddress = dsr_get_curr_ip();
74 ppacket->pstruNetworkData->dOverhead = DSR_ACK_OPTION_LEN+DSR_OPTION_HEADER_SIZE;
75 ppacket->pstruNetworkData->dPacketSize = DSR_ACK_OPTION_LEN+DSR_OPTION_HEADER_SIZE;
76 ppacket->pstruNetworkData->nTTL = 2;
77 //Transmit ack
78 memcpy(&pevent,pstruEventDetails,sizeof* pstruEventDetails);
79 pevent.dPacketSize = DSR_ACK_OPTION_LEN+DSR_OPTION_HEADER_SIZE;
80 pevent.nApplicationId = 0;
81 pevent.nEventType = NETWORK_OUT_EVENT;
82 pevent.nPacketId = 0;
83 pevent.nProtocolId = fn_NetSim_Stack_GetNWProtocol(pevent.nDeviceId);
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*/
94int fn_NetSim_DSR_ProcessAckOption(NetSim_EVENTDETAILS* pstruEventDetails)
95{
96 NetSim_PACKET* packet = pstruEventDetails->pPacket;
97 NETSIM_ID nSource = packet->nSourceId;
98 DSR_EMPTY_MAINT_BUFFER(pstruEventDetails->nDeviceId,nSource);
99 fn_NetSim_Packet_FreePacket(packet);
100 pstruEventDetails->pPacket=NULL;
101 return 1;
102}
103
104
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