2#include "Application.h"
3#include "NetSim_utility.h"
5static FILE* fpApp = NULL;
7void init_application_log()
9 if (get_protocol_log_status(
"APPLICATION_PACKET_LOG"))
12 sprintf(s,
"%s\\%s", pszIOLogPath,
"Application_Packet_Log.csv");
13 fpApp = fopen(s,
"w");
16 fnSystemError(
"Unable to open %s file", s);
21 fprintf(fpApp,
"%s,%s,%s,%s,%s,",
22 "Application Name",
"Application ID",
"Source",
"Destination",
"Packet ID");
24 fprintf(fpApp,
"%s,%s,%s,%s,",
25 "Segment ID",
"Packet or Segment Start Time(ms)",
"Packet or Segment End Time(ms)",
"Packet or Segment size(Bytes)");
27 fprintf(fpApp,
"%s,%s,%s,",
28 "Latency(Microseconds)",
"Jitter(Microseconds)",
"Throughput(Mbps)");
36void print_application_log(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* packet)
40 double latency, jitter;
41 int TwoWayApplicationflag = 0, linkType = 0;
42 NETSIM_ID nDestinationId = get_first_dest_from_packet(packet);
43 latency = packet->pstruAppData->dEndTime - packet->pstruAppData->dStartTime;
45 strcpy(Appname, pstruappinfo->name);
47 if (nDestinationId == 0)
49 if (pstruappinfo->nAppType == TRAFFIC_INTERACTIVE_GAMING || pstruappinfo->nAppType == TRAFFIC_EMAIL || pstruappinfo->nAppType == TRAFFIC_HTTP)
51 TwoWayApplicationflag = 1;
52 if (get_first_dest_from_packet(packet) == pstruappinfo->sourceList[0])
55 strcat(Appname,
"_UL");
60 strcat(Appname,
"_DL");
64 if(TwoWayApplicationflag == 0 || (TwoWayApplicationflag == 1 && linkType == 1))
66 if (pstruappinfo->uplink.prevPacketLatency == -1 || packet->nPacketId == pstruappinfo->uplink.firstPacketReceived)
68 pstruappinfo->uplink.firstPacketReceived = packet->nPacketId;
69 if (packet->pstruAppData->nSegmentId == 0 || packet->pstruAppData->nSegmentId == 1)
72 jitter = fabs(latency - pstruappinfo->uplink.prevPacketLatency);
76 jitter = fabs(latency - pstruappinfo->uplink.prevPacketLatency);
78 if (packet->pstruAppData->nSegmentId == 0 || packet->pstruAppData->nPacketFragment == Segment_LastFragment)
79 pstruappinfo->uplink.prevStartTime = packet->pstruAppData->dStartTime;
80 pstruappinfo->uplink.prevEndTime = packet->pstruAppData->dEndTime;
81 pstruappinfo->uplink.prevPacketLatency = latency;
84 else if (TwoWayApplicationflag == 1 && linkType == 2)
86 if (pstruappinfo->downlink.prevPacketLatency == -1 || packet->nPacketId == pstruappinfo->downlink.firstPacketReceived)
88 pstruappinfo->downlink.firstPacketReceived = packet->nPacketId;
89 if (packet->pstruAppData->nSegmentId == 0 || packet->pstruAppData->nSegmentId == 1)
92 jitter = fabs(latency - pstruappinfo->downlink.prevPacketLatency);
96 jitter = fabs(latency - pstruappinfo->downlink.prevPacketLatency);
99 if (packet->pstruAppData->nSegmentId == 0 || packet->pstruAppData->nPacketFragment == Segment_LastFragment)
100 pstruappinfo->downlink.prevStartTime = packet->pstruAppData->dStartTime;
101 pstruappinfo->downlink.prevEndTime = packet->pstruAppData->dEndTime;
102 pstruappinfo->downlink.prevPacketLatency = latency;
108 fprintf(stderr,
"Unknown Application and Link Type");
111 fprintf(fpApp,
"%s,%d,%s,",
112 Appname, pstruappinfo->nConfigId, DEVICE_NAME(packet->nSourceId));
114 fprintf(fpApp,
"%s,%lld,%d,",
115 DEVICE_NAME(nDestinationId), packet->nPacketId, packet->pstruAppData->nSegmentId);
117 fprintf(fpApp,
"%lf,%lf,%lf,",
118 (packet->pstruAppData->dStartTime / MILLISECOND), (packet->pstruAppData->dEndTime / MILLISECOND), packet->pstruAppData->dPacketSize);
120 fprintf(fpApp,
"%lf,%lf,-1,",
123 fprintf(fpApp,
"\n");
126void close_application_log()
132bool get_protocol_log_status(
char* logname)
136 sprintf(str,
"%s/%s", pszIOPath,
"ProtocolLogsConfig.txt");
137 fp = fopen(str,
"r");
142 while (fgets(data, BUFSIZ, fp))
145 sprintf(str,
"%s=true", logname);
146 if (!_strnicmp(data, str, strlen(str)))