Skip to content

Commit

Permalink
Deleted callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyyeh committed Nov 16, 2022
1 parent 0542a1a commit 2ecfe1d
Showing 1 changed file with 1 addition and 257 deletions.
258 changes: 1 addition & 257 deletions test/MockRelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,7 @@ TEST(sock, sock_open_invalid_filter)
const struct sock_fprog ether_relay_fprog = {0,{}};
EXPECT_EQ(sock_open(&ether_relay_fprog), -1);
}
/*
TEST(sock, prepare_socket)
{
relay_config *config = new struct relay_config;;
int local_sock = -1, server_sock = -1;
int socket_type = -1;
socklen_t socket_type_len = sizeof(socket_type);
prepare_socket(&local_sock, &server_sock, config);
EXPECT_GE(local_sock, 0);
EXPECT_GE(server_sock, 0);
EXPECT_EQ(0, getsockopt(local_sock, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len));
EXPECT_EQ(SOCK_DGRAM, socket_type);
socket_type = -1;
socket_type_len = sizeof(socket_type);
EXPECT_EQ(0, getsockopt(server_sock, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len));
EXPECT_EQ(SOCK_DGRAM, socket_type);
close(local_sock);
close(server_sock);
delete config;
}
*/

TEST(helper, send_udp)
{
int sock = 0;
Expand Down Expand Up @@ -551,242 +531,6 @@ TEST(relay, relay_relay_reply)
sendUdpCount = 0;
}

TEST(callback, solicit) {
evutil_socket_t fd = 1;
short event = 1;

struct relay_config config{};
config.is_option_79 = true;
config.link_address.sin6_addr.__in6_u.__u6_addr8[15] = 0x01;

config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");

struct sockaddr_in6 addr;
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(RELAY_PORT);
inet_pton(AF_INET6, "::1", &addr.sin6_addr);

std::shared_ptr<swss::DBConnector> state_db = std::make_shared<swss::DBConnector> ("STATE_DB", 0);
config.state_db = state_db;
config.filter = sock_open(&lo_ether_relay_fprog);
EXPECT_GE(config.filter, 0);
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
int local_sock = 0;
int server_sock = 0;
config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");
prepare_relay_config(&config, &local_sock, config.filter);

uint8_t solicit[] = { //SOLICIT
0x01, 0x2f, 0xf4, 0xc8, 0x00, 0x01, 0x00, 0x0e,
0x00, 0x01, 0x00, 0x01, 0x25, 0x3a, 0x37, 0xb9,
0x5a, 0xc6, 0xb0, 0x12, 0xe8, 0xb4, 0x00, 0x06,
0x00, 0x04, 0x00, 0x17, 0x00, 0x18, 0x00, 0x08,
0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c,
0xb0, 0x12, 0xe8, 0xb4, 0x00, 0x00, 0x0e, 0x10,
0x00, 0x00, 0x15, 0x18
};

sendto(sock, solicit, sizeof(solicit), 0, (sockaddr*)&addr, sizeof(addr));
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait 2 seconds for socket to receive data for consistent passing test
callback(fd, event, &config);
EXPECT_GE(sendUdpCount, 2);
sendUdpCount = 0;

close(local_sock);
close(server_sock);
}

TEST(callback, relay_forward) {
evutil_socket_t fd = 1;
short event = 1;

struct relay_config config{};
config.is_option_79 = true;
config.link_address.sin6_addr.__in6_u.__u6_addr8[15] = 0x01;

config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");

struct sockaddr_in6 addr;
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(RELAY_PORT);
inet_pton(AF_INET6, "::1", &addr.sin6_addr);

std::shared_ptr<swss::DBConnector> state_db = std::make_shared<swss::DBConnector> ("STATE_DB", 0);
config.state_db = state_db;
config.filter = sock_open(&lo_ether_relay_fprog);
EXPECT_GE(config.filter, 0);
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
int local_sock = 0;
int server_sock = 0;
config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");
prepare_relay_config(&config, &local_sock, config.filter);

uint8_t relay_forward[] = { //RELAY_FORWARD
0x0c, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x01, 0x5a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x09, 0x00, 0x34, 0x01, 0x2f,
0xf4, 0xc8, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x01,
0x00, 0x01, 0x25, 0x3a, 0x37, 0xb9, 0x5a, 0xc6,
0xb0, 0x12, 0xe8, 0xb4, 0x00, 0x06, 0x00, 0x04,
0x00, 0x17, 0x00, 0x18, 0x00, 0x08, 0x00, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0xb0, 0x12,
0xe8, 0xb4, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x00,
0x15, 0x18
};

sendto(sock, relay_forward, sizeof(relay_forward), 0, (sockaddr*)&addr, sizeof(addr));
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait 2 seconds for socket to receive data for consistent passing test
callback(fd, event, &config);
EXPECT_GE(sendUdpCount, 2);
sendUdpCount = 0;

close(local_sock);
close(server_sock);
}

TEST(callback_dual_tor, solicit) {
evutil_socket_t fd = 1;
short event = 1;

struct relay_config config{};
config.is_option_79 = true;
config.link_address.sin6_addr.__in6_u.__u6_addr8[15] = 0x01;

config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");

struct sockaddr_in6 addr;
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(RELAY_PORT);
inet_pton(AF_INET6, "::1", &addr.sin6_addr);

std::shared_ptr<swss::DBConnector> state_db = std::make_shared<swss::DBConnector> ("STATE_DB", 0);
state_db->hset("HW_MUX_CABLE_TABLE|lo", "state", "standby");
std::shared_ptr<swss::DBConnector> config_db = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
config_db->hset(config.mux_key + "lo", "tagging_mode", "untagged");
std::shared_ptr<swss::Table> mStateDbMuxTablePtr = std::make_shared<swss::Table> (
state_db.get(), "HW_MUX_CABLE_TABLE"
);

config.state_db = state_db;
config.mux_table = mStateDbMuxTablePtr;
config.interface = "lo";
config.filter = sock_open(&lo_ether_relay_fprog);
config.mux_key = "VLAN_MEMBER|Vlan000|";
config.config_db = config_db;

EXPECT_GE(config.filter, 0);
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
int local_sock = 0;
int server_sock = 0;
config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");
prepare_relay_config(&config, &local_sock, config.filter);

uint8_t solicit[] = { /* SOLICIT */
0x01, 0x2f, 0xf4, 0xc8, 0x00, 0x01, 0x00, 0x0e,
0x00, 0x01, 0x00, 0x01, 0x25, 0x3a, 0x37, 0xb9,
0x5a, 0xc6, 0xb0, 0x12, 0xe8, 0xb4, 0x00, 0x06,
0x00, 0x04, 0x00, 0x17, 0x00, 0x18, 0x00, 0x08,
0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c,
0xb0, 0x12, 0xe8, 0xb4, 0x00, 0x00, 0x0e, 0x10,
0x00, 0x00, 0x15, 0x18
};

sendto(sock, solicit, sizeof(solicit), 0, (sockaddr*)&addr, sizeof(addr));
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait 2 seconds for socket to receive data for consistent passing test
callback_dual_tor(fd, event, &config);
EXPECT_EQ(sendUdpCount, 0);
sendUdpCount = 0;

config.state_db->hset("HW_MUX_CABLE_TABLE|lo", "state", "active");
sendto(sock, solicit, sizeof(solicit), 0, (sockaddr*)&addr, sizeof(addr));
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait 2 seconds for socket to receive data for consistent passing test
callback_dual_tor(fd, event, &config);
EXPECT_GE(sendUdpCount, 2);
sendUdpCount = 0;

close(local_sock);
close(server_sock);
}

TEST(callback_dual_tor, relay_forward) {
evutil_socket_t fd = 1;
short event = 1;

struct relay_config config{};
config.is_option_79 = true;
config.link_address.sin6_addr.__in6_u.__u6_addr8[15] = 0x01;

config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");

struct sockaddr_in6 addr;
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(RELAY_PORT);
inet_pton(AF_INET6, "::1", &addr.sin6_addr);

std::shared_ptr<swss::DBConnector> state_db = std::make_shared<swss::DBConnector> ("STATE_DB", 0);
state_db->hset("HW_MUX_CABLE_TABLE|lo", "state", "standby");
std::shared_ptr<swss::DBConnector> config_db = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
config_db->hset(config.mux_key + "lo", "tagging_mode", "untagged");
std::shared_ptr<swss::Table> mStateDbMuxTablePtr = std::make_shared<swss::Table> (
state_db.get(), "HW_MUX_CABLE_TABLE"
);

config.state_db = state_db;
config.mux_table = mStateDbMuxTablePtr;
config.interface = "lo";
config.filter = sock_open(&lo_ether_relay_fprog);
config.mux_key = "VLAN_MEMBER|Vlan000|";
config.config_db = config_db;

EXPECT_GE(config.filter, 0);
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
int local_sock = 0;
int server_sock = 0;
config.servers.push_back("fc02:2000::1");
config.servers.push_back("fc02:2000::2");
prepare_relay_config(&config, &local_sock, config.filter);

uint8_t relay_forward[] = { /* RELAY_FORWARD */
0x0c, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x01, 0x5a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x09, 0x00, 0x34, 0x01, 0x2f,
0xf4, 0xc8, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x01,
0x00, 0x01, 0x25, 0x3a, 0x37, 0xb9, 0x5a, 0xc6,
0xb0, 0x12, 0xe8, 0xb4, 0x00, 0x06, 0x00, 0x04,
0x00, 0x17, 0x00, 0x18, 0x00, 0x08, 0x00, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0xb0, 0x12,
0xe8, 0xb4, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x00,
0x15, 0x18
};

sendto(sock, relay_forward, sizeof(relay_forward), 0, (sockaddr*)&addr, sizeof(addr));
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait 2 seconds for socket to receive data for consistent passing test
callback_dual_tor(fd, event, &config);
EXPECT_EQ(sendUdpCount, 0);
sendUdpCount = 0;

config.state_db->hset("HW_MUX_CABLE_TABLE|lo", "state", "active");
sendto(sock, relay_forward, sizeof(relay_forward), 0, (sockaddr*)&addr, sizeof(addr));
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait 2 seconds for socket to receive data for consistent passing test
callback_dual_tor(fd, event, &config);
EXPECT_GE(sendUdpCount, 2);
sendUdpCount = 0;

close(local_sock);
close(server_sock);
}

TEST(relay, signal_init) {
signal_init();
EXPECT_NE((uintptr_t)ev_sigint, NULL);
Expand Down

0 comments on commit 2ecfe1d

Please sign in to comment.