1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
23 from nose.tools import eq_
24 from nose.tools import ok_
25 from ryu.lib import addrconv
26 from ryu.lib.packet import packet
27 from ryu.lib.packet import ethernet
28 from ryu.lib.packet import ipv4
29 from ryu.lib.packet import sctp
30 from ryu.ofproto import ether
31 from ryu.ofproto import inet
34 LOG = logging.getLogger(__name__)
37 class Test_sctp(unittest.TestCase):
47 self.src_port, self.dst_port, self.vtag, self.csum,
50 self.buf = b'\x16\x2e\x04\xd2\x05\xe3\x0a\x78\x00\x00\x00\x00'
52 def setUp_with_data(self):
61 self.payload_data = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a'
63 self.data = sctp.chunk_data(
64 unordered=self.unordered, begin=self.begin, end=self.end,
65 tsn=self.tsn, sid=self.sid, payload_data=self.payload_data)
67 self.chunks = [self.data]
70 self.src_port, self.dst_port, self.vtag, self.csum,
73 self.buf += b'\x00\x07\x00\x1a\x00\x00\x30\x39\x00\x01\x00\x00' + \
74 b'\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a'
76 def setUp_with_init(self):
78 self.length = 20 + 8 + 20 + 8 + 4 + 16 + 16
79 self.init_tag = 123456
85 self.p_ipv4 = sctp.param_ipv4('192.168.1.1')
86 self.p_ipv6 = sctp.param_ipv6('fe80::647e:1aff:fec4:8284')
87 self.p_cookie_preserve = sctp.param_cookie_preserve(5000)
88 self.p_ecn = sctp.param_ecn()
89 self.p_host_addr = sctp.param_host_addr(b'test host\x00')
90 self.p_support_type = sctp.param_supported_addr(
91 [sctp.PTYPE_IPV4, sctp.PTYPE_IPV6, sctp.PTYPE_COOKIE_PRESERVE,
92 sctp.PTYPE_ECN, sctp.PTYPE_HOST_ADDR])
94 self.p_ipv4, self.p_ipv6, self.p_cookie_preserve,
95 self.p_ecn, self.p_host_addr, self.p_support_type]
97 self.init = sctp.chunk_init(
98 init_tag=self.init_tag, a_rwnd=self.a_rwnd, os=self.os,
99 mis=self.mis, i_tsn=self.i_tsn, params=self.params)
101 self.chunks = [self.init]
104 self.src_port, self.dst_port, self.vtag, self.csum,
107 self.buf += b'\x01\x00\x00\x5c\x00\x01\xe2\x40\x00\x00\x26\x94' + \
108 b'\x00\x03\x00\x03\x00\x01\xe2\x40' + \
109 b'\x00\x05\x00\x08\xc0\xa8\x01\x01' + \
110 b'\x00\x06\x00\x14' + \
111 b'\xfe\x80\x00\x00\x00\x00\x00\x00' + \
112 b'\x64\x7e\x1a\xff\xfe\xc4\x82\x84' + \
113 b'\x00\x09\x00\x08\x00\x00\x13\x88' + \
114 b'\x80\x00\x00\x04' + \
115 b'\x00\x0b\x00\x0e' + \
116 b'\x74\x65\x73\x74\x20\x68\x6f\x73\x74\x00\x00\x00' + \
117 b'\x00\x0c\x00\x0e\x00\x05\x00\x06\x00\x09\x80\x00' + \
120 def setUp_with_init_ack(self):
122 self.length = 20 + 8 + 8 + 20 + 8 + 4 + 16
123 self.init_tag = 123456
129 self.p_state_cookie = sctp.param_state_cookie(b'\x01\x02\x03')
130 self.p_ipv4 = sctp.param_ipv4('192.168.1.1')
131 self.p_ipv6 = sctp.param_ipv6('fe80::647e:1aff:fec4:8284')
132 self.p_unrecognized_param = sctp.param_unrecognized_param(
134 self.p_ecn = sctp.param_ecn()
135 self.p_host_addr = sctp.param_host_addr(b'test host\x00')
137 self.p_state_cookie, self.p_ipv4, self.p_ipv6,
138 self.p_unrecognized_param, self.p_ecn, self.p_host_addr]
140 self.init_ack = sctp.chunk_init_ack(
141 init_tag=self.init_tag, a_rwnd=self.a_rwnd, os=self.os,
142 mis=self.mis, i_tsn=self.i_tsn, params=self.params)
144 self.chunks = [self.init_ack]
147 self.src_port, self.dst_port, self.vtag, self.csum,
150 self.buf += b'\x02\x00\x00\x54\x00\x01\xe2\x40\x00\x00\x26\x94' + \
151 b'\x00\x03\x00\x03\x00\x01\xe2\x40' + \
152 b'\x00\x07\x00\x07\x01\x02\x03\x00' + \
153 b'\x00\x05\x00\x08\xc0\xa8\x01\x01' + \
154 b'\x00\x06\x00\x14' + \
155 b'\xfe\x80\x00\x00\x00\x00\x00\x00' + \
156 b'\x64\x7e\x1a\xff\xfe\xc4\x82\x84' + \
157 b'\x00\x08\x00\x08\xff\xff\x00\x04' + \
158 b'\x80\x00\x00\x04' + \
159 b'\x00\x0b\x00\x0e' + \
160 b'\x74\x65\x73\x74\x20\x68\x6f\x73\x74\x00\x00\x00'
162 def setUp_with_sack(self):
164 self.length = 16 + 2 * 2 * 5 + 4 * 5
165 self.tsn_ack = 123456
169 self.gapacks = [[2, 3], [10, 12], [20, 24], [51, 52], [62, 63]]
170 self.duptsns = [123458, 123466, 123476, 123507, 123518]
172 self.sack = sctp.chunk_sack(
173 tsn_ack=self.tsn_ack, a_rwnd=self.a_rwnd,
174 gapack_num=self.gapack_num, duptsn_num=self.duptsn_num,
175 gapacks=self.gapacks, duptsns=self.duptsns)
177 self.chunks = [self.sack]
180 self.src_port, self.dst_port, self.vtag, self.csum,
183 self.buf += b'\x03\x00\x00\x38\x00\x01\xe2\x40' + \
184 b'\x00\x00\x26\x94\x00\x05\x00\x05' + \
185 b'\x00\x02\x00\x03\x00\x0a\x00\x0c\x00\x14\x00\x18' + \
186 b'\x00\x33\x00\x34\x00\x3e\x00\x3f' + \
187 b'\x00\x01\xe2\x42\x00\x01\xe2\x4a\x00\x01\xe2\x54' + \
188 b'\x00\x01\xe2\x73\x00\x01\xe2\x7e'
190 def setUp_with_heartbeat(self):
194 self.p_heartbeat = sctp.param_heartbeat(b'\x01\x02\x03\x04')
196 self.heartbeat = sctp.chunk_heartbeat(info=self.p_heartbeat)
198 self.chunks = [self.heartbeat]
201 self.src_port, self.dst_port, self.vtag, self.csum,
204 self.buf += b'\x04\x00\x00\x0c' + \
205 b'\x00\x01\x00\x08' + \
208 def setUp_with_heartbeat_ack(self):
212 self.p_heartbeat = sctp.param_heartbeat(
213 b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88')
215 self.heartbeat_ack = sctp.chunk_heartbeat_ack(info=self.p_heartbeat)
217 self.chunks = [self.heartbeat_ack]
220 self.src_port, self.dst_port, self.vtag, self.csum,
223 self.buf += b'\x05\x00\x00\x10' + \
224 b'\x00\x01\x00\x0c' + \
225 b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88'
227 def setUp_with_abort(self):
229 self.length = 4 + 8 + 16 + 8 + 4 + 20 + 8 + 4 + 8 + 8 + 4 + 12 \
232 self.c_invalid_stream_id = sctp.cause_invalid_stream_id(4096)
233 self.c_missing_param = sctp.cause_missing_param(
234 [sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
235 sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR])
236 self.c_stale_cookie = sctp.cause_stale_cookie(b'\x00\x00\x13\x88')
237 self.c_out_of_resource = sctp.cause_out_of_resource()
238 self.c_unresolvable_addr = sctp.cause_unresolvable_addr(
239 sctp.param_host_addr(b'test host\x00'))
240 self.c_unrecognized_chunk = sctp.cause_unrecognized_chunk(
242 self.c_invalid_param = sctp.cause_invalid_param()
243 self.c_unrecognized_param = sctp.cause_unrecognized_param(
245 self.c_no_userdata = sctp.cause_no_userdata(b'\x00\x01\xe2\x40')
246 self.c_cookie_while_shutdown = sctp.cause_cookie_while_shutdown()
247 self.c_restart_with_new_addr = sctp.cause_restart_with_new_addr(
248 sctp.param_ipv4('192.168.1.1'))
249 self.c_user_initiated_abort = sctp.cause_user_initiated_abort(
250 b'Key Interrupt.\x00')
251 self.c_protocol_violation = sctp.cause_protocol_violation(
252 b'Unknown reason.\x00')
255 self.c_invalid_stream_id, self.c_missing_param,
256 self.c_stale_cookie, self.c_out_of_resource,
257 self.c_unresolvable_addr, self.c_unrecognized_chunk,
258 self.c_invalid_param, self.c_unrecognized_param,
259 self.c_no_userdata, self.c_cookie_while_shutdown,
260 self.c_restart_with_new_addr, self.c_user_initiated_abort,
261 self.c_protocol_violation]
263 self.abort = sctp.chunk_abort(causes=self.causes)
265 self.chunks = [self.abort]
268 self.src_port, self.dst_port, self.vtag, self.csum,
271 self.buf += b'\x06\x00\x00\x90' + \
272 b'\x00\x01\x00\x08\x10\x00\x00\x00' + \
273 b'\x00\x02\x00\x10\x00\x00\x00\x04' + \
274 b'\x00\x05\x00\x06\x00\x09\x00\x0b' + \
275 b'\x00\x03\x00\x08\x00\x00\x13\x88' + \
276 b'\x00\x04\x00\x04' + \
277 b'\x00\x05\x00\x14' + \
278 b'\x00\x0b\x00\x0e' + \
279 b'\x74\x65\x73\x74\x20\x68\x6f\x73\x74\x00\x00\x00' + \
280 b'\x00\x06\x00\x08\xff\x00\x00\x04' + \
281 b'\x00\x07\x00\x04' + \
282 b'\x00\x08\x00\x08\xff\xff\x00\x04' + \
283 b'\x00\x09\x00\x08\x00\x01\xe2\x40' + \
284 b'\x00\x0a\x00\x04' + \
285 b'\x00\x0b\x00\x0c' + \
286 b'\x00\x05\x00\x08\xc0\xa8\x01\x01' + \
287 b'\x00\x0c\x00\x13' + \
288 b'\x4b\x65\x79\x20\x49\x6e\x74\x65' + \
289 b'\x72\x72\x75\x70\x74\x2e\x00\x00' + \
290 b'\x00\x0d\x00\x14' + \
291 b'\x55\x6e\x6b\x6e\x6f\x77\x6e\x20' + \
292 b'\x72\x65\x61\x73\x6f\x6e\x2e\x00'
294 def setUp_with_shutdown(self):
297 self.tsn_ack = 123456
299 self.shutdown = sctp.chunk_shutdown(tsn_ack=self.tsn_ack)
301 self.chunks = [self.shutdown]
304 self.src_port, self.dst_port, self.vtag, self.csum,
307 self.buf += b'\x07\x00\x00\x08\x00\x01\xe2\x40'
309 def setUp_with_shutdown_ack(self):
313 self.shutdown_ack = sctp.chunk_shutdown_ack()
315 self.chunks = [self.shutdown_ack]
318 self.src_port, self.dst_port, self.vtag, self.csum,
321 self.buf += b'\x08\x00\x00\x04'
323 def setUp_with_error(self):
325 self.length = 4 + 8 + 16 + 8 + 4 + 20 + 8 + 4 + 8 + 8 + 4 + 12 \
328 self.c_invalid_stream_id = sctp.cause_invalid_stream_id(4096)
329 self.c_missing_param = sctp.cause_missing_param(
330 [sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
331 sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR])
332 self.c_stale_cookie = sctp.cause_stale_cookie(b'\x00\x00\x13\x88')
333 self.c_out_of_resource = sctp.cause_out_of_resource()
334 self.c_unresolvable_addr = sctp.cause_unresolvable_addr(
335 sctp.param_host_addr(b'test host\x00'))
336 self.c_unrecognized_chunk = sctp.cause_unrecognized_chunk(
338 self.c_invalid_param = sctp.cause_invalid_param()
339 self.c_unrecognized_param = sctp.cause_unrecognized_param(
341 self.c_no_userdata = sctp.cause_no_userdata(b'\x00\x01\xe2\x40')
342 self.c_cookie_while_shutdown = sctp.cause_cookie_while_shutdown()
343 self.c_restart_with_new_addr = sctp.cause_restart_with_new_addr(
344 sctp.param_ipv4('192.168.1.1'))
345 self.c_user_initiated_abort = sctp.cause_user_initiated_abort(
346 b'Key Interrupt.\x00')
347 self.c_protocol_violation = sctp.cause_protocol_violation(
348 b'Unknown reason.\x00')
351 self.c_invalid_stream_id, self.c_missing_param,
352 self.c_stale_cookie, self.c_out_of_resource,
353 self.c_unresolvable_addr, self.c_unrecognized_chunk,
354 self.c_invalid_param, self.c_unrecognized_param,
355 self.c_no_userdata, self.c_cookie_while_shutdown,
356 self.c_restart_with_new_addr, self.c_user_initiated_abort,
357 self.c_protocol_violation]
359 self.error = sctp.chunk_error(causes=self.causes)
361 self.chunks = [self.error]
364 self.src_port, self.dst_port, self.vtag, self.csum,
367 self.buf += b'\x09\x00\x00\x90' + \
368 b'\x00\x01\x00\x08\x10\x00\x00\x00' + \
369 b'\x00\x02\x00\x10\x00\x00\x00\x04' + \
370 b'\x00\x05\x00\x06\x00\x09\x00\x0b' + \
371 b'\x00\x03\x00\x08\x00\x00\x13\x88' + \
372 b'\x00\x04\x00\x04' + \
373 b'\x00\x05\x00\x14' + \
374 b'\x00\x0b\x00\x0e' + \
375 b'\x74\x65\x73\x74\x20\x68\x6f\x73\x74\x00\x00\x00' + \
376 b'\x00\x06\x00\x08\xff\x00\x00\x04' + \
377 b'\x00\x07\x00\x04' + \
378 b'\x00\x08\x00\x08\xff\xff\x00\x04' + \
379 b'\x00\x09\x00\x08\x00\x01\xe2\x40' + \
380 b'\x00\x0a\x00\x04' + \
381 b'\x00\x0b\x00\x0c' + \
382 b'\x00\x05\x00\x08\xc0\xa8\x01\x01' + \
383 b'\x00\x0c\x00\x13' + \
384 b'\x4b\x65\x79\x20\x49\x6e\x74\x65' + \
385 b'\x72\x72\x75\x70\x74\x2e\x00\x00' + \
386 b'\x00\x0d\x00\x14' + \
387 b'\x55\x6e\x6b\x6e\x6f\x77\x6e\x20' + \
388 b'\x72\x65\x61\x73\x6f\x6e\x2e\x00'
390 def setUp_with_cookie_echo(self):
393 self.cookie = b'\x12\x34\x56\x78'
395 self.cookie_echo = sctp.chunk_cookie_echo(cookie=self.cookie)
397 self.chunks = [self.cookie_echo]
400 self.src_port, self.dst_port, self.vtag, self.csum,
403 self.buf += b'\x0a\x00\x00\x08\x12\x34\x56\x78'
405 def setUp_with_cookie_ack(self):
409 self.cookie_ack = sctp.chunk_cookie_ack()
411 self.chunks = [self.cookie_ack]
414 self.src_port, self.dst_port, self.vtag, self.csum,
417 self.buf += b'\x0b\x00\x00\x04'
419 def setUp_with_ecn_echo(self):
422 self.low_tsn = 123456
424 self.ecn_echo = sctp.chunk_ecn_echo(low_tsn=self.low_tsn)
426 self.chunks = [self.ecn_echo]
429 self.src_port, self.dst_port, self.vtag, self.csum,
432 self.buf += b'\x0c\x00\x00\x08\x00\x01\xe2\x40'
434 def setUp_with_cwr(self):
437 self.low_tsn = 123456
439 self.cwr = sctp.chunk_cwr(low_tsn=self.low_tsn)
441 self.chunks = [self.cwr]
444 self.src_port, self.dst_port, self.vtag, self.csum,
447 self.buf += b'\x0d\x00\x00\x08\x00\x01\xe2\x40'
449 def setUp_with_shutdown_complete(self):
453 self.shutdown_complete = sctp.chunk_shutdown_complete()
455 self.chunks = [self.shutdown_complete]
458 self.src_port, self.dst_port, self.vtag, self.csum,
461 self.buf += b'\x0e\x00\x00\x04'
463 def setUp_with_multi_chunks(self):
466 self.s_tsn_ack = 123456
468 self.s_gapack_num = 0
469 self.s_duptsn_num = 0
470 self.s_gapacks = None
471 self.s_duptsns = None
473 self.sack = sctp.chunk_sack(
474 tsn_ack=self.s_tsn_ack, a_rwnd=self.s_a_rwnd)
476 self.d1_unordered = 0
479 self.d1_length = 16 + 10
483 self.d1_payload_id = 0
484 self.d1_payload_data = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a'
486 self.data1 = sctp.chunk_data(
487 begin=self.d1_begin, tsn=self.d1_tsn, sid=self.d1_sid,
488 payload_data=self.d1_payload_data)
490 self.d2_unordered = 0
493 self.d2_length = 16 + 10
497 self.d2_payload_id = 0
498 self.d2_payload_data = b'\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a'
500 self.data2 = sctp.chunk_data(
501 end=self.d2_end, tsn=self.d2_tsn, sid=self.d2_sid,
502 seq=self.d2_seq, payload_data=self.d2_payload_data)
504 self.chunks = [self.sack, self.data1, self.data2]
507 self.src_port, self.dst_port, self.vtag, self.csum,
510 self.buf += b'\x03\x00\x00\x10\x00\x01\xe2\x40' + \
511 b'\x00\x00\x26\x94\x00\x00\x00\x00' + \
512 b'\x00\x02\x00\x1a\x00\x00\x30\x39\x00\x01\x00\x00' + \
513 b'\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a' + \
514 b'\x00\x01\x00\x1a\x00\x00\x30\x3a\x00\x01\x00\x01' + \
515 b'\x00\x00\x00\x00\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a'
521 eq_(self.src_port, self.sc.src_port)
522 eq_(self.dst_port, self.sc.dst_port)
523 eq_(self.vtag, self.sc.vtag)
524 eq_(self.csum, self.sc.csum)
525 eq_(self.chunks, self.sc.chunks)
527 def test_init_with_data(self):
528 self.setUp_with_data()
531 def test_init_with_init(self):
532 self.setUp_with_init()
535 def test_init_with_init_ack(self):
536 self.setUp_with_init_ack()
539 def test_init_with_sack(self):
540 self.setUp_with_sack()
543 def test_init_with_heartbeat(self):
544 self.setUp_with_heartbeat()
547 def test_init_with_heartbeat_ack(self):
548 self.setUp_with_heartbeat_ack()
551 def test_init_with_abort(self):
552 self.setUp_with_abort()
555 def test_init_with_shutdown(self):
556 self.setUp_with_shutdown()
559 def test_init_with_shutdown_ack(self):
560 self.setUp_with_shutdown_ack()
563 def test_init_with_error(self):
564 self.setUp_with_error()
567 def test_init_with_cookie_echo(self):
568 self.setUp_with_cookie_echo()
571 def test_init_with_cookie_ack(self):
572 self.setUp_with_cookie_ack()
575 def test_init_with_ecn_echo(self):
576 self.setUp_with_ecn_echo()
579 def test_init_with_cwr(self):
580 self.setUp_with_cwr()
583 def test_init_with_shutdown_complete(self):
584 self.setUp_with_shutdown_complete()
587 def test_init_with_multi_chunks(self):
588 self.setUp_with_multi_chunks()
591 def test_parser(self):
592 _res = self.sc.parser(six.binary_type(self.buf))
593 if type(_res) is tuple:
597 # to calculate the lengths of parameters.
598 self.sc.serialize(None, None)
600 eq_(self.src_port, res.src_port)
601 eq_(self.dst_port, res.dst_port)
602 eq_(self.vtag, res.vtag)
603 eq_(self.csum, res.csum)
604 eq_(str(self.chunks), str(res.chunks))
606 def test_parser_with_data(self):
607 self.setUp_with_data()
610 def test_parser_with_init(self):
611 self.setUp_with_init()
614 def test_parser_with_init_ack(self):
615 self.setUp_with_init_ack()
618 def test_parser_with_sack(self):
619 self.setUp_with_sack()
622 def test_parser_with_heartbeat(self):
623 self.setUp_with_heartbeat()
626 def test_parser_with_heartbeat_ack(self):
627 self.setUp_with_heartbeat_ack()
630 def test_parser_with_abort(self):
631 self.setUp_with_abort()
634 def test_parser_with_shutdown(self):
635 self.setUp_with_shutdown()
638 def test_parser_with_shutdown_ack(self):
639 self.setUp_with_shutdown_ack()
642 def test_parser_with_error(self):
643 self.setUp_with_error()
646 def test_parser_with_cookie_echo(self):
647 self.setUp_with_cookie_echo()
650 def test_parser_with_cookie_ack(self):
651 self.setUp_with_cookie_ack()
654 def test_parser_with_ecn_echo(self):
655 self.setUp_with_ecn_echo()
658 def test_parser_with_cwr(self):
659 self.setUp_with_cwr()
662 def test_parser_with_shutdown_complete(self):
663 self.setUp_with_shutdown_complete()
666 def test_parser_with_multi_chunks(self):
667 self.setUp_with_multi_chunks()
670 def _test_serialize(self):
671 buf = self.sc.serialize(bytearray(), None)
672 res = struct.unpack_from(sctp.sctp._PACK_STR, buf)
673 eq_(self.src_port, res[0])
674 eq_(self.dst_port, res[1])
675 eq_(self.vtag, res[2])
676 # skip compare checksum
677 # eq_(self.csum, res[3])
679 return buf[sctp.sctp._MIN_LEN:]
681 def test_serialize(self):
682 self._test_serialize()
684 def test_serialize_with_data(self):
685 self.setUp_with_data()
686 buf = self._test_serialize()
687 res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
688 eq_(sctp.chunk_data.chunk_type(), res[0])
690 (self.unordered << 2) |
694 eq_(self.length, res[2])
695 eq_(self.tsn, res[3])
696 eq_(self.sid, res[4])
697 eq_(self.seq, res[5])
698 eq_(self.payload_id, res[6])
699 eq_(self.payload_data, buf[sctp.chunk_data._MIN_LEN:])
701 def test_serialize_with_init(self):
702 self.setUp_with_init()
703 buf = self._test_serialize()
704 res = struct.unpack_from(sctp.chunk_init._PACK_STR, buf)
705 eq_(sctp.chunk_init.chunk_type(), res[0])
706 eq_(self.flags, res[1])
707 eq_(self.length, res[2])
708 eq_(self.init_tag, res[3])
709 eq_(self.a_rwnd, res[4])
711 eq_(self.mis, res[6])
712 eq_(self.i_tsn, res[7])
714 buf = buf[sctp.chunk_init._MIN_LEN:]
715 res1 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
716 eq_(sctp.param_ipv4.param_type(), res1[0])
718 eq_('192.168.1.1', addrconv.ipv4.bin_to_text(
719 buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
722 res2 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
723 eq_(sctp.param_ipv6.param_type(), res2[0])
725 eq_('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
726 buf[sctp.param_ipv6._MIN_LEN:sctp.param_ipv6._MIN_LEN + 16]))
729 res3 = struct.unpack_from(sctp.param_cookie_preserve._PACK_STR,
731 eq_(sctp.param_cookie_preserve.param_type(), res3[0])
736 res4 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
737 eq_(sctp.param_ecn.param_type(), res4[0])
741 res5 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
742 eq_(sctp.param_host_addr.param_type(), res5[0])
744 eq_(b'test host\x00',
745 buf[sctp.param_host_addr._MIN_LEN:
746 sctp.param_host_addr._MIN_LEN + 10])
749 res6 = struct.unpack_from(sctp.param_supported_addr._PACK_STR, buf)
751 eq_(sctp.param_supported_addr.param_type(), res6[0])
753 buf = buf[sctp.param_supported_addr._MIN_LEN:]
756 while offset < len(buf):
757 (tmp, ) = struct.unpack_from('!H', buf, offset)
759 offset += struct.calcsize('!H')
761 eq_(sctp.PTYPE_IPV4, res6[2])
762 eq_(sctp.PTYPE_IPV6, res6[3])
763 eq_(sctp.PTYPE_COOKIE_PRESERVE, res6[4])
764 eq_(sctp.PTYPE_ECN, res6[5])
765 eq_(sctp.PTYPE_HOST_ADDR, res6[6])
767 def test_serialize_with_init_ack(self):
768 self.setUp_with_init_ack()
769 buf = self._test_serialize()
770 res = struct.unpack_from(sctp.chunk_init_ack._PACK_STR, buf)
771 eq_(sctp.chunk_init_ack.chunk_type(), res[0])
772 eq_(self.flags, res[1])
773 eq_(self.length, res[2])
774 eq_(self.init_tag, res[3])
775 eq_(self.a_rwnd, res[4])
777 eq_(self.mis, res[6])
778 eq_(self.i_tsn, res[7])
780 buf = buf[sctp.chunk_init_ack._MIN_LEN:]
781 res1 = struct.unpack_from(sctp.param_state_cookie._PACK_STR, buf)
782 eq_(sctp.param_state_cookie.param_type(), res1[0])
785 buf[sctp.param_state_cookie._MIN_LEN:
786 sctp.param_state_cookie._MIN_LEN + 3])
789 res2 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
790 eq_(sctp.param_ipv4.param_type(), res2[0])
792 eq_('192.168.1.1', addrconv.ipv4.bin_to_text(
793 buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
796 res3 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
797 eq_(sctp.param_ipv6.param_type(), res3[0])
799 eq_('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
800 buf[sctp.param_ipv6._MIN_LEN:sctp.param_ipv6._MIN_LEN + 16]))
803 res4 = struct.unpack_from(
804 sctp.param_unrecognized_param._PACK_STR, buf)
805 eq_(sctp.param_unrecognized_param.param_type(), res4[0])
807 eq_(b'\xff\xff\x00\x04',
808 buf[sctp.param_unrecognized_param._MIN_LEN:
809 sctp.param_unrecognized_param._MIN_LEN + 4])
812 res5 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
813 eq_(sctp.param_ecn.param_type(), res5[0])
817 res6 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
818 eq_(sctp.param_host_addr.param_type(), res6[0])
820 eq_(b'test host\x00',
821 buf[sctp.param_host_addr._MIN_LEN:
822 sctp.param_host_addr._MIN_LEN + 10])
824 def test_serialize_with_sack(self):
825 self.setUp_with_sack()
826 buf = self._test_serialize()
827 res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
828 eq_(sctp.chunk_sack.chunk_type(), res[0])
829 eq_(self.flags, res[1])
830 eq_(self.length, res[2])
831 eq_(self.tsn_ack, res[3])
832 eq_(self.a_rwnd, res[4])
833 eq_(self.gapack_num, res[5])
834 eq_(self.duptsn_num, res[6])
836 buf = buf[sctp.chunk_sack._MIN_LEN:]
838 for _ in range(self.gapack_num):
839 (gap_s, gap_e) = struct.unpack_from(
840 sctp.chunk_sack._GAPACK_STR, buf)
843 buf = buf[sctp.chunk_sack._GAPACK_LEN:]
845 for _ in range(self.duptsn_num):
846 (duptsn, ) = struct.unpack_from(
847 sctp.chunk_sack._DUPTSN_STR, buf)
848 duptsns.append(duptsn)
849 buf = buf[sctp.chunk_sack._DUPTSN_LEN:]
850 eq_(self.gapacks, gapacks)
851 eq_(self.duptsns, duptsns)
853 def test_serialize_with_heartbeat(self):
854 self.setUp_with_heartbeat()
855 buf = self._test_serialize()
856 res = struct.unpack_from(sctp.chunk_heartbeat._PACK_STR, buf)
857 eq_(sctp.chunk_heartbeat.chunk_type(), res[0])
858 eq_(self.flags, res[1])
859 eq_(self.length, res[2])
861 buf = buf[sctp.chunk_heartbeat._MIN_LEN:]
862 res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
863 eq_(sctp.param_heartbeat.param_type(), res1[0])
865 eq_(b'\x01\x02\x03\x04',
866 buf[sctp.param_heartbeat._MIN_LEN:
867 sctp.param_heartbeat._MIN_LEN + 4])
869 def test_serialize_with_heartbeat_ack(self):
870 self.setUp_with_heartbeat_ack()
871 buf = self._test_serialize()
872 res = struct.unpack_from(sctp.chunk_heartbeat_ack._PACK_STR, buf)
873 eq_(sctp.chunk_heartbeat_ack.chunk_type(), res[0])
874 eq_(self.flags, res[1])
875 eq_(self.length, res[2])
877 buf = buf[sctp.chunk_heartbeat_ack._MIN_LEN:]
878 res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
879 eq_(sctp.param_heartbeat.param_type(), res1[0])
881 eq_(b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88',
882 buf[sctp.param_heartbeat._MIN_LEN:
883 sctp.param_heartbeat._MIN_LEN + 8])
885 def test_serialize_with_abort(self):
886 self.setUp_with_abort()
887 buf = self._test_serialize()
888 res = struct.unpack_from(sctp.chunk_abort._PACK_STR, buf)
889 eq_(sctp.chunk_abort.chunk_type(), res[0])
890 flags = self.tflag << 0
892 eq_(self.length, res[2])
894 buf = buf[sctp.chunk_abort._MIN_LEN:]
895 res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
896 eq_(sctp.cause_invalid_stream_id.cause_code(), res1[0])
901 res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
902 eq_(sctp.cause_missing_param.cause_code(), res2[0])
906 for count in range(4):
907 (tmp, ) = struct.unpack_from(
908 '!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
910 eq_(str([sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
911 sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR]),
915 res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
916 eq_(sctp.cause_stale_cookie.cause_code(), res3[0])
918 eq_(b'\x00\x00\x13\x88',
919 buf[sctp.cause_stale_cookie._MIN_LEN:
920 sctp.cause_stale_cookie._MIN_LEN + 4])
923 res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
924 eq_(sctp.cause_out_of_resource.cause_code(), res4[0])
928 res5 = struct.unpack_from(
929 sctp.cause_unresolvable_addr._PACK_STR, buf)
930 eq_(sctp.cause_unresolvable_addr.cause_code(), res5[0])
932 eq_(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
933 b'\x20\x68\x6f\x73\x74\x00\x00\x00',
934 buf[sctp.cause_unresolvable_addr._MIN_LEN:
935 sctp.cause_unresolvable_addr._MIN_LEN + 16])
938 res6 = struct.unpack_from(
939 sctp.cause_unrecognized_chunk._PACK_STR, buf)
940 eq_(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
942 eq_(b'\xff\x00\x00\x04',
943 buf[sctp.cause_unrecognized_chunk._MIN_LEN:
944 sctp.cause_unrecognized_chunk._MIN_LEN + 4])
947 res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
948 eq_(sctp.cause_invalid_param.cause_code(), res7[0])
952 res8 = struct.unpack_from(
953 sctp.cause_unrecognized_param._PACK_STR, buf)
954 eq_(sctp.cause_unrecognized_param.cause_code(), res8[0])
956 eq_(b'\xff\xff\x00\x04',
957 buf[sctp.cause_unrecognized_param._MIN_LEN:
958 sctp.cause_unrecognized_param._MIN_LEN + 4])
961 res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
962 eq_(sctp.cause_no_userdata.cause_code(), res9[0])
964 eq_(b'\x00\x01\xe2\x40',
965 buf[sctp.cause_no_userdata._MIN_LEN:
966 sctp.cause_no_userdata._MIN_LEN + 4])
969 res10 = struct.unpack_from(
970 sctp.cause_cookie_while_shutdown._PACK_STR, buf)
971 eq_(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
975 res11 = struct.unpack_from(
976 sctp.cause_restart_with_new_addr._PACK_STR, buf)
977 eq_(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
979 eq_(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
980 buf[sctp.cause_restart_with_new_addr._MIN_LEN:
981 sctp.cause_restart_with_new_addr._MIN_LEN + 8])
984 res12 = struct.unpack_from(
985 sctp.cause_user_initiated_abort._PACK_STR, buf)
986 eq_(sctp.cause_user_initiated_abort.cause_code(), res12[0])
988 eq_(b'Key Interrupt.\x00',
989 buf[sctp.cause_user_initiated_abort._MIN_LEN:
990 sctp.cause_user_initiated_abort._MIN_LEN + 15])
993 res13 = struct.unpack_from(
994 sctp.cause_protocol_violation._PACK_STR, buf)
995 eq_(sctp.cause_protocol_violation.cause_code(), res13[0])
997 eq_(b'Unknown reason.\x00',
998 buf[sctp.cause_protocol_violation._MIN_LEN:
999 sctp.cause_protocol_violation._MIN_LEN + 16])
1001 def test_serialize_with_shutdown(self):
1002 self.setUp_with_shutdown()
1003 buf = self._test_serialize()
1004 res = struct.unpack_from(sctp.chunk_shutdown._PACK_STR, buf)
1005 eq_(sctp.chunk_shutdown.chunk_type(), res[0])
1006 eq_(self.flags, res[1])
1007 eq_(self.length, res[2])
1008 eq_(self.tsn_ack, res[3])
1010 def test_serialize_with_shutdown_ack(self):
1011 self.setUp_with_shutdown_ack()
1012 buf = self._test_serialize()
1013 res = struct.unpack_from(sctp.chunk_shutdown_ack._PACK_STR, buf)
1014 eq_(sctp.chunk_shutdown_ack.chunk_type(), res[0])
1015 eq_(self.flags, res[1])
1016 eq_(self.length, res[2])
1018 def test_serialize_with_error(self):
1019 self.setUp_with_error()
1020 buf = self._test_serialize()
1021 res = struct.unpack_from(sctp.chunk_error._PACK_STR, buf)
1022 eq_(sctp.chunk_error.chunk_type(), res[0])
1023 eq_(self.flags, res[1])
1024 eq_(self.length, res[2])
1026 buf = buf[sctp.chunk_error._MIN_LEN:]
1027 res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
1028 eq_(sctp.cause_invalid_stream_id.cause_code(), res1[0])
1033 res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
1034 eq_(sctp.cause_missing_param.cause_code(), res2[0])
1038 for count in range(4):
1039 (tmp, ) = struct.unpack_from(
1040 '!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
1042 eq_(str([sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
1043 sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR]),
1047 res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
1048 eq_(sctp.cause_stale_cookie.cause_code(), res3[0])
1050 eq_(b'\x00\x00\x13\x88',
1051 buf[sctp.cause_stale_cookie._MIN_LEN:
1052 sctp.cause_stale_cookie._MIN_LEN + 4])
1055 res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
1056 eq_(sctp.cause_out_of_resource.cause_code(), res4[0])
1060 res5 = struct.unpack_from(
1061 sctp.cause_unresolvable_addr._PACK_STR, buf)
1062 eq_(sctp.cause_unresolvable_addr.cause_code(), res5[0])
1064 eq_(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
1065 b'\x20\x68\x6f\x73\x74\x00\x00\x00',
1066 buf[sctp.cause_unresolvable_addr._MIN_LEN:
1067 sctp.cause_unresolvable_addr._MIN_LEN + 16])
1070 res6 = struct.unpack_from(
1071 sctp.cause_unrecognized_chunk._PACK_STR, buf)
1072 eq_(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
1074 eq_(b'\xff\x00\x00\x04',
1075 buf[sctp.cause_unrecognized_chunk._MIN_LEN:
1076 sctp.cause_unrecognized_chunk._MIN_LEN + 4])
1079 res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
1080 eq_(sctp.cause_invalid_param.cause_code(), res7[0])
1084 res8 = struct.unpack_from(
1085 sctp.cause_unrecognized_param._PACK_STR, buf)
1086 eq_(sctp.cause_unrecognized_param.cause_code(), res8[0])
1088 eq_(b'\xff\xff\x00\x04',
1089 buf[sctp.cause_unrecognized_param._MIN_LEN:
1090 sctp.cause_unrecognized_param._MIN_LEN + 4])
1093 res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
1094 eq_(sctp.cause_no_userdata.cause_code(), res9[0])
1096 eq_(b'\x00\x01\xe2\x40',
1097 buf[sctp.cause_no_userdata._MIN_LEN:
1098 sctp.cause_no_userdata._MIN_LEN + 4])
1101 res10 = struct.unpack_from(
1102 sctp.cause_cookie_while_shutdown._PACK_STR, buf)
1103 eq_(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
1107 res11 = struct.unpack_from(
1108 sctp.cause_restart_with_new_addr._PACK_STR, buf)
1109 eq_(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
1111 eq_(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
1112 buf[sctp.cause_restart_with_new_addr._MIN_LEN:
1113 sctp.cause_restart_with_new_addr._MIN_LEN + 8])
1116 res12 = struct.unpack_from(
1117 sctp.cause_user_initiated_abort._PACK_STR, buf)
1118 eq_(sctp.cause_user_initiated_abort.cause_code(), res12[0])
1120 eq_(b'Key Interrupt.\x00',
1121 buf[sctp.cause_user_initiated_abort._MIN_LEN:
1122 sctp.cause_user_initiated_abort._MIN_LEN + 15])
1125 res13 = struct.unpack_from(
1126 sctp.cause_protocol_violation._PACK_STR, buf)
1127 eq_(sctp.cause_protocol_violation.cause_code(), res13[0])
1129 eq_(b'Unknown reason.\x00',
1130 buf[sctp.cause_protocol_violation._MIN_LEN:
1131 sctp.cause_protocol_violation._MIN_LEN + 16])
1133 def test_serialize_with_cookie_echo(self):
1134 self.setUp_with_cookie_echo()
1135 buf = self._test_serialize()
1136 res = struct.unpack_from(sctp.chunk_cookie_echo._PACK_STR, buf)
1137 eq_(sctp.chunk_cookie_echo.chunk_type(), res[0])
1138 eq_(self.flags, res[1])
1139 eq_(self.length, res[2])
1141 buf[sctp.chunk_cookie_echo._MIN_LEN:
1142 sctp.chunk_cookie_echo._MIN_LEN + 4])
1144 def test_serialize_with_cookie_ack(self):
1145 self.setUp_with_cookie_ack()
1146 buf = self._test_serialize()
1147 res = struct.unpack_from(sctp.chunk_cookie_ack._PACK_STR, buf)
1148 eq_(sctp.chunk_cookie_ack.chunk_type(), res[0])
1149 eq_(self.flags, res[1])
1150 eq_(self.length, res[2])
1152 def test_serialize_with_ecn_echo(self):
1153 self.setUp_with_ecn_echo()
1154 buf = self._test_serialize()
1155 res = struct.unpack_from(sctp.chunk_ecn_echo._PACK_STR, buf)
1156 eq_(sctp.chunk_ecn_echo.chunk_type(), res[0])
1157 eq_(self.flags, res[1])
1158 eq_(self.length, res[2])
1159 eq_(self.low_tsn, res[3])
1161 def test_serialize_with_cwr(self):
1162 self.setUp_with_cwr()
1163 buf = self._test_serialize()
1164 res = struct.unpack_from(sctp.chunk_cwr._PACK_STR, buf)
1165 eq_(sctp.chunk_cwr.chunk_type(), res[0])
1166 eq_(self.flags, res[1])
1167 eq_(self.length, res[2])
1168 eq_(self.low_tsn, res[3])
1170 def test_serialize_with_shutdown_complete(self):
1171 self.setUp_with_shutdown_complete()
1172 buf = self._test_serialize()
1173 res = struct.unpack_from(
1174 sctp.chunk_shutdown_complete._PACK_STR, buf)
1175 eq_(sctp.chunk_shutdown_complete.chunk_type(), res[0])
1176 flags = self.tflag << 0
1178 eq_(self.length, res[2])
1180 def test_serialize_with_multi_chunks(self):
1181 self.setUp_with_multi_chunks()
1182 buf = self._test_serialize()
1183 res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
1184 eq_(sctp.chunk_sack.chunk_type(), res[0])
1185 eq_(self.s_flags, res[1])
1186 eq_(self.s_length, res[2])
1187 eq_(self.s_tsn_ack, res[3])
1188 eq_(self.s_a_rwnd, res[4])
1189 eq_(self.s_gapack_num, res[5])
1190 eq_(self.s_duptsn_num, res[6])
1192 buf = buf[self.s_length:]
1193 res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
1194 eq_(sctp.chunk_data.chunk_type(), res[0])
1196 (self.d1_unordered << 2) |
1197 (self.d1_begin << 1) |
1199 eq_(d1_flags, res[1])
1200 eq_(self.d1_length, res[2])
1201 eq_(self.d1_tsn, res[3])
1202 eq_(self.d1_sid, res[4])
1203 eq_(self.d1_seq, res[5])
1204 eq_(self.d1_payload_id, res[6])
1205 eq_(self.d1_payload_data,
1206 buf[sctp.chunk_data._MIN_LEN:
1207 sctp.chunk_data._MIN_LEN + 10])
1209 buf = buf[self.d1_length:]
1210 res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
1211 eq_(sctp.chunk_data.chunk_type(), res[0])
1213 (self.d2_unordered << 2) |
1214 (self.d2_begin << 1) |
1216 eq_(d2_flags, res[1])
1217 eq_(self.d2_length, res[2])
1218 eq_(self.d2_tsn, res[3])
1219 eq_(self.d2_sid, res[4])
1220 eq_(self.d2_seq, res[5])
1221 eq_(self.d2_payload_id, res[6])
1222 eq_(self.d2_payload_data,
1223 buf[sctp.chunk_data._MIN_LEN:
1224 sctp.chunk_data._MIN_LEN + 10])
1226 def test_build_sctp(self):
1227 eth = ethernet.ethernet('00:aa:aa:aa:aa:aa', '00:bb:bb:bb:bb:bb',
1229 ip4 = ipv4.ipv4(4, 5, 16, 0, 0, 2, 0, 64, inet.IPPROTO_SCTP, 0,
1230 '192.168.1.1', '10.144.1.1')
1231 pkt = eth / ip4 / self.sc
1233 eth = pkt.get_protocol(ethernet.ethernet)
1235 eq_(eth.ethertype, ether.ETH_TYPE_IP)
1237 ip4 = pkt.get_protocol(ipv4.ipv4)
1239 eq_(ip4.proto, inet.IPPROTO_SCTP)
1241 sc = pkt.get_protocol(sctp.sctp)
1245 def test_build_sctp_with_data(self):
1246 self.setUp_with_data()
1247 self.test_build_sctp()
1249 def test_build_sctp_with_init(self):
1250 self.setUp_with_init()
1251 self.test_build_sctp()
1253 def test_build_sctp_with_init_ack(self):
1254 self.setUp_with_init_ack()
1255 self.test_build_sctp()
1257 def test_build_sctp_with_sack(self):
1258 self.setUp_with_sack()
1259 self.test_build_sctp()
1261 def test_build_sctp_with_heartbeat(self):
1262 self.setUp_with_heartbeat()
1263 self.test_build_sctp()
1265 def test_build_sctp_with_heartbeat_ack(self):
1266 self.setUp_with_heartbeat_ack()
1267 self.test_build_sctp()
1269 def test_build_sctp_with_abort(self):
1270 self.setUp_with_abort()
1271 self.test_build_sctp()
1273 def test_build_sctp_with_shutdown(self):
1274 self.setUp_with_shutdown()
1275 self.test_build_sctp()
1277 def test_build_sctp_with_shutdown_ack(self):
1278 self.setUp_with_shutdown_ack()
1279 self.test_build_sctp()
1281 def test_build_sctp_with_error(self):
1282 self.setUp_with_error()
1283 self.test_build_sctp()
1285 def test_build_sctp_with_cookie_echo(self):
1286 self.setUp_with_cookie_echo()
1287 self.test_build_sctp()
1289 def test_build_sctp_with_cookie_ack(self):
1290 self.setUp_with_cookie_ack()
1291 self.test_build_sctp()
1293 def test_build_sctp_with_ecn_echo(self):
1294 self.setUp_with_ecn_echo()
1295 self.test_build_sctp()
1297 def test_build_sctp_with_cwr(self):
1298 self.setUp_with_cwr()
1299 self.test_build_sctp()
1301 def test_build_sctp_with_shutdown_complete(self):
1302 self.setUp_with_shutdown_complete()
1303 self.test_build_sctp()
1305 def tset_build_sctp_with_multi_chunks(self):
1306 self.setUp_with_multi_chunks()
1307 self.test_build_sctp()
1309 def test_to_string(self):
1310 sctp_values = {'src_port': self.src_port,
1311 'dst_port': self.dst_port,
1314 'chunks': self.chunks}
1315 _sctp_str = ','.join(['%s=%s' % (k, sctp_values[k])
1316 for k, _ in inspect.getmembers(self.sc)
1317 if k in sctp_values])
1318 sctp_str = '%s(%s)' % (sctp.sctp.__name__, _sctp_str)
1320 eq_(str(self.sc), sctp_str)
1321 eq_(repr(self.sc), sctp_str)
1323 def test_to_string_with_data(self):
1324 self.setUp_with_data()
1325 self.test_to_string()
1327 def test_to_string_with_init(self):
1328 self.setUp_with_init()
1329 self.test_to_string()
1331 def test_to_string_with_init_ack(self):
1332 self.setUp_with_init_ack()
1333 self.test_to_string()
1335 def test_to_string_with_sack(self):
1336 self.setUp_with_sack()
1337 self.test_to_string()
1339 def test_to_string_with_heartbeat(self):
1340 self.setUp_with_heartbeat()
1341 self.test_to_string()
1343 def test_to_string_with_heartbeat_ack(self):
1344 self.setUp_with_heartbeat_ack()
1345 self.test_to_string()
1347 def test_to_string_with_abort(self):
1348 self.setUp_with_abort()
1349 self.test_to_string()
1351 def test_to_string_with_shutdown(self):
1352 self.setUp_with_shutdown()
1353 self.test_to_string()
1355 def test_to_string_with_shutdown_ack(self):
1356 self.setUp_with_shutdown_ack()
1357 self.test_to_string()
1359 def test_to_string_with_error(self):
1360 self.setUp_with_error()
1361 self.test_to_string()
1363 def test_to_string_with_cookie_echo(self):
1364 self.setUp_with_cookie_echo()
1365 self.test_to_string()
1367 def test_to_string_with_cookie_ack(self):
1368 self.setUp_with_cookie_ack()
1369 self.test_to_string()
1371 def test_to_string_with_ecn_echo(self):
1372 self.setUp_with_ecn_echo()
1373 self.test_to_string()
1375 def test_to_string_with_cwr(self):
1376 self.setUp_with_cwr()
1377 self.test_to_string()
1379 def test_to_string_with_shutdown_complete(self):
1380 self.setUp_with_shutdown_complete()
1381 self.test_to_string()
1383 def test_to_string_with_multi_chunks(self):
1384 self.setUp_with_multi_chunks()
1385 self.test_to_string()
1387 def test_json(self):
1388 jsondict = self.sc.to_jsondict()
1389 sc = sctp.sctp.from_jsondict(jsondict['sctp'])
1390 eq_(str(self.sc), str(sc))
1392 def test_json_with_data(self):
1393 self.setUp_with_data()
1396 def test_json_with_init(self):
1397 self.setUp_with_init()
1400 def test_json_with_init_ack(self):
1401 self.setUp_with_init_ack()
1404 def test_json_with_sack(self):
1405 self.setUp_with_sack()
1408 def test_json_with_heartbeat(self):
1409 self.setUp_with_heartbeat()
1412 def test_json_with_heartbeat_ack(self):
1413 self.setUp_with_heartbeat_ack()
1416 def test_json_with_abort(self):
1417 self.setUp_with_abort()
1420 def test_json_with_shutdown(self):
1421 self.setUp_with_shutdown()
1424 def test_json_with_shutdown_ack(self):
1425 self.setUp_with_shutdown_ack()
1428 def test_json_with_error(self):
1429 self.setUp_with_error()
1432 def test_json_with_cookie_echo(self):
1433 self.setUp_with_cookie_echo()
1436 def test_json_with_cookie_ack(self):
1437 self.setUp_with_cookie_ack()
1440 def test_json_with_ecn_echo(self):
1441 self.setUp_with_ecn_echo()
1444 def test_json_with_cwr(self):
1445 self.setUp_with_cwr()
1448 def test_json_with_shutdown_complete(self):
1449 self.setUp_with_shutdown_complete()
1452 def test_json_with_multi_chunks(self):
1453 self.setUp_with_multi_chunks()