NetSim Source Code Help
Loading...
Searching...
No Matches
APP_OUT.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
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* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24#include "main.h"
25#include "Application.h"
26
27static void add_app_info_to_packet(NetSim_PACKET* packet, double time, double size, UINT appId)
28{
29 packet->pstruAppData->dArrivalTime = time;
30 packet->pstruAppData->dEndTime = time;
31 if (packet->nPacketType != PacketType_Control)
32 {
33 packet->pstruAppData->dOverhead = 0;
34 packet->pstruAppData->dPayload = size;
35 }
36 else
37 {
38 packet->pstruAppData->dPayload = 0;
39 packet->pstruAppData->dOverhead = size;
40 }
43 packet->pstruAppData->nApplicationId = appId;
44}
45
47 UINT destCount, NETSIM_ID* dest)
48{
49 APPLICATION_TYPE nappType = pstruPacket->pstruAppData->nAppType;
50
51 if (nappType == TRAFFIC_FTP || nappType == TRAFFIC_DATABASE)
52 {
53 NetSim_PACKET* packet = pstruPacket;
54 while (packet->pstruNextPacket)
55 packet = packet->pstruNextPacket;
56 packet->pstruAppData->nAppEndFlag = 1;
58 }
59 else if (nappType == TRAFFIC_HTTP)
60 {
61 //Do nothing
62 NetSim_PACKET* packet = pstruPacket;
63 if (pstruPacket->pstruAppData->nAppEndFlag)
64 {
65 while (packet->pstruNextPacket)
66 {
67 packet->pstruAppData->nAppEndFlag = 0;
68 packet = packet->pstruNextPacket;
69 }
70 packet->pstruAppData->nAppEndFlag = 1;
71 }
72 }
73 else if (nappType == TRAFFIC_COAP)
74 {
75 //DO nothing
76 }
77 else if (nappType == TRAFFIC_EMAIL)
78 {
80 pstruPacket->nSourceId,
81 get_first_dest_from_packet(pstruPacket),
83 }
84 else if (nappType == TRAFFIC_PEER_TO_PEER)
85 {
86 NetSim_PACKET* packet = pstruPacket;
87 while (packet->pstruNextPacket)
88 packet = packet->pstruNextPacket;
89 packet->pstruAppData->nAppEndFlag = 1;
90 }
91 else if (nappType == TRAFFIC_EMULATION)
92 {
93 //do nothing
94 }
95 else
96 {
98 pstruPacket->nSourceId,
99 destCount,
100 dest,
102 }
103}
104
106 NetSim_PACKET* packet, NETSIM_ID nDeviceId)
107{
110 {
111 //Socket buffer is NULL
112 //Create event for transport out
118#pragma warning(disable:4312)
120#pragma warning(default:4312)
121 //Add Transport out event
123 }
124
125 //Place the packet to socket buffer
126 fn_NetSim_Socket_PassPacketToInterface(nDeviceId, packet, s);
127}
128
130 NetSim_PACKET* packet, NETSIM_ID nDeviceId)
131{
132 NetSim_EVENTDETAILS pevent;
133 while (packet)
134 {
135 memset(&pevent, 0, sizeof pevent);
136 pevent.dEventTime = ldEventTime;
137 pevent.dPacketSize = packet->pstruAppData->dPacketSize;
139 pevent.nDeviceId = nDeviceId;
140 pevent.nDeviceType = DEVICE_TYPE(nDeviceId);
142 pevent.nPacketId = packet->nPacketId;
143 pevent.nProtocolId = appInfo->protocol;
144 pevent.nSegmentId = packet->pstruAppData->nSegmentId;
145 pevent.pPacket = packet;
146 pevent.szOtherDetails = (void*)s;
147 packet = packet->pstruNextPacket;
148 pevent.pPacket->pstruNextPacket = NULL;
149 fnpAddEvent(&pevent);
150 }
151}
152
154 NetSim_PACKET* packet, NETSIM_ID nDeviceId)
155{
156 if (appInfo->protocol == APP_PROTOCOL_NULL)
157 send_to_transport_layer(s, appInfo, packet, nDeviceId);
158 else
159 send_to_next_protocol(s, appInfo, packet, nDeviceId);
160}
161
163{
164 if (type == TRAFFIC_EMAIL)
165 return get_email_app_info(detail);
166
167 return detail;
168}
169
171{
172 void* otherDetails = pstruEventDetails->szOtherDetails;
175
177 if (!pstruPacket) return; //No packet to send
178
179 APPLICATION_TYPE nappType = pstruPacket->pstruAppData->nAppType;
180
181 UINT destCount;
182 NETSIM_ID* dest = get_dest_from_packet(pstruPacket, &destCount);
183
186 pstruPacket->nSourceId,
187 pstruPacket->pstruTransportData->nSourcePort,
189 if (!s)
190 {
191 fnNetSimError("Socket is NULL for application %d.\n",
193 return;
194 }
195
196 //Initialize the application data
199
200
201
202
203
205 if (!appInfo)
206 {
207 fnNetSimError("Application info is NULL in application out event id = %lld\n", pstruEventDetails->nEventId);
208 return;
209 }
210
211 pstruPacket->pstruTransportData->nTransportProtocol = appInfo->trxProtocol;
212
213 //Fragment the packet
214 int nSegmentCount = 0;
215 double segmentsize = fn_NetSim_Stack_GetMSS(pstruPacket);
216 nSegmentCount = fn_NetSim_Stack_FragmentPacket(pstruPacket, (int)fn_NetSim_Stack_GetMSS(pstruPacket));
217
218 set_app_end_and_generate_next_packet(pstruPacket, otherDetails, destCount, dest);
219
220 //Add the dummy payload to packet
221 fn_NetSim_Add_DummyPayload(pstruPacket, appInfo);
222
223 appmetrics_src_add(appInfo, pstruPacket);
224
225 appout_send_packet(s, appInfo, pstruPacket, nDeviceId);
226}
static void set_app_end_and_generate_next_packet(NetSim_PACKET *pstruPacket, ptrAPPLICATION_INFO appInfo, UINT destCount, NETSIM_ID *dest)
Definition: APP_OUT.c:46
static void add_app_info_to_packet(NetSim_PACKET *packet, double time, double size, UINT appId)
Definition: APP_OUT.c:27
void handle_app_out()
Definition: APP_OUT.c:170
static void send_to_next_protocol(ptrSOCKETINTERFACE s, ptrAPPLICATION_INFO appInfo, NetSim_PACKET *packet, NETSIM_ID nDeviceId)
Definition: APP_OUT.c:129
static void appout_send_packet(ptrSOCKETINTERFACE s, ptrAPPLICATION_INFO appInfo, NetSim_PACKET *packet, NETSIM_ID nDeviceId)
Definition: APP_OUT.c:153
static void send_to_transport_layer(ptrSOCKETINTERFACE s, ptrAPPLICATION_INFO appInfo, NetSim_PACKET *packet, NETSIM_ID nDeviceId)
Definition: APP_OUT.c:105
static ptrAPPLICATION_INFO get_app_info(void *detail, APPLICATION_TYPE type)
Definition: APP_OUT.c:162
unsigned int NETSIM_ID
Definition: Animation.h:45
int fn_NetSim_Application_GenerateNextPacket(ptrAPPLICATION_INFO appInfo, NETSIM_ID nSource, UINT destCount, NETSIM_ID *nDestination, double time)
Definition: Application.c:377
int fn_NetSim_Add_DummyPayload(NetSim_PACKET *packet, ptrAPPLICATION_INFO info)
Definition: Application.c:641
ptrAPPLICATION_INFO get_email_app_info(void *detail)
void appmetrics_src_add(ptrAPPLICATION_INFO appInfo, _In_ NetSim_PACKET *packet)
int fn_NetSim_Application_StartDataAPP(ptrAPPLICATION_INFO appInfo, double time)
ptrAPPLICATION_INFO fn_NetSim_Application_Email_GenerateNextPacket(DETAIL *detail, NETSIM_ID nSourceId, NETSIM_ID nDestinationId, double time)
ptrSOCKETINTERFACE fnGetSocket(NETSIM_ID nAppId, NETSIM_ID nSourceId, NETSIM_ID nSourcePort, NETSIM_ID nDestPort)
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
int fn_NetSim_Stack_FragmentPacket(NetSim_PACKET *pstruPacket, int nMSS)
@ PacketType_Control
Definition: Packet.h:66
NETSIM_ID * get_dest_from_packet(NetSim_PACKET *packet, UINT *count)
enum enum_ApplicationType APPLICATION_TYPE
NETSIM_ID get_first_dest_from_packet(NetSim_PACKET *packet)
@ TRAFFIC_EMAIL
Definition: Packet.h:148
@ TRAFFIC_COAP
Definition: Packet.h:155
@ TRAFFIC_FTP
Definition: Packet.h:144
@ TRAFFIC_DATABASE
Definition: Packet.h:146
@ TRAFFIC_HTTP
Definition: Packet.h:145
@ TRAFFIC_PEER_TO_PEER
Definition: Packet.h:149
@ TRAFFIC_EMULATION
Definition: Packet.h:151
EXPORTED double ldEventTime
Definition: Stack.h:838
double fn_NetSim_Stack_GetMSS(const NetSim_PACKET *pPacket)
void fn_NetSim_Socket_PassPacketToInterface(NETSIM_ID deviceId, NetSim_PACKET *packet, ptrSOCKETINTERFACE socketInterface)
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
@ APP_PROTOCOL_NULL
Definition: Stack.h:151
@ APPLICATION_OUT_EVENT
Definition: Stack.h:112
@ TRANSPORT_OUT_EVENT
Definition: Stack.h:110
bool fn_NetSim_Socket_GetBufferStatus(ptrSOCKETINTERFACE s)
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
Structure to store application information.
Definition: Application.h:97
APPLICATION_LAYER_PROTOCOL protocol
Definition: Application.h:113
TRANSPORT_LAYER_PROTOCOL trxProtocol
Definition: Application.h:112
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
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
unsigned long long int nEventId
Definition: Stack.h:745
APPLICATION_TYPE nAppType
Definition: Packet.h:171
TRANSPORT_LAYER_PROTOCOL nTransportProtocol
Definition: Packet.h:186
unsigned short int nSourcePort
Definition: Packet.h:184
unsigned short int nDestinationPort
Definition: Packet.h:185
long long int nPacketId
Definition: Packet.h:256
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition: Packet.h:273
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
PACKET_TYPE nPacketType
Definition: Packet.h:257
struct stru_NetSim_Packet_TransportLayer * pstruTransportData
Definition: Packet.h:274
NETSIM_ID nSourceId
Definition: Packet.h:263