NetSim Source Code Help
Loading...
Searching...
No Matches
DSFrame.c
Go to the documentation of this file.
1#include "main.h"
2#include "802_22.h"
3/** The DS-MAP message defines the access to the downstream information.
4The length of the DS-MAP shall be an integer number of bytes. This function is used to
5generate the FCH frame,DS-MAP packet,US-MAP packet,DCD,UCD etc.*/
6int fn_NetSim_CR_FormDSFrame(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId,double dTime)
7{
8 NetSim_PACKET* pstruPacket;
9 unsigned int nSize;
10 BS_PHY* pstruBSPhy;
11 BS_MAC* pstruBSMAC;
12 int nBurstId;
13 int flag;
14 unsigned int nSlotRequire;
15 SYMBOL_PARAMETER* pstruSymbol;
16 pstruBSPhy = DEVICE_PHYVAR(nDeviceId,nInterfaceId);
17 pstruBSMAC = DEVICE_MACVAR(nDeviceId,nInterfaceId);
18 pstruSymbol = pstruBSPhy->pstruSymbolParameter;
19
20 flag =1;
21 if(pstruBSPhy->nFrameNumber==0)
22 flag=3;
23
24 //Fill the first symbol by FCH frame
25 //Generate the FCH frame
26 pstruPacket = fn_NetSim_CR_GenerateBroadcastCtrlPacket(nDeviceId,nInterfaceId,MMM_FCH);
27 pstruPacket->dEventTime = dTime;
28 pstruPacket->pstruMacData->dArrivalTime = dTime;
29 //Add FCH to BS MAC
30 nBurstId = fn_NetSim_CR_FillDSFrame(FCH_SIZE,pstruBSMAC->pstruDSBurst,pstruSymbol,flag,&nSlotRequire);
32 //Generate DS-MAP packet
33 pstruPacket = fn_NetSim_CR_FormDSMAP(nDeviceId,nInterfaceId);
34 pstruPacket->dEventTime = dTime;
35 pstruPacket->pstruMacData->dArrivalTime = dTime;
36 nSize = (unsigned int)fnGetPacketSize(pstruPacket);
37 nBurstId = fn_NetSim_CR_FillDSFrame(nSize,pstruBSMAC->pstruDSBurst,pstruSymbol,flag,&nSlotRequire);
39 //Generate US-MAP packet
40 pstruPacket = fn_NetSim_CR_FormUSMAP(nDeviceId,nInterfaceId);
41 pstruPacket->dEventTime = dTime;
42 pstruPacket->pstruMacData->dArrivalTime = dTime;
43 nSize = (unsigned int)fnGetPacketSize(pstruPacket);
44 nBurstId = fn_NetSim_CR_FillDSFrame(nSize,pstruBSMAC->pstruDSBurst,pstruSymbol,flag,&nSlotRequire);
46 //Generate UCD packet
47 pstruPacket = fn_NetSim_CR_FormUCD(nDeviceId,nInterfaceId);
48 pstruPacket->dEventTime = dTime;
49 pstruPacket->pstruMacData->dArrivalTime = dTime;
50 nSize = (unsigned int)fnGetPacketSize(pstruPacket);
51 nBurstId = fn_NetSim_CR_FillDSFrame(nSize,pstruBSMAC->pstruDSBurst,pstruSymbol,flag,&nSlotRequire);
53 //Generate DCD Packet
54 pstruPacket = fn_NetSim_CR_FormDCD(nDeviceId,nInterfaceId);
55 pstruPacket->dEventTime = dTime;
56 pstruPacket->pstruMacData->dArrivalTime = dTime;
57 nSize = (unsigned int)fnGetPacketSize(pstruPacket);
58 nBurstId = fn_NetSim_CR_FillDSFrame(nSize,pstruBSMAC->pstruDSBurst,pstruSymbol,flag,&nSlotRequire);
60 //Add other broadcast mac pdu
61 pstruBSMAC->chsFrameCount--;
62 if(pstruBSMAC->chsFrameCount <=0)
63 {
64 pstruBSMAC->nCHSREQFlag = ZERO;
65 pstruBSMAC->chsFrameCount = 0;
66 }
67 while(pstruBSMAC->pstruBroadcastPDU)
68 {
69 pstruPacket = pstruBSMAC->pstruBroadcastPDU;
70 pstruBSMAC->pstruBroadcastPDU = pstruBSMAC->pstruBroadcastPDU->pstruNextPacket;
71 pstruPacket->pstruNextPacket = NULL;
72 nSize = (unsigned int)fnGetPacketSize(pstruPacket);
73 nBurstId = fn_NetSim_CR_FillDSFrame(nSize,pstruBSMAC->pstruDSBurst,pstruSymbol,flag,&nSlotRequire);
74 if(nBurstId)
76 else
77 printf("No slot");
78 }
79 return 1;
80}
81/** This function is used to transmit the appropriate DSBurst. */
83{
86 unsigned int nBurstId = pstruBSMac->nDSBurst;
87 NetSim_PACKET* pstruMACPdu;
88 SYMBOL_PARAMETER* pstruSymbol = pstruBSPhy->pstruSymbolParameter;
89 if(pstruBSPhy->pstruOpratingChannel == NULL || pstruBSMac->dDSFrameTime <= pstruEventDetails->dEventTime)
90 {
91 return -1; //UCS notification or DSFrame over
92 }
93 //check for a packet
94 if(nBurstId <pstruSymbol->nDownLinkSymbol && pstruBSMac->pstruDSBurst[nBurstId]->pstruMACPDU)
95 {
96TRANSMITDSBURST:
98 if(pstruMACPdu->nControlDataType/100 == MAC_PROTOCOL_IEEE802_22)
99 {
100 switch(pstruMACPdu->nControlDataType%100)
101 {
102 case MMM_DS_MAP:
103 pstruBSMac->pstruDSMAP = NULL;
104 break;
105 case MMM_US_MAP:
106 pstruBSMac->pstruUSMAP = NULL;
107 break;
108 case MMM_UCD:
109 pstruBSMac->pstruUCD = NULL;
110 break;
111 case MMM_DCD:
112 pstruBSMac->pstruDCD = NULL;
113 break;
114 }
115 }
116
117 //Prepare physical out event
119 if(pstruMACPdu->pstruAppData)
121 else
124 pstruEventDetails->nPacketId = pstruMACPdu->nPacketId;
127 pstruEventDetails->pPacket = pstruMACPdu;
129 }
130 else
131 {
132 pstruBSMac->nDSBurst++;
133 nBurstId++;
134 if(nBurstId <pstruSymbol->nDownLinkSymbol && pstruBSMac->pstruDSBurst[nBurstId]->pstruMACPDU)
135 goto TRANSMITDSBURST;
136 }
137 return 1;
138}
139
int fn_NetSim_CR_FillDSFrame(unsigned int size, DS_BURST **pstruDSBurst, SYMBOL_PARAMETER *pstruSymbolParameter, int nFlag, unsigned int *nSlotRequire)
NetSim_PACKET * fn_NetSim_CR_UNFillSlot(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, unsigned int nBurstId)
@ MMM_UCD
Definition: 802_22.h:175
@ MMM_US_MAP
Upstream access definition, defines the access to the upstream information.
Definition: 802_22.h:177
@ MMM_DCD
Definition: 802_22.h:172
@ MMM_DS_MAP
Downstream access definition, defines the access to the downstream information.
Definition: 802_22.h:174
@ MMM_FCH
Definition: 802_22.h:230
NetSim_PACKET * fn_NetSim_CR_FormUSMAP(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
Definition: USMAP.c:9
#define FCH_SIZE
FCH Size is 3 Bytes.
Definition: 802_22.h:120
NetSim_PACKET * fn_NetSim_CR_FormDSMAP(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
Definition: DSMAP.c:10
NetSim_PACKET * fn_NetSim_CR_FormDCD(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
Definition: DCD.c:5
int fn_NetSim_CR_AddPacketToDSBurst(DS_BURST *pstruDSBurst, NetSim_PACKET *pstruPacket)
NetSim_PACKET * fn_NetSim_CR_FormUCD(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
Definition: UCD.c:5
NetSim_PACKET * fn_NetSim_CR_GenerateBroadcastCtrlPacket(int nDeviceId, int nInterfaceId, MANAGEMENT_MESSAGE nMessageType)
unsigned int NETSIM_ID
Definition: Animation.h:45
unsigned int nBurstId
Definition: Burst.c:16
int fn_NetSim_CR_FormDSFrame(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, double dTime)
Definition: DSFrame.c:6
int fn_NetSim_CR_TransmitDSBurst()
Definition: DSFrame.c:82
double fnGetPacketSize(NetSim_PACKET *pstruData)
@ ZERO
Definition: Stack.h:76
#define DEVICE_PHYVAR(DeviceId, InterfaceId)
Definition: Stack.h:797
@ MAC_PROTOCOL_IEEE802_22
Definition: Stack.h:210
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
unsigned int nDSBurst
Current DS burst
Definition: 802_22.h:798
double dDSFrameTime
Definition: 802_22.h:806
DS_BURST ** pstruDSBurst
DS-Burst each is one symbol long.
Definition: 802_22.h:799
DSMAP * pstruDSMAP
Definition: 802_22.h:800
USMAP * pstruUSMAP
Definition: 802_22.h:801
NetSim_PACKET * pstruBroadcastPDU
Definition: 802_22.h:812
unsigned int nFrameNumber
Current super frame number
Definition: 802_22.h:829
struct stru_802_22_Channel * pstruOpratingChannel
Currently operating channel.
Definition: 802_22.h:840
SYMBOL_PARAMETER * pstruSymbolParameter
Definition: 802_22.h:854
NetSim_PACKET * pstruMACPDU
Definition: 802_22.h:822
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
long long int nPacketId
Definition: Packet.h:256
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition: Packet.h:273
double dEventTime
Definition: Packet.h:262
unsigned int nControlDataType
Definition: Packet.h:258
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276