def get_ipap_message_auction(self, auction: Auction, use_ipv6: bool, s_address: str, port: int, message: IpapMessage): """ Updates the ipap_message given as parameter with the infomation of the auction :param auction: auction to include in the message :param use_ipv6: whether or not it use ipv6 :param s_address: source address :param port: source port :param message: ipap message to modify an include the information. """ auction_template_id = auction.get_auction_data_template() auction_template = self.ipap_template_container.get_template(auction_template_id) message.make_template(auction_template) option_template_id = auction.get_option_auction_template() option_template = self.ipap_template_container.get_template(option_template_id) # Following lines are used for inserting only non mandatory fields mandatory_fields = option_template.get_template_type_mandatory_field(option_template.get_type()) optional_fields = self.get_non_mandatory_fields(auction.action, mandatory_fields) option_template.set_max_fields(option_template.get_num_fields() + len(optional_fields)) for field in optional_fields: ipap_field = self.field_container.get_field(field.get_eno(), field.get_ftype()) option_template.add_field(ipap_field.get_length(), UnknownField.KNOWN, True, ipap_field) message.make_template(option_template) self.include_auction_templates(auction_template, auction, message) self.include_auction_data_record(auction_template, auction, message, use_ipv6, s_address, port) self.include_option_data_record(option_template, auction, message)
def include_auction_templates(self, template: IpapTemplate, auction: Auction, message: IpapMessage): """ Inserts templates associated with the auction :param template auction template :param auction auction being included in the message. :param message: message being built. :return: """ for i in range(1, ObjectType.IPAP_MAX_OBJECT_TYPE.value): list_types = template.get_object_template_types(ObjectType(i)) for templ_type in list_types: templ_id = auction.get_bidding_object_template(ObjectType(i), templ_type) message.make_template(self.ipap_template_container.get_template(templ_id))
def get_ipap_message(self, bidding_object: BiddingObject, auction: Auction, template_container: IpapTemplateContainer, message: IpapMessage): if bidding_object.get_parent_key() != auction.get_key(): raise ValueError( "the auction is not the same as the one referenced in the bidding object" ) # Find both templates types for the bidding object. tempType = IpapTemplate.get_data_template( bidding_object.get_template_object_type()) data_template_id = auction.get_bidding_object_template( bidding_object.get_template_object_type(), tempType) tempType = IpapTemplate.get_opts_template( bidding_object.get_template_object_type()) option_template_id = auction.get_bidding_object_template( bidding_object.get_template_object_type(), tempType) # Insert BiddingObject's templates. 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. for element_name in bidding_object.elements: config_params = bidding_object.elements[element_name] self.include_data_record(data_template, bidding_object, element_name, config_params, message) # Include option records. for option_name in bidding_object.options: interval = bidding_object.calculate_interval(option_name) config_params = bidding_object.options[option_name] self.include_options_record(option_template, bidding_object, option_name, interval.start, interval.stop, config_params, message)
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