{"action":"created","issue":{"url":"https://api.github.com/repos/kbandla/dpkt/issues/309","repository_url":"https://api.github.com/repos/kbandla/dpkt","labels_url":"https://api.github.com/repos/kbandla/dpkt/issues/309/labels{/name}","comments_url":"https://api.github.com/repos/kbandla/dpkt/issues/309/comments","events_url":"https://api.github.com/repos/kbandla/dpkt/issues/309/events","html_url":"https://github.com/kbandla/dpkt/pull/309","id":192211508,"number":309,"title":"SCTP Parser Enhancement","user":{"login":"wmnsk","id":6134010,"avatar_url":"https://avatars.githubusercontent.com/u/6134010?v=3","gravatar_id":"","url":"https://api.github.com/users/wmnsk","html_url":"https://github.com/wmnsk","followers_url":"https://api.github.com/users/wmnsk/followers","following_url":"https://api.github.com/users/wmnsk/following{/other_user}","gists_url":"https://api.github.com/users/wmnsk/gists{/gist_id}","starred_url":"https://api.github.com/users/wmnsk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmnsk/subscriptions","organizations_url":"https://api.github.com/users/wmnsk/orgs","repos_url":"https://api.github.com/users/wmnsk/repos","events_url":"https://api.github.com/users/wmnsk/events{/privacy}","received_events_url":"https://api.github.com/users/wmnsk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-11-29T07:53:47Z","updated_at":"2016-11-29T15:00:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/kbandla/dpkt/pulls/309","html_url":"https://github.com/kbandla/dpkt/pull/309","diff_url":"https://github.com/kbandla/dpkt/pull/309.diff","patch_url":"https://github.com/kbandla/dpkt/pull/309.patch"},"body":"# SCTP Parser Enhancement\r\n\r\nImplemented more precise decoding feature for SCTP. Please review :-)\r\n\r\n### Problem\r\n\r\nCurrently sctp.py can parse only;\r\n\r\n* SCTP Common Headers\r\n  * Source Port\r\n  * Destination Port\r\n  * Verification Tag\r\n  * Checksum\r\n* SCTP Chunk Headers\r\n  * Chunk Type\r\n  * Chunk Flags\r\n  * Chunk Length\r\n\r\nThe problem here is that it's hard to reach values in upper layers like diameter, as some more header fields exist in DATA type of SCTP chunk.  \r\n\r\n### What's done\r\n\r\nThis enhancement includes the parser for **ALL fields** in each type defined in [RFC4960](https://tools.ietf.org/html/rfc4960).! Now we can get the values in upper layer simply by writing like;\r\n\r\n\r\n```python\r\nif isinstance(ip.data, dpkt.sctp.SCTP):\r\n  sctp = ip.data\r\n  for i in xrange(len(sctp.chunks))\r\n    sctpchunk = sctp.chunks[i]\r\n      if isinstance(sctpchunk, dpkt.sctp.ChunkData):\r\n        diameter = sctpchunk.data  # <= GOT IT! Let's start decoding with diameter.py!\r\n      else:\r\n        pass\r\n```\r\n\r\nOther types are also supported. For example, we can count the number of **HEARTBEAT** and **HEARTBEAT_ACK**.\r\n\r\n```python\r\nif isinstance(ip.data, dpkt.sctp.SCTP):\r\n  sctp = ip.data\r\n  hb_count = 0\r\n  hba_count = 0\r\n  for i in xrange(len(sctp.chunks))\r\n    sctpchunk = sctp.chunks[i]\r\n      if isinstance(sctpchunk, dpkt.sctp.ChunkHeartbeat):\r\n        hb_count += 1\r\n        print 'HB Found. HB INFO: %s' % binascii.hexlify(sctpchunk.hb_info)\r\n      elif isinstance(sctpchunk, dpkt.sctp.ChunkHeartbeat):\r\n        hba_count += 1\r\n        print 'HBAck Found. HB INFO: %s' % binascii.hexlify(sctpchunk.hb_info)\r\n      else:\r\n        pass\r\n```\r\n\r\n### Changes\r\n\r\nImplemented the subclasses for each type of chunks, referring [RFC4960](https://tools.ietf.org/html/rfc4960).  \r\nThe fields to be decoded are describled in the docstring of each subclass. Here's the example for **DATA** type.\r\n\r\n\r\n```\r\nEXAMPLE: Chunk Type DATA from RFC.\r\n\r\n        0                   1                   2                   3\r\n        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |     Source Port Number        |     Destination Port Number   |\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |                      Verification Tag                         |\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |                           Checksum                            |\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |   Type = 0    | Reserved|U|B|E|    Length                     |  # ^ fields supported currently\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |                              TSN                              |  # v Implemented by this commit\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |      Stream Identifier S      |   Stream Sequence Number n    |\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       |                  Payload Protocol Identifier                  |\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n       \\                                                               \\\r\n       /                 User Data (seq n of Stream S)                 /\r\n       \\                                                               \\\r\n       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n\r\n```\r\n\r\n```python\r\n# Subclass for type DATA.\r\n\r\nclass ChunkData(Chunk):\r\n    \"\"\"SCTP DATA Chunk.\r\n    This Class is to handle the 'DATA' type of SCTP Chunk.\r\n    Supported fields are;\r\n     - Chunk type\r\n     - Chunk flags\r\n     - Chunk length\r\n     - Transmission sequence number\r\n     - Stream identifier\r\n     - Stream sequence number\r\n     - Payload protocol identifier\r\n\r\n    TODO: Longer class information....\r\n\r\n    Attributes:\r\n        __hdr__: Generic Chunk Header fields of SCTP.\r\n        __hdr_spec__: Type-specific Chunk Header fields of SCTP.\r\n        TODO.\r\n    \"\"\"\r\n    __hdr_spec__ = (\r\n        ('tsn', 'I', 0),\r\n        ('stream_id', 'H', 0),\r\n        ('stream_seq', 'H', 0),\r\n        ('proto_id', 'I', 0)\r\n    )\r\n    __hdr__ = Chunk.__hdr__ + __hdr_spec__\r\n\r\n    def unpack(self, buf):\r\n        super(ChunkData, self).unpack(buf)\r\n        self.data = self.data[:self.len - self.__hdr_len__]\r\n\r\n```\r\n\r\nThese subclasses are inherited from 'Chunk' class which has currently been implemented.  \r\n`__hdr_spec__` is the type-specific fields(chunk headers), and appended to `__hdr__`.  \r\nIf the type has no additional header, `__hdr__` is exactly same as the one in Chunk class.\r\n\r\n### NOTICE\r\n\r\n* The test methods are done in the same manner as before to keep it simple, but not testing all the subclasses newly implemented, as the sample SCTP byte arrays are not enough.\r\n* Packet creation has not implemented fully in this commit, which is the same in current implementation.\r\n"},"comment":{"url":"https://api.github.com/repos/kbandla/dpkt/issues/comments/263593006","html_url":"https://github.com/kbandla/dpkt/pull/309#issuecomment-263593006","issue_url":"https://api.github.com/repos/kbandla/dpkt/issues/309","id":263593006,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2016-11-29T15:00:02Z","updated_at":"2016-11-29T15:00:02Z","body":"\n[![Coverage Status](https://coveralls.io/builds/9044292/badge)](https://coveralls.io/builds/9044292)\n\nCoverage increased (+0.1%) to 85.107% when pulling **381f9047aa7099e7ba0578144a1c87911bb5e6bd on wmnsk:sctp_enhancement** into **5265b149f3e19c32f054bbe1657724871a5c1105 on kbandla:master**.\n"}}
{"actor":{"display_login":"coveralls"}}