Example #1
0
void CEmulatorCmd::StartLoop()
{
	static CString msg("Enter command: [Press '?' for list of available commands]\n");
	static CString input;
	while(true)
	{
		CUtils::WaitForInput(input, msg, false);
		input.ToLower();
		if(input == "q"){
			break;
		}else if(input == "?"){
			PrintAvailableCmds();
		}else if(input == "p"){
			CEIBEmulator::GetInstance().GetDB().Print();
		}else if(input == "s"){
			HandleSendCommand();
		}else if (input == "d"){
			CEIBEmulator::GetInstance().GetHandler().DisconnectClients();
		}else{
			LOG_SCREEN("Unknown command. [Press '?' for list of available commands]\n");
		}

	}
}
int SenderStatusProxy::HandleCommand(const char* command) {
	string s = command;
	/*int length = s.length();
	int index = s.find(' ');
	string comm_name = s.substr(0, index);
	string args = s.substr(index + 1, length - index - 1);
	 */

	list<string> parts;
	Split(s, ' ', parts);
	if (parts.size() == 0)
		return 0;

	char msg[512];
	if (parts.front().compare("Send") == 0) {
		parts.erase(parts.begin());
		HandleSendCommand(parts);
	}
	else if (parts.front().compare("TcpSend") == 0) {
			parts.erase(parts.begin());
			HandleTcpSendCommand(parts);
	}
	else if (parts.front().compare("SetRate") == 0) {
		if (parts.size() == 2) {
			int rate = atoi(parts.back().c_str());
			SetSendRate(rate); //ptr_sender->SetSendRate(rate);
		}
	}
	else if (parts.front().compare("SetRetxTimeoutRatio") == 0) {
		if (parts.size() == 2) {
			file_retx_timeout_ratio = atoi(parts.back().c_str());

			char buf[256];
			sprintf(buf, "Retransmission timeout ratio has been set to %d%%.", atoi(parts.back().c_str()));
			SendMessageLocal(COMMAND_RESPONSE, buf);
		}
	}
	else if (parts.front().compare("SetTCRate") == 0) {
		if (parts.size() == 2) {
			double rate = atoi(parts.back().c_str()) / 8.0;
			string dev = ptr_sender->GetInterfaceName();
			char buf[256];
			sprintf(buf, "sudo tc qdisc del dev %s root", dev.c_str());
			ExecSysCommand(buf);
			sprintf(buf, "sudo tc qdisc add dev %s handle 1: root htb", dev.c_str());
			ExecSysCommand(buf);
			sprintf(buf, "sudo tc class add dev %s parent 1: classid 1:1 htb rate %fMbps", dev.c_str(), rate);
			ExecSysCommand(buf);
			sprintf(buf, "sudo tc filter add dev %s parent 1: protocol ip prio 1 u32 match ip src 10.1.1.2/32 flowid 1:1", dev.c_str());
			ExecSysCommand(buf);

			sprintf(buf, "Send rate has been set to %d Mbps by TC.", atoi(parts.back().c_str()));
			SendMessageLocal(COMMAND_RESPONSE, buf);
		}
	}
	else if (parts.front().compare("CreateLogFile") == 0) {
		if (parts.size() == 2) {
			CreateNewLogFile(parts.back().c_str());
			SendMessageLocal(COMMAND_RESPONSE, "New log file created.");
		}
	}
	else if (parts.front().compare("SetLogSwitch") == 0) {
		if (parts.size() == 2) {
			if (parts.back().compare("On") == 0) {
				FMTP::is_log_enabled = true;
				SendMessageLocal(COMMAND_RESPONSE, "Log switch set to ON.");
			}
			else if (parts.back().compare("Off") == 0) {
				FMTP::is_log_enabled = false;
				SendMessageLocal(COMMAND_RESPONSE, "Log switch set to OFF.");
			}
		}
	}
	else if (parts.front().compare("CreateDataFile") == 0) {
		if (parts.size() == 3) {
			parts.pop_front();
			string file_name = parts.front();
			parts.pop_front();
			unsigned long size = strtoul(parts.front().c_str(), NULL, 0);
			GenerateDataFile(file_name, size);
			SendMessageLocal(COMMAND_RESPONSE, "Data file generated.");
		}
	}
	else if (parts.front().compare("StartExperiment") == 0) {
		SendMessageLocal(INFORMATIONAL, "Starting experiments...");
		//exp_manager.StartExperiment(this, ptr_sender);
		exp_manager2.StartExperiment2(this, ptr_sender);
		SendMessageLocal(INFORMATIONAL, "All experiments finished.");
	}
	else if (parts.front().compare("StartExperimentRetrans") == 0) {
		SendMessageLocal(INFORMATIONAL, "Starting low-speed experiments...");
		exp_manager.StartExperimentRetrans(this, ptr_sender);
		SendMessageLocal(INFORMATIONAL, "All experiments finished.");
	}
	else if (parts.front().compare("StartExperimentLS") == 0) {
		SendMessageLocal(INFORMATIONAL, "Starting low-speed experiments...");
		exp_manager.StartExperimentLowSpeed(this, ptr_sender);
		SendMessageLocal(INFORMATIONAL, "All experiments finished.");
	}
	else if (parts.front().compare("StartLDMIntegration") == 0) {
		if (parts.size() != 2)
			return -1;

		if (integrator != NULL) {
			integrator->Stop();
			delete integrator;
		}
		integrator = new LdmIntegrator(ptr_sender, parts.back(), this);
		integrator->Start();
		SendMessageLocal(INFORMATIONAL, "LDM Integrator has been started.");
	}
	else if (parts.front().compare("StopLDMIntegration") == 0) {
		if (integrator != NULL)
			integrator->Stop();

		SendMessageLocal(INFORMATIONAL, "LDM Integrator has been stopped.");
	}
	else if (parts.front().compare("SetSchedRR") == 0) {
		if (parts.size() == 2) {
			if (parts.back().compare("TRUE") == 0) {
				ptr_sender->SetSchedRR(true);
				SendMessageLocal(INFORMATIONAL, "Sending thread has been set to SCHED_RR mode.");
			}
			else {
				ptr_sender->SetSchedRR(false);
				SendMessageLocal(INFORMATIONAL, "Sending thread has been set to SCHED_RR mode.");
			}
		}
	}
	else {
		StatusProxy::HandleCommand(command);
	}

	return 1;
}
Example #3
0
int SenderStatusProxy::HandleCommand(char* command) {
	string s = command;
	/*int length = s.length();
	int index = s.find(' ');
	string comm_name = s.substr(0, index);
	string args = s.substr(index + 1, length - index - 1);
	 */

	list<string> parts;
	Split(s, ' ', parts);
	if (parts.size() == 0)
		return 0;

	char msg[512];
	if (parts.front().compare("Send") == 0) {
		parts.erase(parts.begin());
		HandleSendCommand(parts);
	}
	else if (parts.front().compare("SetRate") == 0) {
		if (parts.size() == 2) {
			int rate = atoi(parts.back().c_str());
			ptr_sender->SetSendRate(rate);
			sprintf(msg, "Data sending rate has been set to %d Mbps.", rate);
			SendMessage(COMMAND_RESPONSE, msg);
		}
	}
	else if (parts.front().compare("SetBufferSize") == 0) {
		if (parts.size() == 2) {
			int size = atoi(parts.back().c_str());
			ptr_sender->SetBufferSize(size);
			sprintf(msg, "Buffer size has been set to %d bytes.", size);
			SendMessage(COMMAND_RESPONSE, msg);
		}
	}
	else if (parts.front().compare("ResetBuffer") == 0) {
		ptr_sender->ResetBuffer();
		SendMessage(COMMAND_RESPONSE, "Buffer has been reset.");
	}
	else if (parts.front().compare("CreateLogFile") == 0) {
		if (parts.size() == 2) {
			CreateNewLogFile(parts.back().c_str());
			SendMessage(COMMAND_RESPONSE, "New log file created.");
		}
	}
	else if (parts.front().compare("SetLogSwitch") == 0) {
		if (parts.size() == 2) {
			if (parts.back().compare("On") == 0) {
				MVCTP::is_log_enabled = true;
				SendMessage(COMMAND_RESPONSE, "Log switch set to ON.");
			}
			else if (parts.back().compare("Off") == 0) {
				MVCTP::is_log_enabled = false;
				SendMessage(COMMAND_RESPONSE, "Log switch set to OFF.");
			}
		}
	}
	else {
		StatusProxy::HandleCommand(command);
	}

	return 1;
}