Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

add arp responder #167

Merged
merged 19 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/aca_arp_responder.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ACA_ARP_Responder{

/* Data plane Ops */
void arp_recv(uint32_t in_port, void *vlanmsg, void *message);
void arp_xmit(uint32_t in_port, void *vlanmsg, void *message);
void arp_xmit(uint32_t in_port, void *vlanmsg, void *message, int is_find);


private:
Expand Down
18 changes: 14 additions & 4 deletions src/aca_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "aca_message_pulsar_consumer.h"
#include "aca_grpc.h"
#include "aca_ovs_l2_programmer.h"
#include "aca_ovs_control.h"
#include "goalstateprovisioner.grpc.pb.h"
#include <thread>
#include <unistd.h> /* for getopt */
Expand All @@ -41,6 +42,8 @@ using namespace std;

// Global variables
std::thread *g_grpc_server_thread = NULL;
std::thread *ovs_monitor_brtun_thread = NULL;
std::thread *ovs_monitor_brint_thread = NULL;
GoalStateProvisionerImpl *g_grpc_server = NULL;
string g_broker_list = EMPTY_STRING;
string g_pulsar_topic = EMPTY_STRING;
Expand Down Expand Up @@ -126,7 +129,7 @@ static void aca_signal_handler(int sig_num)
int main(int argc, char *argv[])
{
int option;
int rc;
int rc = 0;

ACA_LOG_INIT(ACALOGNAME);

Expand Down Expand Up @@ -207,11 +210,18 @@ int main(int argc, char *argv[])

aca_ovs_l2_programmer::ACA_OVS_L2_Programmer::get_instance().setup_ovs_bridges_if_need();

ACA_OVS_Control::get_instance().monitor("br-int", "resume");

ACA_Message_Pulsar_Consumer network_config_consumer(g_broker_list, g_pulsar_subsription_name);
rc = network_config_consumer.consumeDispatched(g_pulsar_topic);
// monitor br-int for dhcp request message
ovs_monitor_brint_thread =
new thread(bind(&ACA_OVS_Control::monitor,
&ACA_OVS_Control::get_instance(), "br-int", "resume"));
ovs_monitor_brint_thread->detach();

// monitor br-tun for arp request message
ACA_OVS_Control::get_instance().monitor("br-tun","resume");

// ACA_Message_Pulsar_Consumer network_config_consumer(g_broker_list, g_pulsar_subsription_name);
// rc = network_config_consumer.consumeDispatched(g_pulsar_topic);
aca_cleanup();
return rc;
}
23 changes: 13 additions & 10 deletions src/ovs/aca_arp_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,13 @@ void ACA_ARP_Responder::arp_recv(uint32_t in_port, void *vlan_hdr, void *message
return;

}
void ACA_ARP_Responder::arp_xmit(uint32_t in_port, void *vlanmsg, void *message){
void ACA_ARP_Responder::arp_xmit(uint32_t in_port, void *vlanmsg, void *message, int is_find){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_found

arp_message *arpmsg = nullptr;
string bridge = "br-tun";
string inport = "in_port=controller";
string whitespace = " ";
string action = "actions=output:" + to_string(in_port);
string rs_action = "actions=resubmit(,22)";
string packetpre = "packet=";
string packet;
string options;
Expand All @@ -243,8 +244,12 @@ void ACA_ARP_Responder::arp_xmit(uint32_t in_port, void *vlanmsg, void *message
ACA_LOG_ERROR("%s","Serialized ARP Reply is null!\n");
return;
}

options = inport + whitespace + packetpre + packet +whitespace + action;
if(is_find){
options = inport + whitespace + packetpre + packet +whitespace + action;
}
else{
options = inport + whitespace + packetpre + packet +whitespace + rs_action;
}

aca_ovs_control::ACA_OVS_Control::get_instance().packet_out(bridge.c_str(),options.c_str());

Expand All @@ -267,22 +272,20 @@ void ACA_ARP_Responder::_parse_arp_request(uint32_t in_port, vlan_message *vlanm
stData.vlan_id = 0;
}

//find the corresponding mac address in the db based on ip and vlan id
// if not find the corresponding mac address in the db based on ip and vlan id, resubmit to table 22
// else construct an arp reply
if(!_arp_db.find(stData,current_arp_data)){
ACA_LOG_DEBUG("ARP entry does not exist! (ip = %s and vlan id = %u)\n",
stData.ipv4_address.c_str(),stData.vlan_id);
//TO DO
arp_xmit(in_port, vlanmsg, arpmsg, 0);
return;
}
else{
ACA_LOG_DEBUG("ARP entry exist (ip = %s and vlan id = %u) with mac = %s\n",
stData.ipv4_address.c_str(),stData.vlan_id,current_arp_data->mac_address.c_str());
arpreply = _pack_arp_reply(arpmsg,current_arp_data->mac_address);
arp_xmit(in_port, vlanmsg, arpreply, 1);
}
if(!arpreply){
return;
}

arp_xmit(in_port, vlanmsg, arpreply);
}

arp_message *ACA_ARP_Responder::_pack_arp_reply(arp_message *arpreq, string mac_address){
Expand Down
3 changes: 0 additions & 3 deletions src/ovs/aca_ovs_l2_programmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ int ACA_OVS_L2_Programmer::setup_ovs_bridges_if_need()
execute_openflow_command("add-flow br-tun \"table=20,priority=1 actions=resubmit(,22)\"",
not_care_culminative_time, overall_rc);

execute_openflow_command("add-flow br-tun \"table=51,priority=1 actions=resubmit(,22)\"",
not_care_culminative_time, overall_rc);

execute_openflow_command("add-flow br-tun \"table=2,priority=25,icmp,icmp_type=8,in_port=\"patch-int\" actions=resubmit(,52)\"",
not_care_culminative_time, overall_rc);

Expand Down
6 changes: 3 additions & 3 deletions test/gtest/aca_test_arp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ TEST(arp_request_test_cases, arps_recv_valid)
// it can be executed by:
//
// child machine (-p 10.213.43.187 -> IP of parent machine):
// aca_tests --gtest_also_run_disabled_tests --gtest_filter=arp_request_test_cases.DISABLED_l2_arp_test_CHILD -p 10.213.43.187
// ./build/tests/aca_tests --gtest_also_run_disabled_tests --gtest_filter=arp_request_test_cases.DISABLED_l2_arp_test_CHILD -p 10.213.43.187
// parent machine (-c 10.213.43.188 -> IP of child machine):
// aca_tests --gtest_also_run_disabled_tests --gtest_filter=arp_request_test_cases.DISABLED_l2_arp_test_PARENT -c 10.213.43.188
// ./build/tests/aca_tests --gtest_also_run_disabled_tests --gtest_filter=arp_request_test_cases.DISABLED_l2_arp_test_PARENT -c 10.213.43.188
//

TEST(arp_request_test_cases, DISABLED_l2_arp_test_one_machine)
Expand Down Expand Up @@ -422,7 +422,7 @@ TEST(arp_request_test_cases, DISABLED_l2_arp_test_PARENT)
// restore demo mode
g_demo_mode = previous_demo_mode;

// test ping
// test valid traffic from parent to child
cmd_string = "docker exec con3 ping -c1 " + vip_address_3;
overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string);
EXPECT_EQ(overall_rc, EXIT_SUCCESS);
Expand Down
4 changes: 2 additions & 2 deletions test/gtest/aca_test_ovs_l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ extern void aca_test_1_port_CREATE_plus_N_neighbors_CREATE(NeighborType input_ne
// it can be executed by:
//
// child machine (-p 10.213.43.187 -> IP of parent machine):
// aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_2_ports_CREATE_test_traffic_CHILD -p 10.213.43.187
// ./build/tests/aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_2_ports_CREATE_test_traffic_CHILD -p 10.213.43.187
// parent machine (-c 10.213.43.188 -> IP of child machine):
// aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_2_ports_CREATE_test_traffic_PARENT -c 10.213.43.188
// ./build/tests/aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_2_ports_CREATE_test_traffic_PARENT -c 10.213.43.188
//
TEST(ovs_l2_test_cases, 2_ports_CREATE_test_traffic_plus_neighbor_internal)
{
Expand Down
6 changes: 3 additions & 3 deletions test/gtest/aca_test_ovs_l3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,9 @@ TEST(ovs_l3_test_cases, DISABLED_2_ports_ROUTING_test_traffic_PARENT)
ASSERT_EQ(overall_rc, EXIT_SUCCESS);

// should not be able to ping port 4 anymore
// overall_rc = Aca_Net_Config::get_instance().execute_system_command(
// "docker exec con1 ping -c1 " + vip_address_4);
// EXPECT_NE(overall_rc, EXIT_SUCCESS);
overall_rc = Aca_Net_Config::get_instance().execute_system_command(
"docker exec con1 ping -c1 " + vip_address_4);
EXPECT_NE(overall_rc, EXIT_SUCCESS);

// but still have to ping port 3 since it is not deleted
overall_rc = Aca_Net_Config::get_instance().execute_system_command(
Expand Down