Skip to content

Commit

Permalink
Generated from commit dc9e6c784dbed7d8f28198cf8afe63ff28ca18a0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pusnow committed Nov 25, 2021
1 parent 22214b8 commit e55fa41
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 125 deletions.
111 changes: 6 additions & 105 deletions app/kens/testtransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ extern "C" {

using namespace E;

/**
* @brief Server application for the transfer test
*
* This application is configured by the following environment variables.
*
* * `CONNECT_ADDR`, `CONNECT_PORT`: Parameters to configure a listening socket.
* * `CONNECT_TIME`: Arbitrary sleeping time before starting the handshake. If
* the handshake is completed but the established connection is not consumed
* by the server's `listen` system call, the backlog count will be decreased
* by one.
* * `START_TIME`: Arbitrary sleeping time before starting the data transfer.
* * `RANDOM_SEED`: This random seed is used to generate a pseudo-random byte
* stream. If a pair of server and client shares the same seed, the seed is
* used to generate and verify the data integrity.
* * `SENDER`: Determines who will send the data. Data transfer can be done in
* either client-to-server and server-to-client directions.
* * `BUFFER_SIZE`: Size of the buffer to be used in every `write` or `read`
* system call.
* * `LOOP_COUNT`: How many times the `write` system call will be invoked.
* * `EXPECT_SIZE`: Expected length of the received data.
*/
class TestTransfer_Accept : public TCPApplication {
public:
TestTransfer_Accept(Host &host,
Expand Down Expand Up @@ -182,26 +161,6 @@ class TestTransfer_Accept : public TCPApplication {
}
};

/**
* @brief Client application for the transfer test
*
* This application is configured by the following environment variables.
*
* * `LISTEN_ADDR`, `LISTEN_PORT`, `BACKLOG`: Parameters to configure a
* listening socket.
* * `ACCEPT_TIME`: Arbitrary sleeping time before accepting sockets. If
* connections arrive during the sleep, they will consume the backlog count.
* * `START_TIME`: Arbitrary sleeping time before starting the data transfer.
* * `RANDOM_SEED`: This random seed is used to generate a pseudo-random byte
* stream. If a pair of server and client shares the same seed, the seed is
* used to generate and verify the data integrity.
* * `SENDER`: Determines who will send the data. Data transfer can be done in
* either client-to-server and server-to-client directions.
* * `BUFFER_SIZE`: Size of the buffer to be used in every `write` or `read`
* system call.
* * `LOOP_COUNT`: How many times the `write` system call will be invoked.
* * `EXPECT_SIZE`: Expected length of the received data.
*/
class TestTransfer_Connect : public TCPApplication {
public:
TestTransfer_Connect(Host &host,
Expand Down Expand Up @@ -318,14 +277,6 @@ class TestTransfer_Connect : public TCPApplication {
}
};

/**
* Direction: Client -> Server
*
* In this case, the client will invoke `write` system call exactly N times, and
* the server will invoke `read` system call exactly N times. Thus, this test
* will gracefully accept cases when the `close` system call is not implemented
* correctly.
*/
TEST_F(TestEnv_Any, TestTransfer_Connect_Send_Symmetric) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -381,14 +332,6 @@ TEST_F(TestEnv_Any, TestTransfer_Connect_Send_Symmetric) {
this->runTest();
}

/**
* Direction: Client -> Server
*
* In this case, the server does not know how many times the `write` system call
* will be invoked by the client. The server will indefinitly wait for the
* `read` system call unless the `EOF` is received. You should implement proper
* `close` semantics to pass this test.
*/
TEST_F(TestEnv_Any, TestTransfer_Connect_Send_EOF) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -444,12 +387,8 @@ TEST_F(TestEnv_Any, TestTransfer_Connect_Send_EOF) {
this->runTest();
}

/**
* Data direction: Server -> Client.
*
* Same as `TestTransfer_Connect_Send_Symmetric` but the data direction is
* changed.
*/
//---------

TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_Symmetric) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -505,11 +444,6 @@ TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_Symmetric) {
this->runTest();
}

/**
* Data direction: Server -> Client.
*
* Same as `TestTransfer_Connect_Send_EOF` but the data direction is changed.
*/
TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_EOF) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -565,13 +499,6 @@ TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_EOF) {
this->runTest();
}

/**
* Data direction: Server -> Client.
*
* In this case, the server uses a very small buffer (128B) while the client
* sends large packets (>=512B). Assuming that a packet has 512B data, it will
* be used to fill the read buffer of 4 consequent `read` system calls.
*/
TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_SmallBuffer1) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -627,14 +554,6 @@ TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_SmallBuffer1) {
this->runTest();
}

/**
* Data direction: Server -> Client.
*
* In this case, the server uses an extreamly small buffer (67B). This is only 3
* bytes larger than the minimum size of the ethernet frame. Unlike the
* previous example, the small buffer size no longer divides the size of the
* large client buffer without remainders.
*/
TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_SmallBuffer2) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -690,9 +609,8 @@ TEST_F(TestEnv_Any, TestTransfer_Connect_Recv_SmallBuffer2) {
this->runTest();
}

/**
* Exactly as same as the `TestTransfer_Connect_Recv_Symmetric`
*/
//======================================

TEST_F(TestEnv_Any, TestTransfer_Accept_Send_Symmetric) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -748,10 +666,6 @@ TEST_F(TestEnv_Any, TestTransfer_Accept_Send_Symmetric) {
this->runTest();
}

/**
* In `TestTransfer_Connect_Recv_EOF` test, the client sends the EOF signal. In
* this test, the server sends the EOF signal.
*/
TEST_F(TestEnv_Any, TestTransfer_Accept_Send_EOF) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -807,9 +721,8 @@ TEST_F(TestEnv_Any, TestTransfer_Accept_Send_EOF) {
this->runTest();
}

/**
* Same as the `TestTransfer_Connect_Send_Symmetric` test.
*/
//---------

TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_Symmetric) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -865,10 +778,6 @@ TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_Symmetric) {
this->runTest();
}

/**
* In `TestTransfer_Connect_Send_EOF` test, the client sends the EOF signal. In
* this test, the server sends the EOF signal.
*/
TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_EOF) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -924,10 +833,6 @@ TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_EOF) {
this->runTest();
}

/**
* Same as the `TestTransfer_Connect_Recv_SmallBuffer1` test except for the data
* transfer direction.
*/
TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_SmallBuffer1) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down Expand Up @@ -983,10 +888,6 @@ TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_SmallBuffer1) {
this->runTest();
}

/**
* Same as the `TestTransfer_Accept_Recv_SmallBuffer2` test except for the data
* transfer direction.
*/
TEST_F(TestEnv_Any, TestTransfer_Accept_Recv_SmallBuffer2) {
std::unordered_map<std::string, std::string> accept_env;
std::unordered_map<std::string, std::string> connect_env;
Expand Down
11 changes: 8 additions & 3 deletions include/E/Networking/E_Host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class HostModule {
*/
Size getWireSpeed(int port_num);

/**
* @brief Get the number of ports
*
* @return the number of ports
*/
size_t getPortCount();

/**
* @brief Prints log with specified log level and format.
* NetworkLog::print_log prints logs specified in log level parameter.
Expand Down Expand Up @@ -340,9 +347,7 @@ class Host : public NetworkModule, public NetworkLog, public RoutingInfo {
class ProcessInfo {
public:
std::shared_ptr<SystemCallApplication> application;
std::unordered_set<int> fdSet;
std::unordered_map<int, Namespace> fdToDomain;
int fdStart;
std::map<int, Namespace> fdToDomain;
};

int pidStart;
Expand Down
36 changes: 19 additions & 17 deletions src/Networking/E_Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ Size HostModule::getWireSpeed(int port_num) {
return host.getWireSpeed(port_num);
}

size_t HostModule::getPortCount() { return host.getPortCount(); }

void HostModule::print_log(uint64_t level, const char *format, ...) {
va_list arglist;
va_start(arglist, format);
Expand Down Expand Up @@ -337,32 +339,33 @@ void Host::returnSystemCall(UUID syscallUUID, int val) {
int Host::createFileDescriptor(int domain, int protocol, int processID) {
assert(processInfoMap.find(processID) != processInfoMap.end());
ProcessInfo &procInfo = processInfoMap.find(processID)->second;
int start = procInfo.fdStart;
int current = start;
int current = 3;
// assert(procInfo.fdSet.find(processID) != procInfo.fdSet.end());
do {
if (procInfo.fdSet.find(current) == procInfo.fdSet.end()) {
procInfo.fdSet.insert(current);
procInfo.fdStart = (current + 1) % MAX_FD;
procInfo.fdToDomain.insert(
std::pair<int, Namespace>(current, Namespace(domain, protocol)));
// found proper fd number
return current;
}

current = (current + 1) % MAX_FD;
} while (start != current);
auto it = procInfo.fdToDomain.begin();

print_log(NetworkLog::SYSCALL_ERROR, "Out of FD for process %d.", processID);
return -1;
while (it != procInfo.fdToDomain.end() && it->first == current) {
++current;
++it;
}

if (current >= MAX_FD) {

print_log(NetworkLog::SYSCALL_ERROR, "Out of FD for process %d.",
processID);
return -1;
}
procInfo.fdToDomain.insert(
std::pair<int, Namespace>(current, Namespace(domain, protocol)));

return current;
}

void Host::removeFileDescriptor(int processID, int fd) {
// TIME_WAIT occurs after process termination
if (processInfoMap.find(processID) != processInfoMap.end()) {
ProcessInfo &procInfo = processInfoMap.find(processID)->second;

procInfo.fdSet.erase(fd);
procInfo.fdToDomain.erase(fd);
}
}
Expand All @@ -373,7 +376,6 @@ int Host::registerProcess(std::shared_ptr<SystemCallApplication> app) {
do {
if (processInfoMap.find(current) == processInfoMap.end()) {
ProcessInfo procInfo;
procInfo.fdStart = 0;
app->pid = current;
procInfo.application = std::move(app);
processInfoMap.insert(
Expand Down

0 comments on commit e55fa41

Please sign in to comment.