AUTOSAR SOME/IP Service Discovery: Ruby parsing library

The main tasks of the Service Discovery Protocol are communicating the availability of functional entities called services in the in-vehicle communication as well as controlling the send behavior of event messages. This allows sending only event messages to receivers requiring them (Publish/Subscribe). The solution described here is also known as SOME/IP-SD (Scalable service-Oriented MiddlewarE over IP - Service Discovery).

KS implementation details

License: CC0-1.0
Minimal Kaitai Struct required: 0.9

This page hosts a formal specification of AUTOSAR SOME/IP Service Discovery using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Runtime library

All parsing code for Ruby generated by Kaitai Struct depends on the Ruby runtime library. You have to install it before you can parse data.

The Ruby runtime library can be installed from RubyGems:

gem install kaitai-struct

Code

Parse a local file and get structure in memory:

data = SomeIpSd.from_file("path/to/local/file.AUTOSAR SOME/IP Service Discovery")

Or parse structure from a string of bytes:

bytes = "\x00\x01\x02..."
data = SomeIpSd.new(Kaitai::Struct::Stream.new(bytes))

After that, one can get various attributes from the structure by invoking getter methods like:

data.flags # => The SOME/IP-SD Header shall start with an 8 Bit field called flags.

Ruby source code to parse AUTOSAR SOME/IP Service Discovery

some_ip_sd.rb

# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

require 'kaitai/struct/struct'

unless Gem::Version.new(Kaitai::Struct::VERSION) >= Gem::Version.new('0.9')
  raise "Incompatible Kaitai Struct Ruby API: 0.9 or later is required, but you have #{Kaitai::Struct::VERSION}"
end


##
# The main tasks of the Service Discovery Protocol are communicating the
# availability of functional entities called services in the in-vehicle
# communication as well as controlling the send behavior of event messages.
# This allows sending only event messages to receivers requiring them (Publish/Subscribe).
# The solution described here is also known as SOME/IP-SD
# (Scalable service-Oriented MiddlewarE over IP - Service Discovery).
# @see https://www.autosar.org/fileadmin/user_upload/standards/foundation/19-11/AUTOSAR_PRS_SOMEIPServiceDiscoveryProtocol.pdf Source
class SomeIpSd < Kaitai::Struct::Struct
  def initialize(_io, _parent = nil, _root = self)
    super(_io, _parent, _root)
    _read
  end

  def _read
    @flags = SdFlags.new(@_io, self, @_root)
    @reserved = @_io.read_bytes(3)
    @len_entries = @_io.read_u4be
    @_raw_entries = @_io.read_bytes(len_entries)
    _io__raw_entries = Kaitai::Struct::Stream.new(@_raw_entries)
    @entries = SomeIpSdEntries.new(_io__raw_entries)
    @len_options = @_io.read_u4be
    @_raw_options = @_io.read_bytes(len_options)
    _io__raw_options = Kaitai::Struct::Stream.new(@_raw_options)
    @options = SomeIpSdOptions.new(_io__raw_options)
    self
  end

  ##
  # @see '' AUTOSAR_PRS_SOMEIPServiceDiscoveryProtocol.pdf - Figure 4.3
  class SdFlags < Kaitai::Struct::Struct
    def initialize(_io, _parent = nil, _root = self)
      super(_io, _parent, _root)
      _read
    end

    def _read
      @reboot = @_io.read_bits_int_be(1) != 0
      @unicast = @_io.read_bits_int_be(1) != 0
      @initial_data = @_io.read_bits_int_be(1) != 0
      @reserved = @_io.read_bits_int_be(5)
      self
    end
    attr_reader :reboot
    attr_reader :unicast
    attr_reader :initial_data
    attr_reader :reserved
  end

  ##
  # The SOME/IP-SD Header shall start with an 8 Bit field called flags.
  attr_reader :flags
  attr_reader :reserved
  attr_reader :len_entries
  attr_reader :entries
  attr_reader :len_options
  attr_reader :options
  attr_reader :_raw_entries
  attr_reader :_raw_options
end