NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Emulation_application.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 "Application.h"
16
17#define EMULATION_APPLICATION_PROTOCOL_DEFAULT _strdup("any")
18#define EMULATION_APPLICATION_FILTER_STRING_DEFAULT _strdup("true")
19#define EMULATION_APPLICATION_PRIORITY_DEFAULT 10
20
21static UINT update_source_ip(NETSIM_IPAddress* realIP, char* szVal, UINT count)
22{
23 UINT i = 0;
24 char* ip;
25 ip = strtok(szVal, ",");
26 while (ip)
27 {
28 if(strcmp(ip, "0.0.0.0"))
29 realIP[i] = STR_TO_IP4(ip);
30 i++;
31 ip = strtok(NULL, ",");
32 }
33
34 if (i != count)
35 {
36 fnNetSimError("Real IP count (%d) and IP configured (%d) mismatched\n", count, i);
37 }
38 return i;
39}
40
41int fn_NetSim_Emulation_InitApplication(ptrAPPLICATION_INFO appInfo)
42{
43 APP_EMULATION_INFO* info = appInfo->appData;
44
45 fnCreatePort(appInfo);
46
47 //Create the socket buffer
48 fnCreateSocketBuffer(appInfo);
49
50 return 0;
51}
52
53int fn_NetSim_Application_ConfigureEmulationTraffic(ptrAPPLICATION_INFO appInfo,void* xmlNetSimNode)
54{
55 char* szVal;
56 APP_EMULATION_INFO* info=(APP_EMULATION_INFO*)calloc(1,sizeof* info);
57 void* xmlChild;
58 appInfo->appData=info;
59 xmlChild=fn_NetSim_xmlGetChildElement(xmlNetSimNode,"EMULATION",0);
60 if(xmlChild)
61 {
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);
65 free(szVal);
66
67 if (isMulticastIP(info->realDestIP))
68 {
69 info->isMulticast = true;
70 info->count = appInfo->nSourceCount;
71
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);
75 }
76 else if (isBroadcastIP(info->realDestIP))
77 {
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);
84 }
85 else
86 {
87 info->count = 1;
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);
93 }
94
95 szVal=fn_NetSim_xmlConfig_GetVal(xmlChild,"SOURCE_REAL_IP",0);
96 if(!szVal)
97 szVal = fn_NetSim_xmlConfig_GetVal(xmlChild, "DEVICE_REAL_IP", 1);
98 info->count = update_source_ip(info->realSourceIP, szVal, info->count);
99 free(szVal);
100
101 szVal=fn_NetSim_xmlConfig_GetVal(xmlChild,"SOURCE_PORT",0);
102 if(szVal)
103 info->nSourcePort=atoi(szVal);
104 free(szVal);
105 szVal=fn_NetSim_xmlConfig_GetVal(xmlChild,"DESTINATION_PORT",0);
106 if(szVal)
107 info->nDestinationPort=atoi(szVal);
108 free(szVal);
109
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);
113 }
114 else
115 return 0;
116 //Assign other value
117 if (!(info->isMulticast || info->isBroadcast))
118 {
119 info->nDestinationId = appInfo->destList[0];
120 info->simDestIP = fn_NetSim_Stack_GetIPAddressAsId(info->nDestinationId, 1);
121 }
122 UINT i;
123 for (i = 0; i < info->count; i++)
124 {
125 info->nSourceId[i] = appInfo->sourceList[i];
126 info->simSourceIP[i] = fn_NetSim_Stack_GetIPAddressAsId(info->nSourceId[i], 1);
127 }
128 fn_NetSim_Emulation_InitApplication(appInfo);
129 //Add the emulation environment variable
130 _putenv("NETSIM_EMULATOR=1");
131 return 0;
132}
133
134void fn_NetSim_Emulation_StartApplication(ptrAPPLICATION_INFO appInfo)
135{
136 if (appInfo->nTransmissionType == MULTICAST)
137 {
138 add_multicast_route(appInfo);
139 join_multicast_group(appInfo, appInfo->dStartTime);
140 }
141}