Example #1
0
void MySQLClient::setup(Host& host, const string& user, const string& password, const string& db) //Setup connection, make DNS Req if necessary
{
  init(); //Initialize client in known state, create socket
  resetTimeout();
  m_host = host;
  if(!host.getPort())
    host.setPort( MYSQL_PORT ); //Default port
    
  m_user = user;
  m_password = password;
  
  m_db = db;

  if( !host.getIp().isNull() )
  {
    connect();
  }
  else //Need to do a DNS Query...
  {
    DBG("DNS Query...\n");
    m_pDnsReq = new DNSRequest();
    m_pDnsReq->setOnReply(this, &MySQLClient::onDNSReply);
    m_pDnsReq->resolve(&m_host);
    DBG("MySQLClient : DNSRequest %p\n", m_pDnsReq);
  }
}
NetUdpSocketErr LwipNetUdpSocket::bind(const Host& me)
{
  err_t err;

  if(!m_pPcb)
    return NETUDPSOCKET_MEM; //NetUdpSocket was not properly initialised, should destroy it & retry

  #if LWIP_IGMP //Multicast support enabled
  if(me.getIp().isMulticast())
  {
    DBG("This is a multicast addr, joining multicast group\r\n");
    m_multicastGroup = me.getIp();
    ip_addr_t multicastGroupAddr = m_multicastGroup.getStruct();
    err = igmp_joingroup(IP_ADDR_ANY, &multicastGroupAddr);
    if(err)
      return NETUDPSOCKET_IF; //Could not find or create group
  }
  #endif

  err = udp_bind( (udp_pcb*) m_pPcb, IP_ADDR_ANY, me.getPort()); //IP_ADDR_ANY : Bind the connection to all local addresses
  if(err)
    return NETUDPSOCKET_INUSE;

  //Setup callback
  udp_recv( (udp_pcb*) m_pPcb, LwipNetUdpSocket::sRecvCb, (void*) this );

  return NETUDPSOCKET_OK;
}
Example #3
0
NetTcpSocketErr LwipNetTcpSocket::bind(const Host& me)
{
  if(!m_pPcb)
    return NETTCPSOCKET_MEM; //NetTcpSocket was not properly initialised, should destroy it & retry
    
  err_t err = tcp_bind( (tcp_pcb*) m_pPcb, IP_ADDR_ANY, me.getPort()); //IP_ADDR_ANY : Bind the connection to all local addresses
  if(err)
    return NETTCPSOCKET_INUSE;
    
  return NETTCPSOCKET_OK;
}
Example #4
0
NetTcpSocketErr LwipNetTcpSocket::connect(const Host& host)
{
  if(!m_pPcb)
    return NETTCPSOCKET_MEM; //NetTcpSocket was not properly initialised, should destroy it & retry
  
  ip_addr_t ip = host.getIp().getStruct();
  err_t err = tcp_connect( (tcp_pcb*) m_pPcb, &ip, host.getPort(), LwipNetTcpSocket::sConnectedCb );
  
  if(err)
    return NETTCPSOCKET_MEM;
    
  return NETTCPSOCKET_OK;
}
Example #5
0
	virtual void SetUp()
	{
		host1 = new Host("TestHost1", 2, &netSystem);
		host2 = new Host("TestHost2", 2, &netSystem);

		uint8_t mac1[6] = {0xBC,0xBC,0xBC,0xBC,0xBC,0xBC};
		uint8_t mac1_2[6] = {0xCB,0xCB,0xCB,0xCB,0xCB,0xCB};
		uint8_t mac2[6] = {0xCD,0xCD,0xCD,0xCD,0xCD,0xCD};
		uint8_t mac2_2[6] = {0xDC,0xDC,0xDC,0xDC,0xDC,0xDC};
		uint8_t ip1[4] = {192,168,0,7};
		uint8_t ip1_2[4] = {192,168,0,8};
		uint8_t ip2[4] = {10,0,1,4};
		uint8_t ip2_2[4] = {10,0,1,5};
		host1->setMACAddr(mac1, 0);
		host1->setMACAddr(mac1_2, 1);
		host1->setARPTable(mac2, ip2);
		host1->setARPTable(mac2_2, ip2_2);
		host1->setIPAddr(ip1, 0);
		host1->setIPAddr(ip1_2, 1);
		host1->setRoutingTable(ip2, 16, 0);
		host1->setRoutingTable(ip2_2, 16, 1);

		host2->setMACAddr(mac2, 0);
		host2->setMACAddr(mac2_2, 1);
		host2->setARPTable(mac1, ip1);
		host2->setARPTable(mac1_2, ip1_2);
		host2->setIPAddr(ip2, 0);
		host2->setIPAddr(ip2_2, 1);
		host2->setRoutingTable(ip1, 16, 0);
		host2->setRoutingTable(ip1_2, 16, 1);

		host1->getPort(0)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));
		host1->getPort(1)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));
		host2->getPort(0)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));
		host2->getPort(1)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));

		switchingHub = new Switch("Switch1", &netSystem);
		switchingHub->addPort(host1->getPort(0));
		switchingHub->addPort(host1->getPort(1));
		switchingHub->addPort(host2->getPort(0));
		switchingHub->addPort(host2->getPort(1));

		switchingHub->addMACEntry(host1->getPort(0), mac1);
		switchingHub->addMACEntry(host1->getPort(1), mac1_2);
		switchingHub->addMACEntry(host2->getPort(0), mac2);
		switchingHub->addMACEntry(host2->getPort(1), mac2_2);


		ethernet1 = new Ethernet(host1);
		ethernet2 = new Ethernet(host2);
		ipv4_1 = new IPv4(host1);
		ipv4_2 = new IPv4(host2);

		interface = Target::allocate(host1);
		interface2 = TCPSolutionProvider::allocate(host2, false, false, false);
		interface->initialize();
		interface2->initialize();
	}
void RoundRobinDistributor::execute() {
    std::unique_ptr<HttpResponse> response;
    Host *host;

    while (1) {
        std::unique_lock<std::mutex> lck(m_queue_mtx);
        //std::cout << "waiting" << std::endl;
        while (m_parsedRequests.empty()) m_queue_cv.wait(lck);
        //std::cout << "notified" << std::endl;
        m_requestTuple_t request = m_parsedRequests.front();
        m_parsedRequests.pop();
        lck.unlock();

        host = &(cluster_nodes->at(request.host));
        debug("Request send to host %s:%d", host->getUrl().c_str(), host->getPort());
        response = host->executeRequest(request.request);

        sendResponse(std::move(response), request.socket);
    }
}
Example #7
0
	virtual void SetUp()
	{
		prev_log = NetworkLog::defaultLevel;
		NetworkLog::defaultLevel |= (
				//(1 << NetworkLog::SYSCALL_RAISED) |
				//(1 << NetworkLog::SYSCALL_FINISHED) |
				//(1 << NetworkLog::PACKET_ALLOC) |
				//(1 << NetworkLog::PACKET_CLONE) |
				//(1 << NetworkLog::PACKET_FREE) |
				//(1 << NetworkLog::PACKET_TO_MODULE) |
				//(1 << NetworkLog::PACKET_FROM_MODULE) |
				//(1 << NetworkLog::PACKET_TO_HOST) |
				//(1 << NetworkLog::PACKET_FROM_HOST) |
				//(1 << NetworkLog::PACKET_QUEUE) |
				//(1 << NetworkLog::TCP_LOG) |
				0UL
		);

		client_hosts = new Host*[num_client];
		ethernet_clients = new Ethernet*[num_client];
		ipv4_clients = new IPv4*[num_client];
		interface_clients = new HostModule*[num_client];

		server_host = new Host("CongestionServer", 1, &netSystem);

		uint8_t server_mac[6] = {0xBC,0xBC,0xBC,0xBC,0xBC,0xBC};
		uint8_t server_ip[4] = {192,168,1,7};
		uint8_t server_mask[4] = {192,168,1,0};
		uint8_t client_mask[4] = {10,0,1,0};

		ethernet_server = new Ethernet(server_host);
		ipv4_server = new IPv4(server_host);

		server_host->setMACAddr(server_mac, 0);
		server_host->setIPAddr(server_ip, 0);
		server_host->setRoutingTable(client_mask, 24, 0);
		server_host->getPort(0)->setPropagationDelay(propagationDelay);
		server_host->getPort(0)->setPortSpeed(port_speed);

		interface_server = Adversary::allocate(server_host);
		interface_server->initialize();

		switchingHub = new Switch("Switch1", &netSystem);
		switchingHub->addPort(server_host->getPort(0));
		switchingHub->addMACEntry(server_host->getPort(0), server_mac);

		char name_buf[128];
		for(int k=0; k<num_client; k++)
		{
			snprintf(name_buf, sizeof(name_buf), "CongestionClient%d", k);
			client_hosts[k] = new Host(name_buf, 2, &netSystem);
			ethernet_clients[k] = new Ethernet(client_hosts[k]);
			ipv4_clients[k] = new IPv4(client_hosts[k]);
			interface_clients[k] = Target::allocate(client_hosts[k]);
			interface_clients[k]->initialize();

			uint8_t client_ip[4] = {10,0,1,10};
			client_ip[3] += k;
			uint8_t client_mac[6] = {0xEE,0xEE,0xEE,0xEE,0xEE,0x00};
			client_mac[5] += k;

			client_hosts[k]->setMACAddr(client_mac, 0);
			client_hosts[k]->setIPAddr(client_ip, 0);
			client_hosts[k]->setRoutingTable(server_mask, 24, 0);
			client_hosts[k]->setARPTable(server_mac, server_ip);
			client_hosts[k]->getPort(0)->setPropagationDelay(propagationDelay);
			client_hosts[k]->getPort(0)->setPortSpeed(port_speed);

			server_host->setARPTable(client_mac, client_ip);

			switchingHub->addPort(client_hosts[k]->getPort(0));
			switchingHub->addMACEntry(client_hosts[k]->getPort(0), client_mac);
		}

		switchingHub->setLinkSpeed(port_speed);
		switchingHub->setQueueSize(64);

		const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
		std::string file_name(test_info->name());
		file_name.append(".pcap");
		switchingHub->enablePCAPLogging(file_name, 64);

	}
Example #8
0
	virtual void SetUp()
	{
		host1 = new Host("TestHost1", 2, &netSystem);
		host2 = new Host("TestHost2", 2, &netSystem);

		uint8_t mac1[6] = {0xBC,0xBC,0xBC,0xBC,0xBC,0xBC};
		uint8_t mac1_2[6] = {0xCB,0xCB,0xCB,0xCB,0xCB,0xCB};
		uint8_t mac2[6] = {0xCD,0xCD,0xCD,0xCD,0xCD,0xCD};
		uint8_t mac2_2[6] = {0xDC,0xDC,0xDC,0xDC,0xDC,0xDC};
		uint8_t ip1[4] = {192,168,0,7};
		uint8_t ip1_2[4] = {192,168,0,8};
		uint8_t ip2[4] = {10,0,1,4};
		uint8_t ip2_2[4] = {10,0,1,5};
		host1->setMACAddr(mac1, 0);
		host1->setMACAddr(mac1_2, 1);
		host1->setARPTable(mac2, ip2);
		host1->setARPTable(mac2_2, ip2_2);
		host1->setIPAddr(ip1, 0);
		host1->setIPAddr(ip1_2, 1);
		host1->setRoutingTable(ip2, 16, 0);
		host1->setRoutingTable(ip2_2, 16, 1);

		host2->setMACAddr(mac2, 0);
		host2->setMACAddr(mac2_2, 1);
		host2->setARPTable(mac1, ip1);
		host2->setARPTable(mac1_2, ip1_2);
		host2->setIPAddr(ip2, 0);
		host2->setIPAddr(ip2_2, 1);
		host2->setRoutingTable(ip1, 16, 0);
		host2->setRoutingTable(ip1_2, 16, 1);

		host1->getPort(0)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));
		host1->getPort(1)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));
		host2->getPort(0)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));
		host2->getPort(1)->setPropagationDelay(TimeUtil::makeTime(1, TimeUtil::MSEC));

		switchingHub = new Switch("Switch1", &netSystem);
		switchingHub->addPort(host1->getPort(0));
		switchingHub->addPort(host1->getPort(1));
		switchingHub->addPort(host2->getPort(0));
		switchingHub->addPort(host2->getPort(1));
		switchingHub->setQueueSize(16);

		switchingHub->addMACEntry(host1->getPort(0), mac1);
		switchingHub->addMACEntry(host1->getPort(1), mac1_2);
		switchingHub->addMACEntry(host2->getPort(0), mac2);
		switchingHub->addMACEntry(host2->getPort(1), mac2_2);

		const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
		std::string file_name(test_info->name());
		file_name.append(".pcap");
		switchingHub->enablePCAPLogging(file_name);

		ethernet1 = new Ethernet(host1);
		ethernet2 = new Ethernet(host2);
		ipv4_1 = new IPv4(host1);
		ipv4_2 = new IPv4(host2);

		interface = Target::allocate(host1);
		interface2 = Adversary::allocate(host2);
		interface->initialize();
		interface2->initialize();
	}