NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
CSMACD.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 "CSMACD.h"
16
17//Function prototype
18int fn_NetSim_CSMACD_Configure_F(void** var);
19int fn_NetSim_CSMACD_Init_F(struct stru_NetSim_Network *NETWORK_Formal,
20 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
21 char *pszAppPath_Formal,
22 char *pszWritePath_Formal,
23 int nVersion_Type,
24 void **fnPointer);
25
26_declspec(dllexport) int fn_NetSim_CSMACD_Configure(void** var)
27{
28 return fn_NetSim_CSMACD_Configure_F(var);
29}
30
31_declspec (dllexport) int fn_NetSim_CSMACD_Init(struct stru_NetSim_Network *NETWORK_Formal,
32 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
33 char *pszAppPath_Formal,
34 char *pszWritePath_Formal,
35 int nVersion_Type,
36 void **fnPointer)
37{
38 char *fcollisioncount,*fcontentionwindow;
39 fcollisioncount = calloc(1,strlen(pszIOPath)+50);
40 fn_NetSim_Utilities_ConcatString(3,fcollisioncount,pszIOPath,"/collisioncount.txt");
41 file_collision = fopen(fcollisioncount,"w");
42
43 if(file_collision == NULL)
44 fnSystemError(fcollisioncount);
45 else
46 {
47 fprintf(file_collision,"Source_ID\tCollision_Count\tTime (Micro Sec)\n");
48 }
49
50
51 fcontentionwindow = calloc(1,strlen(pszIOPath)+50);
52 fn_NetSim_Utilities_ConcatString(3,fcontentionwindow,pszIOPath,"/ContentionWindow.txt");
53 file_contention = fopen(fcontentionwindow,"w");
54
55 if(file_contention == NULL)
56 fnSystemError(fcontentionwindow);
57 else
58 {
59 fprintf(file_contention,"Source_ID\tContention_Window\tTime (Micro Sec)\n");
60 }
61
62 return fn_NetSim_CSMACD_Init_F(NETWORK_Formal,pstruEventDetails_Formal,pszAppPath_Formal,
63 pszWritePath_Formal,nVersion_Type,fnPointer);
64}
65
66_declspec (dllexport) int fn_NetSim_CSMACD_Run()
67{
68 switch(pstruEventDetails->nEventType)
69 {
70 case MAC_OUT_EVENT:
71 fn_NetSim_CSMACD_MacOut();
72 break;
73 case MAC_IN_EVENT:
74 fn_NetSim_CSMACD_MacIn();
75 break;
76 case PHYSICAL_OUT_EVENT:
77 fn_NetSim_CSMACD_PhyOut();
78 break;
79 case PHYSICAL_IN_EVENT:
80 fn_NetSim_CSMACD_PhyIn();
81 break;
82 case TIMER_EVENT:
83 {
84 switch(pstruEventDetails->nSubEventType)
85 {
86 case WAIT_FOR_RANDOM_TIME:
87 case PERSISTANCE_WAIT:
88 fn_NetSim_CSMACS_PersistanceWait();
89 break;
90 default:
91 fnNetSimError("Unknown subevent type %d in %s.",pstruEventDetails->nSubEventType,
92 __FUNCTION__);
93 break;
94 }
95 }
96 break;
97 default:
98 fnNetSimError("Unknown event type %d in %s.",pstruEventDetails->nEventType,
99 __FUNCTION__);
100 break;
101 }
102 return 0;
103}
104
105_declspec(dllexport) int fn_NetSim_CSMACD_Finish()
106{
107 fclose(file_collision);
108 fclose(file_contention);
109 return 0;
110}
111
112_declspec (dllexport) char* fn_NetSim_CSMACD_Trace(int nSubEvent)
113{
114 return GetStringCSMACD_Subevent(nSubEvent);
115}
116_declspec(dllexport) int fn_NetSim_CSMACD_FreePacket(NetSim_PACKET* pstruPacket)
117{
118 pstruPacket;
119 return 0;
120}
121
122/**
123This function is called by NetworkStack.dll, to copy the aloha protocol
124details from source packet to destination.
125*/
126_declspec(dllexport) int fn_NetSim_CSMACD_CopyPacket(NetSim_PACKET* pstruDestPacket,NetSim_PACKET* pstruSrcPacket)
127{
128 pstruDestPacket;
129 pstruSrcPacket;
130 return 0;
131}
132
133/**
134This function write the Metrics
135*/
136_declspec(dllexport) int fn_NetSim_CSMACD_Metrics(PMETRICSWRITER metricsWriter)
137{
138 metricsWriter;
139 return 0;
140}
141
142/**
143This function will return the string to write packet trace heading.
144*/
145_declspec(dllexport) char* fn_NetSim_CSMACD_ConfigPacketTrace()
146{
147 return "";
148}
149
150/**
151This function will return the string to write packet trace.
152*/
153_declspec(dllexport) char* fn_NetSim_CSMACD_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
154{
155 pstruPacket;
156 ppszTrace;
157 return "";
158}