NetSim Source Code Help
Loading...
Searching...
No Matches
PacketForward.c
Go to the documentation of this file.
1#include "main.h"
2#include "802_22.h"
3/** This function is used to check whether the destination is present or not.
4If it presents,it broadcast the data packet */
6{
7 NetSim_BUFFER* pstruBuffer;
11 BS_MAC* pstruBSMac = (BS_MAC*)DEVICE_MACVAR(nDeviceId,nInterfaceId);
12 //Check the destination
13 if(isBroadcastPacket(pstruPacket))
14 {
15 //Broadcast packet
16 NETSIM_ID nloop;
17 pstruPacket = fn_NetSim_CR_BS_PackPacket(pstruBSMac,pstruPacket);
18 if(!pstruPacket)
19 return 1;
20 for(nloop = 0;nloop<NETWORK->ppstruDeviceList[nDeviceId-1]->nNumOfInterface;nloop++)
21 {
22 if(!DEVICE_MAC_NW_INTERFACE(nDeviceId,nloop+1))
23 continue;
24 if(nloop+1==nInterfaceId)
25 {
26 NetSim_PACKET* list = pstruBSMac->pstruDSPacketList;
27 if(!list)
28 {
29 pstruBSMac->pstruDSPacketList = fn_NetSim_Packet_CopyPacket(pstruPacket);
30 }
31 else
32 {
33 while(list->pstruNextPacket)
34 list = list->pstruNextPacket;
36 }
37 continue;
38 }
39 //Place the packet to access interface
40 pstruBuffer = DEVICE_MAC_NW_INTERFACE(nDeviceId,nloop+1)->pstruAccessBuffer;
41 if(!fn_NetSim_GetBufferStatus(pstruBuffer))
42 {
43 //Add the MAC out event
50 }
52 }
53 fn_NetSim_Packet_FreePacket(pstruPacket);
54 }
55 else
56 {
57 UINT destCount;
58 NETSIM_ID* dest = get_dest_from_packet(pstruPacket, &destCount);
59 UINT i;
60 int nSID = 0;
61 for (i = 0; i < destCount; i++)
62 {
63 nSID = pstruBSMac->anSIDFromDevId[dest[i]];
64 if (nSID)
65 break;
66 }
67 if(nSID)
68 {
69 NetSim_PACKET* list = pstruBSMac->pstruDSPacketList;
70 if(!list)
71 {
72 pstruBSMac->pstruDSPacketList = pstruPacket;
73 }
74 else
75 {
76 while(list->pstruNextPacket)
77 list = list->pstruNextPacket;
78 list->pstruNextPacket = pstruPacket;
79 }
80 pstruPacket->nTransmitterId = pstruPacket->nReceiverId;
81 pstruPacket->nReceiverId = destCount > 1 ? 0 : dest[0];
82 }
83
84 if(isMulticastPacket(pstruPacket) || !nSID)
85 {
86 //Broadcasting to other port
87 NETSIM_ID nloop;
88 pstruPacket = fn_NetSim_CR_BS_PackPacket(pstruBSMac,pstruPacket);
89 if(!pstruPacket)
90 return 1;
91 for(nloop = 0;nloop<NETWORK->ppstruDeviceList[nDeviceId-1]->nNumOfInterface;nloop++)
92 {
93 if(nloop == nInterfaceId-1)
94 continue;
95 //Place the packet to access interface
96 pstruBuffer = DEVICE_MAC_NW_INTERFACE(nDeviceId,nloop+1)->pstruAccessBuffer;
97 if(!fn_NetSim_GetBufferStatus(pstruBuffer))
98 {
99 //Add the MAC out event
106 }
107 fn_NetSim_CR_FreePacket_F(pstruPacket);
108 fn_NetSim_Packet_AddPacketToList(pstruBuffer,pstruPacket,0);
109 }
110 }
111 }
112 return 0;
113}
int fn_NetSim_CR_FreePacket_F(const NetSim_PACKET *pstruPacket)
NetSim_PACKET * fn_NetSim_CR_BS_PackPacket(BS_MAC *pstruBSMac, NetSim_PACKET *pstruPacket)
Definition: Fragmentation.c:8
unsigned int NETSIM_ID
Definition: Animation.h:45
#define UINT
Definition: Linux.h:38
bool fn_NetSim_GetBufferStatus(NetSim_BUFFER *pstruBuffer)
Definition: Scheduling.c:41
NETSIM_ID * get_dest_from_packet(NetSim_PACKET *packet, UINT *count)
bool isMulticastPacket(NetSim_PACKET *packet)
bool isBroadcastPacket(NetSim_PACKET *packet)
int fn_NetSim_CR_BS_ForwardDataPacket()
Definition: PacketForward.c:5
#define DEVICE_MAC_NW_INTERFACE(DeviceId, InterfaceId)
Definition: Stack.h:793
MAC_LAYER_PROTOCOL fn_NetSim_Stack_GetMacProtocol(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
@ MAC_OUT_EVENT
Definition: Stack.h:106
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fn_NetSim_Packet_CopyPacket(pstruPacket)
Definition: main.h:182
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
#define fn_NetSim_Packet_AddPacketToList(pstruBuffer, pstruPacket, nInsertionType)
Definition: main.h:179
int * anSIDFromDevId
Have the list of CPE associated with BS. If SID is set CPE is associated else not.
Definition: 802_22.h:802
NetSim_PACKET * pstruDSPacketList
Definition: 802_22.h:816
NETSIM_ID nNumOfInterface
Definition: Stack.h:714
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
NETSIM_ID nInterfaceId
Definition: Stack.h:751
struct stru_NetSim_Device ** ppstruDeviceList
Definition: Stack.h:737
NETSIM_ID nReceiverId
Definition: Packet.h:266
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
NETSIM_ID nTransmitterId
Definition: Packet.h:265