Changeset 3608 for branch/UMPA/umpa/protocols/TCP.py
- Timestamp:
- 08/23/08 16:48:00 (5 years ago)
- Files:
-
- 1 modified
-
branch/UMPA/umpa/protocols/TCP.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branch/UMPA/umpa/protocols/TCP.py
r3479 r3608 20 20 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 21 22 """ 23 This module contains TCP (Transmission Control Protocol) protocol 24 implementation. 25 """ 26 22 27 from umpa.protocols import _consts 23 28 from umpa.protocols import _fields … … 28 33 29 34 class _HPort(_fields.EnumField): 35 """ 36 TCP uses the notion of port numbers to identify sending and receiving 37 application end-points on a host, or Internet sockets. 38 """ 39 30 40 bits = 16 31 41 auto = False … … 324 334 325 335 class _HSequenceNumber(_fields.IntField): 326 """The sequence number of the first data octet in this segment (except 336 """ 337 The sequence number of the first data octet in this segment (except 327 338 when SYN is present). 328 339 329 340 See RFC 793 for more. 330 341 """ 342 331 343 bits = 32 332 344 auto = True 345 333 346 def _generate_value(self): 347 """ 348 Generate value for undefined field yet. 349 350 @return: auto-generated value of the field. 351 """ 352 334 353 # TODO: implemention real auto-filling here ;) 335 354 # otherwise we can simple return 0 … … 337 356 338 357 class _HAcknowledgmentNumber(_fields.IntField): 339 """If the ACK control bit is set this field contains the value of the 358 """ 359 If the ACK control bit is set this field contains the value of the 340 360 next sequence number the sender of the segment is expecting to receive. 341 361 342 362 See RFC 793 for more. 343 363 """ 364 344 365 bits = 32 345 366 auto = True 367 346 368 def _generate_value(self): 369 """ 370 Generate value for undefined field yet. 371 372 @return: auto-generated value of the field. 373 """ 374 347 375 # TODO: implemention real auto-filling here ;) 348 376 # otherwise we can simple return 0 … … 350 378 351 379 class _HDataOffset(_fields.SpecialIntField): 352 """The number of 32 bit words in the TCP Header. This indicates where 380 """ 381 The number of 32 bit words in the TCP Header. This indicates where 353 382 the data begins. 354 383 355 384 See RFC 793 for more. 356 385 """ 386 357 387 bits = 4 358 388 auto = True 389 359 390 def _generate_value(self): 391 """ 392 Generate value for undefined field yet. 393 394 @return: auto-generated value of the field. 395 """ 396 360 397 # returns in 32-bits units 361 398 return 5 + self._tmp_value / 32 # 5 is a minimum value 362 399 363 400 class _HReserved(_fields.IntField): 364 """Reserved for future use. 401 """ 402 Reserved for future use. 365 403 366 404 See RFC 793 for more. 367 405 """ 406 368 407 bits = 6 369 408 auto = True 409 370 410 def _generate_value(self): 411 """ 412 Generate value for undefined field yet. 413 414 @return: auto-generated value of the field. 415 """ 416 371 417 return 0 372 418 373 419 class _HWindow(_fields.IntField): 374 """The number of data octets beginning with the one indicated in the 420 """ 421 The number of data octets beginning with the one indicated in the 375 422 acknowledgment field which the sender of this segment is willing to accept. 376 423 377 424 See RFC 793 for more. 378 425 """ 426 379 427 bits = 16 380 428 auto = True 429 381 430 def _generate_value(self): 431 """ 432 Generate value for undefined field yet. 433 434 @return: auto-generated value of the field. 435 """ 436 382 437 # TODO: implemention real auto-filling here ;) 383 438 # otherwise we can simple return 0 … … 385 440 386 441 class _HUrgentPointer(_fields.IntField): 387 """This field communicates the current value of the urgent pointer as a 442 """ 443 This field communicates the current value of the urgent pointer as a 388 444 positive offset from the sequence number in this segment. 389 445 390 446 See RFC 793 for more. 391 447 """ 448 392 449 bits = 16 393 450 auto = True 451 394 452 def _generate_value(self): 453 """ 454 Generate value for undefined field yet. 455 456 @return: auto-generated value of the field. 457 """ 458 395 459 # TODO: implemention real auto-filling here ;) 396 460 # otherwise we can simple return 0 … … 398 462 399 463 class TCP(_protocols.Protocol): 400 """This is Transmission Control Protocol. 464 """ 465 Transmission Control Protocol implementation. 466 401 467 It the most common protocol in the Internet on fourth layer 402 468 of the OSI model. 403 469 """ 470 404 471 layer = 4 # layer of the OSI 405 472 protocol_id = _consts.PROTOCOL_TCP … … 412 479 413 480 def __init__(self, **kw): 481 """ 482 Create a new TCP(). 483 484 @param **kw: pass to super-constructor. 485 """ 486 414 487 control_bits = ('urg', 'ack', 'psh', 'rst', 'syn', 'fin') 415 488 control_bits_predefined = dict.fromkeys(control_bits, 0) … … 450 523 451 524 def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 525 """ 526 Handle with fields before calling fillout() for them. 527 528 Set Padding field and calculate header length. 529 530 @type raw_value: C{int} 531 @param raw_value: currently raw value for the packet. 532 533 @type bit: C{int} 534 @param bit: currently length of the protocol. 535 536 @type protocol_container: C{tuple} 537 @param protocol_container: tuple of protocols included in the packet. 538 539 @type protocol_bits: C{int} 540 @param protocol_bits: currently length of the packet. 541 542 @return: C{raw_value, bit} 543 """ 544 452 545 # Padding 453 546 self._get_field('_padding')._tmp_value = \ … … 461 554 462 555 def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 556 """ 557 Handle with fields after calling fillout() for them. 558 559 Calculate header checksum with new instance of PseudoHeader object. 560 561 @type raw_value: C{int} 562 @param raw_value: currently raw value for the packet. 563 564 @type bit: C{int} 565 @param bit: currently length of the protocol. 566 567 @type protocol_container: C{tuple} 568 @param protocol_container: tuple of protocols included in the packet. 569 570 @type protocol_bits: C{int} 571 @param protocol_bits: currently length of the packet. 572 573 @return: C{raw_value, bit} 574 """ 575 463 576 # rev_offset it the offset from the right side 464 577 cksum_rev_offset = bit - self.get_offset('_checksum') - \
