Esempio n. 1
0
 //**************************************************************
 //main distance vector execution function that calls other routines
 //**************************************************************
 void dvRouting(struct node * connectTable)
 {
	char * hostname;
	int len;
	
	if(gethostname(hostname, len) != 0) {
		fprintf(stderr, "router: gethostname error\n");
		return;
	}
 
	dvRoutingTable * table;
	table = initDVroutingTable(connectTable);

	if(!fork()){	//needs to be threads
		receiveUpdate(table, connectTable, hostname);
	}
	
	updateExchange(table, connectTable, hostname);

	printRoutingTable(table);

 }
Esempio n. 2
0
int processSelect(int socs)
{
	for (int i = 0; i < socs; i++)
	{
		if (FD_ISSET(baseSocket, &read))
		{
			int res;
			//incoming message....
			memset(recvBuf, '\0', sizeof(recvBuf));
			res = recv(baseSocket, recvBuf, recvBufLen, 0);
			if (res > 0)
			{
				cout << "recieved: " << recvBuf << endl;
				switch (recvBuf[0])
				{
				case 'P':
					printRoutingTable();
					break;
				case 'L':
					linkCostChange();
					break;
				default:
					cout << "Unkown command recieved on base." << endl;
				}

			}
		}
		for (auto iter = table.begin(); iter != table.end(); iter++)
		{
			routingEntry entry = iter->second;
			if (FD_ISSET(entry.listenSocket, &read) != 0)
			{
				int res;
				//incoming message....
				memset(recvBuf, '\0', sizeof(recvBuf));
				res = recv(entry.listenSocket, recvBuf, recvBufLen, 0);
				if (res > 0)
				{
					cout << "received: " << recvBuf << endl;
					switch (recvBuf[0])
					{
					case 'P':
						//printRoutingTable();
						break;
					case 'U':
						routerUpdate((string)recvBuf, iter->first);
						break;
					case 'L':
						//linkCostChange();
						break;
					}

				}
				else if(WSAGetLastError() != WSAEWOULDBLOCK)
				{
					cout << "error on recv(): " << WSAGetLastError() << endl;
				}
			}
			//else if (FD_ISSET(entry.sendSocket, &write) != 0)
			//{
			//	 /*connected to new socket should send routing table....*/
			//	generateUMessage(iter->first);
			//	//cout << "sending table to " << iter->first << endl;
			//	int numBytes = send(entry.sendSocket, sendBuf, strlen(sendBuf), 0);
			//	if (numBytes == -1)
			//		cout << "Error sending message to neighbor: "<< WSAGetLastError() << endl;
			//	Sleep(1000);
			//}
		}
	}

	return 1;
}
Esempio n. 3
0
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;
      }

    }
  }
}