15#include "Application.h"
17#define EMULATION_APPLICATION_PROTOCOL_DEFAULT _strdup("any")
18#define EMULATION_APPLICATION_FILTER_STRING_DEFAULT _strdup("true")
19#define EMULATION_APPLICATION_PRIORITY_DEFAULT 10
21static UINT update_source_ip(NETSIM_IPAddress* realIP,
char* szVal, UINT count)
25 ip = strtok(szVal,
",");
28 if(strcmp(ip,
"0.0.0.0"))
29 realIP[i] = STR_TO_IP4(ip);
31 ip = strtok(NULL,
",");
36 fnNetSimError(
"Real IP count (%d) and IP configured (%d) mismatched\n", count, i);
41int fn_NetSim_Emulation_InitApplication(ptrAPPLICATION_INFO appInfo)
43 APP_EMULATION_INFO* info = appInfo->appData;
45 fnCreatePort(appInfo);
48 fnCreateSocketBuffer(appInfo);
53int fn_NetSim_Application_ConfigureEmulationTraffic(ptrAPPLICATION_INFO appInfo,
void* xmlNetSimNode)
56 APP_EMULATION_INFO* info=(APP_EMULATION_INFO*)calloc(1,
sizeof* info);
58 appInfo->appData=info;
59 xmlChild=fn_NetSim_xmlGetChildElement(xmlNetSimNode,
"EMULATION",0);
62 szVal = fn_NetSim_xmlConfig_GetVal(xmlChild,
"DESTINATION_REAL_IP", 1);
63 if (szVal && strcmp(szVal,
"0.0.0.0"))
64 info->realDestIP = STR_TO_IP4(szVal);
67 if (isMulticastIP(info->realDestIP))
69 info->isMulticast =
true;
70 info->count = appInfo->nSourceCount;
72 info->realSourceIP = calloc(info->count,
sizeof* info->realSourceIP);
73 info->nSourceId = calloc(info->count,
sizeof* info->nSourceId);
74 info->simSourceIP = calloc(info->count,
sizeof* info->simSourceIP);
76 else if (isBroadcastIP(info->realDestIP))
78 info->isBroadcast =
true;
79 info->isMulticast =
false;
80 info->count = appInfo->nSourceCount;
81 info->realSourceIP = calloc(info->count,
sizeof* info->realSourceIP);
82 info->nSourceId = calloc(info->count,
sizeof* info->nSourceId);
83 info->simSourceIP = calloc(info->count,
sizeof* info->simSourceIP);
88 info->isMulticast =
false;
89 info->isBroadcast =
false;
90 info->realSourceIP = calloc(1,
sizeof* info->realSourceIP);
91 info->nSourceId = calloc(1,
sizeof* info->nSourceId);
92 info->simSourceIP = calloc(1,
sizeof* info->simSourceIP);
95 szVal=fn_NetSim_xmlConfig_GetVal(xmlChild,
"SOURCE_REAL_IP",0);
97 szVal = fn_NetSim_xmlConfig_GetVal(xmlChild,
"DEVICE_REAL_IP", 1);
98 info->count = update_source_ip(info->realSourceIP, szVal, info->count);
101 szVal=fn_NetSim_xmlConfig_GetVal(xmlChild,
"SOURCE_PORT",0);
103 info->nSourcePort=atoi(szVal);
105 szVal=fn_NetSim_xmlConfig_GetVal(xmlChild,
"DESTINATION_PORT",0);
107 info->nDestinationPort=atoi(szVal);
110 getXmlVar(&info->protocol, PROTOCOL, xmlChild, 0, _STRING, EMULATION_APPLICATION);
111 getXmlVar(&info->filterString, FILTER_STRING, xmlChild, 0, _STRING, EMULATION_APPLICATION);
112 getXmlVar(&info->priority, PRIORITY, xmlChild, 0, _UINT, EMULATION_APPLICATION);
117 if (!(info->isMulticast || info->isBroadcast))
119 info->nDestinationId = appInfo->destList[0];
120 info->simDestIP = fn_NetSim_Stack_GetIPAddressAsId(info->nDestinationId, 1);
123 for (i = 0; i < info->count; i++)
125 info->nSourceId[i] = appInfo->sourceList[i];
126 info->simSourceIP[i] = fn_NetSim_Stack_GetIPAddressAsId(info->nSourceId[i], 1);
128 fn_NetSim_Emulation_InitApplication(appInfo);
130 _putenv(
"NETSIM_EMULATOR=1");
134void fn_NetSim_Emulation_StartApplication(ptrAPPLICATION_INFO appInfo)
136 if (appInfo->nTransmissionType == MULTICAST)
138 add_multicast_route(appInfo);
139 join_multicast_group(appInfo, appInfo->dStartTime);