-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestAliasConflict.py
executable file
·243 lines (227 loc) · 8.23 KB
/
testAliasConflict.py
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python
'''
Tests a node's response to seeing messages with its alias
@author: Bob Jacobsen
'''
# Expects:
# :X17020573N;
# :X16304573N;
# :X15050573N;
# :X10700573N;
# :X10701573N020304050607;
# :X19087573N020304050607;
import connection as connection
import canolcbutils
import verifyNodeGlobal
import verifyNodeAddressed
import time
def usage() :
print ""
print "Called standalone, tests a node's response to"
print "seeing messages with its alias"
print ""
print "Default connection detail taken from connection.py"
print ""
print "-a --alias source alias (default 123)"
print "-d --dest dest alias (default 123)"
print "-t find destination alias automatically"
print "-v verbose"
print "-V very verbose"
import getopt, sys
def main():
alias = connection.thisNodeAlias;
dest = connection.testNodeAlias;
verbose = False
identifynode = False
# argument processing
try:
opts, remainder = getopt.getopt(sys.argv[1:], "d:a:vVt", ["alias=", "dest="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for opt, arg in opts:
if opt == "-v":
verbose = True
elif opt == "-V":
verbose = True
connection.network.verbose = True
elif opt in ("-a", "--alias"):
alias = int(arg) # needs hex decode
elif opt in ("-d", "--dest"):
dest = int(arg) # needs hex decode
elif opt == "-t":
identifynode = True
else:
assert False, "unhandled option"
if identifynode :
import getUnderTestAlias
dest, otherNodeId = getUnderTestAlias.get(alias, None, verbose)
retval = test(alias, dest, connection, verbose)
connection.network.close()
return retval
def test(alias, dest, connection, verbose) :
# Note: This test assumes that the response will be
# to reacquire another alias after the conflicted one is
# dropped. This isn't required behavior by standard, but
# is a necessary condition for the test to continue and
# check another conflict condition.
#
# Sending a global message (that normally doesn't get a response)
# by sending verifyNodeGlobal with a nodeID that doesn't match any valid
if verbose : print " check no-response global message with alias conflict"
connection.network.send(verifyNodeGlobal.makeframe(dest, [0,0,0,0,0,1]))
reply = connection.network.receive()
if reply == None :
print "no response received to conflict frame"
return 21
if not reply.startswith(":X10703") :
print "Expected first AMR"
return 22
if int(reply[7:10],16) != dest :
print "incorrect alias in AMR"
return 23
reply = connection.network.receive()
if reply == None :
print "no response received to conflict frame"
return 21
if not reply.startswith(":X17") :
print "Expected first CID"
return 22
if int(reply[7:10],16) == 0 :
print "received alias == 0"
return 23
dest = int(reply[7:10],16)
# pull & drop rest of sequence
reply = connection.network.receive() # CID 2
reply = connection.network.receive() # CID 3
reply = connection.network.receive() # CID 4
timeout = connection.network.timeout
connection.network.timeout = 1.0
reply = connection.network.receive() # RID
connection.network.timeout = timeout
# dump everything until nothing heard
while (reply != None) :
reply = connection.network.receive()
# Sending a global message (that normally does get a response)
if verbose : print " check response-inducing global message with alias conflict"
connection.network.send(verifyNodeGlobal.makeframe(dest, None))
reply = connection.network.receive()
if reply == None :
print "no response received to conflict frame"
return 21
if not reply.startswith(":X10703") :
print "Expected second AMR"
return 22
if int(reply[7:10],16) != dest :
print "incorrect alias in AMR"
return 23
reply = connection.network.receive()
if reply == None :
print "no response received to conflict frame"
return 31
if not reply.startswith(":X17") :
print "Expected second CID"
return 32
if int(reply[7:10],16) == 0 :
print "received alias == 0"
return 33
dest = int(reply[7:10],16)
# pull & drop rest of sequence
reply = connection.network.receive() # CID 2
reply = connection.network.receive() # CID 3
reply = connection.network.receive() # CID 4
timeout = connection.network.timeout
connection.network.timeout = 1.0
reply = connection.network.receive() # RID
connection.network.timeout = timeout
# dump everything until nothing heard
while (reply != None) :
reply = connection.network.receive()
# Sending an addressed message to some other alias (note arguments backwards, on purpose)
if verbose : print " check addressed message with alias conflict"
connection.network.send(verifyNodeAddressed.makeframe(dest, alias, None))
reply = connection.network.receive()
if reply == None :
print "no response received to conflict frame"
return 21
if not reply.startswith(":X10703") :
print "Expected third AMR"
return 22
if int(reply[7:10],16) != dest :
print "incorrect alias in AMR"
return 23
reply = connection.network.receive()
if reply == None :
if verbose : print "no response received to conflict frame"
return 41
if not reply.startswith(":X17") :
if verbose : print "Expected third CID"
return 42
if int(reply[7:10],16) == 0 :
print "received alias == 0"
return 43
dest = int(reply[7:10],16)
# pull & drop rest of sequence
reply = connection.network.receive() # CID 2
reply = connection.network.receive() # CID 3
reply = connection.network.receive() # CID 4
timeout = connection.network.timeout
connection.network.timeout = 1.0
reply = connection.network.receive() # RID
connection.network.timeout = timeout
# dump everything until nothing heard
while (reply != None) :
reply = connection.network.receive()
# send a CheckID
if verbose : print " check CheckID with alias conflict"
connection.network.send(canolcbutils.makeframestring(0x17020000+dest, None))
reply = connection.network.receive()
if reply == None :
if verbose : print "no response received to CID"
return 51
if int(reply[7:10],16) != dest :
if verbose : print "mismatched reply alias"
return 52
if not reply.startswith(":X10700") :
if verbose : print "CID reply not correct, RID expected"
return 53
# send a ReserveID
connection.network.send(canolcbutils.makeframestring(0x10700000+dest, None))
if verbose : print " check ReserveID with alias conflict"
reply = connection.network.receive()
if reply == None :
print "no response received to conflict frame"
return 21
if not reply.startswith(":X10703") :
print "Expected fourth AMR"
return 22
if int(reply[7:10],16) != dest :
print "incorrect alias in AMR"
return 23
reply = connection.network.receive()
if reply == None :
if verbose : print "no response received to conflict frame"
return 61
if not reply.startswith(":X17") :
if verbose : print "Expected fourth CID"
return 62
if int(reply[7:10],16) == 0 :
print "received alias == 0"
return 63
dest = int(reply[7:10],16)
# pull & drop rest of sequence
reply = connection.network.receive() # CID 2
reply = connection.network.receive() # CID 3
reply = connection.network.receive() # CID 4
timeout = connection.network.timeout
connection.network.timeout = 1.0
reply = connection.network.receive() # RID
connection.network.timeout = timeout
# dump everything until nothing heard
while (reply != None) :
reply = connection.network.receive()
return 0
if __name__ == '__main__':
main()