int main(int argc, char** argv){ Cpu& cpu = *Cpu::create_cpu(); bool end = false; char line[512]; while (!end && !cin.eof() && cin.getline(line, 512)){ switch (line[0]){ case 'r': cmd_reg(line, *cpu.getMips()); break; case 'p': cmd_pc(line, *cpu.getMips()); break; case 'm': cmd_mem(line, *cpu.getMem()); break; case '.': cmd_exe(line, cpu); break; case 'q': end = true; break; default: COMMAND_UNKNOWN(); }; } Cpu::delete_cpu(&cpu); return EXIT_SUCCESS; };
//--------------------------------------------------------------------------------------------------------------------- int cmd_fsm(msg_info_t * info) { if (!info) { dbg("Input parameter fail: Cannot proceed\n"); return -1; } int result = 0; dmm_entry *bce = NULL; struct in6_addr hw_address = EUI64_to_EUI48(info->mn_iid); bce = dmm_cache_get(&conf.OurAddress, &hw_address); switch (info->msg_event) { /* * Two possible events: * PBU reception; * PBA reception. * All other received messages are discarded */ case hasPBU: if (bce) { if (info->lifetime.tv_sec > 0) { if (IN6_ARE_ADDR_EQUAL(&bce->mn_serv_mar_addr, &info->src)) { dbg("Same serving MAR: %x:%x:%x:%x:%x:%x:%x:%x\n", NIP6ADDR(&info->src)); cmd_refresh_binding_entry(bce, info); cmd_reg(bce); dmm_cache_release(bce); } else { dbg("PBU for an existing MN ... update serving MAR\n"); cmd_update_binding_entry(bce, info); cmd_reg_dmm(bce); dmm_cache_release(bce); } } else if (info->lifetime.tv_sec == 0 && info->lifetime.tv_nsec == 0) { dbg("PBU with Lifetime = 0... start Location Deregistration\n"); if (IN6_ARE_ADDR_EQUAL(&info->src, &bce->mn_serv_mar_addr)) //Received PBU from serving MAG { dbg("Deregistration case...\n"); cmd_dereg(bce, info, 1); dmm_cache_release(bce); dmm_cache_delete(bce); } else { //Received PBU from an already unregistered MAG dbg("Deregistration for not registered MAG, doing nothing\n"); dmm_cache_release(bce); } } } else { dbg("No DMM entry found for %x:%x:%x:%x:%x:%x:%x:%x ... \n", NIP6ADDR(&info->mn_iid)); if (info->lifetime.tv_sec > 0) { dbg("PBU for a new MN ... Location Registration starting now...\n"); bce = dmm_cache_alloc(BCE_DMM); if (bce) { insert_into_hnp_cache(hw_address, info->mn_prefix); result = cmd_create_binding_entry(bce, info); if (result >= 0) cmd_reg(bce); else break; dmm_cache_add(bce); } } else if ((info->lifetime.tv_sec == 0) && (info->lifetime.tv_nsec == 0)) { dbg("PBU with Lifetime = 0 for a not-registered MN. PBU discarded\n"); } } break; case hasPBA: if (bce) { dbg("Received PBA from Previous MAR: BCE updated\n"); if (is_pba_is_response_to_last_pbu_sent(info, bce)) { dbg("Finish Location Registration\n"); bce->PBA_flags = info->PBA_flags; bce->lifetime.tv_nsec = 0; if (!IN6_IS_ADDR_UNSPECIFIED(&info->mn_serv_mar_addr)) { cmd_end_reg_dmm(bce, &info->mn_prefix); } } dmm_cache_release(bce); } else { dbg("WARNING: Received PBA for a not registered MN\n"); } break; default: dbg("No action for this event (%d) at current state!\n", info->msg_event); } return result; }