NetSim Source Code Help
Loading...
Searching...
No Matches
Emulation_application.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
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
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
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];
121 }
122 UINT i;
123 for (i = 0; i < info->count; i++)
124 {
125 info->nSourceId[i] = appInfo->sourceList[i];
127 }
129 //Add the emulation environment variable
130 _putenv("NETSIM_EMULATOR=1");
131 return 0;
132}
133
135{
136 if (appInfo->nTransmissionType == MULTICAST)
137 {
138 add_multicast_route(appInfo);
139 join_multicast_group(appInfo, appInfo->dStartTime);
140 }
141}
void add_multicast_route(ptrAPPLICATION_INFO info)
int fnCreateSocketBuffer(ptrAPPLICATION_INFO appInfo)
void join_multicast_group(ptrAPPLICATION_INFO info, double time)
void fnCreatePort(ptrAPPLICATION_INFO info)
void fn_NetSim_Emulation_StartApplication(ptrAPPLICATION_INFO appInfo)
static UINT update_source_ip(NETSIM_IPAddress *realIP, char *szVal, UINT count)
int fn_NetSim_Application_ConfigureEmulationTraffic(ptrAPPLICATION_INFO appInfo, void *xmlNetSimNode)
int fn_NetSim_Emulation_InitApplication(ptrAPPLICATION_INFO appInfo)
bool isBroadcastIP(NETSIM_IPAddress ip)
#define STR_TO_IP4(ipstr)
Definition: IP_Addressing.h:94
bool isMulticastIP(NETSIM_IPAddress ip)
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
void _putenv(char *s)
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
char * fn_NetSim_xmlConfig_GetVal(void *xmlNetSimNode, const char *szName, int flag)
#define getXmlVar(var, name, xmlNode, flag, type, protocol)
Definition: Stack.h:1046
@ _UINT
Definition: Stack.h:1037
@ _STRING
Definition: Stack.h:1033
NETSIM_IPAddress fn_NetSim_Stack_GetIPAddressAsId(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
@ MULTICAST
Definition: Stack.h:365
void * fn_NetSim_xmlGetChildElement(void *xmlNetSimNode, const char *childName, int count)
Structure to store the emulation application information.
Definition: Application.h:222
NETSIM_IPAddress * realSourceIP
Definition: Application.h:230
NETSIM_IPAddress * simSourceIP
Definition: Application.h:232
Structure to store application information.
Definition: Application.h:97
NETSIM_ID * destList
Definition: Application.h:106
unsigned int nSourceCount
Definition: Application.h:103
TRANSMISSION_TYPE nTransmissionType
Definition: Application.h:101
NETSIM_ID * sourceList
Definition: Application.h:105