Пример #1
0
    def test_import(self):
        print('In test import')
        self.ipap_message2.set_syn(True)
        self.ipap_message2.set_seqno(300)
        self.ipap_message2.output()

        str_msg = self.ipap_message2.get_message()
        ipap_message3 = IpapMessage(1, 1, True, str_msg)

        str_msg = 'aqui estoy'
        with self.assertRaises(ValueError):
            ipap_message4 = IpapMessage(1, 1, True, str_msg)
    def is_auction_message(msg: str) -> IpapMessage:
        """
        Establishes whether the given message is a valid auction message.

        :param msg: message to verify
        :return: An IpapMessage if it is a valid message, raise ValueError otherwise.
        """
        return IpapMessage(0, 0, True, msg)
    def build_syn_message(self, sequence_nbr: int) -> IpapMessage:
        """
        Builds a syn message to start a connection

        :param sequence_nbr: sequence number for the message
        :return: message with the syn flag set
        """
        message = IpapMessage(domain_id=int(self.domain), ipap_version=IpapMessage.IPAP_VERSION, _encode_network=True)
        message.set_syn(True)
        message.set_seqno(sequence_nbr)
        return message
 def build_ack_message(self, sequence_nbr: int, ack_nbr: int) -> IpapMessage:
     """
     Builds an ack to respond other messages
     :param sequence_nbr: sequence number for the message
     :param ack_nbr: ack number to send within the message
     :return:
     """
     message = IpapMessage(domain_id=int(self.domain), ipap_version=IpapMessage.IPAP_VERSION, _encode_network=True)
     message.set_ack(True)
     message.set_seqno(sequence_nbr)
     message.set_ack_seq_no(ack_nbr)
     return message
 def build_fin_message(self, sequence_nbr: int, ack_nbr: int) -> IpapMessage:
     """
     Builds a fin message to teardown a connection
     :param sequence_nbr: sequence number for the message
     :param ack_nbr: ack number to send within the message
     :return: message with the fin flag set
     """
     message = IpapMessage(domain_id=int(self.domain), ipap_version=IpapMessage.IPAP_VERSION, _encode_network=True)
     message.set_fin(True)
     message.set_seqno(sequence_nbr)
     message.set_ack_seq_no(ack_nbr)
     return message
 def build_syn_ack_message(self, sequence_nbr: int, ack_nbr: int) -> IpapMessage:
     """
     Builds an ack to respond syn_ack message
     :param sequence_nbr: sequence number for the message
     :param ack_nbr: ack number to send within the message
     :return:
     """
     print('build syn ack message {0}.{1}'.format(str(sequence_nbr), str(ack_nbr)))
     message = IpapMessage(domain_id=int(self.domain), ipap_version=IpapMessage.IPAP_VERSION, _encode_network=True)
     message.set_syn(True)
     message.set_ack(True)
     message.set_seqno(sequence_nbr)
     message.set_ack_seq_no(ack_nbr)
     return message
Пример #7
0
    def get_ipap_message(self, auctions: list, use_ipv6: bool, s_address: str, port: int) -> IpapMessage:
        """
        Gets an ipap_message to transfer the information of the auctions given as parameter.

        :param auctions: List of auctions to convert to a message
        :param use_ipv6: whether or not it use ipv6
        :param s_address: source address
        :param port: source port
        :return: ipap message with auction information.
        """
        message = IpapMessage(self.domain, IpapMessage.IPAP_VERSION, True)

        for auction in auctions:
            self.get_ipap_message_auction(auction, use_ipv6, s_address, port, message)

        message.output()
        return message
Пример #8
0
    def get_ipap_message(
            self, bidding_objects: List[BiddingObject],
            template_container: IpapTemplateContainer) -> IpapMessage:
        """
        get the ipap_message that contains all the bidding objects within the list given

        :param bidding_objects: bidding objects to include in the message.
        :param template_container: container with all the registered templates
        :return: ipap_message with the information
        """
        ipap_bidding_object_parser = IpapBiddingObjectParser(self.domain)
        message = IpapMessage(self.domain, IpapMessage.IPAP_VERSION, True)
        auction_manager = AuctionManager(self.domain)

        for bidding_object in bidding_objects:
            auction = auction_manager.get_auction(
                bidding_object.get_parent_key())
            ipap_bidding_object_parser.get_ipap_message(
                bidding_object, auction, template_container, message)

        return message
Пример #9
0
    def test_read_data_records(self):
        ipap_message = IpapMessage(1, 1, False)
        template_id = ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        ipap_message.add_field(template_id, 0, 30)

        ipap_data_record = IpapDataRecord(templ_id=template_id)
        ipap_field_value1 = IpapValueField()
        value = 12231213
        ipap_field_value1.set_value_uint64(value)

        # Replace the value
        ipap_data_record.insert_field(0, 30, ipap_field_value1)
        ipap_message.include_data(template_id, ipap_data_record)

        lst = self.ipap_message_parser.read_data_records(
            ipap_message, template_id)
        self.assertEqual(len(lst), 1)

        lst = self.ipap_message_parser.read_data_records(ipap_message, 100)
        self.assertEqual(len(lst), 0)
Пример #10
0
    def test_read_template(self):
        ipap_message = IpapMessage(1, 1, False)
        template_id = ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        ipap_message.add_field(template_id, 0, 30)

        ipap_data_record = IpapDataRecord(templ_id=template_id)
        ipap_field_value1 = IpapValueField()
        value = 12231213
        ipap_field_value1.set_value_uint64(value)

        # Replace the value
        ipap_data_record.insert_field(0, 30, ipap_field_value1)
        ipap_message.include_data(template_id, ipap_data_record)

        template = self.ipap_message_parser.read_template(
            ipap_message, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.assertEqual(template.get_type(),
                         TemplateType.IPAP_SETID_AUCTION_TEMPLATE)

        with self.assertRaises(ValueError):
            template = self.ipap_message_parser.read_template(
                ipap_message, TemplateType.IPAP_OPTNS_AUCTION_TEMPLATE)
    def get_ipap_message(self, allocation: Allocation, template_container: IpapTemplateContainer) -> IpapMessage:
        """

        :return:
        """
        message = IpapMessage(self.domain, IpapMessage.IPAP_VERSION, True)

        auction_manager = AuctionManager(self.domain)
        auction = auction_manager.get_auction(allocation.get_auction_key())

        # Find both templates types for the bidding object.
        temp_type = IpapTemplate.get_data_template(allocation.get_template_object_type())
        data_template_id = auction.get_bidding_object_template(allocation.get_template_object_type(), temp_type)

        temp_type = IpapTemplate.get_opts_template(allocation.get_template_object_type())
        option_template_id = auction.get_bidding_object_template(allocation.get_template_object_type(), temp_type)

        # Insert allocations's templates.a
        data_template = template_container.get_template(data_template_id)
        message.make_template(data_template)

        option_template = template_container.get_template(option_template_id)
        message.make_template(option_template)

        # Include data records.
        self.include_data_record(data_template, allocation, 'Record_1', allocation.config_params, message)

        # Include option records.
        index = 1
        for interval in allocation.intervals:
            record_id = 'Record_{0}'.format(str(index))
            self.include_options_record(option_template, allocation,
                                        record_id, interval.start, interval.stop, message)
            index = index + 1

        return message
Пример #12
0
 def setUp(self):
     self.ipap_message = IpapMessage(1, 1, False)
     self.ipap_message2 = IpapMessage(1, 1, True)