int InstrAssert::execute(Stack &s) { Oper last = s.last(); if (!(*_value == *last)) throw AssertError(_value, last); return 1; }
void Assert(bool cond, const char *, std::string file, uint32_t line, std::string func, std::string message) { if(!cond) { throw(AssertError(std::move(message), std::move(file), line, std::move(func))); } }
void Vm::print(){ if (vmt->empty()) throw EmptyStackError(); if (vmt->back()->getType() != INT8) throw AssertError(); if (_verbose) std::cout<<static_cast<Int8 const *>(vmt->back())->getValue()<<std::endl; else std::cout<<static_cast<Int8 const *>(vmt->back())->getValue(); }
void Vm::assert(IOperand const * io){ if (vmt->empty() || vmt->back()->getType() != io->getType() || vmt->back()->toString() != io->toString() ) throw AssertError(); }
//------------------------------------------------------------------------------ const Enb_properties_array_t *enb_config_init(char* lib_config_file_name_pP) //------------------------------------------------------------------------------ { config_t cfg; config_setting_t *setting = NULL; config_setting_t *subsetting = NULL; config_setting_t *setting_srb1 = NULL; config_setting_t *setting_mme_addresses = NULL; config_setting_t *setting_mme_address = NULL; config_setting_t *setting_enb = NULL; int num_enb_properties = 0; int enb_properties_index = 0; int num_enbs = 0; int num_mme_address = 0; int num_otg_elements =0; int num_component_carriers =0; int i = 0; int j = 0; int parse_errors = 0; libconfig_int enb_id = 0; const char* cell_type = NULL; const char* tac = 0; const char* enb_name = NULL; const char* mcc = 0; const char* mnc = 0; const char* frame_type = NULL; const char* prefix_type = NULL; libconfig_int Nid_cell = 0; libconfig_int my_int; char* ipv4 = NULL; char* ipv6 = NULL; char* active = NULL; char* preference = NULL; const char* active_enb[EPC_TEST_SCENARIO_MAX_ENB]; char* enb_interface_name_for_S1U = NULL; char* enb_ipv4_address_for_S1U = NULL; libconfig_int enb_port_for_S1U = 0; char* enb_interface_name_for_S1_MME = NULL; char* enb_ipv4_address_for_S1_MME = NULL; char *address = NULL; char *cidr = NULL; char *astring = NULL; memset((char*)active_enb, 0 , EPC_TEST_SCENARIO_MAX_ENB * sizeof(char*)); config_init(&cfg); if (lib_config_file_name_pP != NULL) { /* Read the file. If there is an error, report it and exit. */ if (! config_read_file(&cfg, lib_config_file_name_pP)) { config_destroy(&cfg); AssertFatal (0, "Failed to parse eNB configuration file %s!\n", lib_config_file_name_pP); } } else { config_destroy(&cfg); AssertFatal (0, "No eNB configuration file provided!\n"); } // Get list of active eNBs, (only these will be configured) setting = config_lookup(&cfg, ENB_CONFIG_STRING_ACTIVE_ENBS); if (setting != NULL) { num_enbs = config_setting_length(setting); for (i = 0; i < num_enbs; i++) { setting_enb = config_setting_get_elem(setting, i); active_enb[i] = config_setting_get_string (setting_enb); AssertFatal (active_enb[i] != NULL, "Failed to parse config file %s, %uth attribute %s \n", lib_config_file_name_pP, i, ENB_CONFIG_STRING_ACTIVE_ENBS); active_enb[i] = strdup(active_enb[i]); num_enb_properties += 1; } } /* Output a list of all eNBs. */ setting = config_lookup(&cfg, ENB_CONFIG_STRING_ENB_LIST); if (setting != NULL) { enb_properties_index = 0; parse_errors = 0; num_enbs = config_setting_length(setting); for (i = 0; i < num_enbs; i++) { setting_enb = config_setting_get_elem(setting, i); if (! config_setting_lookup_int(setting_enb, ENB_CONFIG_STRING_ENB_ID, &enb_id)) { /* Calculate a default eNB ID */ # if defined(ENABLE_USE_MME) uint32_t hash; hash = s1ap_generate_eNB_id (); enb_id = i + (hash & 0xFFFF8); # else enb_id = i; # endif } if ( !( config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_CELL_TYPE, &cell_type) && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_ENB_NAME, &enb_name) && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_TRACKING_AREA_CODE, &tac) && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_MOBILE_COUNTRY_CODE, &mcc) && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_MOBILE_NETWORK_CODE, &mnc) ) ) { AssertError (0, parse_errors ++, "Failed to parse eNB configuration file %s, %u th enb\n", lib_config_file_name_pP, i); continue; // FIXME this prevents segfaults below, not sure what happens after function exit } // search if in active list for (j=0; j < num_enb_properties; j++) { if (strcmp(active_enb[j], enb_name) == 0) { g_enb_properties.properties[enb_properties_index] = calloc(1, sizeof(Enb_properties_t)); g_enb_properties.properties[enb_properties_index]->eNB_id = enb_id; if (strcmp(cell_type, "CELL_MACRO_ENB") == 0) { g_enb_properties.properties[enb_properties_index]->cell_type = CELL_MACRO_ENB; } else if (strcmp(cell_type, "CELL_HOME_ENB") == 0) { g_enb_properties.properties[enb_properties_index]->cell_type = CELL_HOME_ENB; } else { AssertError (0, parse_errors ++, "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for cell_type choice: CELL_MACRO_ENB or CELL_HOME_ENB !\n", lib_config_file_name_pP, i, cell_type); } g_enb_properties.properties[enb_properties_index]->eNB_name = strdup(enb_name); g_enb_properties.properties[enb_properties_index]->tac = (uint16_t)atoi(tac); g_enb_properties.properties[enb_properties_index]->mcc = (uint16_t)atoi(mcc); g_enb_properties.properties[enb_properties_index]->mnc = (uint16_t)atoi(mnc); g_enb_properties.properties[enb_properties_index]->mnc_digit_length = strlen(mnc); AssertFatal((g_enb_properties.properties[enb_properties_index]->mnc_digit_length == 2) || (g_enb_properties.properties[enb_properties_index]->mnc_digit_length == 3), "BAD MNC DIGIT LENGTH %d", g_enb_properties.properties[i]->mnc_digit_length); setting_mme_addresses = config_setting_get_member (setting_enb, ENB_CONFIG_STRING_MME_IP_ADDRESS); num_mme_address = config_setting_length(setting_mme_addresses); g_enb_properties.properties[enb_properties_index]->nb_mme = 0; for (j = 0; j < num_mme_address; j++) { setting_mme_address = config_setting_get_elem(setting_mme_addresses, j); if ( !( config_setting_lookup_string(setting_mme_address, ENB_CONFIG_STRING_MME_IPV4_ADDRESS, (const char **)&ipv4) && config_setting_lookup_string(setting_mme_address, ENB_CONFIG_STRING_MME_IPV6_ADDRESS, (const char **)&ipv6) && config_setting_lookup_string(setting_mme_address, ENB_CONFIG_STRING_MME_IP_ADDRESS_ACTIVE, (const char **)&active) && config_setting_lookup_string(setting_mme_address, ENB_CONFIG_STRING_MME_IP_ADDRESS_PREFERENCE, (const char **)&preference) ) ) { AssertError (0, parse_errors ++, "Failed to parse eNB configuration file %s, %u th enb %u th mme address !\n", lib_config_file_name_pP, i, j); continue; // FIXME will prevent segfaults below, not sure what happens at function exit... } g_enb_properties.properties[enb_properties_index]->nb_mme += 1; g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].ipv4_address = strdup(ipv4); g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].ipv6_address = strdup(ipv6); if (strcmp(active, "yes") == 0) { g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].active = 1; } // else { (calloc) if (strcmp(preference, "ipv4") == 0) { g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].ipv4 = 1; } else if (strcmp(preference, "ipv6") == 0) { g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].ipv6 = 1; } else if (strcmp(preference, "no") == 0) { g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].ipv4 = 1; g_enb_properties.properties[enb_properties_index]->mme_ip_address[j].ipv6 = 1; } } // NETWORK_INTERFACES subsetting = config_setting_get_member (setting_enb, ENB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG); if (subsetting != NULL) { if ( ( config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_ENB_INTERFACE_NAME_FOR_S1_MME, (const char **)&enb_interface_name_for_S1_MME) && config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_ENB_IPV4_ADDRESS_FOR_S1_MME, (const char **)&enb_ipv4_address_for_S1_MME) && config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_ENB_INTERFACE_NAME_FOR_S1U, (const char **)&enb_interface_name_for_S1U) && config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_ENB_IPV4_ADDR_FOR_S1U, (const char **)&enb_ipv4_address_for_S1U) && config_setting_lookup_int(subsetting, ENB_CONFIG_STRING_ENB_PORT_FOR_S1U, &enb_port_for_S1U) ) ) { g_enb_properties.properties[enb_properties_index]->enb_interface_name_for_S1U = strdup(enb_interface_name_for_S1U); cidr = enb_ipv4_address_for_S1U; address = strtok(cidr, "/"); if (address) { IPV4_STR_ADDR_TO_INT_NWBO ( address, g_enb_properties.properties[enb_properties_index]->enb_ipv4_address_for_S1U, "BAD IP ADDRESS FORMAT FOR eNB S1_U !\n" ); } g_enb_properties.properties[enb_properties_index]->enb_port_for_S1U = enb_port_for_S1U; g_enb_properties.properties[enb_properties_index]->enb_interface_name_for_S1_MME = strdup(enb_interface_name_for_S1_MME); cidr = enb_ipv4_address_for_S1_MME; address = strtok(cidr, "/"); if (address) { IPV4_STR_ADDR_TO_INT_NWBO ( address, g_enb_properties.properties[enb_properties_index]->enb_ipv4_address_for_S1_MME, "BAD IP ADDRESS FORMAT FOR eNB S1_MME !\n" ); } } } } } } } g_enb_properties.number = num_enb_properties; AssertError (enb_properties_index == num_enb_properties, parse_errors ++, "Failed to parse eNB configuration file %s, mismatch between %u active eNBs and %u corresponding defined eNBs !\n", lib_config_file_name_pP, num_enb_properties, enb_properties_index); AssertFatal (parse_errors == 0, "Failed to parse eNB configuration file %s, found %d error%s !\n", lib_config_file_name_pP, parse_errors, parse_errors > 1 ? "s" : ""); enb_config_display(); return &g_enb_properties; }