示例#1
0
文件: cli.c 项目: draringi/gini
/*
 * Handler for the connection "route" command
 * route show
 * route add -dev eth0|tap0 -net nw_addr -netmask mask [-gw gw_addr]
 * route del route_number
 */
void routeCmd()
{
	char *next_tok;
	char tmpbuf[MAX_TMPBUF_LEN];
	uchar net_addr[4], net_mask[4], nxth_addr[4];
	int interface, del_route;
	char dev_name[MAX_DNAME_LEN];

	// set defaults for optional parameters
	bzero(nxth_addr, 4);

	next_tok = strtok(NULL, " \n");

	if (next_tok != NULL)
	{
		if (!strcmp(next_tok, "add"))
		{
			GET_NEXT_PARAMETER("-dev", "route:: missing device name ..");
			strcpy(dev_name, next_tok);
			interface = gAtoi(next_tok);

			GET_NEXT_PARAMETER("-net", "route:: missing network address ..");
			Dot2IP(next_tok, net_addr);

			GET_NEXT_PARAMETER("-netmask", "route:: missing netmask ..");
			Dot2IP(next_tok, net_mask);

			verbose(2, "[routeCmd]:: Device %s Interface %d, net_addr %s, netmask %s ",
			       dev_name, interface, IP2Dot(tmpbuf, net_addr), IP2Dot((tmpbuf+20), net_mask));

			if (((next_tok = strtok(NULL, " \n")) != NULL) &&
			    (!strcmp("-gw", next_tok)))
			{
				next_tok = strtok(NULL, " \n");
				Dot2IP(next_tok, nxth_addr);
			}
			addRouteEntry(route_tbl, net_addr, net_mask, nxth_addr, interface);
		}
		else if (!strcmp(next_tok, "del"))
		{
			next_tok = strtok(NULL, " \n");
			del_route = gAtoi(next_tok);
			deleteRouteEntryByIndex(route_tbl, del_route);
		}
		else if (!strcmp(next_tok, "show"))
			printRouteTable(route_tbl);
	}
	return;
}
示例#2
0
/*
*	note:  commandView only accept absolute path, that hier[0] == 0
*/
void Tracker::commandView(string content, vector<ULL> hier, ostream & xout){
	/*
	view ic
	view oc
	view flit
	view regin
	view regvc
	view vc
	view port
	*/
	if (hier[0] != 0)
	{
		// commandView only accept absolute path
		cerr << "Error occured in NIRGAM." << endl;
		return ;
	}
	// remove absolute path flag
	hier.erase(hier.begin());

	if (strcasecmp(content.c_str(), "ic") == 0)
	{
		if (hier.size() == 2)
			printIcOverview(hier[0], hier[1], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "oc") == 0)
	{
		if (hier.size() == 0)
			printOCsOverviewTitled(xout);
		else if (hier.size() == 1)
			printOCsOverviewTitled(hier[0], xout);
		else if (hier.size() == 2)
			printOcOverviewTitled(hier[0], hier[1], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "flit") == 0)
	{
		if (hier.size() == 1)
			searchAndPrintFlit(hier[0], xout);
		else
			cerr << "Flit sequence error" << endl;
	}
	else if (strcasecmp(content.c_str(), "regin") == 0)
	{
		if (hier.size() == 2)
			printOcRegin(hier[0], hier[1], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "regvc") == 0)
	{
		if (hier.size() == 2)
			printOcRegvc(hier[0], hier[1], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "vc") == 0)
	{
		if (hier.size() == 0)
			printIcVcs(xout);
		else if (hier.size() == 1)
			printIcVcs(hier[0], xout);
		else if (hier.size() == 2)
			printIcVcs(hier[0], hier[1], xout);
		else if (hier.size() == 3)
			printIcVc(hier[0], hier[1], hier[2], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "port") == 0)
	{
		if (hier.size() == 1)
			printPortTable(hier[0], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "va") == 0)
	{
		if (hier.size() == 1)
			printVaVcFree(hier[0], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else if (strcasecmp(content.c_str(), "rt") == 0)
	{
		if (hier.size() == 1)
			printRouteTable(hier[0], xout);
		else 
			cerr << "Can't recognize location you input" << endl;
	}
	else
		cerr << content << " is not recognized" << endl;
}