Beispiel #1
0
  def test_00(self):
    """
    SOME/IP-SD Subscribe eventgroup
    """
    # build SOME/IP-SD packet
    sdp = sd.SD()

    sdp.flags = 0x00
    sdp.entry_array = [
      sd.SDEntry_EventGroup(srv_id=0x1111,n_opt_1=1,inst_id=0x2222,major_ver=0x03,eventgroup_id=0x04,cnt=0x0,ttl=0x05)]
    sdp.option_array = [
      sd.SDOption_IP4_EndPoint(addr="192.168.0.1",l4_proto=0x11,port=0xd903)]

    # build request and reply packages
    p = Ether()/IP(src=ETH_IFACE_A.ip,dst=ETH_IFACE_B.ip)/UDP(sport=ETH_IFACE_A.port,dport=ETH_IFACE_B.port)/sdp.getSomeip(True)
    r = Ether()/IP(src=ETH_IFACE_B.ip,dst=ETH_IFACE_A.ip)/UDP(sport=ETH_IFACE_B.port,dport=ETH_IFACE_A.port)/sdp.getSomeip(True)
    r['SD'].entry_array[0].type = sd.SDEntry_EventGroup.TYPE_EVTGRP_SUBSCRIBE_ACK

    # 'dummy-ly' use a couple of threads to emulate traffic
    t_send = threading.Thread(name='sender',target=self._test_00_sender,args=(p,))
    t_rcv = threading.Thread(name='receiver',target=self._test_00_rcver,args=(2,r,))
    t_send.start()
    t_rcv.start()
    t_send.join()
    t_rcv.join()
Beispiel #2
0
def test_0c_SD():
    p = sd.SD()

    # length of package without entries nor options
    assert (len(binascii.hexlify(bytes(p))) / 2 == 12)

    # some Entries to array and size check
    p.setEntryArray([sd.SDEntry_Service(), sd.SDEntry_EventGroup()])
    assert (struct.unpack("!L", bytes(p)[4:8])[0] == 32)
    # make sure individual entry added as list
    p.setEntryArray(sd.SDEntry_Service())
    assert (isinstance(p.entry_array, list))
    assert (len(p.entry_array) == 1)
    # empty entry array
    p.setEntryArray([])
    assert (struct.unpack("!L", bytes(p)[4:8])[0] == 0)

    # some Options to array and size check
    p.setOptionArray([sd.SDOption_IP4_EndPoint(), sd.SDOption_IP4_EndPoint()])
    assert (struct.unpack("!L", bytes(p)[8:12])[0] == 24)
    # make sure individual option added as list
    p.setOptionArray(sd.SDOption_IP4_EndPoint())
    assert (isinstance(p.option_array, list))
    assert (len(p.option_array) == 1)
    # empty option array
    p.setOptionArray([])
    assert (struct.unpack("!L", bytes(p)[8:12])[0] == 0)

    # some Entries&Options to array and size check
    p.setEntryArray([sd.SDEntry_Service(), sd.SDEntry_EventGroup()])
    p.setOptionArray([sd.SDOption_IP4_EndPoint(), sd.SDOption_IP4_EndPoint()])
    assert (struct.unpack("!L", bytes(p)[4:8])[0] == 32)
    assert (struct.unpack("!L", bytes(p)[40:44])[0] == 24)
Beispiel #3
0
    def test_0c_SD(self):
        p = sd.SD()

        # length of package without entries nor options
        self.assertTrue(len(binascii.hexlify(str(p))) / 2 == 12)

        # some Entries to array and size check
        p.setEntryArray([sd.SDEntry_Service(), sd.SDEntry_EventGroup()])
        self.assertTrue(struct.unpack("!L", str(p)[4:8])[0] == 32)
        p.setEntryArray([])
        self.assertTrue(struct.unpack("!L", str(p)[4:8])[0] == 0)

        # some Options to array and size check
        p.setOptionArray(
            [sd.SDOption_IP4_EndPoint(),
             sd.SDOption_IP4_EndPoint()])
        self.assertTrue(struct.unpack("!L", str(p)[8:12])[0] == 24)
        p.setOptionArray([])
        self.assertTrue(struct.unpack("!L", str(p)[8:12])[0] == 0)

        # some Entries&Options to array and size check
        p.setEntryArray([sd.SDEntry_Service(), sd.SDEntry_EventGroup()])
        p.setOptionArray(
            [sd.SDOption_IP4_EndPoint(),
             sd.SDOption_IP4_EndPoint()])
        self.assertTrue(struct.unpack("!L", str(p)[4:8])[0] == 32)
        self.assertTrue(struct.unpack("!L", str(p)[40:44])[0] == 24)
    def test_01(self):
        """ SOME/IP-SD : Example for a serialization protocol, 6.7.3.7 Example of SOME/IP-SD PDU."""
        # build SOME/IP-SD packet
        sdp = sd.SD()

        sdp.flags = 0x80
        sdp.entry_array = [
            sd.SDEntry_Service(type=sd.SDEntry_Service.TYPE_SRV_FINDSERVICE,
                               srv_id=0x4711,
                               inst_id=0xffff,
                               major_ver=0xff,
                               ttl=3600,
                               minor_ver=0xffffffff),
            sd.SDEntry_Service(type=sd.SDEntry_Service.TYPE_SRV_OFFERSERVICE,
                               n_opt_1=1,
                               srv_id=0x1234,
                               inst_id=0x0001,
                               major_ver=0x01,
                               ttl=3,
                               minor_ver=0x00000032)
        ]
        sdp.option_array = [
            sd.SDOption_IP4_EndPoint(addr="192.168.0.1",
                                     l4_proto=0x11,
                                     port=0xd903)
        ]

        # SEND MESSAGE
        sip = Ether() / IP(src=ETH_IFACE_B.ip, dst=ETH_IFACE_A.ip) / UDP(
            sport=ETH_IFACE_B.port,
            dport=ETH_IFACE_A.port) / sdp.getSomeip(stacked=True)
        sendp(sip, iface=ETH_IFACE_B.name)
Beispiel #5
0
def test_0b_SD_GetSomeipPacket():
    p_sd = sd.SD()

    sd_len = binascii.hexlify(bytes(p_sd))

    p_someip = p_sd.getSomeip()
    assert (len(binascii.hexlify(bytes(p_someip))) / 2,
            someip.SOMEIP._OVERALL_LEN_NOPAYLOAD)

    p = p_sd.getSomeip(stacked=True)
    assert (len(binascii.hexlify(bytes(p))) / 2,
            someip.SOMEIP._OVERALL_LEN_NOPAYLOAD + 12)
Beispiel #6
0
    def test_0a_SD_Flags(self):
        p = sd.SD()

        p.setFlag("REBOOT", 1)
        self.assertTrue(p.flags == 0x80)
        p.setFlag("REBOOT", 0)
        self.assertTrue(p.flags == 0x00)
        p.setFlag("UNICAST", 1)
        self.assertTrue(p.flags == 0x40)
        p.setFlag("UNICAST", 0)
        self.assertTrue(p.flags == 0x00)

        p.setFlag("REBOOT", 1)
        p.setFlag("UNICAST", 1)
        self.assertTrue(p.flags == 0xc0)
Beispiel #7
0
    def test_00_SOMEIPSD(self):
        p_sd = sd.SD()
        p_someip = p_sd.getSomeip()

        # check SOME/IP-SD defaults
        self.assertTrue(binascii.hexlify(str(p_someip.msg_id)) == "ffff8100")
        self.assertTrue(p_someip.msg_type == someip.SOMEIP.TYPE_NOTIFICATION)

        # length of SOME/IP-SD without entries nor options
        p = p_someip / p_sd
        self.assertTrue(struct.unpack("!L", str(p)[4:8])[0] == 20)

        # check SOME/IP-SD lengths (note : lengths calculated on package construction)
        del (p)
        p_sd.setEntryArray([sd.SDEntry_Service()])
        p_sd.setOptionArray([sd.SDOption_IP4_EndPoint()])
        p = p_someip / p_sd
        self.assertTrue(struct.unpack("!L", str(p)[4:8])[0] == 48)
Beispiel #8
0
def test_0a_SD_Flags():
    p = sd.SD()

    p.setFlag("REBOOT", 1)
    assert (p.flags == 0x80)
    assert (p.getFlag("REBOOT") == 1)
    p.setFlag("REBOOT", 0)
    assert (p.flags == 0x00)
    assert (p.getFlag("REBOOT") == 0)
    p.setFlag("UNICAST", 1)
    assert (p.flags == 0x40)
    assert (p.getFlag("UNICAST") == 1)
    p.setFlag("UNICAST", 0)
    assert (p.flags == 0x00)
    assert (p.getFlag("UNICAST") == 0)

    p.setFlag("REBOOT", 1)
    p.setFlag("UNICAST", 1)
    assert (p.flags == 0xc0)
    assert (p.getFlag("REBOOT") == 1)
    assert (p.getFlag("UNICAST") == 1)

    # non-existing Flag
    assert (p.getFlag('NON_EXISTING_FLAG') == None)