NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
BSM.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 "Application.h"
15
16int fn_NetSim_Application_BSM(PAPP_BSM_INFO info,
17 double* fSize,
18 double* ldArrival,
19 unsigned long* uSeed,
20 unsigned long* uSeed1,
21 unsigned long* uSeed2,
22 unsigned long* uSeed3)
23{
24 double time = 0.0;
25 do
26 {
27 fnDistribution(info->packetSizeDistribution, fSize, uSeed, uSeed1, info->dPacketSize);
28 } while (*fSize <= 1.0);
29 //Call the Distribution DLL to generate inter arrival time
30 do
31 {
32 fnDistribution(info->IATDistribution, &time, uSeed, uSeed1, info->dIAT);
33 } while (time <= 0.0);
34 *ldArrival = *ldArrival + time;
35
36 //generate random time in range of[-5,5]
37 time = NETSIM_RAND_RN(info->dRandomWaitTime*-1, info->dRandomWaitTime);
38 *ldArrival += time;
39 return 1;
40}
41
42/** This function is used to start the Database, FTP and Custom applications */
43int fn_NetSim_Application_StartBSM(ptrAPPLICATION_INFO appInfo, double time)
44{
45 PAPP_BSM_INFO info = (PAPP_BSM_INFO)appInfo->appData;
46
47 if (appInfo->dEndTime <= time)
48 return 0;
49
50 fnCreatePort(appInfo);
51
52 NETSIM_ID nSource = appInfo->sourceList[0];
53 NETSIM_ID* nDest = appInfo->destList;
54 UINT destCount = appInfo->nDestCount;
55
56 double arrivalTime = 0;
57 double packetSize = 0;
58
59 //Create the socket buffer
60 fnCreateSocketBuffer(appInfo);
61
62 //Generate the app start event
63 fn_NetSim_Application_BSM((PAPP_BSM_INFO)appInfo->appData,
64 &packetSize,
65 &arrivalTime,
66 &(NETWORK->ppstruDeviceList[nSource - 1]->ulSeed[0]),
67 &(NETWORK->ppstruDeviceList[nSource - 1]->ulSeed[1]),
68 &(NETWORK->ppstruDeviceList[nSource - 1]->ulSeed[0]),
69 &(NETWORK->ppstruDeviceList[nSource - 1]->ulSeed[1]));
70
71 pstruEventDetails->dEventTime = time + arrivalTime;
72 pstruEventDetails->dPacketSize = packetSize;
73 pstruEventDetails->nApplicationId = appInfo->id;
74 pstruEventDetails->nDeviceId = nSource;
75 pstruEventDetails->nDeviceType = DEVICE_TYPE(nSource);
76 pstruEventDetails->nEventType = TIMER_EVENT;
77 pstruEventDetails->nInterfaceId = 0;
78 pstruEventDetails->nPacketId = 0;
79 pstruEventDetails->nProtocolId = PROTOCOL_APPLICATION;
80 pstruEventDetails->nSegmentId = 0;
81 pstruEventDetails->nSubEventType = event_APP_START;
82
83 pstruEventDetails->pPacket =
84 fn_NetSim_Application_GeneratePacket(appInfo,
85 pstruEventDetails->dEventTime,
86 nSource,
87 destCount,
88 nDest,
89 ++appInfo->nPacketId,
90 appInfo->nAppType,
91 appInfo->qos,
92 appInfo->sourcePort,
93 appInfo->destPort);
94 pstruEventDetails->szOtherDetails = appInfo;
95 fnpAddEvent(pstruEventDetails);
96
97 return 0;
98}
99
100/* Below function are out of scope for NetSim.
101 * An User can modify these function to implement Vanet packet type.
102 */
103
104bool add_sae_j2735_payload(NetSim_PACKET* packet, ptrAPPLICATION_INFO info)
105{
106 // Add the payload based on SAE J2735 or any other standard
107 // return true after adding.
108 return false;
109}
110
111void process_saej2735_packet(NetSim_PACKET* packet)
112{
113 //Add the code to process the SAE J2735 packet.
114 //This function is called in Application_IN event.
115}