Ejemplo n.º 1
0
    def get_arc(self, arc):
        """Returns sc-addr of arc element begin
        @param arc sc-addr of arc to get beign
        @return If there are no any errors, then returns sc-addr of arc begin; 
        otherwise returns None
        """
        # send request
        params = struct.pack("=HH", arc.seg, arc.offset)
        data = struct.pack("=BBII", SctpCommandType.SCTP_CMD_GET_ARC, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack("=BIBI", data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack("=HH", data)

        addr2 = ScAddr(0, 0)
        data = self.receiveData(4)
        addr2.seg, addr2.offset = struct.unpack("=HH", data)

        return (addr, addr2)
Ejemplo n.º 2
0
    def get_arc(self, arc):
        """Returns sc-addr of arc element begin
        @param arc sc-addr of arc to get beign
        @return If there are no any errors, then returns sc-addr of arc begin; 
        otherwise returns None
        """
        # send request
        params = struct.pack('=HH', arc.seg, arc.offset)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_GET_ARC, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)
        
        addr2 = ScAddr(0, 0)
        data = self.receiveData(4)
        addr2.seg, addr2.offset = struct.unpack('=HH', data)

        return (addr, addr2)
Ejemplo n.º 3
0
    def find_links_with_content(self, data):
        """Find sc-links with specified content
        @param data: Content data for search
        @return: Returns list of sc-addrs of founded sc-links. If there are any error, then return None
        """
        # send request
        params = struct.pack('=I%ds' % len(data), len(data), data)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_FIND_LINKS, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize < 4:
            return None

        res = []
        data = self.receiveData(resSize)
        resCount = struct.unpack('=I', data[:4])[0]
        for i in xrange(resCount):
            addr = ScAddr(0, 0)
            data = data[4:]
            addr.seg, addr.offset = struct.unpack('=HH', data)
            res.append(addr)

        return res
Ejemplo n.º 4
0
    def create_arc(self, arc_type, begin_addr, end_addr):
        """Create new arc in sc-memory with specified type and begin, end elements
        @param arc_type: Type of sc-arc
        @param begin_addr: sc-addr of begin arc element
        @param end_addr: sc-addr of end arc element
        @return: If sc-arc was created, then returns it sc-addr; otherwise return None
        """
        # send request
        params = struct.pack('=HHHHH', arc_type, begin_addr.seg, begin_addr.offset, end_addr.seg, end_addr.offset)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_ARC, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 5
0
    def find_links_with_content(self, data):
        """Find sc-links with specified content
        @param data: Content data for search
        @return: Returns list of sc-addrs of founded sc-links. If there are any error, then return None
        """
        # send request
        params = struct.pack('=I%ds' % len(data), len(data), data)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_FIND_LINKS, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize < 4:
            return None

        res = []
        data = self.receiveData(resSize)
        resCount = struct.unpack('=I', data[:4])[0]
        for i in range(resCount):
            addr = ScAddr(0, 0)
            data = data[4:]
            addr.seg, addr.offset = struct.unpack('=HH', data[:4])
            res.append(addr)

        return res
Ejemplo n.º 6
0
    def create_arc(self, arc_type, begin_addr, end_addr):
        """Create new arc in sc-memory with specified type and begin, end elements
        @param arc_type: Type of sc-arc
        @param begin_addr: sc-addr of begin arc element
        @param end_addr: sc-addr of end arc element
        @return: If sc-arc was created, then returns it sc-addr; otherwise return None
        """
        # send request
        params = struct.pack('=HHHHH', arc_type, begin_addr.seg, begin_addr.offset, end_addr.seg, end_addr.offset)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_ARC, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 7
0
    def find_element_by_system_identifier(self, idtf_data):
        """Find sc-element by it system identifier
        @param idtf_data: Identifier data for search
        @return: Returns sc-addrs of founded sc-element.
        If there are any error or sc-element wasn't found, then return None
        """
        # send request
        params = struct.pack('=I%ds' % len(idtf_data), len(idtf_data),
                             idtf_data)
        data = struct.pack('=BBII',
                           SctpCommandType.SCTP_CMD_FIND_ELEMENT_BY_SYSITDF, 0,
                           0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize < 4:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 8
0
    def create_node(self, el_type):
        """Create new sc-node in memory with specified type
        @param el_type: Type of node that would be created
        @return: If sc-node was created, then returns it sc-addr; otherwise return None
        """

        # send request
        params = struct.pack('=H', el_type)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_NODE, 0, 0,
                           len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 9
0
    def create_link(self):
        """Create new sc-link in memory
        @return: If sc-link was created, then returns it sc-addr; otherwise return None
        """
        # send request
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_LINK, 0, 0, 0)
        alldata = data

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 10
0
    def create_link(self):
        """Create new sc-link in memory
        @return: If sc-link was created, then returns it sc-addr; otherwise return None
        """
        # send request
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_LINK, 0, 0, 0)
        alldata = data

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 11
0
    def find_element_by_system_identifier(self, idtf_data):
        """Find sc-element by it system identifier
        @param idtf_data: Identifier data for search
        @return: Returns sc-addrs of founded sc-element.
        If there are any error or sc-element wasn't found, then return None
        """
        # send request
        params = struct.pack('=I%ds' % len(idtf_data), len(idtf_data), idtf_data)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_FIND_ELEMENT_BY_SYSITDF, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize < 4:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 12
0
    def create_node(self, el_type):
        """Create new sc-node in memory with specified type
        @param el_type: Type of node that would be created
        @return: If sc-node was created, then returns it sc-addr; otherwise return None
        """

        # send request
        params = struct.pack('=H', el_type)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_NODE, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
Ejemplo n.º 13
0
    def iterate_elements(self, iterator_type, *args):
        """Iterate element by specified template and return results
        """
        params = None
        params_count = None
        if iterator_type == SctpIteratorType.SCTP_ITERATOR_3A_A_F:
            params_count = 3
            params = struct.pack('=BHHHH', iterator_type, args[0], args[1], args[2].seg, args[2].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_3F_A_A:
            params_count = 3
            params = struct.pack('=BHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_3F_A_F:
            params_count = 3
            params = struct.pack('=BHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2].seg, args[2].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_A_A_F_A_A:
            params_count = 5
            params = struct.pack('=BHHHHHH', iterator_type, args[0], args[1], args[2].seg, args[2].offset, args[3], args[4])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_A_A_F_A_F:
            params_count = 5
            params = struct.pack('=BHHHHHHH', iterator_type, args[0], args[1], args[2].seg, args[2].offset, args[3], args[4].seg, args[4].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_F_A_A_A_A:
            params_count = 5
            params = struct.pack('=BHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2], args[3], args[4])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_F_A_F_A_A:
            params_count = 5
            params = struct.pack('=BHHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2].seg, args[2].offset, args[3], args[4])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_F_A_F_A_F:
            params_count = 5
            params = struct.pack('=BHHHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2].seg, args[2].offset, args[3], args[4].seg, args[4].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F:
            params_count = 5
            params = struct.pack('=BHHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2], args[3], args[4].seg, args[4].offset)

        params_len = len(params)
        # send request
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_ITERATE_ELEMENTS, 0, 0, params_len)
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize == 0:
            return None

        res_count_data = self.receiveData(4)
        res_count = struct.unpack('=I', res_count_data)[0]

        if res_count == 0:
            return None

        results = []
        for idx in xrange(res_count):
            result_item = []
            for j in xrange(params_count):
                addr_data = self.receiveData(4)
                addr = ScAddr(0, 0)
                addr.seg, addr.offset = struct.unpack('=HH', addr_data)
                result_item.append(addr)

            results.append(result_item)


        return results
Ejemplo n.º 14
0
    def iterate_elements(self, iterator_type, *args):
        """Iterate element by specified template and return results
        """
        params = None
        params_count = None
        if iterator_type == SctpIteratorType.SCTP_ITERATOR_3A_A_F:
            params_count = 3
            params = struct.pack('=BHHHH', iterator_type, args[0], args[1], args[2].seg, args[2].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_3F_A_A:
            params_count = 3
            params = struct.pack('=BHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_3F_A_F:
            params_count = 3
            params = struct.pack('=BHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2].seg, args[2].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_A_A_F_A_A:
            params_count = 5
            params = struct.pack('=BHHHHHH', iterator_type, args[0], args[1], args[2].seg, args[2].offset, args[3], args[4])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_A_A_F_A_F:
            params_count = 5
            params = struct.pack('=BHHHHHHH', iterator_type, args[0], args[1], args[2].seg, args[2].offset, args[3], args[4].seg, args[4].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_F_A_A_A_A:
            params_count = 5
            params = struct.pack('=BHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2], args[3], args[4])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_F_A_F_A_A:
            params_count = 5
            params = struct.pack('=BHHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2].seg, args[2].offset, args[3], args[4])
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5_F_A_F_A_F:
            params_count = 5
            params = struct.pack('=BHHHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2].seg, args[2].offset, args[3], args[4].seg, args[4].offset)
        elif iterator_type == SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F:
            params_count = 5
            params = struct.pack('=BHHHHHHH', iterator_type, args[0].seg, args[0].offset, args[1], args[2], args[3], args[4].seg, args[4].offset)

        params_len = len(params)
        # send request
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_ITERATE_ELEMENTS, 0, 0, params_len)
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize == 0:
            return None

        res_count_data = self.receiveData(4)
        res_count = struct.unpack('=I', res_count_data)[0]

        if res_count == 0:
            return None

        results = []
        for idx in range(res_count):
            result_item = []
            for j in range(params_count):
                addr_data = self.receiveData(4)
                addr = ScAddr(0, 0)
                addr.seg, addr.offset = struct.unpack('=HH', addr_data)
                result_item.append(addr)

            results.append(result_item)


        return results