summaryrefslogtreecommitdiff
path: root/cesar/maximus/python/py/test_tx_rx.py
blob: ac1867ec2b273a5fd64a835c68e824c731f0deb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/python

print "\n*** " + __file__ + " ***\n"

import sys
sys.path.append('./test')
sys.path.append('../test')
import startup

from interface import *
from maximus import *
from struct import pack

m = Maximus()
m.init(sys.argv)


# TEST TX AND RX
# To be run with "test_tx_rx.elf" station executable
# (to be compiled under "/trunk/maximus/stationtest").

# Create station(s)
sta1 = m.create_sta ()

# Enable channel perturbation
m.disturb_channel()

# Set tonemask
fcall1 = m.create_fcall('set_tonemask')
fcall1.send(sta1)

def create_fcall_128():
    # Create a fcall for an MPDU containing one PB of 128 octets
    fc_mode = 2 # PHY_FC_MODE_AV_1
    short_ppdu = False
    mod = 2 # PHY_MOD_MINI_ROBO
    fecrate = 0 # PHY_FEC_RATE_1_2
    pb_size = 0 # PHY_PB_SIZE_136
    gil = 1 # PHY_GIL_567
    pb_nb = 1
    fcall_128 = m.create_fcall('prepare_rx')
    fcall_128.add_param_ushort("fc_mode", fc_mode)
    fcall_128.add_param_bool("short_ppdu", short_ppdu)
    fcall_128.add_param_ushort("mod", mod)
    fcall_128.add_param_ushort("fecrate", fecrate)
    fcall_128.add_param_ushort("pb_size", pb_size)
    fcall_128.add_param_ushort("gil", gil)
    fcall_128.add_param_ushort("pb_nb", pb_nb)
    return fcall_128

def create_fcall_512_1():
    # Create a fcall for an MPDU containing one PB of 512 octets with a FC 1.0
    fc_mode =  0 # PHY_FC_MODE_HYBRID_1
    short_ppdu = False
    mod = 3 # PHY_MOD_TM
    fecrate = 0 # PHY_FEC_RATE_1_2
    pb_size = 1 # PHY_PB_SIZE_520
    gil = 1 # PHY_GIL_567
    pb_nb = 1
    fcall_512_1 = m.create_fcall('prepare_rx')
    fcall_512_1.add_param_ushort("fc_mode", fc_mode)
    fcall_512_1.add_param_bool("short_ppdu", short_ppdu)
    fcall_512_1.add_param_ushort("mod", mod)
    fcall_512_1.add_param_ushort("fecrate", fecrate)
    fcall_512_1.add_param_ushort("pb_size", pb_size)
    fcall_512_1.add_param_ushort("gil", gil)
    fcall_512_1.add_param_ushort("pb_nb", pb_nb)
    return fcall_512_1

def create_fcall_512_3():
    # Create a fcall for an MPDU containing 3 PBs of 512 octets
    fc_mode = 2 # PHY_FC_MODE_AV_1
    short_ppdu = False
    mod = 0 # PHY_MOD_ROBO
    fecrate = 0 # PHY_FEC_RATE_1_2
    pb_size = 1 # PHY_PB_SIZE_520
    gil = 0 # PHY_GIL_417
    pb_nb = 3
    fcall_512_3 = m.create_fcall('prepare_rx')
    fcall_512_3.add_param_ushort("fc_mode", fc_mode)
    fcall_512_3.add_param_bool("short_ppdu", short_ppdu)
    fcall_512_3.add_param_ushort("mod", mod)
    fcall_512_3.add_param_ushort("fecrate", fecrate)
    fcall_512_3.add_param_ushort("pb_size", pb_size)
    fcall_512_3.add_param_ushort("gil", gil)
    fcall_512_3.add_param_ushort("pb_nb", pb_nb)
    return fcall_512_3

def create_fcall_short_fc10():
    # Create a fcall for a short PPDU with a FC 1.0
    fc_mode =  0 # PHY_FC_MODE_HYBRID_1
    short_ppdu = True
    fcall_short_fc10 = m.create_fcall('prepare_rx')
    fcall_short_fc10.add_param_ushort("fc_mode", fc_mode)
    fcall_short_fc10.add_param_bool("short_ppdu", short_ppdu)
    fcall_short_fc10.add_param_ushort("mod", 0)
    fcall_short_fc10.add_param_ushort("fecrate", 0)
    fcall_short_fc10.add_param_ushort("pb_size", 0)
    fcall_short_fc10.add_param_ushort("gil", 0)
    fcall_short_fc10.add_param_ushort("pb_nb", 0)
    return fcall_short_fc10

def get_pad(n):
    pad = ''
    for i in range (0,n):
        pad += pack('B', 0)
    return pad

# Test following functions:
# - send(self, maximus, fc_mode=4, short_ppdu=0, mod=4, file=None)
# - sendnrecv(self, maximus, fc_mode=4, short_ppdu=0, mod=4, file=None, timeout=None, filter=None, count=1)
# - recv(maximus, timeout=None, filter=None, count=1)

# Send an MPDU containing one PB of 128 octets
fcall_128 = create_fcall_128()
fcall_128.send(sta1)
macFrame1 = MACFrame()
fc_av_1 = (0, 456, 789, 10)
macFrame1.set_fc_av(fc_av_1)
msdu1 = 'This is the MPDU payload'
macFrame1.set_msdu(msdu1)
macFrame1.set_macframeheader(MACFrameHeader(MFL=len(msdu1)-1))
macFrame1.send(m)
rsp1 = recv(m)
if rsp1[0].get_fc_av() != fc_av_1:
    print "fc_av_1 =", rsp1[0].get_fc_av()
    raise Error("fc_av_1")
if rsp1[0].get_pblist()[0] != MACFrameHeader(MFL=len(msdu1)-1).get() + msdu1 + macFrame1.get_icv() + get_pad(98):
    print "msdu1 =", rsp1[0].get_pblist()[0]
    raise Error("msdu1")
m.wait(100000)

# Send an MPDU containing 3 PBs of 512 octets
fcall_512_3 = create_fcall_512_3()
fcall_512_3.send(sta1)
macFrame2 = MACFrame()
fc_av_2 = fc_av_1
macFrame2.set_fc_av(fc_av_2)
msdu2 = 1500*'a'
macFrame2.set_msdu(msdu2)
macFrame2.set_macframeheader(MACFrameHeader(MFL=len(msdu2)-1))
rsp2 = macFrame2.sendnrecv(m)
if rsp2[0].get_fc_av() != fc_av_2:
    print "fc_av_2 =", rsp2[0].get_fc_av()
    raise Error("fc_av_2")
if rsp2[0].get_pblist()[0] != MACFrameHeader(MFL=len(msdu2)-1).get() + 510*'a' \
or rsp2[0].get_pblist()[1] != 512*'a' \
or rsp2[0].get_pblist()[2] != 478*'a' + macFrame2.get_icv() + get_pad(30):
    print "msdu2 =", rsp2[0].get_pblist()[0], rsp2[0].get_pblist()[1], rsp2[0].get_pblist()[2]
    raise Error("msdu2")
m.wait(100000)

# Send a short PPDU with a FC 1.0
fcall_short_fc10 = create_fcall_short_fc10()
fcall_short_fc10.send(sta1)
macFrame3 = MACFrame()
fc_10_3 = 1
macFrame3.set_fc_10(fc_10_3)
fc_av_3 = (123, 456, 789, 10)
macFrame3.set_fc_av(fc_av_3)
macFrame3.send(maximus=m, short_ppdu=True)
# no rsp3
m.wait(100000)

# Send an MPDU containing one PB of 512 octets with a FC 1.0
fcall_512_1 = create_fcall_512_1()
fcall_512_1.send(sta1)
macFrame4 = MACFrame()
fc_10_4 = 10
macFrame4.set_fc_10(fc_10_4)
fc_av_4 = fc_av_1
macFrame4.set_fc_av(fc_av_4)
msdu4 = 200*'b'
macFrame4.set_msdu(msdu4)
macFrame4.set_macframeheader(MACFrameHeader(MFL=len(msdu4)-1))
macFrame4.send(m)
rsp4 = recv(m)
if rsp4[0].get_fc_10() != fc_10_4:
    print "fc_10_4 =", rsp4[0].get_fc_10()
    raise Error("fc_10_4")
if rsp4[0].get_fc_av() != fc_av_4:
    print "fc_av_4 =", rsp4[0].get_fc_av()
    raise Error("fc_av_4")
if rsp4[0].get_pblist()[0] != MACFrameHeader(MFL=len(msdu4)-1).get() + msdu4 + macFrame4.get_icv() + get_pad(306):
    print "msdu4 =", rsp4[0].get_pblist()[0]
    raise Error("msdu4")
m.wait(100000)

# Send an MPDU containing one PB of 128 octets, created from an MME
fcall_128 = create_fcall_128()
fcall_128.send(sta1)
icv5 = 'ICV!'
macFrame5 = MACFrame(ICV=icv5)
fc_av_5 = fc_av_1
macFrame5.set_fc_av(fc_av_5)
mmheader5 = 'MMHeader 19 octets!'
mmentry5 = '--- This is the Management Message Entry ---'
msdu5 = MME(MMHeader=mmheader5, MMEntry=mmentry5)
macFrame5.set_msdu(msdu5)
macFrame5.set_macframeheader(MACFrameHeader(MFL=len(mmheader5)+len(mmentry5)-1))
rsp5 = macFrame5.sendnrecv(m)
if rsp5[0].get_fc_av() != fc_av_5:
    print "fc_av_5 =", rsp5[0].get_fc_av()
    raise Error("fc_av_5")
if rsp5[0].get_pblist()[0] != MACFrameHeader(MFL=len(mmheader5)+len(mmentry5)-1).get() + mmheader5 + mmentry5 + macFrame5.get_icv() + get_pad(59):
    print "msdu5 =", rsp5[0].get_pblist()[0]
    raise Error("msdu5")
m.wait(100000)

# Uninitialize PHY
fcall2 = m.create_fcall('uninit_phy')
fcall2.send(sta1)

# Remove station(s)
sta1.remove()

print "\n*** END ***\n"