NetSim Source Code Help
Loading...
Searching...
No Matches
USFrame.c
Go to the documentation of this file.
1#include "main.h"
2#include "802_22.h"
3/** The MAC data elements that are contained in upstream bursts shall be mapped to the
4US sub frame in a different order. They are first mapped horizontally, OFDM symbol by
5OFDM symbol, in the same logical sub channel.
6
7Once a logical sub channel has been filled to the end of the upstream sub frame,
8the balance of the MAC data elements shall be mapped to the next logical sub channel,
9in an increasing sub channel order. This process continues until all of the sub channels
10and symbols allocated to the burst are filled. If the quantity of MAC data elements is
11insufficient to fill an upstream burst so that an integer number of OFDMA slots is
12occupied once encoded, zero padding shall be inserted at the end.
13
14Alternatively, the horizontal laying of the MAC data elements may fill one sub channel
15with at least 7 OFDM symbols at a time and continue on the following sub channels.
16However, when all logical sub channels have been filled, the next MAC data elements
17shall be placed in the first available logical sub channel in the following burst.
18The width of the last vertical burst will be between 7 and 13 symbols depending on the
19total number of symbols in the upstream sub frame. */
21{
23 int nLoop;
24 double dSize[MAX_FID];
25 double dTSize=0;
26 NetSim_PACKET* pstruPacket,*pstruTempPacket;
29 CPE_MAC* pstruCPEMAC = (CPE_MAC*)DEVICE_MACVAR(nDeviceId,nInterfaceId);
30 for(nLoop=1;nLoop<MAX_FID;nLoop++)
31 {
32 dSize[nLoop] =0;
33 pstruPacket = pstruCPEMAC->pstruQueuedPacketList[nLoop];
34 if(pstruCPEMAC->pstruServiceParameter->SFID[nLoop]==0 && nLoop > 2)
35 continue;
36 while(pstruPacket)
37 {
38 dSize[nLoop] += fnGetPacketSize(pstruPacket);
39 pstruPacket = pstruPacket->pstruNextPacket;
40 }
41 dTSize += dSize[nLoop];
42 }
43 if(dTSize > pstruCPEMAC->BWRequestInfo->dBytesAllocated)
44 {
45 double dAlloc = pstruCPEMAC->BWRequestInfo->dBytesAllocated;
46 for(nLoop=1;nLoop<MAX_FID;nLoop++)
47 {
48 double d;
49 BW_REQUEST* pstruBWRequest;
50 d = dSize[nLoop];
51 dSize[nLoop] -= dAlloc;
52 if(dSize[nLoop] <= 0)
53 {
54 dAlloc -= d;
55 continue;
56 }
57 //BW request needs to be sent
60 add_dest_to_packet(pstruPacket, pstruCPEMAC->nBSID);
61 pstruPacket->nPacketPriority = Priority_High;
62 pstruPacket->nPacketType = PacketType_Control;
63 pstruPacket->nReceiverId = pstruCPEMAC->nBSID;
64 pstruPacket->nSourceId = nDeviceId;
65 pstruPacket->nTransmitterId = nDeviceId;
66 pstruPacket->nQOS = pstruCPEMAC->pstruQueuedPacketList[nLoop]->nQOS;
69 pstruPacket->pstruMacData->dPacketSize = 3;
70 pstruPacket->pstruMacData->dOverhead = 3;
71 pstruBWRequest = (BW_REQUEST*)fnpAllocateMemory(1,sizeof *pstruBWRequest);
72 pstruBWRequest->nType = 0;
73 pstruBWRequest->nBR = (int)(d);
74 pstruPacket->pstruMacData->Packet_MACProtocol = pstruBWRequest;
75
76 //Add the packet to mac queue
77 pstruTempPacket = pstruCPEMAC->pstruQueuedPacketList[0];
78 if(!pstruTempPacket)
79 {
80 pstruCPEMAC->pstruQueuedPacketList[0] = pstruPacket;
81 }
82 else
83 {
84 while(pstruTempPacket->pstruNextPacket)
85 pstruTempPacket = pstruTempPacket->pstruNextPacket;
86 pstruTempPacket->pstruNextPacket = pstruPacket;
87 }
88 dAlloc = 0;
89 }
90 }
91 if(pstruCPEMAC->BWRequestInfo->dBytesAllocated)
92 {
93 double dByte = pstruCPEMAC->BWRequestInfo->dBytesAllocated;
94 int nId = 1;
95 while(dByte && nId < 8)
96 {
97 NetSim_PACKET* pPacket;
98 pPacket = pstruCPEMAC->pstruQueuedPacketList[nId];
99 if(pPacket)
100 {
101 double size;
102 size = fnGetPacketSize(pPacket);
103 if(size <= dByte)
104 dByte -= size;
105 else
106 break;
107 pstruCPEMAC->pstruQueuedPacketList[nId] = pstruCPEMAC->pstruQueuedPacketList[nId]->pstruNextPacket;
108 pPacket->pstruNextPacket = NULL;
109 fn_NetSim_AddPacketToList(&(pstruCPEMAC->pstruUSBurst),pPacket);
110 }
111 else
112 nId++;
113 }
114 //Add an event to transmit US-Burst
124
125
126 }
127 while(pstruCPEMAC->pstruQueuedPacketList[0])
128 {
129 NetSim_PACKET* p = pstruCPEMAC->pstruQueuedPacketList[0];
130 pstruCPEMAC->pstruQueuedPacketList[0] = pstruCPEMAC->pstruQueuedPacketList[0]->pstruNextPacket;
131 p->pstruNextPacket=NULL;
132 //Generate physical out event
142 }
143 return 0;
144}
145/** The MAC data elements that are contained in upstream bursts shall be mapped to the
146US sub frame in a different order. They are first mapped horizontally, OFDM symbol by
147OFDM symbol, in the same logical sub channel.
148
149Once a logical sub channel has been filled to the end of the upstream sub frame,
150the balance of the MAC data elements shall be mapped to the next logical sub channel,
151in an increasing sub channel order. This process continues until all of the sub channels
152and symbols allocated to the burst are filled. If the quantity of MAC data elements is
153insufficient to fill an upstream burst so that an integer number of OFDMA slots is
154occupied once encoded, zero padding shall be inserted at the end.
155
156Alternatively, the horizontal laying of the MAC data elements may fill one sub channel
157with at least 7 OFDM symbols at a time and continue on the following sub channels.
158However, when all logical sub channels have been filled, the next MAC data elements
159shall be placed in the first available logical sub channel in the following burst.
160The width of the last vertical burst will be between 7 and 13 symbols depending on the
161total number of symbols in the upstream sub frame. */
163{
166 CPE_MAC* pstruCPEMac = (CPE_MAC*)DEVICE_MACVAR(nDeviceId,nInterfaceId);
167 NetSim_PACKET* pstruPacket = pstruCPEMac->pstruUSBurst;
168 if(!pstruPacket)
169 return 1; //No more US burst
170 pstruCPEMac->pstruUSBurst = pstruCPEMac->pstruUSBurst->pstruNextPacket;
171 pstruPacket->pstruNextPacket = NULL;
172 //Update the MAC data
175 //Create phy out event
177 if (pstruPacket->pstruAppData)
178 {
181 }
182 else
183 {
186 }
188 pstruEventDetails->nPacketId = pstruPacket->nPacketId;
190 pstruEventDetails->pPacket = pstruPacket;
192 /* Check for Application end flag */
193 if(pstruPacket->pstruAppData && pstruPacket->pstruAppData->nAppEndFlag == 1)
194 {
195 //Application is ending
196 fn_NetSim_TerminateServiceFlow(nDeviceId,nInterfaceId,pstruPacket);
197 }
198 return 0;
199}
int fn_NetSim_AddPacketToList(NetSim_PACKET **list, NetSim_PACKET *packet)
@ MMM_BW_REQUEST
Definition: 802_22.h:232
int fn_NetSim_TerminateServiceFlow(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET *pstruPacket)
Definition: DSx.c:213
#define CR_CONTROL_PACKET(MMM)
Definition: 802_22.h:235
@ TRANSMIT_US_BURST_CONTROL
Definition: 802_22.h:156
@ TRANSMIT_US_BURST
Definition: 802_22.h:155
#define MAX_FID
Definition: 802_22.h:74
unsigned int NETSIM_ID
Definition: Animation.h:45
#define fnpAllocateMemory(count, size)
Definition: Memory.h:34
double fnGetPacketSize(NetSim_PACKET *pstruData)
@ PacketType_Control
Definition: Packet.h:66
void add_dest_to_packet(NetSim_PACKET *packet, NETSIM_ID dest)
@ Priority_High
Definition: Packet.h:82
@ MAC_PROTOCOL_IEEE802_22
Definition: Stack.h:210
@ TIMER_EVENT
Definition: Stack.h:114
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
@ MAC_LAYER
Definition: Stack.h:95
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
int fn_NetSim_CR_TransmitUSBurst()
Definition: USFrame.c:162
int fn_NetSim_CR_FormUSBurst()
Definition: USFrame.c:20
#define fn_NetSim_Packet_CreatePacket(layer)
Definition: main.h:186
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
CPE structure for IEEE 802.22 MAC.
Definition: 802_22.h:869
struct stru_802_22_CPE_BWRequestInfo * BWRequestInfo
Definition: 802_22.h:890
NetSim_PACKET * pstruUSBurst
Definition: 802_22.h:893
NETSIM_ID nBSID
Definition: 802_22.h:870
CR_SERVICE * pstruServiceParameter
Definition: 802_22.h:892
NetSim_PACKET * pstruQueuedPacketList[MAX_FID]
Definition: 802_22.h:891
unsigned int SFID[8]
Definition: DSx.h:36
unsigned int nBR
Definition: 802_22.h:1221
unsigned int nType
Definition: 802_22.h:1220
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
NETSIM_ID nReceiverId
Definition: Packet.h:266
unsigned int nControlDataType
Definition: Packet.h:258
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
NETSIM_ID nTransmitterId
Definition: Packet.h:265
QUALITY_OF_SERVICE nQOS
Definition: Packet.h:261
PACKET_TYPE nPacketType
Definition: Packet.h:257
PACKET_PRIORITY nPacketPriority
Definition: Packet.h:260
NETSIM_ID nSourceId
Definition: Packet.h:263
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276