NetSim Source Code Help
Loading...
Searching...
No Matches
P2P_Mac.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
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* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24#include "main.h"
25#include "P2P.h"
26#include "P2P_Enum.h"
27
29{
32
34 NetSim_PACKET* pstruPacket;
35
36 if (pstruEventDetails->nSubEventType == P2P_MAC_IDLE)
37 {
38 P2P_MAC_SET_IDLE(d, in);
40 }
41
42 if (P2P_MAC_IS_BUSY(d, in)) return -1; // Mac is busy.
43
44 //Get the packet from the Interface buffer
45 pstruPacket = fn_NetSim_Packet_GetPacketFromBuffer(buf, 1);
46 if (!pstruPacket) return -2;
47
48 fnValidatePacket(pstruPacket);
49
50 P2P_MAC_SET_BUSY(d, in);
51
52 //Place the packet to physical layer
53 //Write physical out event.
54 //Append mac details in packet
56 pstruPacket->pstruMacData->dEndTime = ldEventTime;
57 if (pstruPacket->pstruNetworkData)
58 {
59 pstruPacket->pstruMacData->dOverhead = 0;
60 pstruPacket->pstruMacData->dPayload = pstruPacket->pstruNetworkData->dPacketSize;
61 pstruPacket->pstruMacData->dPacketSize = pstruPacket->pstruMacData->dOverhead +
62 pstruPacket->pstruMacData->dPayload;
63 }
64 if (pstruPacket->pstruMacData->Packet_MACProtocol &&
65 !pstruPacket->pstruMacData->dontFree)
66 {
68 pstruPacket->pstruMacData->Packet_MACProtocol = NULL;
69 }
71 pstruPacket->pstruMacData->dStartTime = ldEventTime;
72 //Update the event details
75 pstruEventDetails->pPacket = pstruPacket;
77 if (pstruPacket->pstruAppData)
78 {
81 }
82 else
83 {
86 }
87 //Add physical out event
89 return 0;
90}
91
93{
97 if (DEVICE_NWLAYER(d))
98 {
99 //Add packet to Network in
100 //Prepare event details for network in
104 //Add network in event
106 }
107 else
108 {
109 bool isTransmitted = false;
110 //Broadcast to all other interface
111 NETSIM_ID i;
112 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
113 {
114 if (i + 1 == in)
115 continue;
116
117 NetSim_BUFFER* buf = DEVICE_ACCESSBUFFER(d, i + 1);
118 //Check for buffer
120 {
121 //Prepare event details for mac out
127 //Add mac out event
129 }
130 //Add packet to mac buffer
132 isTransmitted == false ? packet : fn_NetSim_Packet_CopyPacket(packet), 0);
133 isTransmitted = true;
134 }
135 }
136 return 0;
137}
unsigned int NETSIM_ID
Definition: Animation.h:45
#define P2P_MAC_IS_BUSY(d, in)
Definition: P2P.h:47
#define P2P_MAC_SET_BUSY(d, in)
Definition: P2P.h:45
#define P2P_MAC_SET_IDLE(d, in)
Definition: P2P.h:46
int P2P_MacIn_Handler()
Definition: P2P_Mac.c:92
int P2P_MacOut_Handler()
Definition: P2P_Mac.c:28
int fnValidatePacket(const NetSim_PACKET *pstruPacket)
bool fn_NetSim_GetBufferStatus(NetSim_BUFFER *pstruBuffer)
Definition: Scheduling.c:41
int fn_NetSim_Packet_FreeMacProtocolData(NetSim_PACKET *pstruPacket)
NetSim_PACKET * fn_NetSim_Packet_GetPacketFromBuffer(NetSim_BUFFER *pstruBuffer, int nFlag)
EXPORTED double ldEventTime
Definition: Stack.h:838
#define DEVICE(DeviceId)
Definition: Stack.h:769
NETWORK_LAYER_PROTOCOL fn_NetSim_Stack_GetNWProtocol(NETSIM_ID nDeviceId)
MAC_LAYER_PROTOCOL fn_NetSim_Stack_GetMacProtocol(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
@ NETWORK_IN_EVENT
Definition: Stack.h:109
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
@ MAC_OUT_EVENT
Definition: Stack.h:106
#define DEVICE_ACCESSBUFFER(DeviceId, InterfaceId)
Definition: Stack.h:794
#define DEVICE_NWLAYER(DeviceId)
Definition: Stack.h:785
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fn_NetSim_Packet_CopyPacket(pstruPacket)
Definition: main.h:182
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
#define fn_NetSim_Packet_AddPacketToList(pstruBuffer, pstruPacket, nInsertionType)
Definition: main.h:179
NETSIM_ID nApplicationId
Definition: Stack.h:752
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
NETSIM_ID nInterfaceId
Definition: Stack.h:751
MAC_LAYER_PROTOCOL nMACProtocol
Definition: Packet.h:223
long long int nPacketId
Definition: Packet.h:256
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition: Packet.h:273
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276