summaryrefslogtreecommitdiff
path: root/cesar/maximus/python/py/test_ether.py
blob: 7168bd642a579a721a0ab08998b4fa1f50d634a9 (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
#!/usr/bin/python

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

from interface import *
from maximus import *
from maximus.ethernet.eth import MAX_SIZE_OF_HEADER
from maximus.mme.mmheader import MAX_SIZE_OF_MMHEADER
from maximus.macframe.msdu import MIN_SIZE_OF_MSDU
from maximus.simu.rx import * # for 'recv()' function
from struct import pack

# Constants to check argument validity
HPAV_MMTYPE_OFFSET = 15 # in octets

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


# TEST ETHER
# To be run with "test_ether.elf" station executable
# (to be compiled under "/trunk/maximus/stationtest").

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

# Init ether
fcall = m.create_fcall('init_ether')
fcall.send(sta1)

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

# Disable the automatic buffer allocation
realloc_buffer(False)

# Ethernet Frame config
dst = '41:42:43:44:45:46'
src = '47:48:49:4a:4b:4c'
vlantag = 0x81004D4E
type = 0x4F50

# MME config
mmheader = 'MMHeader 19 octets!'
mmentry = '--- This is the Management Message Entry ---'
expected_mmheader = mmheader[0:HPAV_MMTYPE_OFFSET] + \
    htohp8 (hptoh8 (mmheader[HPAV_MMTYPE_OFFSET]) + 1) + \
    mmheader[HPAV_MMTYPE_OFFSET + 1:]
expected_mmentry = '\0'

# Send an Ethernet Frame asynchronously
frame1 = Eth()
frame1.dst = dst
frame1.src = src
frame1.vlantag = vlantag
frame1.type = type
msdu1 = 'This is the Ethernet payload'
frame1.payload = msdu1
alloc_buffer (m, sta1, buffer_nb = 1)
frame1.send(m, sta1)
rsp1 = recv (m, count = 2)

# Test the 1st received MSDU (Eth) object
i = 0 # the second received frame is the BUFFER RELEASED message
if rsp1[i].dst != dst:
    print "dst1 =", rsp1[i].dst
    raise Error("dst1")
if rsp1[i].src != src:
    print "src1 =", rsp1[i].src
    raise Error("src1")
if rsp1[i].vlantag != vlantag:
    print "vlantag1 =", hex(rsp1[i].vlantag)
    raise Error("vlantag1")
if rsp1[i].type != type:
    print "type1 =", hex(rsp1[i].type)
    raise Error("type1")
if str(rsp1[i].payload) != msdu1:
    print len(str(rsp1[i].payload))
    print "msdu1 =", str(rsp1[i].payload)
    raise Error("msdu1")

m.wait(100000)

# Send an Ethernet Frame synchronously
frame2 = Eth()
frame2.dst = dst
frame2.src = src
frame2.vlantag = vlantag
frame2.type = type
msdu2 = 'This is the Ethernet payload'
frame2.payload = msdu2
alloc_buffer (m, sta1, buffer_nb = 1)
rsp2 = frame2.sendnrecv (m, sta1, count = 2)

# Test the 1st received MSDU (Eth) object
i = 0 # the second received frame is the BUFFER RELEASED message
if rsp2[i].dst != dst:
    print "dst2 =", rsp2[i].dst
    raise Error("dst2")
if rsp2[i].src != src:
    print "src2 =", rsp2[i].src
    raise Error("src2")
if rsp2[i].vlantag != vlantag:
    print "vlantag2 =", hex(rsp2[i].vlantag)
    raise Error("vlantag2")
if rsp2[i].type != type:
    print "type2 =", hex(rsp2[i].type)
    raise Error("type2")
if str(rsp2[i].payload) != msdu2:
    print "msdu2 =", str(rsp2[i].payload)
    raise Error("msdu2")

m.wait(100000)

# Send an MME asynchronously
mme3 = MME(MMHeader=mmheader, MMEntry=mmentry)
alloc_buffer (m, sta1, buffer_nb = 1)
mme3.send(m, sta1)
rsp3 = recv (m, count = 2)

# Test the 1st received MSDU (MME) object
i = 0 # the second received frame is the BUFFER RELEASED message
if rsp3[i].get_mmheader () != expected_mmheader:
    print "mmheader3 =", rsp3[i].get_mmheader()
    raise Error("mmheader3")
if rsp3[i].get_mmentry () != expected_mmentry:
    print "mmentry3 =", rsp3[i].get_mmentry()
    raise Error("mmentry3")

m.wait(100000)

# Send an MME synchronously
mme4 = MME(MMHeader=mmheader, MMEntry=mmentry)
alloc_buffer (m, sta1, buffer_nb = 1)
rsp4 = mme4.sendnrecv (m, sta1, count = 2)

# Test the 1st received MSDU (Eth) object
i = 0 # the second received frame is the BUFFER RELEASED message
if rsp4[i].get_mmheader () != expected_mmheader:
    print "mmheader4 =", rsp4[i].get_mmheader()
    raise Error("mmheader4")
if rsp4[i].get_mmentry () != expected_mmentry:
    print "mmentry4 =", rsp4[i].get_mmentry()
    raise Error("mmentry4")

m.wait(100000)

# Uninit ether
fcall2 = m.create_fcall('uninit_ether')
fcall2.send(sta1)

# Remove station(s)
sta1.remove()

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