int main(int argc, char **argv) { int ch=1; int ret; while (ch != 0) { ch = get_input(); LOG("Your choice = %d\n", ch); switch (ch) { case 1: { char dataFile[25] = { 0 }; LOG("Please load original routing table data file\n"); scanf("%s", dataFile); ort = loadOrigRoutingTable(dataFile); if (!ort){ DEBUG("%s:%d error in constructing original routing table\n", __FUNCTION__, __LINE__); return -1; } DEBUG("%s:%d ort=%p &lsp=%p\n", __FUNCTION__, __LINE__, ort, &lsp); ret = constructLSP(ort, &lsp); if (ret != 0) { DEBUG("Link State Packets construction failure\n"); } else { LOG("Link State Packets construction success\n"); printLSP(lsp, ort->numOfRouters); } allocRoutingTables(ort->numOfRouters); } break; case 2: { int routerId; LOG("Please select a router\n"); scanf("%d", &routerId); routerId--; buildRoutingTable2(routerId); LOG("The routing table for router %d is\n", routerId); printRoutingTable(routerId); } break; case 3: { int srcRouterId; int dstRouterId; LOG("Please input the source and the destination router\n"); scanf("%d", &srcRouterId); scanf("%d", &dstRouterId); computePath(srcRouterId, dstRouterId, &path); LOG("The shrtest path from %d to %d is %d", srcRouterId, dstRouterId, srcRouterId); printRoutePath(&path); LOG("%d\n", dstRouterId); LOG ("Num of Hops = %d\n",path.numOfHops); free(path.rt); break; } } } }
void Tracker::enterDebuger(){ string cmd; //cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); while (true) { cout << "NoC"<<">"; vector<string> cmd = parseCmd(); if (cmd.size() == 0) continue; if (strcasecmp(cmd[0].c_str(), "quit")==0) break; else if (strcasecmp(cmd[0].c_str(), "help")==0) printDebugerHelp(0, cout); else if (strcasecmp(cmd[0].c_str(), "now")==0) cout << g_simCount << endl; else if (strcasecmp(cmd[0].c_str(), "dl") == 0){ char mode=0; string fileName=""; int ff = isfout(cmd, fileName, mode); if (ff == 1) { ofstream fout; if(mode == (char)ofstream::app) fout.open((gc_resultHome + fileName).c_str(), ofstream::app); else fout.open((gc_resultHome + fileName).c_str(), ofstream::out); if (!fout.is_open()) cout<<"Cannot open "<< (gc_resultHome + fileName) << "__" <<endl; else{ printDeadlock(fout); fout.close(); } } else if(ff == -1){ cout << "Miss output file name" << endl; // error, filename not input } else if (ff == 0) printDeadlock(cout); else; } else if (strcasecmp(cmd[0].c_str(), "rt") == 0){ bool noerr = true; if (cmd.size() == 3){ if (cmd[1].find_first_not_of("0123456789") == string::npos && cmd[2].find_first_not_of("0123456789") == string::npos){ int srcId = atoi(cmd[1].c_str()); int destId = atoi(cmd[2].c_str()); printRoutePath(srcId, destId, cout); } else noerr = false; } else noerr = false; if (!noerr) cout << "rt: rt srcId destId" << endl; } else if (strcasecmp(cmd[0].c_str(), "set")==0){ bool noerr = true; if (cmd.size() == 3){ if (strcasecmp(cmd[1].c_str(), "tile")==0) { if (cmd[2].find_first_not_of("0123456789") != string::npos) // not a integer noerr = false; else{ int tileId = atoi(cmd[2].c_str()); bool ret = enterDebugerTile(tileId); if (ret == false) break; // exit debugger } } else noerr = false; } else noerr = false; if (!noerr) cout << "set: set tile [tileId]" << endl; } else if (strcasecmp(cmd[0].c_str(), "view")==0) { bool noerr = true; if (cmd.size() >= 3) { vector<ULL> hier = parseHier(cmd[2]); if (hier.size() == 0){ cout << "Can't recognize location you input" << endl; noerr = false; } else{ if (hier[0] == 1) // rel path to abs path hier[0] = 0; char mode=0; string fileName=""; int ff = isfout(cmd, fileName, mode); if (ff == 1) { ofstream fout; if(mode == (char)ofstream::app) fout.open((gc_resultHome + fileName).c_str(), ofstream::app); else fout.open((gc_resultHome + fileName).c_str(), ofstream::out); if (!fout.is_open()) cout<<"Cannot open "<< (gc_resultHome + fileName) << "__" <<endl; else{ commandView(cmd[1], hier, fout); fout.close(); } } else if(ff == -1){ cout << "Miss output file name" << endl; // error, filename not input } else if (ff == 0) commandView(cmd[1], hier, cout); else; } } else cerr << "view: miss arguments" << endl; } else cout << "No such command" << endl; } }