From 1c121dce1c2005cb1e59e2c6010b648fdf3bd9fb Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 10 Mar 2021 13:11:55 +0800 Subject: [PATCH 01/37] fix invalid pointer bug --- src/ovs/aca_arp_responder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ovs/aca_arp_responder.cpp b/src/ovs/aca_arp_responder.cpp index ef853449..5dd8de6c 100644 --- a/src/ovs/aca_arp_responder.cpp +++ b/src/ovs/aca_arp_responder.cpp @@ -242,14 +242,14 @@ void ACA_ARP_Responder::arp_xmit(uint32_t in_port, void *vlanmsg, void *message, } if (is_found) { options = inport + whitespace + packetpre + packet + whitespace + action; + //delete the constructed arp reply + delete arpmsg; } 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()); - - delete arpmsg; } void ACA_ARP_Responder::_parse_arp_request(uint32_t in_port, vlan_message *vlanmsg, From a271fe34ced960fef63011d166a4ee1010727fa4 Mon Sep 17 00:00:00 2001 From: lly Date: Tue, 16 Mar 2021 22:37:37 +0800 Subject: [PATCH 02/37] [Fix #223]remove arp test case on one machine --- test/gtest/aca_test_arp.cpp | 123 ------------------------------------ 1 file changed, 123 deletions(-) diff --git a/test/gtest/aca_test_arp.cpp b/test/gtest/aca_test_arp.cpp index 4b0571bb..84cce268 100644 --- a/test/gtest/aca_test_arp.cpp +++ b/test/gtest/aca_test_arp.cpp @@ -198,129 +198,6 @@ TEST(arp_request_test_cases, arps_recv_valid) // ./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) -{ - string cmd_string; - arp_config stArpCfgIn; - int overall_rc; - - aca_test_reset_environment(); - - // monitor br-tun for arp request message - ovs_monitor_thread = - new thread(bind(&ACA_OVS_Control::monitor, &ACA_OVS_Control::get_instance(), "br-tun", "resume")); - ovs_monitor_thread->detach(); - - GoalState GoalState_builder; - - SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); - new_subnet_states->set_operation_type(OperationType::INFO); - SubnetConfiguration *SubnetConiguration_builder = - new_subnet_states->mutable_configuration(); - SubnetConiguration_builder->set_revision_number(1); - SubnetConiguration_builder->set_vpc_id(vpc_id_1); - SubnetConiguration_builder->set_id(subnet_id_1); - SubnetConiguration_builder->set_cidr(subnet1_cidr); - SubnetConiguration_builder->set_tunnel_id(123); - - auto *subnetConfig_GatewayBuilder(new SubnetConfiguration_Gateway); - subnetConfig_GatewayBuilder->set_ip_address(subnet1_gw_ip); - subnetConfig_GatewayBuilder->set_mac_address(subnet1_gw_mac); - SubnetConiguration_builder->set_allocated_gateway(subnetConfig_GatewayBuilder); - - NeighborState *new_neighbor_states = GoalState_builder.add_neighbor_states(); - - new_neighbor_states->set_operation_type(OperationType::CREATE); - - // fill in neighbor state structs - NeighborConfiguration *NeighborConfiguration_builder = - new_neighbor_states->mutable_configuration(); - NeighborConfiguration_builder->set_revision_number(1); - - NeighborConfiguration_builder->set_vpc_id(vpc_id_1); - NeighborConfiguration_builder->set_id(port_id_3); - NeighborConfiguration_builder->set_mac_address(vmac_address_3); - NeighborConfiguration_builder->set_host_ip_address("172.16.62.158"); - - NeighborConfiguration_FixedIp *FixedIp_builder = - NeighborConfiguration_builder->add_fixed_ips(); - FixedIp_builder->set_neighbor_type(NeighborType::L2); - FixedIp_builder->set_subnet_id(subnet_id_1); - FixedIp_builder->set_ip_address(vip_address_3); - - GoalStateOperationReply gsOperationalReply; - - overall_rc = Aca_Comm_Manager::get_instance().update_goal_state( - GoalState_builder, gsOperationalReply); - ASSERT_EQ(overall_rc, EXIT_SUCCESS); - - NeighborConfiguration_builder->set_mac_address(vmac_address_1); - FixedIp_builder->set_ip_address(vip_address_1); - - overall_rc = Aca_Comm_Manager::get_instance().update_goal_state( - GoalState_builder, gsOperationalReply); - ASSERT_EQ(overall_rc, EXIT_SUCCESS); - - - // create docker instances for test - // con1 - overall_rc = Aca_Net_Config::get_instance().execute_system_command( - "docker run -itd --cap-add=NET_ADMIN --name con1 --net=none alpine sh"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - cmd_string = "ovs-docker add-port br-int eth1 con1 --macaddress=" + vmac_address_1 + " --ipaddress="+vip_address_1 + "/24"; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - - cmd_string = "ovs-docker set-vlan br-int eth1 con1 1"; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - - - // con2 - overall_rc = Aca_Net_Config::get_instance().execute_system_command( - "docker run -itd --cap-add=NET_ADMIN --name con2 --net=none alpine sh"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - cmd_string = "ovs-docker add-port br-int eth1 con2 --macaddress=" + vmac_address_3 + " --ipaddress="+vip_address_3 + "/24"; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - cmd_string = "ovs-docker set-vlan br-int eth1 con2 1"; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - // test ping - cmd_string = "docker exec con1 ping -c1 " + vip_address_3; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - - cmd_string = "docker exec con2 ping -c1 " + vip_address_1; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - - - //clean up - overall_rc = Aca_Net_Config::get_instance().execute_system_command( - "ovs-docker del-ports br-int con1"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - overall_rc = Aca_Net_Config::get_instance().execute_system_command( - "ovs-docker del-ports br-int con2"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - overall_rc = Aca_Net_Config::get_instance().execute_system_command("docker rm con1 -f"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - - overall_rc = Aca_Net_Config::get_instance().execute_system_command("docker rm con2 -f"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); -} - - TEST(arp_request_test_cases, DISABLED_l2_arp_test_PARENT) { From 8e019a9350b2b5c92259afd041998f6bc4d9f51e Mon Sep 17 00:00:00 2001 From: lly Date: Sat, 4 Sep 2021 15:45:44 +0800 Subject: [PATCH 03/37] some minor change --- include/aca_message_pulsar_consumer.h | 4 +++ src/comm/aca_message_pulsar_consumer.cpp | 39 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 5732379d..0be0d2ea 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -20,6 +20,8 @@ #include "pulsar/ConsumerConfiguration.h" #include "pulsar/Message.h" #include "pulsar/Result.h" +#include "pulsar/ConsumerType.h" +//#include "pulsar/KeySharedPolicy.h" using namespace pulsar; @@ -58,6 +60,8 @@ class ACA_Message_Pulsar_Consumer { void setBrokers(string brokers); void setLastTopicName(string topic); + + void listener(Consumer consumer, const Message& message); }; } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index ee7723df..540181a6 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -65,6 +65,44 @@ void ACA_Message_Pulsar_Consumer::setSubscriptionName(string subscription_name) this->subscription_name = subscription_name; } + +// void listener(Consumer consumer, const Message& message){ +// alcor::schema::GoalState deserialized_GoalState; +// alcor::schema::GoalStateOperationReply gsOperationalReply; +// int rc; +// int overall_rc = EXIT_SUCCESS; +// Result result; +// Message message; +// Consumer consumer; + +// ACA_LOG_DEBUG("\n<=====incoming message: %s\n", +// message.getDataAsString().c_str()); + +// rc = Aca_Comm_Manager::get_instance().deserialize( +// (unsigned char *)message.getData(), message.getLength(), deserialized_GoalState); +// if (rc == EXIT_SUCCESS) { +// rc = Aca_Comm_Manager::get_instance().update_goal_state( +// deserialized_GoalState, gsOperationalReply); + +// // TODO: send gsOperationalReply back to controller + +// if (rc != EXIT_SUCCESS) { +// ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); +// overall_rc = rc; +// } else { +// ACA_LOG_INFO("Successfully updated host with latest goal state %d.\n", rc); +// } + +// } else { +// ACA_LOG_ERROR("Deserialization failed with error code %d.\n", rc); +// overall_rc = rc; +// } + +// // Now acknowledge message +// consumer.acknowledge(message.getMessageId()); +// } + + bool ACA_Message_Pulsar_Consumer::consumeDispatched(string topic) { alcor::schema::GoalState deserialized_GoalState; @@ -74,6 +112,7 @@ bool ACA_Message_Pulsar_Consumer::consumeDispatched(string topic) Result result; Message message; Consumer consumer; + //this->consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(KeySharedPolicy).setMessageListener(messageListener) result = this->ptr_client->subscribe(topic,this->subscription_name,this->consumer_config,consumer); if (result != Result::ResultOk){ From 5de960848b88246f992d12d984869d71e3b88494 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 20 Oct 2021 23:04:34 +0800 Subject: [PATCH 04/37] Add listeners for multicast and unicast consumer --- build/Dockerfile | 2 +- build/aca-machine-init.sh | 2 +- include/aca_message_pulsar_consumer.h | 51 ++++-- src/CMakeLists.txt | 1 + src/aca_main.cpp | 9 +- src/comm/aca_message_pulsar_consumer.cpp | 201 +++++++++++------------ src/comm/aca_message_pulsar_producer.cpp | 1 + test/gtest/aca_test_main.cpp | 2 +- 8 files changed, 146 insertions(+), 123 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 68b102ea..8c1c7195 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -185,7 +185,7 @@ RUN echo "5--- installing openvswitch dependancies ---" && \ test -f /usr/bin/ovs-vsctl && rm -rf /usr/local/sbin/ov* /usr/local/bin/ov* /usr/local/bin/vtep* && \ cd ~ -ENV PULSAR_RELEASE_TAG='pulsar-2.6.1' +ENV PULSAR_RELEASE_TAG='pulsar-2.8.1' RUN echo "6--- installing pulsar dependacies ---" && \ mkdir -p /var/local/git/pulsar && \ wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client.deb -O /var/local/git/pulsar/apache-pulsar-client.deb && \ diff --git a/build/aca-machine-init.sh b/build/aca-machine-init.sh index 1a7162be..8ac558a5 100755 --- a/build/aca-machine-init.sh +++ b/build/aca-machine-init.sh @@ -199,7 +199,7 @@ echo "6--- installing openvswitch dependancies ---" && \ test -f /usr/bin/ovs-vsctl && rm -rf /usr/local/sbin/ov* /usr/local/bin/ov* /usr/local/bin/vtep* && \ cd ~ -PULSAR_RELEASE_TAG='pulsar-2.8.0' +PULSAR_RELEASE_TAG='pulsar-2.8.1' echo "7--- installing pulsar dependacies ---" && \ mkdir -p /var/local/git/pulsar && \ wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client.deb -O /var/local/git/pulsar/apache-pulsar-client.deb && \ diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 0be0d2ea..4572c454 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -21,7 +21,7 @@ #include "pulsar/Message.h" #include "pulsar/Result.h" #include "pulsar/ConsumerType.h" -//#include "pulsar/KeySharedPolicy.h" +#include "pulsar/KeySharedPolicy.h" using namespace pulsar; @@ -31,37 +31,58 @@ namespace aca_message_pulsar { class ACA_Message_Pulsar_Consumer { private: - string brokers_list; //IP addresses of pulsar brokers, format: pulsar:://:, example: pulsar://10.213.43.188:9092 + string brokers_list; // IP addresses of pulsar brokers, format: pulsar:://:, example: pulsar://10.213.43.188:9092 - string subscription_name; //Subscription name of the pulsar consumer + string multicast_subscription_name; // Subscription name of the multicast pulsar consumer + string unicast_subscription_name; // Subscription name of the unicast pulsar consumer - string topic_name; //A string representation of the topic to be consumed, for example: /hostid/00000000-0000-0000-0000-000000000000/netwconf/ + string multicast_topic_name; //A string representation of the topic to be consumed, for example: /hostid/00000000-0000-0000-0000-000000000000/netwconf/ + string unicast_topic_name; - ConsumerConfiguration consumer_config; //Configuration of the pulsar consumer + ConsumerConfiguration multicast_consumer_config; //Configuration of the mulitcast pulsar consumer + ConsumerConfiguration unicast_consumer_config; //Configuration of the unicast pulsar consumer - Client *ptr_client; //A pointer to the pulsar client + Client *ptr_multicast_client; //A pointer to the multicast pulsar client + Client *ptr_unicast_client; //A pointer to the unicast pulsar client + + Consumer multicast_consumer; + Consumer unicast_consumer; + + private: + void setMulticastSubscriptionName(string subscription_name); + + void setUnicastSubscriptionName(string subscription_name); + + void setBrokers(string brokers); + + void setMulticastTopicName(string topic); + + void setUnicastTopicName(string topic); + + public: - ACA_Message_Pulsar_Consumer(string brokers, string subscription_name); + ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); ~ACA_Message_Pulsar_Consumer(); string getBrokers() const; - string getLastTopicName() const; + string getMulticastTopicName() const; - string getSubscriptionName() const; + string getUnicastTopicName() const; - void setSubscriptionName(string subscription_name); + string getMulticastSubscriptionName() const; - bool consumeDispatched(string topic); + string getUnicastSubscriptionName() const; - private: - void setBrokers(string brokers); + bool multicastConsumerDispatched(); + + bool unicastConsumerDispatched(int stickyHash); - void setLastTopicName(string topic); + //static void listener(Consumer consumer, const Message& message); - void listener(Consumer consumer, const Message& message); + }; } // namespace aca_message_pulsar diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3accc472..5a0f4992 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,6 +103,7 @@ target_link_libraries(AlcorControlAgent grpc) target_link_libraries(AlcorControlAgent ${PROTOBUF_LIBRARY}) target_link_libraries(AlcorControlAgent ${_GRPC_GRPCPP_UNSECURE}) + add_dependencies(AlcorControlAgentLib proto grpc) add_subdirectory(proto3) add_subdirectory(grpc) \ No newline at end of file diff --git a/src/aca_main.cpp b/src/aca_main.cpp index 30e338ac..8da120aa 100644 --- a/src/aca_main.cpp +++ b/src/aca_main.cpp @@ -42,7 +42,7 @@ using std::string; // Defines #define ACALOGNAME "AlcorControlAgent" static char EMPTY_STRING[] = ""; -static char BROKER_LIST[] = "pulsar://localhost:6502"; +static char BROKER_LIST[] = "pulsar://localhost:6650"; static char PULSAR_TOPIC[] = "Host-ts-1"; static char PULSAR_SUBSCRIPTION_NAME[] = "Test-Subscription"; static char GRPC_SERVER_PORT[] = "50001"; @@ -287,9 +287,10 @@ int main(int argc, char *argv[]) //// 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_Message_Pulsar_Consumer network_config_consumer(g_pulsar_topic, g_broker_list, g_pulsar_subsription_name); + network_config_consumer.multicastConsumerDispatched(); + //network_config_consumer.unicastConsumerDispatched(0); + pause(); aca_cleanup(); diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 540181a6..93dd0150 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -24,25 +24,69 @@ using pulsar::ConsumerConfiguration; using pulsar::Consumer; using pulsar::Message; using pulsar::Result; +using pulsar::KeySharedPolicy; +using pulsar::StickyRange; namespace aca_message_pulsar { -ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string brokers, string subscription_name) + +void listener(Consumer consumer, const Message& message){ + alcor::schema::GoalState deserialized_GoalState; + alcor::schema::GoalStateOperationReply gsOperationalReply; + int rc; + Result result; + printf("\n<=====incoming message: %s\n", + message.getDataAsString().c_str()); + + ACA_LOG_DEBUG("\n<=====incoming message: %s\n", + message.getDataAsString().c_str()); + + rc = Aca_Comm_Manager::get_instance().deserialize( + (unsigned char *)message.getData(), message.getLength(), deserialized_GoalState); + if (rc == EXIT_SUCCESS) { + rc = Aca_Comm_Manager::get_instance().update_goal_state( + deserialized_GoalState, gsOperationalReply); + + // TODO: send gsOperationalReply back to controller + + if (rc != EXIT_SUCCESS) { + ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); + } else { + ACA_LOG_INFO("Successfully updated host with latest goal state %d.\n", rc); + } + + } else { + ACA_LOG_ERROR("Deserialization failed with error code %d.\n", rc); + } + + // Now acknowledge message + consumer.acknowledge(message.getMessageId()); +} + +ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) { + setUnicastTopicName(topic); + setMulticastTopicName(topic); setBrokers(brokers); - setSubscriptionName(subscription_name); + setUnicastSubscriptionName(subscription_name); + setMulticastSubscriptionName(subscription_name); ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); - ACA_LOG_DEBUG("Consumer subscription name: %s\n", this->subscription_name.c_str()); - - // Create the client - this->ptr_client= new Client(brokers); + ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); + ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); + ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); + ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); + + // Create the clients + this->ptr_multicast_client= new Client(brokers); + this->ptr_unicast_client = new Client(brokers); } ACA_Message_Pulsar_Consumer::~ACA_Message_Pulsar_Consumer() { - delete this->ptr_client; + delete this->ptr_multicast_client; + delete this->ptr_unicast_client; } string ACA_Message_Pulsar_Consumer::getBrokers() const @@ -50,130 +94,85 @@ string ACA_Message_Pulsar_Consumer::getBrokers() const return this->brokers_list; } -string ACA_Message_Pulsar_Consumer::getLastTopicName() const +string ACA_Message_Pulsar_Consumer::getMulticastTopicName() const { - return this->topic_name; + return this->multicast_topic_name; } -string ACA_Message_Pulsar_Consumer::getSubscriptionName() const +string ACA_Message_Pulsar_Consumer::getMulticastSubscriptionName() const { - return this->subscription_name; + return this->multicast_subscription_name; } -void ACA_Message_Pulsar_Consumer::setSubscriptionName(string subscription_name) +string ACA_Message_Pulsar_Consumer::getUnicastTopicName() const { - this->subscription_name = subscription_name; + return this->unicast_topic_name; } +string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const +{ + return this->unicast_subscription_name; +} -// void listener(Consumer consumer, const Message& message){ -// alcor::schema::GoalState deserialized_GoalState; -// alcor::schema::GoalStateOperationReply gsOperationalReply; -// int rc; -// int overall_rc = EXIT_SUCCESS; -// Result result; -// Message message; -// Consumer consumer; - -// ACA_LOG_DEBUG("\n<=====incoming message: %s\n", -// message.getDataAsString().c_str()); - -// rc = Aca_Comm_Manager::get_instance().deserialize( -// (unsigned char *)message.getData(), message.getLength(), deserialized_GoalState); -// if (rc == EXIT_SUCCESS) { -// rc = Aca_Comm_Manager::get_instance().update_goal_state( -// deserialized_GoalState, gsOperationalReply); - -// // TODO: send gsOperationalReply back to controller -// if (rc != EXIT_SUCCESS) { -// ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); -// overall_rc = rc; -// } else { -// ACA_LOG_INFO("Successfully updated host with latest goal state %d.\n", rc); -// } +bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ + Result result; + Consumer consumer; + KeySharedPolicy keySharedPolicy; -// } else { -// ACA_LOG_ERROR("Deserialization failed with error code %d.\n", rc); -// overall_rc = rc; -// } + keySharedPolicy.setKeySharedMode(STICKY); + // Set sticky ranges with specified hash value + // StickyRange stickyRange = std::make_pair(stickyHash,stickyHash); + // keySharedPolicy.getStickyRanges(); -// // Now acknowledge message -// consumer.acknowledge(message.getMessageId()); -// } + //Use key shared mode + this->unicast_consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(keySharedPolicy).setMessageListener(listener); + result = this->ptr_unicast_client->subscribe(this->unicast_topic_name,this->unicast_subscription_name,this->unicast_consumer_config,this->unicast_consumer); + if (result != Result::ResultOk){ + ACA_LOG_ERROR("Failed to subscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} -bool ACA_Message_Pulsar_Consumer::consumeDispatched(string topic) -{ - alcor::schema::GoalState deserialized_GoalState; - alcor::schema::GoalStateOperationReply gsOperationalReply; - int rc; - int overall_rc = EXIT_SUCCESS; +bool ACA_Message_Pulsar_Consumer::multicastConsumerDispatched(){ Result result; - Message message; - Consumer consumer; - //this->consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(KeySharedPolicy).setMessageListener(messageListener) - result = this->ptr_client->subscribe(topic,this->subscription_name,this->consumer_config,consumer); + // Use the default exclusive mode + this->multicast_consumer_config.setMessageListener(listener); + result = this->ptr_multicast_client->subscribe(this->multicast_topic_name,this->multicast_subscription_name,this->multicast_consumer_config,this->multicast_consumer); if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to subscribe topic: %s\n", topic.c_str()); + ACA_LOG_ERROR("Failed to subscribe multicast topic: %s\n", this->multicast_topic_name.c_str()); return EXIT_FAILURE; } + return EXIT_SUCCESS; +} - ACA_LOG_DEBUG("Consumer consuming messages from topic: %s\n", topic.c_str()); - //Receive message - while(true){ - result = consumer.receive(message); +void ACA_Message_Pulsar_Consumer::setBrokers(string brokers) +{ + this->brokers_list = brokers; +} - if (result != Result::ResultOk) { - ACA_LOG_ERROR("Failed to receive message from topic: %s\n",topic.c_str()); - return EXIT_FAILURE; - } +void ACA_Message_Pulsar_Consumer::setMulticastTopicName(string topic) +{ + this->multicast_topic_name = topic; +} - else{ - // Print the ordering key (if any) - if (message.hasOrderingKey()) { - ACA_LOG_DEBUG("%s -> ", message.getOrderingKey().c_str()); - } - // Print the payload - ACA_LOG_DEBUG("\n<=====incoming message: %s\n", - message.getDataAsString().c_str()); - - rc = Aca_Comm_Manager::get_instance().deserialize( - (unsigned char *)message.getData(), message.getLength(), deserialized_GoalState); - if (rc == EXIT_SUCCESS) { - rc = Aca_Comm_Manager::get_instance().update_goal_state( - deserialized_GoalState, gsOperationalReply); - - // TODO: send gsOperationalReply back to controller - - if (rc != EXIT_SUCCESS) { - ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); - overall_rc = rc; - } else { - ACA_LOG_INFO("Successfully updated host with latest goal state %d.\n", rc); - } - } else { - ACA_LOG_ERROR("Deserialization failed with error code %d.\n", rc); - overall_rc = rc; - } - - // Now acknowledge message - consumer.acknowledge(message); - } - } - return overall_rc; +void ACA_Message_Pulsar_Consumer::setMulticastSubscriptionName(string subscription_name) +{ + this->multicast_subscription_name = subscription_name; } -void ACA_Message_Pulsar_Consumer::setBrokers(string brokers) +void ACA_Message_Pulsar_Consumer::setUnicastTopicName(string topic) { - this->brokers_list = brokers; + this->unicast_topic_name = topic; } -void ACA_Message_Pulsar_Consumer::setLastTopicName(string topic) +void ACA_Message_Pulsar_Consumer::setUnicastSubscriptionName(string subscription_name) { - this->topic_name = topic; + this->unicast_subscription_name = subscription_name; } } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_producer.cpp b/src/comm/aca_message_pulsar_producer.cpp index 553242fa..d75035be 100644 --- a/src/comm/aca_message_pulsar_producer.cpp +++ b/src/comm/aca_message_pulsar_producer.cpp @@ -77,6 +77,7 @@ bool ACA_Message_Pulsar_Producer::publish(string message) // Flush all produced messages producer.flush(); + producer.close(); return EXIT_SUCCESS; } diff --git a/test/gtest/aca_test_main.cpp b/test/gtest/aca_test_main.cpp index 26354cc5..6af09f34 100644 --- a/test/gtest/aca_test_main.cpp +++ b/test/gtest/aca_test_main.cpp @@ -67,7 +67,7 @@ string remote_ip_2 = "172.17.0.3"; // for docker network uint neighbors_to_create = 10; static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost -static string mq_test_topic = "my-topic"; +static string mq_test_topic = "Host-ts-1"; int processor_count = std::thread::hardware_concurrency(); /* From previous tests, we found that, for x number of cores, From 81550939e4c48455c169051b38dca0f40e9953cb Mon Sep 17 00:00:00 2001 From: lly00 Date: Tue, 26 Oct 2021 21:54:53 +0800 Subject: [PATCH 05/37] Add CLI parameter for pulsar hashed key --- src/CMakeLists.txt | 2 +- src/aca_main.cpp | 13 +++++++++---- src/comm/aca_message_pulsar_consumer.cpp | 8 +++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a0f4992..b973e57e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,7 +59,7 @@ find_path(LIBEVENT_INCLUDE_DIR FIND_LIBRARY(LIBUUID_LIBRARIES uuid) FIND_LIBRARY(RDKAFKA rdkafka /usr/lib/x86_64-linux-gnu NO_DEFAULT_PATH) FIND_LIBRARY(CPPKAFKA cppkafka /usr/local/lib NO_DEFAULT_PATH) -FIND_LIBRARY(PULSAR pulsar /usr/lib NO_DEFAULT_PATH) +FIND_LIBRARY(PULSAR pulsar /usr/local/lib NO_DEFAULT_PATH) FIND_LIBRARY(MESSAGEMANAGER messagemanager ${CMAKE_CURRENT_SOURCE_DIR}/../include NO_DEFAULT_PATH) link_libraries(${RDKAFKA} ${CPPKAFKA} ${PULSAR}) link_libraries(/usr/lib/x86_64-linux-gnu/libuuid.so) diff --git a/src/aca_main.cpp b/src/aca_main.cpp index 8da120aa..8e4b52fe 100644 --- a/src/aca_main.cpp +++ b/src/aca_main.cpp @@ -59,6 +59,7 @@ GoalStateProvisionerClientImpl *g_grpc_client = NULL; string g_broker_list = EMPTY_STRING; string g_pulsar_topic = EMPTY_STRING; string g_pulsar_subsription_name = EMPTY_STRING; +string g_pulsar_hashed_key = "0"; string g_grpc_server_port = EMPTY_STRING; string g_ofctl_command = EMPTY_STRING; string g_ofctl_target = EMPTY_STRING; @@ -183,7 +184,7 @@ int main(int argc, char *argv[]) signal(SIGINT, aca_signal_handler); signal(SIGTERM, aca_signal_handler); - while ((option = getopt(argc, argv, "a:p:b:h:g:s:c:t:o:md")) != -1) { + while ((option = getopt(argc, argv, "a:p:b:h:g:k:s:c:t:o:md")) != -1) { switch (option) { case 'a': g_ncm_address = optarg; @@ -200,6 +201,9 @@ int main(int argc, char *argv[]) case 'g': g_pulsar_subsription_name = optarg; break; + case 'k': + g_pulsar_hashed_key = optarg; + break; case 's': g_grpc_server_port = optarg; break; @@ -226,6 +230,7 @@ int main(int argc, char *argv[]) "\t\t[-b pulsar broker list]\n" "\t\t[-h pulsar host topic to listen]\n" "\t\t[-g pulsar subscription name]\n" + "\t\t[-k pulsar hashed key]\n" "\t\t[-s gRPC server port\n" "\t\t[-c ofctl command]\n" "\t\t[-m enable demo mode]\n" @@ -288,9 +293,9 @@ int main(int argc, char *argv[]) //ACA_OVS_Control::get_instance().monitor("br-tun", "resume"); ACA_Message_Pulsar_Consumer network_config_consumer(g_pulsar_topic, g_broker_list, g_pulsar_subsription_name); - network_config_consumer.multicastConsumerDispatched(); - //network_config_consumer.unicastConsumerDispatched(0); - + //network_config_consumer.multicastConsumerDispatched(); + network_config_consumer.unicastConsumerDispatched(atoi(g_pulsar_hashed_key.c_str())); + pause(); aca_cleanup(); diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 93dd0150..c47233a5 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -36,8 +36,6 @@ void listener(Consumer consumer, const Message& message){ alcor::schema::GoalStateOperationReply gsOperationalReply; int rc; Result result; - printf("\n<=====incoming message: %s\n", - message.getDataAsString().c_str()); ACA_LOG_DEBUG("\n<=====incoming message: %s\n", message.getDataAsString().c_str()); @@ -79,7 +77,7 @@ ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string br ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); // Create the clients - this->ptr_multicast_client= new Client(brokers); + //this->ptr_multicast_client= new Client(brokers); this->ptr_unicast_client = new Client(brokers); } @@ -122,8 +120,8 @@ bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ keySharedPolicy.setKeySharedMode(STICKY); // Set sticky ranges with specified hash value - // StickyRange stickyRange = std::make_pair(stickyHash,stickyHash); - // keySharedPolicy.getStickyRanges(); + StickyRange stickyRange = std::make_pair(stickyHash,stickyHash); + keySharedPolicy.setStickyRanges({stickyRange}); //Use key shared mode this->unicast_consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(keySharedPolicy).setMessageListener(listener); From 00fd7c762777178c77aa5bfd68e15aa2a1813527 Mon Sep 17 00:00:00 2001 From: FangJin98 Date: Mon, 29 Nov 2021 12:58:17 +0800 Subject: [PATCH 06/37] add mq test --- test/CMakeLists.txt | 2 +- test/gtest/aca_test_main.cpp | 63 ++++++------ test/gtest/aca_test_mq.cpp | 186 +++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 29 deletions(-) create mode 100644 test/gtest/aca_test_mq.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index abfa55e9..5e9c4e4b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,7 +49,7 @@ add_executable( gtest/aca_test_zeta_programming.cpp gtest/aca_test_arp.cpp gtest/aca_test_on_demand.cpp -) + gtest/aca_test_mq.cpp) # Link test executable against gtest & gtest_main target_link_libraries(aca_tests gtest gtest_main) diff --git a/test/gtest/aca_test_main.cpp b/test/gtest/aca_test_main.cpp index 6af09f34..09677ad4 100644 --- a/test/gtest/aca_test_main.cpp +++ b/test/gtest/aca_test_main.cpp @@ -19,6 +19,10 @@ #include "aca_grpc.h" #include "aca_grpc_client.h" #include "aca_message_pulsar_producer.h" +#include "aca_message_pulsar_consumer.h" +#include "aca_ovs_control.h" +#include "aca_net_config.h" +#include "aca_comm_mgr.h" #include /* for getopt */ #include #include @@ -26,7 +30,8 @@ using namespace std; using namespace aca_message_pulsar; - +using aca_net_config::Aca_Net_Config; +using aca_comm_manager::Aca_Comm_Manager; #define ACALOGNAME "AlcorControlAgentTest" // Global variables @@ -62,12 +67,37 @@ std::atomic_ulong g_total_update_GS_time(0); bool g_debug_mode = true; bool g_demo_mode = false; -string remote_ip_1 = "172.17.0.2"; // for docker network -string remote_ip_2 = "172.17.0.3"; // for docker network +extern string project_id; +extern string vpc_id_1; +extern string vpc_id_2; +extern string subnet_id_1; +extern string subnet_id_2; +extern string port_id_1; +extern string port_id_2; +extern string port_id_3; +extern string port_id_4; +extern string port_name_1; +extern string port_name_2; +extern string port_name_3; +extern string port_name_4; +extern string vmac_address_1; +extern string vmac_address_2; +extern string vmac_address_3; +extern string vmac_address_4; +extern string vip_address_1; +extern string vip_address_2; +extern string vip_address_3; +extern string vip_address_4; +extern string subnet1_gw_ip; +extern string subnet2_gw_ip; +extern string subnet1_gw_mac; +extern string subnet2_gw_mac; +static string subnet1_cidr = "10.10.0.0/24"; +static string subnet2_cidr = "10.10.1.0/24"; +extern string remote_ip_1="172.17.0.2"; // for docker network +extern string remote_ip_2= "172.17.0.3"; // for docker network uint neighbors_to_create = 10; -static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost -static string mq_test_topic = "Host-ts-1"; int processor_count = std::thread::hardware_concurrency(); /* From previous tests, we found that, for x number of cores, @@ -78,29 +108,6 @@ int processor_count = std::thread::hardware_concurrency(); */ int thread_pools_size = (processor_count == 0) ? 1 : ((ceil(1.3 * processor_count)) / 2); -// -// Test suite: pulsar_test_cases -// -// Testing the pulsar implementation where AlcorControlAgent is the consumer -// and aca_test is acting as producer -// Note: it will require a pulsar setup on localhost therefore this test is DISABLED by default -// it can be executed by: -// -// aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_consumer_test -// -TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) -{ - int retcode = 0; - const int MESSAGES_TO_SEND = 10; - string message = "Test Message"; - - ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); - - for (int i = 0; i < MESSAGES_TO_SEND; i++) { - retcode = producer.publish(message); - EXPECT_EQ(retcode, EXIT_SUCCESS); - } -} static void aca_cleanup() { diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp new file mode 100644 index 00000000..2ed0fce7 --- /dev/null +++ b/test/gtest/aca_test_mq.cpp @@ -0,0 +1,186 @@ +// +// Created by FangJ on 2021/11/29. +// +// MIT License +// Copyright(c) 2020 Futurewei Cloud +// +// Permission is hereby granted, +// free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#include "aca_log.h" +#include "gtest/gtest.h" +#include "goalstate.pb.h" +#include "aca_grpc.h" +#include "aca_grpc_client.h" +#include "aca_message_pulsar_producer.h" +#include "aca_net_config.h" +#include "aca_comm_mgr.h" + +using namespace std; +using namespace aca_message_pulsar; +using aca_net_config::Aca_Net_Config; +using aca_comm_manager::Aca_Comm_Manager; +#define ACALOGNAME "AlcorControlAgentTest" + + +extern string project_id; +extern string vpc_id_1; +extern string vpc_id_2; +extern string subnet_id_1; +extern string subnet_id_2; +extern string port_id_1; +extern string port_id_2; +extern string port_id_3; +extern string port_id_4; +extern string port_name_1; +extern string port_name_2; +extern string port_name_3; +extern string port_name_4; +extern string vmac_address_1; +extern string vmac_address_2; +extern string vmac_address_3; +extern string vmac_address_4; +extern string vip_address_1; +extern string vip_address_2; +extern string vip_address_3; +extern string vip_address_4; +extern string subnet1_gw_ip; +extern string subnet2_gw_ip; +extern string subnet1_gw_mac; +extern string subnet2_gw_mac; +static string subnet1_cidr = "10.10.0.0/24"; +static string subnet2_cidr = "10.10.1.0/24"; + +extern string remote_ip_1; // for docker network +extern string remote_ip_2; // for docker network + +extern void aca_test_reset_environment(); +GoalState buildGoalState(); + +static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost +static string mq_test_topic = "Host-ts-1"; + +// +// Test suite: pulsar_test_cases +// +// Testing the pulsar implementation where AlcorControlAgent is the consumer +// and aca_test is acting as producer +// Note: it will require a pulsar setup on localhost therefore this test is DISABLED by default +// it can be executed by: +// +// ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_consumer_test +// + +TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) +{ + int retcode = 0; + int overall_rc=0; + string cmd_string; + + int seralizedLength=10000; + unsigned char serializedGoalState[seralizedLength]; + string GoalStateString = "Test Message"; + GoalState mGoalState=buildGoalState(); + + aca_test_reset_environment(); + + overall_rc = Aca_Net_Config::get_instance().execute_system_command( + "docker run -itd --cap-add=NET_ADMIN --name con3 --net=none alpine sh"); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + + cmd_string = "ovs-docker add-port br-int eth1 con3 --macaddress=" + vmac_address_1 + " --ipaddress="+ vip_address_1 + "/24"; + overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; + + if(mGoalState.SerializePartialToArray(serializedGoalState,seralizedLength)){ + ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); + } + GoalStateString.append(reinterpret_cast (serializedGoalState)); + ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); + retcode = producer.publish(GoalStateString); + EXPECT_EQ(retcode, EXIT_SUCCESS); + + // 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); + overall_rc = EXIT_SUCCESS; + + //clean up + overall_rc = Aca_Net_Config::get_instance().execute_system_command( + "ovs-docker del-ports br-int con3"); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + + overall_rc = Aca_Net_Config::get_instance().execute_system_command("docker rm con3 -f"); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); +} + + +GoalState buildGoalState(){ + GoalState GoalState_builder; + + PortState *new_port_states = GoalState_builder.add_port_states(); + new_port_states->set_operation_type(OperationType::CREATE); + + // fill in port state structs for port 1 + PortConfiguration *PortConfiguration_builder = new_port_states->mutable_configuration(); + PortConfiguration_builder->set_revision_number(1); + PortConfiguration_builder->set_update_type(UpdateType::FULL); + PortConfiguration_builder->set_id(port_id_1); + + PortConfiguration_builder->set_vpc_id(vpc_id_1); + PortConfiguration_builder->set_name(port_name_1); + PortConfiguration_builder->set_mac_address(vmac_address_1); + PortConfiguration_builder->set_admin_state_up(true); + + PortConfiguration_FixedIp *FixedIp_builder = PortConfiguration_builder->add_fixed_ips(); + FixedIp_builder->set_subnet_id(subnet_id_1); + FixedIp_builder->set_ip_address(vip_address_1); + + PortConfiguration_SecurityGroupId *SecurityGroup_builder = + PortConfiguration_builder->add_security_group_ids(); + SecurityGroup_builder->set_id("1"); + + + SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); + new_subnet_states->set_operation_type(OperationType::INFO); + + // fill in subnet state structs + SubnetConfiguration *SubnetConiguration_builder = + new_subnet_states->mutable_configuration(); + SubnetConiguration_builder->set_revision_number(1); + SubnetConiguration_builder->set_vpc_id(vpc_id_1); + SubnetConiguration_builder->set_id(subnet_id_1); + SubnetConiguration_builder->set_cidr("10.0.0.0/24"); + SubnetConiguration_builder->set_tunnel_id(20); + + NeighborState *new_neighbor_states = GoalState_builder.add_neighbor_states(); + new_neighbor_states->set_operation_type(OperationType::CREATE); + + // fill in neighbor state structs + NeighborConfiguration *NeighborConfiguration_builder = + new_neighbor_states->mutable_configuration(); + NeighborConfiguration_builder->set_revision_number(1); + + NeighborConfiguration_builder->set_vpc_id(vpc_id_1); + NeighborConfiguration_builder->set_id(port_id_3); + NeighborConfiguration_builder->set_mac_address(vmac_address_3); + NeighborConfiguration_builder->set_host_ip_address(remote_ip_2); + + NeighborConfiguration_FixedIp *FixedIp_builder2 = + NeighborConfiguration_builder->add_fixed_ips(); + FixedIp_builder2->set_neighbor_type(NeighborType::L2); + FixedIp_builder2->set_subnet_id(subnet_id_1); + FixedIp_builder2->set_ip_address(vip_address_3); + + return GoalState_builder; +} \ No newline at end of file From 5311466607075653babaaaf706064a78bbcf6f79 Mon Sep 17 00:00:00 2001 From: FangJin98 Date: Mon, 29 Nov 2021 16:28:51 +0800 Subject: [PATCH 07/37] mq publish serialized goalstate. --- test/gtest/aca_test_mq.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 2ed0fce7..ab6e2eb4 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -87,7 +87,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) int seralizedLength=10000; unsigned char serializedGoalState[seralizedLength]; - string GoalStateString = "Test Message"; + string GoalStateString; GoalState mGoalState=buildGoalState(); aca_test_reset_environment(); @@ -101,10 +101,18 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) EXPECT_EQ(overall_rc, EXIT_SUCCESS); overall_rc = EXIT_SUCCESS; - if(mGoalState.SerializePartialToArray(serializedGoalState,seralizedLength)){ + cmd_string = "ovs-docker set-vlan br-int eth1 con3 1"; + overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; + +// if(mGoalState.SerializePartialToArray(serializedGoalState,seralizedLength)){ +// ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); +// } + if(mGoalState.SerializeToString(&GoalStateString)){ ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); } - GoalStateString.append(reinterpret_cast (serializedGoalState)); +// GoalStateString.append(reinterpret_cast (serializedGoalState)); ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); retcode = producer.publish(GoalStateString); EXPECT_EQ(retcode, EXIT_SUCCESS); From 869655acdbeda241e672578f9903194c494eef0c Mon Sep 17 00:00:00 2001 From: FangJin98 Date: Mon, 29 Nov 2021 20:53:29 +0800 Subject: [PATCH 08/37] add GoalStateV2 test case --- test/gtest/aca_test_mq.cpp | 211 ++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 98 deletions(-) diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index ab6e2eb4..4d96137a 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -21,14 +21,15 @@ #include "aca_grpc.h" #include "aca_grpc_client.h" #include "aca_message_pulsar_producer.h" -#include "aca_net_config.h" -#include "aca_comm_mgr.h" +#include "aca_message_pulsar_consumer.h" +#include "aca_ovs_l2_programmer.h" +#include "aca_ovs_control.h" +#define ACALOGNAME "AlcorControlAgentTest" using namespace std; using namespace aca_message_pulsar; -using aca_net_config::Aca_Net_Config; -using aca_comm_manager::Aca_Comm_Manager; -#define ACALOGNAME "AlcorControlAgentTest" +using namespace aca_ovs_l2_programmer; +using aca_ovs_control::ACA_OVS_Control; extern string project_id; @@ -52,143 +53,157 @@ extern string vip_address_1; extern string vip_address_2; extern string vip_address_3; extern string vip_address_4; -extern string subnet1_gw_ip; -extern string subnet2_gw_ip; -extern string subnet1_gw_mac; -extern string subnet2_gw_mac; -static string subnet1_cidr = "10.10.0.0/24"; -static string subnet2_cidr = "10.10.1.0/24"; - extern string remote_ip_1; // for docker network extern string remote_ip_2; // for docker network +extern bool g_demo_mode; extern void aca_test_reset_environment(); -GoalState buildGoalState(); +extern void aca_test_create_default_port_state(PortState *new_port_states); +extern void aca_test_create_default_subnet_state(SubnetState *new_subnet_states); +extern void aca_test_1_neighbor_CREATE_DELETE(NeighborType input_neighbor_type); +extern void aca_test_1_neighbor_CREATE_DELETE_V2(NeighborType input_neighbor_type); +extern void aca_test_1_port_CREATE_plus_neighbor_CREATE(NeighborType input_neighbor_type); +extern void aca_test_1_port_CREATE_plus_neighbor_CREATE_V2(NeighborType input_neighbor_type); +extern void aca_test_10_neighbor_CREATE(NeighborType input_neighbor_type); +extern void aca_test_10_neighbor_CREATE_V2(NeighborType input_neighbor_type); +extern void aca_test_1_port_CREATE_plus_N_neighbors_CREATE(NeighborType input_neighbor_type, + uint neighbors_to_create); +extern void +aca_test_1_port_CREATE_plus_N_neighbors_CREATE_V2(NeighborType input_neighbor_type, + uint neighbors_to_create); static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost static string mq_test_topic = "Host-ts-1"; + // // Test suite: pulsar_test_cases // -// Testing the pulsar implementation where AlcorControlAgent is the consumer -// and aca_test is acting as producer -// Note: it will require a pulsar setup on localhost therefore this test is DISABLED by default -// it can be executed by: -// -// ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_consumer_test +// Note: it requires a pulsar setup on localhost therefore this test is DISABLED by default // +// This case tests the pulsar consumer implementation. +// First run this case by executing: +// ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_consumer_test +// Then run the following producer test cases. TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) { int retcode = 0; int overall_rc=0; + int length=1000; + ulong not_care_culminative_time; string cmd_string; + string testSubscription="testv2"; + unsigned char serializedGoalState[length]; - int seralizedLength=10000; - unsigned char serializedGoalState[seralizedLength]; - string GoalStateString; - GoalState mGoalState=buildGoalState(); + bool previous_demo_mode = g_demo_mode; + g_demo_mode = true; aca_test_reset_environment(); - overall_rc = Aca_Net_Config::get_instance().execute_system_command( - "docker run -itd --cap-add=NET_ADMIN --name con3 --net=none alpine sh"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); + ACA_Message_Pulsar_Consumer consumer(mq_test_topic, + mq_broker_ip, + testSubscription); + consumer.multicastConsumerDispatched(); + pause(); - cmd_string = "ovs-docker add-port br-int eth1 con3 --macaddress=" + vmac_address_1 + " --ipaddress="+ vip_address_1 + "/24"; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; + g_demo_mode = previous_demo_mode; +} - cmd_string = "ovs-docker set-vlan br-int eth1 con3 1"; - overall_rc = Aca_Net_Config::get_instance().execute_system_command(cmd_string); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); + +// This case tests the pulsar producer implementation and publishes a GoalState to the subscribed topic. +// First run pulsar_consumer_test then execute +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_test + +TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) +{ + int retcode = 0; + int overall_rc=0; + int length=1000; + ulong not_care_culminative_time; + string cmd_string; + string GoalStateString; + unsigned char serializedGoalState[length]; + + GoalState GoalState_builder; + PortState *new_port_states = GoalState_builder.add_port_states(); + SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "del-br br-int", not_care_culminative_time, overall_rc); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "del-br br-tun", not_care_culminative_time, overall_rc); + + overall_rc = ACA_OVS_L2_Programmer::get_instance().setup_ovs_bridges_if_need(); + ASSERT_EQ(overall_rc, EXIT_SUCCESS); overall_rc = EXIT_SUCCESS; -// if(mGoalState.SerializePartialToArray(serializedGoalState,seralizedLength)){ -// ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); -// } - if(mGoalState.SerializeToString(&GoalStateString)){ + // fill in port state structs + aca_test_create_default_port_state(new_port_states); + + // fill in subnet state structs + aca_test_create_default_subnet_state(new_subnet_states); + + if(GoalState_builder.SerializeToString(&GoalStateString)){ ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); } -// GoalStateString.append(reinterpret_cast (serializedGoalState)); + ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); retcode = producer.publish(GoalStateString); EXPECT_EQ(retcode, EXIT_SUCCESS); - // 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); - overall_rc = EXIT_SUCCESS; + ACA_LOG_INFO("%s","Waiting for GoalState update.\n"); + sleep(2); - //clean up - overall_rc = Aca_Net_Config::get_instance().execute_system_command( - "ovs-docker del-ports br-int con3"); + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; - overall_rc = Aca_Net_Config::get_instance().execute_system_command("docker rm con3 -f"); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); } +// This case tests the pulsar producer implementation and publishes a GoalStateV2 to the subscribed topic. +// First run pulsar_consumer_test then execute +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_testv2 +TEST(pulsar_test_cases, DISABLED_pulsar_producer_testv2) +{ + int retcode = 0; + int overall_rc=0; + int length=1000; + ulong not_care_culminative_time; + string cmd_string; + string GoalStateString; + unsigned char serializedGoalState[length]; -GoalState buildGoalState(){ - GoalState GoalState_builder; + aca_test_reset_environment(); - PortState *new_port_states = GoalState_builder.add_port_states(); - new_port_states->set_operation_type(OperationType::CREATE); + GoalStateV2 GoalState_builder; + PortState new_port_states; + SubnetState new_subnet_states; - // fill in port state structs for port 1 - PortConfiguration *PortConfiguration_builder = new_port_states->mutable_configuration(); - PortConfiguration_builder->set_revision_number(1); - PortConfiguration_builder->set_update_type(UpdateType::FULL); - PortConfiguration_builder->set_id(port_id_1); + aca_test_create_default_port_state(&new_port_states); + auto &port_states_map = *GoalState_builder.mutable_port_states(); + port_states_map[port_id_1] = new_port_states; - PortConfiguration_builder->set_vpc_id(vpc_id_1); - PortConfiguration_builder->set_name(port_name_1); - PortConfiguration_builder->set_mac_address(vmac_address_1); - PortConfiguration_builder->set_admin_state_up(true); + aca_test_create_default_subnet_state(&new_subnet_states); + auto &subnet_states_map = *GoalState_builder.mutable_subnet_states(); + subnet_states_map[subnet_id_1] = new_subnet_states; - PortConfiguration_FixedIp *FixedIp_builder = PortConfiguration_builder->add_fixed_ips(); - FixedIp_builder->set_subnet_id(subnet_id_1); - FixedIp_builder->set_ip_address(vip_address_1); + if(GoalState_builder.SerializeToString(&GoalStateString)){ + ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); + } - PortConfiguration_SecurityGroupId *SecurityGroup_builder = - PortConfiguration_builder->add_security_group_ids(); - SecurityGroup_builder->set_id("1"); + ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); + retcode = producer.publish(GoalStateString); + EXPECT_EQ(retcode, EXIT_SUCCESS); + ACA_LOG_INFO("%s","Waiting for GoalStateV2 update.\n"); + sleep(2); - SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); - new_subnet_states->set_operation_type(OperationType::INFO); + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; - // fill in subnet state structs - SubnetConfiguration *SubnetConiguration_builder = - new_subnet_states->mutable_configuration(); - SubnetConiguration_builder->set_revision_number(1); - SubnetConiguration_builder->set_vpc_id(vpc_id_1); - SubnetConiguration_builder->set_id(subnet_id_1); - SubnetConiguration_builder->set_cidr("10.0.0.0/24"); - SubnetConiguration_builder->set_tunnel_id(20); - - NeighborState *new_neighbor_states = GoalState_builder.add_neighbor_states(); - new_neighbor_states->set_operation_type(OperationType::CREATE); - - // fill in neighbor state structs - NeighborConfiguration *NeighborConfiguration_builder = - new_neighbor_states->mutable_configuration(); - NeighborConfiguration_builder->set_revision_number(1); - - NeighborConfiguration_builder->set_vpc_id(vpc_id_1); - NeighborConfiguration_builder->set_id(port_id_3); - NeighborConfiguration_builder->set_mac_address(vmac_address_3); - NeighborConfiguration_builder->set_host_ip_address(remote_ip_2); - - NeighborConfiguration_FixedIp *FixedIp_builder2 = - NeighborConfiguration_builder->add_fixed_ips(); - FixedIp_builder2->set_neighbor_type(NeighborType::L2); - FixedIp_builder2->set_subnet_id(subnet_id_1); - FixedIp_builder2->set_ip_address(vip_address_3); - - return GoalState_builder; } \ No newline at end of file From c6ef0fbf9467efc256e5a89d720d54efa8f3e0ab Mon Sep 17 00:00:00 2001 From: FangJin98 Date: Fri, 3 Dec 2021 18:37:45 +0800 Subject: [PATCH 09/37] add unicast test cases --- test/gtest/aca_test_mq.cpp | 91 +++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 5 deletions(-) diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 4d96137a..086ad523 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -74,13 +74,20 @@ aca_test_1_port_CREATE_plus_N_neighbors_CREATE_V2(NeighborType input_neighbor_ty static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost static string mq_test_topic = "Host-ts-1"; - +static string mq_subscription = "test_subscription"; +static string mq_key="3dda2801-d675-4688-a63f-dcda8d327f50"; // 3dda2801-d675-4688-a63f-dcda8d327f50 9192a4d4-ffff-4ece-b3f0-8d36e3d88001 +static int mq_hash=21485; // 21485 49755 // // Test suite: pulsar_test_cases // -// Note: it requires a pulsar setup on localhost therefore this test is DISABLED by default -// +// Note: it requires a pulsar setup on localhost therefore this test is DISABLED by default. +// You will need three terminals: +// Terminal(1): run pulsar standalone. +// Terminal(2): run pulsar consumer test case. +// Terminal(3): run pulsar producer test cases. + + // This case tests the pulsar consumer implementation. // First run this case by executing: // ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_consumer_test @@ -93,7 +100,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) int length=1000; ulong not_care_culminative_time; string cmd_string; - string testSubscription="testv2"; + unsigned char serializedGoalState[length]; bool previous_demo_mode = g_demo_mode; @@ -103,13 +110,38 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, - testSubscription); + mq_subscription); consumer.multicastConsumerDispatched(); pause(); g_demo_mode = previous_demo_mode; } +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_test +TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) +{ + int retcode = 0; + int overall_rc=0; + int length=1000; + ulong not_care_culminative_time; + string cmd_string; + + unsigned char serializedGoalState[length]; + + bool previous_demo_mode = g_demo_mode; + g_demo_mode = true; + + aca_test_reset_environment(); + + ACA_Message_Pulsar_Consumer consumer(mq_test_topic, + mq_broker_ip, + mq_subscription); + consumer.unicastConsumerDispatched(mq_hash); + pause(); + + g_demo_mode = previous_demo_mode; +} + // This case tests the pulsar producer implementation and publishes a GoalState to the subscribed topic. // First run pulsar_consumer_test then execute @@ -162,6 +194,55 @@ TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) overall_rc = EXIT_SUCCESS; } +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_hash_producer_test +TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) +{ + int retcode = 0; + int overall_rc=0; + int length=1000; + ulong not_care_culminative_time; + string cmd_string; + string GoalStateString; + unsigned char serializedGoalState[length]; + + GoalState GoalState_builder; + PortState *new_port_states = GoalState_builder.add_port_states(); + SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "del-br br-int", not_care_culminative_time, overall_rc); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "del-br br-tun", not_care_culminative_time, overall_rc); + + overall_rc = ACA_OVS_L2_Programmer::get_instance().setup_ovs_bridges_if_need(); + ASSERT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; + + // fill in port state structs + aca_test_create_default_port_state(new_port_states); + + // fill in subnet state structs + aca_test_create_default_subnet_state(new_subnet_states); + + if(GoalState_builder.SerializeToString(&GoalStateString)){ + ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); + } + + ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); + retcode = producer.publish(GoalStateString,mq_key); + EXPECT_EQ(retcode, EXIT_SUCCESS); + + ACA_LOG_INFO("%s","Waiting for GoalState update.\n"); + sleep(2); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; + +} + // This case tests the pulsar producer implementation and publishes a GoalStateV2 to the subscribed topic. // First run pulsar_consumer_test then execute // sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_testv2 From 103a7510c7095f6b165a142443fc399ea2a6c0a9 Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 3 Dec 2021 18:59:18 +0800 Subject: [PATCH 10/37] Pulsar producer can publish key-shared messages. --- include/aca_message_pulsar_producer.h | 4 ++++ src/comm/aca_message_pulsar_producer.cpp | 28 ++++++++++++++++++++++++ test/gtest/aca_test_mq.cpp | 4 ++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/aca_message_pulsar_producer.h b/include/aca_message_pulsar_producer.h index 0990b620..97e3c2a7 100644 --- a/include/aca_message_pulsar_producer.h +++ b/include/aca_message_pulsar_producer.h @@ -50,8 +50,12 @@ class ACA_Message_Pulsar_Producer { bool publish(string message); + bool publish(string message, string orderingKey); + + private: void setBrokers(string brokers); + }; } // aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_producer.cpp b/src/comm/aca_message_pulsar_producer.cpp index d75035be..4188b6e5 100644 --- a/src/comm/aca_message_pulsar_producer.cpp +++ b/src/comm/aca_message_pulsar_producer.cpp @@ -82,6 +82,34 @@ bool ACA_Message_Pulsar_Producer::publish(string message) } +bool ACA_Message_Pulsar_Producer::publish(string message, string orderingKey) +{ + Result result; + + // Create a producer + Producer producer; + result = this->ptr_client->createProducer(this->topic_name,producer); + if(result != ResultOk){ + ACA_LOG_ERROR("Failed to create producer, result=%d.\n", result); + return EXIT_FAILURE; + } + + // Create a message + Message msg = MessageBuilder().setContent(message).setOrderingKey(key).build(); + result = producer.send(msg); + if(result != ResultOk){ + ACA_LOG_ERROR("Failed to send message %s.\n", message.c_str()); + return EXIT_FAILURE; + } + + ACA_LOG_INFO("Successfully send message %s\n", message.c_str()); + + // Flush all produced messages + producer.flush(); + producer.close(); + return EXIT_SUCCESS; + +} void ACA_Message_Pulsar_Producer::setBrokers(string brokers) { //TODO: validate string as IP address diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 086ad523..380748fe 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -75,8 +75,8 @@ aca_test_1_port_CREATE_plus_N_neighbors_CREATE_V2(NeighborType input_neighbor_ty static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost static string mq_test_topic = "Host-ts-1"; static string mq_subscription = "test_subscription"; -static string mq_key="3dda2801-d675-4688-a63f-dcda8d327f50"; // 3dda2801-d675-4688-a63f-dcda8d327f50 9192a4d4-ffff-4ece-b3f0-8d36e3d88001 -static int mq_hash=21485; // 21485 49755 +static string mq_key="9192a4d4-ffff-4ece-b3f0-8d36e3d88001"; // 3dda2801-d675-4688-a63f-dcda8d327f50 9192a4d4-ffff-4ece-b3f0-8d36e3d88001 +static int mq_hash=49775; // 21485 49755 // // Test suite: pulsar_test_cases From 46b2316782ada1aa075e28a1ed446726834873be Mon Sep 17 00:00:00 2001 From: lly00 Date: Fri, 3 Dec 2021 20:42:49 +0800 Subject: [PATCH 11/37] add test cases for mq --- include/aca_message_pulsar_producer.h | 2 +- src/comm/aca_message_pulsar_producer.cpp | 2 +- test/gtest/aca_test_main.cpp | 31 ++---------------------- test/gtest/aca_test_mq.cpp | 8 ++---- 4 files changed, 6 insertions(+), 37 deletions(-) diff --git a/include/aca_message_pulsar_producer.h b/include/aca_message_pulsar_producer.h index 97e3c2a7..269ad7e4 100644 --- a/include/aca_message_pulsar_producer.h +++ b/include/aca_message_pulsar_producer.h @@ -50,7 +50,7 @@ class ACA_Message_Pulsar_Producer { bool publish(string message); - bool publish(string message, string orderingKey); + bool publish(string message, string key); private: diff --git a/src/comm/aca_message_pulsar_producer.cpp b/src/comm/aca_message_pulsar_producer.cpp index 4188b6e5..a518615a 100644 --- a/src/comm/aca_message_pulsar_producer.cpp +++ b/src/comm/aca_message_pulsar_producer.cpp @@ -82,7 +82,7 @@ bool ACA_Message_Pulsar_Producer::publish(string message) } -bool ACA_Message_Pulsar_Producer::publish(string message, string orderingKey) +bool ACA_Message_Pulsar_Producer::publish(string message, string key) { Result result; diff --git a/test/gtest/aca_test_main.cpp b/test/gtest/aca_test_main.cpp index 09677ad4..0ee784b8 100644 --- a/test/gtest/aca_test_main.cpp +++ b/test/gtest/aca_test_main.cpp @@ -67,35 +67,8 @@ std::atomic_ulong g_total_update_GS_time(0); bool g_debug_mode = true; bool g_demo_mode = false; -extern string project_id; -extern string vpc_id_1; -extern string vpc_id_2; -extern string subnet_id_1; -extern string subnet_id_2; -extern string port_id_1; -extern string port_id_2; -extern string port_id_3; -extern string port_id_4; -extern string port_name_1; -extern string port_name_2; -extern string port_name_3; -extern string port_name_4; -extern string vmac_address_1; -extern string vmac_address_2; -extern string vmac_address_3; -extern string vmac_address_4; -extern string vip_address_1; -extern string vip_address_2; -extern string vip_address_3; -extern string vip_address_4; -extern string subnet1_gw_ip; -extern string subnet2_gw_ip; -extern string subnet1_gw_mac; -extern string subnet2_gw_mac; -static string subnet1_cidr = "10.10.0.0/24"; -static string subnet2_cidr = "10.10.1.0/24"; -extern string remote_ip_1="172.17.0.2"; // for docker network -extern string remote_ip_2= "172.17.0.3"; // for docker network +string remote_ip_1="172.17.0.2"; // for docker network +string remote_ip_2= "172.17.0.3"; // for docker network uint neighbors_to_create = 10; int processor_count = std::thread::hardware_concurrency(); diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 380748fe..ca89595c 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -108,9 +108,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer(mq_test_topic, - mq_broker_ip, - mq_subscription); + ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); consumer.multicastConsumerDispatched(); pause(); @@ -133,9 +131,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer(mq_test_topic, - mq_broker_ip, - mq_subscription); + ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); consumer.unicastConsumerDispatched(mq_hash); pause(); From dde2e948de74eccc4b72707ca986704014e357d8 Mon Sep 17 00:00:00 2001 From: lly00 Date: Fri, 3 Dec 2021 21:18:04 +0800 Subject: [PATCH 12/37] fix pulsar path --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b973e57e..5a0f4992 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,7 +59,7 @@ find_path(LIBEVENT_INCLUDE_DIR FIND_LIBRARY(LIBUUID_LIBRARIES uuid) FIND_LIBRARY(RDKAFKA rdkafka /usr/lib/x86_64-linux-gnu NO_DEFAULT_PATH) FIND_LIBRARY(CPPKAFKA cppkafka /usr/local/lib NO_DEFAULT_PATH) -FIND_LIBRARY(PULSAR pulsar /usr/local/lib NO_DEFAULT_PATH) +FIND_LIBRARY(PULSAR pulsar /usr/lib NO_DEFAULT_PATH) FIND_LIBRARY(MESSAGEMANAGER messagemanager ${CMAKE_CURRENT_SOURCE_DIR}/../include NO_DEFAULT_PATH) link_libraries(${RDKAFKA} ${CPPKAFKA} ${PULSAR}) link_libraries(/usr/lib/x86_64-linux-gnu/libuuid.so) From 1c89be9bfe1ebda3a2672a36135f85ff23bc664b Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 7 Dec 2021 11:43:02 +0800 Subject: [PATCH 13/37] add deserialize of GoalStateV2 --- include/aca_comm_mgr.h | 4 ++++ src/comm/aca_comm_mgr.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/aca_comm_mgr.h b/include/aca_comm_mgr.h index e658f303..05734ee5 100644 --- a/include/aca_comm_mgr.h +++ b/include/aca_comm_mgr.h @@ -28,6 +28,9 @@ class Aca_Comm_Manager { int deserialize(const unsigned char *mq_buffer, size_t buffer_length, alcor::schema::GoalState &parsed_struct); + int deserialize(const unsigned char *mq_buffer, size_t buffer_length, + alcor::schema::GoalStateV2 &parsed_struct); + int update_goal_state(alcor::schema::GoalState &goal_state_message, alcor::schema::GoalStateOperationReply &gsOperationReply); @@ -47,6 +50,7 @@ class Aca_Comm_Manager { void print_goal_state(alcor::schema::GoalState parsed_struct); void print_goal_state(alcor::schema::GoalStateV2 parsed_struct); + }; } // namespace aca_comm_manager #endif diff --git a/src/comm/aca_comm_mgr.cpp b/src/comm/aca_comm_mgr.cpp index dd6e12d9..6050855e 100644 --- a/src/comm/aca_comm_mgr.cpp +++ b/src/comm/aca_comm_mgr.cpp @@ -38,6 +38,38 @@ Aca_Comm_Manager &Aca_Comm_Manager::get_instance() return instance; } +int Aca_Comm_Manager::deserialize(const unsigned char *mq_buffer, + size_t buffer_length, GoalStateV2 &parsed_struct) +{ + int rc; + + if (mq_buffer == NULL) { + rc = -EINVAL; + ACA_LOG_ERROR("Empty mq_buffer data rc: %d\n", rc); + return rc; + } + + if (parsed_struct.IsInitialized() == false) { + rc = -EINVAL; + ACA_LOG_ERROR("Uninitialized parsed_struct rc: %d\n", rc); + return rc; + } + + // Verify that the version of the library that we linked against is + // compatible with the version of the headers we compiled against. + GOOGLE_PROTOBUF_VERIFY_VERSION; + + if (parsed_struct.ParseFromArray(mq_buffer, buffer_length)) { + ACA_LOG_INFO("%s", "Successfully converted message to protobuf struct\n"); + + return EXIT_SUCCESS; + } else { + rc = -EXIT_FAILURE; + ACA_LOG_ERROR("Failed to convert message to protobuf struct rc: %d\n", rc); + return rc; + } +} + int Aca_Comm_Manager::deserialize(const unsigned char *mq_buffer, size_t buffer_length, GoalState &parsed_struct) { From f89bb7e46e2feedce50e6f808fc12434f8826df1 Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 7 Dec 2021 11:43:52 +0800 Subject: [PATCH 14/37] change consumer covert message into GoalStateV2 --- src/comm/aca_message_pulsar_consumer.cpp | 9 +++------ src/comm/aca_message_pulsar_producer.cpp | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 93dd0150..8e3cfd8e 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -32,12 +32,10 @@ namespace aca_message_pulsar { void listener(Consumer consumer, const Message& message){ - alcor::schema::GoalState deserialized_GoalState; + alcor::schema::GoalStateV2 deserialized_GoalState; alcor::schema::GoalStateOperationReply gsOperationalReply; int rc; Result result; - printf("\n<=====incoming message: %s\n", - message.getDataAsString().c_str()); ACA_LOG_DEBUG("\n<=====incoming message: %s\n", message.getDataAsString().c_str()); @@ -48,7 +46,6 @@ void listener(Consumer consumer, const Message& message){ rc = Aca_Comm_Manager::get_instance().update_goal_state( deserialized_GoalState, gsOperationalReply); - // TODO: send gsOperationalReply back to controller if (rc != EXIT_SUCCESS) { ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); @@ -122,8 +119,8 @@ bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ keySharedPolicy.setKeySharedMode(STICKY); // Set sticky ranges with specified hash value - // StickyRange stickyRange = std::make_pair(stickyHash,stickyHash); - // keySharedPolicy.getStickyRanges(); + StickyRange stickyRange = std::make_pair(stickyHash,stickyHash); + keySharedPolicy.setStickyRanges({stickyRange}); //Use key shared mode this->unicast_consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(keySharedPolicy).setMessageListener(listener); diff --git a/src/comm/aca_message_pulsar_producer.cpp b/src/comm/aca_message_pulsar_producer.cpp index 4188b6e5..fb97d839 100644 --- a/src/comm/aca_message_pulsar_producer.cpp +++ b/src/comm/aca_message_pulsar_producer.cpp @@ -95,7 +95,7 @@ bool ACA_Message_Pulsar_Producer::publish(string message, string orderingKey) } // Create a message - Message msg = MessageBuilder().setContent(message).setOrderingKey(key).build(); + Message msg = MessageBuilder().setContent(message).setOrderingKey(orderingKey).build(); result = producer.send(msg); if(result != ResultOk){ ACA_LOG_ERROR("Failed to send message %s.\n", message.c_str()); From e9ce7e0e716c2f74bc17346e6bc31f0dbe7c5be2 Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 7 Dec 2021 11:47:55 +0800 Subject: [PATCH 15/37] Add publish GoalStateV2 test --- test/gtest/aca_test_mq.cpp | 74 +++----------------------------------- 1 file changed, 5 insertions(+), 69 deletions(-) diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 380748fe..1c95d39c 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -76,7 +76,7 @@ static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running static string mq_test_topic = "Host-ts-1"; static string mq_subscription = "test_subscription"; static string mq_key="9192a4d4-ffff-4ece-b3f0-8d36e3d88001"; // 3dda2801-d675-4688-a63f-dcda8d327f50 9192a4d4-ffff-4ece-b3f0-8d36e3d88001 -static int mq_hash=49775; // 21485 49755 +static int mq_hash=49775; // 21485 49775 // // Test suite: pulsar_test_cases @@ -95,14 +95,6 @@ static int mq_hash=49775; // 21485 49755 TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) { - int retcode = 0; - int overall_rc=0; - int length=1000; - ulong not_care_culminative_time; - string cmd_string; - - unsigned char serializedGoalState[length]; - bool previous_demo_mode = g_demo_mode; g_demo_mode = true; @@ -120,13 +112,8 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) // sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_test TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) { - int retcode = 0; - int overall_rc=0; - int length=1000; - ulong not_care_culminative_time; string cmd_string; - unsigned char serializedGoalState[length]; bool previous_demo_mode = g_demo_mode; g_demo_mode = true; @@ -145,55 +132,6 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) // This case tests the pulsar producer implementation and publishes a GoalState to the subscribed topic. // First run pulsar_consumer_test then execute -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_test - -TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) -{ - int retcode = 0; - int overall_rc=0; - int length=1000; - ulong not_care_culminative_time; - string cmd_string; - string GoalStateString; - unsigned char serializedGoalState[length]; - - GoalState GoalState_builder; - PortState *new_port_states = GoalState_builder.add_port_states(); - SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); - - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "del-br br-int", not_care_culminative_time, overall_rc); - - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "del-br br-tun", not_care_culminative_time, overall_rc); - - overall_rc = ACA_OVS_L2_Programmer::get_instance().setup_ovs_bridges_if_need(); - ASSERT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - - // fill in port state structs - aca_test_create_default_port_state(new_port_states); - - // fill in subnet state structs - aca_test_create_default_subnet_state(new_subnet_states); - - if(GoalState_builder.SerializeToString(&GoalStateString)){ - ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); - } - - ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); - retcode = producer.publish(GoalStateString); - EXPECT_EQ(retcode, EXIT_SUCCESS); - - ACA_LOG_INFO("%s","Waiting for GoalState update.\n"); - sleep(2); - - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - -} // sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_hash_producer_test TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) { @@ -226,7 +164,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) aca_test_create_default_subnet_state(new_subnet_states); if(GoalState_builder.SerializeToString(&GoalStateString)){ - ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); + ACA_LOG_INFO("%s","Successfully covert GoalState to message\n"); } ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); @@ -234,7 +172,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) EXPECT_EQ(retcode, EXIT_SUCCESS); ACA_LOG_INFO("%s","Waiting for GoalState update.\n"); - sleep(2); + sleep(1); ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); @@ -249,13 +187,11 @@ TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) TEST(pulsar_test_cases, DISABLED_pulsar_producer_testv2) { - int retcode = 0; + int retcode=0; int overall_rc=0; - int length=1000; ulong not_care_culminative_time; string cmd_string; string GoalStateString; - unsigned char serializedGoalState[length]; aca_test_reset_environment(); @@ -272,7 +208,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_producer_testv2) subnet_states_map[subnet_id_1] = new_subnet_states; if(GoalState_builder.SerializeToString(&GoalStateString)){ - ACA_LOG_INFO("%s","Successfully covert protobuf struct to message\n"); + ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); } ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); From 3d4f6a0c95a3e1b56c1b97cf5369178582ba7eb3 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 9 Dec 2021 11:02:33 +0800 Subject: [PATCH 16/37] fix pulsar producer orderingKey bugs --- src/comm/aca_message_pulsar_producer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/comm/aca_message_pulsar_producer.cpp b/src/comm/aca_message_pulsar_producer.cpp index d99e960c..115e50d0 100644 --- a/src/comm/aca_message_pulsar_producer.cpp +++ b/src/comm/aca_message_pulsar_producer.cpp @@ -82,7 +82,7 @@ bool ACA_Message_Pulsar_Producer::publish(string message) } -bool ACA_Message_Pulsar_Producer::publish(string message, string key) +bool ACA_Message_Pulsar_Producer::publish(string message, string orderingKey) { Result result; @@ -116,4 +116,4 @@ void ACA_Message_Pulsar_Producer::setBrokers(string brokers) this->brokers_list = brokers; } -} // namespace aca_message_pulsar \ No newline at end of file +} // namespace aca_message_pulsar From ad9a372fa1dc223e7698a2978758762356b08bba Mon Sep 17 00:00:00 2001 From: lly00 Date: Fri, 17 Dec 2021 21:28:37 +0800 Subject: [PATCH 17/37] add head files --- include/aca_async_grpc_subscribe_server.h | 58 +++++++++++++++++++++++ src/aca_main.cpp | 33 ++++++++++++- test/gtest/aca_test_ovs_l2.cpp | 2 +- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 include/aca_async_grpc_subscribe_server.h diff --git a/include/aca_async_grpc_subscribe_server.h b/include/aca_async_grpc_subscribe_server.h new file mode 100644 index 00000000..13406eab --- /dev/null +++ b/include/aca_async_grpc_subscribe_server.h @@ -0,0 +1,58 @@ +// MIT License +// Copyright(c) 2020 Futurewei Cloud +// +// Permission is hereby granted, +// free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#include + +#include +#include +#include "subscribeinfoprovisioner.grpc.pb.h" + +using grpc::Server; +using grpc::ServerAsyncResponseWriter; +using grpc::ServerBuilder; +using grpc::ServerCompletionQueue; +using grpc::ServerContext; +using grpc::Status; + +class Aca_Async_GRPC_Subscribe_Server final { + public: + ~Aca_Async_GRPC_Subscribe_Server(); + Aca_Async_GRPC_Subscribe_Server(); + void Run(); + void StopServer(); + + private: + class CallData { +public: + CallData(alcor::schema::SubscribeInfoProvisioner::AsyncService *service, + ServerCompletionQueue *cq); + void Proceed(); + +private: + alcor::schema::SubscribeInfoProvisioner::AsyncService *service_; + ServerCompletionQueue *cq_; + ServerContext ctx_; + alcor::schema::GoalState request_; + alcor::schema::GoalStateOperationReply reply_; + ServerAsyncResponseWriter responder_; + + enum CallStatus { CREATE, PROCESS, FINISH }; + CallStatus status_; + }; + + void HandleRpcs(); + std::unique_ptr cq_; + alcor::schema::GoalStateProvisioner::AsyncService service_; + std::unique_ptr server_; +}; \ No newline at end of file diff --git a/src/aca_main.cpp b/src/aca_main.cpp index 8e4b52fe..2129763a 100644 --- a/src/aca_main.cpp +++ b/src/aca_main.cpp @@ -46,21 +46,25 @@ static char BROKER_LIST[] = "pulsar://localhost:6650"; static char PULSAR_TOPIC[] = "Host-ts-1"; static char PULSAR_SUBSCRIPTION_NAME[] = "Test-Subscription"; static char GRPC_SERVER_PORT[] = "50001"; +static char GRPC_SUBSCRIBE_SERVER_PORT[] = "50002"; static char OFCTL_COMMAND[] = "monitor"; static char OFCTL_TARGET[] = "br-int"; -using namespace std; +using namespace std; SUBSCRIBE // Global variables std::thread *g_grpc_server_thread = NULL; +std::thread *g_grpc_subscribe_server_thread = NULL; std::thread *g_grpc_client_thread = NULL; GoalStateProvisionerAsyncServer *g_grpc_server = NULL; +SubscribeInfoProvisionerAsyncServer *g_grpc_subscribe_server = NULL; GoalStateProvisionerClientImpl *g_grpc_client = NULL; string g_broker_list = EMPTY_STRING; string g_pulsar_topic = EMPTY_STRING; string g_pulsar_subsription_name = EMPTY_STRING; string g_pulsar_hashed_key = "0"; string g_grpc_server_port = EMPTY_STRING; +string g_grpc_subscribeggi_server_port = EMPTY_STRING; string g_ofctl_command = EMPTY_STRING; string g_ofctl_target = EMPTY_STRING; string g_ofctl_options = EMPTY_STRING; @@ -138,6 +142,23 @@ static void aca_cleanup() ACA_LOG_ERROR("%s", "Unable to call delete, grpc server thread pointer is null.\n"); } + if (g_grpc_subscribe_server != NULL) { + g_grpc_subscribe_server->ShutDownServer(); + delete g_grpc_subscribe_server; + g_grpc_subscribe_server = NULL; + ACA_LOG_INFO("%s", "Cleaned up grpc subscribe server.\n"); + } else { + ACA_LOG_ERROR("%s", "Unable to call delete, grpc subscribe server pointer is null.\n"); + } + + if (g_grpc_subscribe_server_thread != NULL) { + delete g_grpc_subscribe_server_thread; + g_grpc_subscribe_server_thread = NULL; + ACA_LOG_INFO("%s", "Cleaned up grpc subscribe server thread.\n"); + } else { + ACA_LOG_ERROR("%s", "Unable to call delete, grpc subscribe server thread pointer is null.\n"); + } + // Stop the grpc client if (g_grpc_client != NULL) { delete g_grpc_client; @@ -253,6 +274,9 @@ int main(int argc, char *argv[]) if (g_grpc_server_port == EMPTY_STRING) { g_grpc_server_port = GRPC_SERVER_PORT; } + if (g_grpc_subscribe_server_port == EMPTY_STRING) { + g_grpc_subscribe_server_port = GRPC_SUBSCRIBE + } if (g_ofctl_command == EMPTY_STRING) { g_ofctl_command = OFCTL_COMMAND; } @@ -265,6 +289,13 @@ int main(int argc, char *argv[]) &GoalStateProvisionerAsyncServer::RunServer, g_grpc_server, thread_pools_size)); g_grpc_server_thread->detach(); + + // Create a separate thread to get subsribe info for pulsar + g_grpc_subscribe_server = new SubscribeInfoProvisionerAsyncServer(); + g_grpc_subscribe_server_thread = new std::thread(std::bind( + &SubscribeInfoProvisionerAsyncServer::RunServer, g_grpc_subscribe_server)); + g_grpc_subscribe_server_thread->detach(); + // Create a separate thread to run the grpc client. g_grpc_client = new GoalStateProvisionerClientImpl(); g_grpc_client_thread = new std::thread( diff --git a/test/gtest/aca_test_ovs_l2.cpp b/test/gtest/aca_test_ovs_l2.cpp index ea44075e..4eed0a0b 100644 --- a/test/gtest/aca_test_ovs_l2.cpp +++ b/test/gtest/aca_test_ovs_l2.cpp @@ -172,7 +172,7 @@ TEST(ovs_l2_test_cases, 2_ports_CREATE_test_traffic_plus_neighbor_internal) g_demo_mode = previous_demo_mode; // are the newly created ports there? - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + ACA_OVS_L2_Programmer::get_instance().( "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); EXPECT_EQ(overall_rc, EXIT_SUCCESS); overall_rc = EXIT_SUCCESS; From 8c56c64359a0b691ea692e83b66a8f9bee5fd6e0 Mon Sep 17 00:00:00 2001 From: Joey Date: Sat, 18 Dec 2021 21:06:43 +0800 Subject: [PATCH 18/37] pulsar consumer now can resubscribe topic name. --- include/aca_message_pulsar_consumer.h | 10 +++++-- src/comm/aca_message_pulsar_consumer.cpp | 35 +++++++++++++++++++++++- test/gtest/aca_test_mq.cpp | 17 ++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 4572c454..bf20830f 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -48,6 +48,9 @@ class ACA_Message_Pulsar_Consumer { Consumer multicast_consumer; Consumer unicast_consumer; + static string empty_topic; +// static string recoverd_topic; + private: void setMulticastSubscriptionName(string subscription_name); @@ -59,7 +62,6 @@ class ACA_Message_Pulsar_Consumer { void setUnicastTopicName(string topic); - public: ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); @@ -80,9 +82,11 @@ class ACA_Message_Pulsar_Consumer { bool unicastConsumerDispatched(int stickyHash); - //static void listener(Consumer consumer, const Message& message); + bool unicastUnsubcribe(); + + bool unicastResubscribe(string topic, int stickyHash); - + //TODO: 断线恢复topic订阅 }; } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 5bbc9125..a260420c 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -30,6 +30,7 @@ using pulsar::StickyRange; namespace aca_message_pulsar { +string aca_message_pulsar::ACA_Message_Pulsar_Consumer::empty_topic=""; void listener(Consumer consumer, const Message& message){ alcor::schema::GoalStateV2 deserialized_GoalState; @@ -111,7 +112,6 @@ string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const return this->unicast_subscription_name; } - bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ Result result; Consumer consumer; @@ -147,6 +147,38 @@ bool ACA_Message_Pulsar_Consumer::multicastConsumerDispatched(){ return EXIT_SUCCESS; } +bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHash) +{ + bool result; + + result = unicastUnsubcribe(); + + if (result==EXIT_SUCCESS){ + setUnicastTopicName(topic); + result = unicastConsumerDispatched(stickyHash); + if (result==EXIT_SUCCESS) { + return EXIT_SUCCESS; + } + } + ACA_LOG_ERROR("Failed to resubscribe unicast topic: %s\n", topic.c_str()); + return EXIT_FAILURE; +} + +bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() +{ + Result result; + if(this->unicast_topic_name==empty_topic){ + ACA_LOG_INFO("The consumer already unsubscribe the unicast topic."); + return EXIT_SUCCESS; + } + result=this->unicast_consumer.unsubscribe(); + if (result != Result::ResultOk){ + ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); + return EXIT_FAILURE; + } + this->unicast_topic_name=empty_topic; + return EXIT_SUCCESS; +} void ACA_Message_Pulsar_Consumer::setBrokers(string brokers) { @@ -173,4 +205,5 @@ void ACA_Message_Pulsar_Consumer::setUnicastSubscriptionName(string subscription this->unicast_subscription_name = subscription_name; } + } // namespace aca_message_pulsar diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index f5946d94..5767ff9a 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -125,6 +125,23 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) g_demo_mode = previous_demo_mode; } +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test +TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) +{ + string cmd_string; + string mq_update_topic="update topic"; + bool previous_demo_mode = g_demo_mode; + g_demo_mode = true; + + aca_test_reset_environment(); + + ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); + consumer.unicastConsumerDispatched(mq_hash); + consumer.unicastResubscribe(mq_update_topic,mq_hash); + pause(); + + g_demo_mode = previous_demo_mode; +} // This case tests the pulsar producer implementation and publishes a GoalState to the subscribed topic. // First run pulsar_consumer_test then execute From 944cbad6b08583a79eda160c890411733844bc44 Mon Sep 17 00:00:00 2001 From: Joey Date: Sat, 18 Dec 2021 22:11:52 +0800 Subject: [PATCH 19/37] add static recovered_topic to support fault tolerance --- include/aca_message_pulsar_consumer.h | 9 +++++---- src/comm/aca_message_pulsar_consumer.cpp | 14 ++++++++++++- test/gtest/aca_test_mq.cpp | 25 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index bf20830f..27d70b72 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -49,7 +49,6 @@ class ACA_Message_Pulsar_Consumer { Consumer unicast_consumer; static string empty_topic; -// static string recoverd_topic; private: void setMulticastSubscriptionName(string subscription_name); @@ -64,7 +63,9 @@ class ACA_Message_Pulsar_Consumer { public: - ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); + static string recovered_topic; + + ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); ~ACA_Message_Pulsar_Consumer(); @@ -78,6 +79,8 @@ class ACA_Message_Pulsar_Consumer { string getUnicastSubscriptionName() const; + static string getRecoveredTopicName(); + bool multicastConsumerDispatched(); bool unicastConsumerDispatched(int stickyHash); @@ -85,8 +88,6 @@ class ACA_Message_Pulsar_Consumer { bool unicastUnsubcribe(); bool unicastResubscribe(string topic, int stickyHash); - - //TODO: 断线恢复topic订阅 }; } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index a260420c..0e7c2ee7 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -32,6 +32,9 @@ namespace aca_message_pulsar { string aca_message_pulsar::ACA_Message_Pulsar_Consumer::empty_topic=""; +string aca_message_pulsar::ACA_Message_Pulsar_Consumer::recovered_topic= + ACA_Message_Pulsar_Consumer::getRecoveredTopicName(); + void listener(Consumer consumer, const Message& message){ alcor::schema::GoalStateV2 deserialized_GoalState; alcor::schema::GoalStateOperationReply gsOperationalReply; @@ -65,6 +68,7 @@ void listener(Consumer consumer, const Message& message){ ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) { setUnicastTopicName(topic); + recovered_topic=topic; setMulticastTopicName(topic); setBrokers(brokers); setUnicastSubscriptionName(subscription_name); @@ -77,7 +81,7 @@ ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string br ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); // Create the clients - //this->ptr_multicast_client= new Client(brokers); + this->ptr_multicast_client= new Client(brokers); this->ptr_unicast_client = new Client(brokers); } @@ -112,6 +116,11 @@ string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const return this->unicast_subscription_name; } +string ACA_Message_Pulsar_Consumer::getRecoveredTopicName() +{ + return "recovered topic test"; +} + bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ Result result; Consumer consumer; @@ -155,6 +164,7 @@ bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHas if (result==EXIT_SUCCESS){ setUnicastTopicName(topic); + recovered_topic=topic; result = unicastConsumerDispatched(stickyHash); if (result==EXIT_SUCCESS) { return EXIT_SUCCESS; @@ -171,7 +181,9 @@ bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() ACA_LOG_INFO("The consumer already unsubscribe the unicast topic."); return EXIT_SUCCESS; } + result=this->unicast_consumer.unsubscribe(); + printf("%s\n",this->unicast_consumer.getTopic().c_str()); if (result != Result::ResultOk){ ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); return EXIT_FAILURE; diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 5767ff9a..f8a76c2a 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -125,6 +125,31 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) g_demo_mode = previous_demo_mode; } +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_recover_test +TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_recover_test) +{ + string cmd_string; + string mq_update_topic="update topic"; + bool previous_demo_mode = g_demo_mode; + g_demo_mode = true; + + aca_test_reset_environment(); + + auto* pt= + new ACA_Message_Pulsar_Consumer(mq_test_topic,mq_broker_ip,mq_subscription); + pt->unicastConsumerDispatched(mq_hash); + pt->unicastResubscribe(mq_update_topic,mq_hash); + delete pt; + + pt= + new ACA_Message_Pulsar_Consumer(ACA_Message_Pulsar_Consumer::recovered_topic,mq_broker_ip,mq_subscription); + pt->unicastConsumerDispatched(mq_hash); + + pause(); + + g_demo_mode = previous_demo_mode; +} + // sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) { From 02cc3c491529d841311bf3316e874cd01063f708 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 22 Dec 2021 19:55:12 +0800 Subject: [PATCH 20/37] overload unicastResubscribe --- include/aca_message_pulsar_consumer.h | 2 ++ src/comm/aca_message_pulsar_consumer.cpp | 37 +++++++++++++++--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 27d70b72..58587dfe 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -88,6 +88,8 @@ class ACA_Message_Pulsar_Consumer { bool unicastUnsubcribe(); bool unicastResubscribe(string topic, int stickyHash); + + bool unicastResubscribe(bool isSubscribe, string topic="", string stickHash=""); }; } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 0e7c2ee7..8903e15d 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -156,6 +156,24 @@ bool ACA_Message_Pulsar_Consumer::multicastConsumerDispatched(){ return EXIT_SUCCESS; } +bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() +{ + Result result; + if(this->unicast_topic_name==empty_topic){ + ACA_LOG_INFO("The consumer already unsubscribe the unicast topic."); + return EXIT_SUCCESS; + } + + result=this->unicast_consumer.unsubscribe(); + printf("%s\n",this->unicast_consumer.getTopic().c_str()); + if (result != Result::ResultOk){ + ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); + return EXIT_FAILURE; + } + this->unicast_topic_name=empty_topic; + return EXIT_SUCCESS; +} + bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHash) { bool result; @@ -174,22 +192,15 @@ bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHas return EXIT_FAILURE; } -bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() + +bool ACA_Message_Pulsar_Consumer::unicastResubscribe(bool isSubscribe, string topic, string stickHash) { - Result result; - if(this->unicast_topic_name==empty_topic){ - ACA_LOG_INFO("The consumer already unsubscribe the unicast topic."); - return EXIT_SUCCESS; + if(!isSubscribe){ + return unicastUnsubcribe(); } - - result=this->unicast_consumer.unsubscribe(); - printf("%s\n",this->unicast_consumer.getTopic().c_str()); - if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); - return EXIT_FAILURE; + else{ + return unicastResubscribe(topic, std::stoi(stickHash)); } - this->unicast_topic_name=empty_topic; - return EXIT_SUCCESS; } void ACA_Message_Pulsar_Consumer::setBrokers(string brokers) From 76a725f86db6b9e79111b703b1d4698019d36921 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 22 Dec 2021 22:01:48 +0800 Subject: [PATCH 21/37] aca_message_pulsar_consumer runs as instance --- include/aca_message_pulsar_consumer.h | 8 +++-- src/comm/aca_message_pulsar_consumer.cpp | 32 +++++++++++++++++- test/gtest/aca_test_mq.cpp | 42 +++++++++++------------- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 58587dfe..43a34f8b 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -65,10 +65,14 @@ class ACA_Message_Pulsar_Consumer { public: static string recovered_topic; - ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); + static ACA_Message_Pulsar_Consumer &get_instance(); + + ACA_Message_Pulsar_Consumer(); - ~ACA_Message_Pulsar_Consumer(); + ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); + ~ACA_Message_Pulsar_Consumer(); + void init(); string getBrokers() const; string getMulticastTopicName() const; diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 8903e15d..a9fb7d4c 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -65,6 +65,36 @@ void listener(Consumer consumer, const Message& message){ consumer.acknowledge(message.getMessageId()); } +ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer() +{ + string default_brokers = "pulsar://localhost:6650"; + string default_topic = "Host-ts-1"; + string default_subscription_name = "test_subscription"; + + setUnicastTopicName(default_topic); + recovered_topic=default_topic; + setMulticastTopicName(default_topic); + setBrokers(default_brokers); + setUnicastSubscriptionName(default_subscription_name); + setMulticastSubscriptionName(default_subscription_name); + + ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); + ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); + ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); + ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); + ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); + + // Create the clients + this->ptr_multicast_client= new Client(default_brokers); + this->ptr_unicast_client = new Client(default_brokers); +} + +ACA_Message_Pulsar_Consumer &ACA_Message_Pulsar_Consumer::get_instance() +{ + static ACA_Message_Pulsar_Consumer instance; + return instance; +} + ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) { setUnicastTopicName(topic); @@ -134,6 +164,7 @@ bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ //Use key shared mode this->unicast_consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(keySharedPolicy).setMessageListener(listener); + ACA_LOG_INFO("%s\n",this->unicast_topic_name.c_str()); result = this->ptr_unicast_client->subscribe(this->unicast_topic_name,this->unicast_subscription_name,this->unicast_consumer_config,this->unicast_consumer); if (result != Result::ResultOk){ ACA_LOG_ERROR("Failed to subscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); @@ -165,7 +196,6 @@ bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() } result=this->unicast_consumer.unsubscribe(); - printf("%s\n",this->unicast_consumer.getTopic().c_str()); if (result != Result::ResultOk){ ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); return EXIT_FAILURE; diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index f8a76c2a..b35062b3 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -99,8 +99,8 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) g_demo_mode = true; aca_test_reset_environment(); - - ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); + ACA_Message_Pulsar_Consumer consumer=ACA_Message_Pulsar_Consumer::get_instance(); +// ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); consumer.multicastConsumerDispatched(); pause(); @@ -118,7 +118,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); + ACA_Message_Pulsar_Consumer consumer = ACA_Message_Pulsar_Consumer::get_instance(); consumer.unicastConsumerDispatched(mq_hash); pause(); @@ -150,7 +150,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_recover_test) g_demo_mode = previous_demo_mode; } -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) { string cmd_string; @@ -160,9 +160,10 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); + ACA_Message_Pulsar_Consumer consumer(mq_update_topic, mq_broker_ip, mq_subscription); consumer.unicastConsumerDispatched(mq_hash); - consumer.unicastResubscribe(mq_update_topic,mq_hash); + consumer.unicastResubscribe(false); + consumer.unicastResubscribe(true,mq_test_topic, to_string(mq_hash)); pause(); g_demo_mode = previous_demo_mode; @@ -181,35 +182,30 @@ TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) string GoalStateString; unsigned char serializedGoalState[length]; - GoalState GoalState_builder; - PortState *new_port_states = GoalState_builder.add_port_states(); - SubnetState *new_subnet_states = GoalState_builder.add_subnet_states(); - - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "del-br br-int", not_care_culminative_time, overall_rc); + GoalStateV2 GoalState_builder; + PortState new_port_states; + SubnetState new_subnet_states; - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "del-br br-tun", not_care_culminative_time, overall_rc); + aca_test_reset_environment(); - overall_rc = ACA_OVS_L2_Programmer::get_instance().setup_ovs_bridges_if_need(); - ASSERT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; + aca_test_create_default_port_state(&new_port_states); + auto &port_states_map = *GoalState_builder.mutable_port_states(); + port_states_map[port_id_1] = new_port_states; - // fill in port state structs - aca_test_create_default_port_state(new_port_states); + aca_test_create_default_subnet_state(&new_subnet_states); + auto &subnet_states_map = *GoalState_builder.mutable_subnet_states(); + subnet_states_map[subnet_id_1] = new_subnet_states; - // fill in subnet state structs - aca_test_create_default_subnet_state(new_subnet_states); if(GoalState_builder.SerializeToString(&GoalStateString)){ - ACA_LOG_INFO("%s","Successfully covert GoalState to message\n"); + ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); } ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); retcode = producer.publish(GoalStateString,mq_key); EXPECT_EQ(retcode, EXIT_SUCCESS); - ACA_LOG_INFO("%s","Waiting for GoalState update.\n"); + ACA_LOG_INFO("%s","Waiting for GoalStateV2 update.\n"); sleep(1); ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( From bd9c5c7691cb356b602fcb84150950fc23e6960a Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 22 Dec 2021 22:15:35 +0800 Subject: [PATCH 22/37] aca_message_pulsar_consumer runs as instance --- include/aca_message_pulsar_consumer.h | 4 +++- src/comm/aca_message_pulsar_consumer.cpp | 17 +++++++++++++++++ test/gtest/aca_test_mq.cpp | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 43a34f8b..393bb6e2 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -72,7 +72,9 @@ class ACA_Message_Pulsar_Consumer { ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); ~ACA_Message_Pulsar_Consumer(); - void init(); + + void init(string topic, string brokers, string subscription_name); + string getBrokers() const; string getMulticastTopicName() const; diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index a9fb7d4c..dc9626a6 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -94,7 +94,24 @@ ACA_Message_Pulsar_Consumer &ACA_Message_Pulsar_Consumer::get_instance() static ACA_Message_Pulsar_Consumer instance; return instance; } +void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subscription_name){ + setUnicastTopicName(topic); + recovered_topic=topic; + setMulticastTopicName(topic); + setBrokers(brokers); + setUnicastSubscriptionName(subscription_name); + setMulticastSubscriptionName(subscription_name); + ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); + ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); + ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); + ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); + ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); + + // Create the clients + this->ptr_multicast_client= new Client(brokers); + this->ptr_unicast_client = new Client(brokers); +} ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) { setUnicastTopicName(topic); diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index b35062b3..b7b52197 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -100,6 +100,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) aca_test_reset_environment(); ACA_Message_Pulsar_Consumer consumer=ACA_Message_Pulsar_Consumer::get_instance(); + consumer.init(mq_test_topic, mq_broker_ip, mq_subscription); // ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); consumer.multicastConsumerDispatched(); pause(); @@ -119,6 +120,7 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) aca_test_reset_environment(); ACA_Message_Pulsar_Consumer consumer = ACA_Message_Pulsar_Consumer::get_instance(); + consumer.init(mq_test_topic, mq_broker_ip, mq_subscription); consumer.unicastConsumerDispatched(mq_hash); pause(); From 2c9724a72a1a2ae79da03f6d2e1afbb70564cf07 Mon Sep 17 00:00:00 2001 From: lly00 Date: Wed, 22 Dec 2021 23:53:39 +0800 Subject: [PATCH 23/37] add grpc thread for subscribe info --- alcor | 2 +- include/aca_comm_mgr.h | 4 + include/aca_grpc_subscribe.h | 96 ++++++++++++ include/aca_message_pulsar_consumer.h | 5 + src/CMakeLists.txt | 1 + src/aca_main.cpp | 10 +- src/comm/aca_comm_mgr.cpp | 30 ++++ src/comm/aca_grpc_subscribe.cpp | 189 +++++++++++++++++++++++ src/comm/aca_message_pulsar_consumer.cpp | 8 - src/grpc/CMakeLists.txt | 9 +- test/gtest/aca_test_main.cpp | 5 - test/gtest/aca_test_ovs_l2.cpp | 2 +- 12 files changed, 340 insertions(+), 21 deletions(-) create mode 100644 include/aca_grpc_subscribe.h create mode 100644 src/comm/aca_grpc_subscribe.cpp diff --git a/alcor b/alcor index f3fd109c..97fc7b84 160000 --- a/alcor +++ b/alcor @@ -1 +1 @@ -Subproject commit f3fd109c65b6b80a960ef4aabb743f8a92788047 +Subproject commit 97fc7b8482320f121889dd4211f71b29a77d6275 diff --git a/include/aca_comm_mgr.h b/include/aca_comm_mgr.h index 05734ee5..75fa9e9d 100644 --- a/include/aca_comm_mgr.h +++ b/include/aca_comm_mgr.h @@ -16,6 +16,7 @@ #define ACA_COMM_MGR_H #include "goalstateprovisioner.grpc.pb.h" +#include "subscribeinfoprovisioner.grpc.pb.h" using std::string; @@ -37,6 +38,9 @@ class Aca_Comm_Manager { int update_goal_state(alcor::schema::GoalStateV2 &goal_state_message, alcor::schema::GoalStateOperationReply &gsOperationReply); + int update_subscribe_info(alcor::schema::NodeSubscribeInfo &subscribe_info_message, + alcor::schema::SubscribeOperationReply &subscribeOperationReply); + // compiler will flag error when below is called Aca_Comm_Manager(Aca_Comm_Manager const &) = delete; void operator=(Aca_Comm_Manager const &) = delete; diff --git a/include/aca_grpc_subscribe.h b/include/aca_grpc_subscribe.h new file mode 100644 index 00000000..32248c43 --- /dev/null +++ b/include/aca_grpc_subscribe.h @@ -0,0 +1,96 @@ +// MIT License +// Copyright(c) 2020 Futurewei Cloud +// +// Permission is hereby granted, +// free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#include + +#include +#include +#include "subscribeinfoprovisioner.grpc.pb.h" +#include "ctpl/ctpl_stl.h" + +using namespace alcor::schema; +using grpc::Server; +using grpc::ServerAsyncReader; +using grpc::ServerAsyncReaderWriter; +using grpc::ServerAsyncResponseWriter; +using grpc::ServerBuilder; +using grpc::ServerCompletionQueue; +using grpc::ServerContext; +using grpc::ServerReader; +using grpc::ServerReaderWriter; +using grpc::ServerWriter; +using grpc::Status; + +class SubscribeInfoProvisionerAsyncServer { + public: + ~SubscribeInfoProvisionerAsyncServer() + { + this->keepReadingFromCq_ = false; + } + + /* + Base class that represents a gRPC call. + When you have a new kind of rpc, add the corresponding enum to CallType + */ + struct AsyncSubscribeInfoProvionerCallBase { + /* + Currently there are two types of CallStatus, INIT and SENT + At the INIT state, a streaming/unary rpc call creates a new streaming/unary call instance, + requests the call and then processes the received data; + AT the SENT state, a streaming call doesn't do anything; but a unary call deletes its own instance, + since this call is already done. + */ + enum CallStatus { INIT, SENT, DESTROY }; + CallStatus status_; + grpc::ServerContext ctx_; + }; + + // struct for PushNodeSubscribeInfoAsyncCall, which is a unary gRPC call + // when adding a new unary rpc call, create a new struct just like PushNodeSubscribeInfoAsyncCall + struct PushNodeSubscribeInfoAsyncCall : public AsyncSubscribeInfoProvionerCallBase { + // Received SubscribeInfo + NodeSubscribeInfo subscribeInfo_; + // Reply to be sent + SubscribeOperationReply subscribeOperationReply_; + + // Object to send reply to client + grpc::ServerAsyncResponseWriter responder_; + + // Constructor + PushNodeSubscribeInfoAsyncCall() : responder_(&ctx_) + { + } + }; + + std::unique_ptr stub_; + std::shared_ptr chan_; + + Status ShutDownServer(); + void RunServer(int thread_pool_size); + void AsyncWorkder(); + /* + Add a corresponding function here to process a new kind of rpc call. + For unary rpcs, please refer to ProcessNodeSubscribeInfoAsyncCall + + */ + void ProcessPushNodeSubscribeInfoAsyncCall(AsyncSubscribeInfoProvionerCallBase *baseCall, + bool ok); + + private: + bool keepReadingFromCq_ = true; + std::unique_ptr server_; + std::unique_ptr cq_; + SubscribeInfoProvisioner::AsyncService service_; + ctpl::thread_pool thread_pool_; +}; diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 4572c454..db4eb5c9 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -80,6 +80,11 @@ class ACA_Message_Pulsar_Consumer { bool unicastConsumerDispatched(int stickyHash); + + + // reset topic and key info + bool reSubscribe(string topic, string key); + //static void listener(Consumer consumer, const Message& message); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b973e57e..bd0312b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ set(SOURCES ./comm/aca_message_pulsar_producer.cpp ./comm/aca_comm_mgr.cpp ./comm/aca_grpc.cpp + ./comm/aca_grpc_subscribe.cpp ./comm/aca_grpc_client.cpp ./dp_abstraction/aca_goal_state_handler.cpp ./dp_abstraction/aca_dataplane_ovs.cpp diff --git a/src/aca_main.cpp b/src/aca_main.cpp index 2129763a..3a7bf953 100644 --- a/src/aca_main.cpp +++ b/src/aca_main.cpp @@ -15,6 +15,7 @@ #include "aca_log.h" #include "aca_util.h" #include "aca_message_pulsar_consumer.h" +#include "aca_grpc_subscribe.h" #include "aca_grpc.h" #include "aca_grpc_client.h" @@ -29,6 +30,7 @@ #include "aca_ovs_control.h" #include "goalstateprovisioner.grpc.pb.h" +#include "subscribeinfoprovisioner.grpc.pb.h" #include #include #include /* for getopt */ @@ -50,7 +52,7 @@ static char GRPC_SUBSCRIBE_SERVER_PORT[] = "50002"; static char OFCTL_COMMAND[] = "monitor"; static char OFCTL_TARGET[] = "br-int"; -using namespace std; SUBSCRIBE +using namespace std; // Global variables std::thread *g_grpc_server_thread = NULL; @@ -64,7 +66,7 @@ string g_pulsar_topic = EMPTY_STRING; string g_pulsar_subsription_name = EMPTY_STRING; string g_pulsar_hashed_key = "0"; string g_grpc_server_port = EMPTY_STRING; -string g_grpc_subscribeggi_server_port = EMPTY_STRING; +string g_grpc_subscribe_server_port = EMPTY_STRING; string g_ofctl_command = EMPTY_STRING; string g_ofctl_target = EMPTY_STRING; string g_ofctl_options = EMPTY_STRING; @@ -275,7 +277,7 @@ int main(int argc, char *argv[]) g_grpc_server_port = GRPC_SERVER_PORT; } if (g_grpc_subscribe_server_port == EMPTY_STRING) { - g_grpc_subscribe_server_port = GRPC_SUBSCRIBE + g_grpc_subscribe_server_port = GRPC_SUBSCRIBE_SERVER_PORT; } if (g_ofctl_command == EMPTY_STRING) { g_ofctl_command = OFCTL_COMMAND; @@ -293,7 +295,7 @@ int main(int argc, char *argv[]) // Create a separate thread to get subsribe info for pulsar g_grpc_subscribe_server = new SubscribeInfoProvisionerAsyncServer(); g_grpc_subscribe_server_thread = new std::thread(std::bind( - &SubscribeInfoProvisionerAsyncServer::RunServer, g_grpc_subscribe_server)); + &SubscribeInfoProvisionerAsyncServer::RunServer, g_grpc_subscribe_server, 1)); g_grpc_subscribe_server_thread->detach(); // Create a separate thread to run the grpc client. diff --git a/src/comm/aca_comm_mgr.cpp b/src/comm/aca_comm_mgr.cpp index 7e2f1953..f2a49ae8 100644 --- a/src/comm/aca_comm_mgr.cpp +++ b/src/comm/aca_comm_mgr.cpp @@ -17,7 +17,9 @@ #include "aca_comm_mgr.h" #include "aca_goal_state_handler.h" #include "aca_dhcp_state_handler.h" +#include "aca_message_pulsar_consumer.h" #include "goalstateprovisioner.grpc.pb.h" +#include "subscribeinfoprovisioner.grpc.pb.h" using namespace std; using namespace alcor::schema; @@ -287,6 +289,34 @@ int Aca_Comm_Manager::update_goal_state(GoalStateV2 &goal_state_message, return rc; } +int Aca_Comm_Manager::update_subscribe_info(NodeSubscribeInfo &subscribe_info_message, + SubscribeOperationReply &subscribeOperationReply) +{ + int exec_command_rc = EXIT_SUCCESS; + int rc = EXIT_SUCCESS; + auto start = chrono::steady_clock::now(); + + + auto subscribe_finished_time = chrono::steady_clock::now(); + //exec_command_rc = ACA_Message_Pulsar_Consumer::get_instance(). + auto subscribe_operation_time = + cast_to_microseconds(subscribe_finished_time - start).count(); + + ACA_LOG_INFO("[METRICS] Elapsed time for subscribe operation took: %ld microseconds or %ld milliseconds\n", + subscribe_operation_time, us_to_ms(subscribe_operation_time)); + + OperationStatus operation_status; + + if (exec_command_rc == EXIT_SUCCESS) + operation_status = OperationStatus::SUCCESS; + else + operation_status = OperationStatus::FAILURE; + subscribeOperationReply.set_operationstatus(operation_status); + + return rc; +} + + void Aca_Comm_Manager::print_goal_state(GoalState parsed_struct) { if (g_debug_mode == false) { diff --git a/src/comm/aca_grpc_subscribe.cpp b/src/comm/aca_grpc_subscribe.cpp new file mode 100644 index 00000000..f7c2e7ef --- /dev/null +++ b/src/comm/aca_grpc_subscribe.cpp @@ -0,0 +1,189 @@ +/* + * + * Copyright 2015 gRPC authors. + * Copyright 2019 The Alcor Authors - file modified. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include "subscribeinfoprovisioner.grpc.pb.h" +#include "aca_comm_mgr.h" +#include "aca_log.h" +#include "aca_grpc_subscribe.h" + +extern string g_grpc_subscribe_server_port; + + +using namespace alcor::schema; +using aca_comm_manager::Aca_Comm_Manager; + +Status SubscribeInfoProvisionerAsyncServer::ShutDownServer() +{ + ACA_LOG_INFO("%s", "Shutdown server"); + server_->Shutdown(); + cq_->Shutdown(); + thread_pool_.stop(); + keepReadingFromCq_ = false; + return Status::OK; +} + +void SubscribeInfoProvisionerAsyncServer::ProcessPushNodeSubscribeInfoAsyncCall( + AsyncSubscribeInfoProvionerCallBase *baseCall, bool ok) +{ + ACA_LOG_DEBUG("Start of ProcessPushNodeSubscribeInfoAsyncCall, OK: %ld, call_status: %ld\n", + ok, baseCall->status_); + PushNodeSubscribeInfoAsyncCall *unaryCall = + static_cast(baseCall); + if (!ok) { + // maybe delete the instance and init a new one? + ACA_LOG_DEBUG("%s\n", "Got a PushNodeSubscribeInfoAsync Call that is NOT OK."); + delete (PushNodeSubscribeInfoAsyncCall *)baseCall; + PushNodeSubscribeInfoAsyncCall *newPushNodeSubscribeInfoAsyncCallInstance = + new PushNodeSubscribeInfoAsyncCall; + newPushNodeSubscribeInfoAsyncCallInstance->status_ = + AsyncSubscribeInfoProvionerCallBase::CallStatus::INIT; + // Request for the call + service_.RequestPushNodeSubscribeInfo( + &newPushNodeSubscribeInfoAsyncCallInstance->ctx_, /*Context of this call*/ + &newPushNodeSubscribeInfoAsyncCallInstance->subscribeInfo_, /*SubscribeInfo to receive*/ + &newPushNodeSubscribeInfoAsyncCallInstance->responder_, /*Responder of call*/ + cq_.get(), /*CQ for new call*/ + cq_.get(), /*CQ for finished call*/ + newPushNodeSubscribeInfoAsyncCallInstance /*The unique tag for the call*/ + ); + } else { + switch (unaryCall->status_) { + case AsyncSubscribeInfoProvionerCallBase::CallStatus::INIT: { + ACA_LOG_DEBUG("%s\n", "Initing a new PushNodeSubscribeInfoAsyncCallInstance, before processing the current one"); + PushNodeSubscribeInfoAsyncCall *newPushNodeSubscribeInfoAsyncCallInstance = + new PushNodeSubscribeInfoAsyncCall; + newPushNodeSubscribeInfoAsyncCallInstance->status_ = + AsyncSubscribeInfoProvionerCallBase::CallStatus::INIT; + // Request for the call + service_.RequestPushNodeSubscribeInfo( + &newPushNodeSubscribeInfoAsyncCallInstance->ctx_, /*Context of this call*/ + &newPushNodeSubscribeInfoAsyncCallInstance->subscribeInfo_, /*SubscribeInfo to receive*/ + &newPushNodeSubscribeInfoAsyncCallInstance->responder_, /*Responder of call*/ + cq_.get(), /*CQ for new call*/ + cq_.get(), /*CQ for finished call*/ + newPushNodeSubscribeInfoAsyncCallInstance /*The unique tag for the call*/ + ); + // process SubscribeInfo in the thread pool + ACA_LOG_DEBUG("%s\n", "Processing a PushNodeSubscribeInfo call..."); + ACA_LOG_DEBUG("%s\n", "Received a SubscribeInfo, need to process it"); + + int rc = Aca_Comm_Manager::get_instance().update_subscribe_info( + unaryCall->subscribeInfo_, unaryCall->subscribeOperationReply_); + if (rc == EXIT_SUCCESS) { + ACA_LOG_INFO("Successfully updated host with latest subscribe info %d.\n", + rc); + } else if (rc == EINPROGRESS) { + ACA_LOG_INFO("Update host with latest subscribe info returned pending, rc=%d.\n", + rc); + } else { + ACA_LOG_ERROR("Failed to update host with latest subscribe info , rc=%d.\n", + rc); + } + unaryCall->status_ = AsyncSubscribeInfoProvionerCallBase::CallStatus::SENT; + unaryCall->responder_.Finish(unaryCall->subscribeOperationReply_, Status::OK, baseCall); + ACA_LOG_DEBUG("%s\n", "V1: responder_->Finish called"); + + } break; + case AsyncSubscribeInfoProvionerCallBase::CallStatus::SENT: { + ACA_LOG_DEBUG("Finished processing %s gRPC call, deleting it.\n", + "PushNodeSubscribeInfo"); + delete unaryCall; + } break; + default: + break; + } + } +} + + + +void SubscribeInfoProvisionerAsyncServer::AsyncWorkder() +{ + while (keepReadingFromCq_) { + ACA_LOG_DEBUG("%s\n", "At the start of the while loop"); + AsyncSubscribeInfoProvionerCallBase *asyncCallBase = NULL; + bool ok = false; + if (!cq_.get()->Next((void **)&asyncCallBase, &ok)) { + ACA_LOG_DEBUG("Completion Queue Shut. Quitting\n"); + break; + } + ACA_LOG_DEBUG("Got message from CQ, is it OK? %ld\n", ok); + + ProcessPushNodeSubscribeInfoAsyncCall(asyncCallBase, ok); + } + ACA_LOG_DEBUG("%s\n", "Out of the for loop, seems like this server is shutting down."); +} + +void SubscribeInfoProvisionerAsyncServer::RunServer(int thread_pool_size) +{ + ACA_LOG_INFO("Start of RunServer, pool size %ld\n", thread_pool_size); + + thread_pool_.resize(thread_pool_size); + ACA_LOG_DEBUG("Async GRPC SERVER: Resized thread pool to %ld threads, start waiting for the pool to have enough threads\n", + thread_pool_size); + /* wait for thread pool to initialize*/ + while (thread_pool_.n_idle() != thread_pool_.size()) { + ACA_LOG_DEBUG("%s\n", "Still waiting...sleep 1 ms"); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + }; + ACA_LOG_DEBUG("Async GRPC SERVER: finised resizing thread pool to %ld threads\n", + thread_pool_size); + // Create the server + ServerBuilder builder; + string GRPC_SERVER_ADDRESS = "0.0.0.0:" + g_grpc_subscribe_server_port; + builder.AddListeningPort(GRPC_SERVER_ADDRESS, grpc::InsecureServerCredentials()); + builder.SetMaxMessageSize(INT_MAX); + builder.SetMaxReceiveMessageSize(INT_MAX); + builder.SetMaxSendMessageSize(INT_MAX); + builder.RegisterService(&service_); + cq_ = builder.AddCompletionQueue(); + server_ = builder.BuildAndStart(); + + // Test with one thread first, will move to multiple threads later + for (int i = 0; i < thread_pool_size; i++) { + // Instantiate a new PushNodeSubscribeInfo call object, and set its status + PushNodeSubscribeInfoAsyncCall *pushNodeSubscribeInfoAsyncCallInstance = + new PushNodeSubscribeInfoAsyncCall; + pushNodeSubscribeInfoAsyncCallInstance->status_ = + AsyncSubscribeInfoProvionerCallBase::CallStatus::INIT; + // Request for the call + service_.RequestPushNodeSubscribeInfo( + &pushNodeSubscribeInfoAsyncCallInstance->ctx_, /*Context of this call*/ + &pushNodeSubscribeInfoAsyncCallInstance->subscribeInfo_, /*Subscribe Info to receive*/ + &pushNodeSubscribeInfoAsyncCallInstance->responder_, /*Responder of call*/ + cq_.get(), /*CQ for new call*/ + cq_.get(), /*CQ for finished call*/ + pushNodeSubscribeInfoAsyncCallInstance /*The unique tag for the call*/ + ); + } + + for (int i = 0; i < thread_pool_size; i++) { + ACA_LOG_DEBUG("Pushing the %ldth async worker into the pool", i); + thread_pool_.push(std::bind(&SubscribeInfoProvisionerAsyncServer::AsyncWorkder, this)); + } +} diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index a435ddf4..5bbc9125 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -32,11 +32,7 @@ namespace aca_message_pulsar { void listener(Consumer consumer, const Message& message){ -<<<<<<< HEAD - alcor::schema::GoalState deserialized_GoalState; -======= alcor::schema::GoalStateV2 deserialized_GoalState; ->>>>>>> 74a78cf1bfe3cd1f26f4ecebde51de40e4b6cb06 alcor::schema::GoalStateOperationReply gsOperationalReply; int rc; Result result; @@ -50,10 +46,6 @@ void listener(Consumer consumer, const Message& message){ rc = Aca_Comm_Manager::get_instance().update_goal_state( deserialized_GoalState, gsOperationalReply); -<<<<<<< HEAD - // TODO: send gsOperationalReply back to controller -======= ->>>>>>> 74a78cf1bfe3cd1f26f4ecebde51de40e4b6cb06 if (rc != EXIT_SUCCESS) { ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); diff --git a/src/grpc/CMakeLists.txt b/src/grpc/CMakeLists.txt index aa9daeb2..928740b3 100644 --- a/src/grpc/CMakeLists.txt +++ b/src/grpc/CMakeLists.txt @@ -24,8 +24,13 @@ set(aca_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/goalstateprovisioner.pb.cc") set(aca_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/goalstateprovisioner.pb.h") set(aca_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/goalstateprovisioner.grpc.pb.cc") set(aca_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/goalstateprovisioner.grpc.pb.h") + +set(aca_proto_sub_srcs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.pb.cc") +set(aca_proto_sub_hdrs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.pb.h") +set(aca_grpc_sub_srcs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.grpc.pb.cc") +set(aca_grpc_sub_hdrs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.grpc.pb.h") add_custom_command( - OUTPUT "${aca_proto_srcs}" "${aca_proto_hdrs}" "${aca_grpc_srcs}" "${aca_grpc_hdrs}" + OUTPUT "${aca_proto_srcs}" "${aca_proto_hdrs}" "${aca_grpc_srcs}" "${aca_grpc_hdrs}" "${aca_proto_sub_srcs}" "${aca_proto__sub_hdrs}" "${aca_grpc_sub_srcs}" "${aca_grpc_sub_hdrs}" COMMAND ${_PROTOBUF_PROTOC} ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" @@ -37,4 +42,4 @@ add_custom_command( # Include generated *.pb.h files include_directories("${CMAKE_CURRENT_BINARY_DIR}") -ADD_LIBRARY(grpc ${aca_proto_srcs} ${aca_proto_hdrs} ${aca_grpc_srcs} ${aca_grpc_hdrs}) \ No newline at end of file +ADD_LIBRARY(grpc ${aca_proto_srcs} ${aca_proto_hdrs} ${aca_grpc_srcs} ${aca_grpc_hdrs} ${aca_proto_sub_srcs} ${aca_proto_sub_hdrs} ${aca_grpc_sub_srcs} ${aca_grpc_sub_hdrs}) \ No newline at end of file diff --git a/test/gtest/aca_test_main.cpp b/test/gtest/aca_test_main.cpp index f5adc82e..0ee784b8 100644 --- a/test/gtest/aca_test_main.cpp +++ b/test/gtest/aca_test_main.cpp @@ -71,11 +71,6 @@ string remote_ip_1="172.17.0.2"; // for docker network string remote_ip_2= "172.17.0.3"; // for docker network uint neighbors_to_create = 10; -<<<<<<< HEAD -static string mq_broker_ip = "pulsar://localhost:6650"; //for the broker running in localhost -static string mq_test_topic = "Host-ts-1"; -======= ->>>>>>> 74a78cf1bfe3cd1f26f4ecebde51de40e4b6cb06 int processor_count = std::thread::hardware_concurrency(); /* From previous tests, we found that, for x number of cores, diff --git a/test/gtest/aca_test_ovs_l2.cpp b/test/gtest/aca_test_ovs_l2.cpp index 4eed0a0b..ea44075e 100644 --- a/test/gtest/aca_test_ovs_l2.cpp +++ b/test/gtest/aca_test_ovs_l2.cpp @@ -172,7 +172,7 @@ TEST(ovs_l2_test_cases, 2_ports_CREATE_test_traffic_plus_neighbor_internal) g_demo_mode = previous_demo_mode; // are the newly created ports there? - ACA_OVS_L2_Programmer::get_instance().( + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); EXPECT_EQ(overall_rc, EXIT_SUCCESS); overall_rc = EXIT_SUCCESS; From ce08f7b1260b5286aa615d77f311b528e9d2df60 Mon Sep 17 00:00:00 2001 From: lly00 Date: Thu, 23 Dec 2021 00:13:06 +0800 Subject: [PATCH 24/37] update subscribe info --- src/comm/aca_comm_mgr.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/comm/aca_comm_mgr.cpp b/src/comm/aca_comm_mgr.cpp index f2a49ae8..85804c78 100644 --- a/src/comm/aca_comm_mgr.cpp +++ b/src/comm/aca_comm_mgr.cpp @@ -25,6 +25,7 @@ using namespace std; using namespace alcor::schema; using namespace aca_goal_state_handler; using namespace aca_dhcp_state_handler; +using namespace aca_message_pulsar; extern string g_rpc_server; extern string g_rpc_protocol; @@ -298,7 +299,9 @@ int Aca_Comm_Manager::update_subscribe_info(NodeSubscribeInfo &subscribe_info_me auto subscribe_finished_time = chrono::steady_clock::now(); - //exec_command_rc = ACA_Message_Pulsar_Consumer::get_instance(). + exec_command_rc = ACA_Message_Pulsar_Consumer::get_instance().unicastResubscribe(subscribe_info_message.subscribe_operation(), + subscribe_info_message.topic(), + subscribe_info_message.key()); auto subscribe_operation_time = cast_to_microseconds(subscribe_finished_time - start).count(); From aeb702778ca30049b7f2659536e65f00f7e22bc5 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 29 Dec 2021 21:53:38 +0800 Subject: [PATCH 25/37] delete multicast producer test cases --- test/gtest/aca_test_mq.cpp | 52 +++----------------------------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index b7b52197..52fd459d 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -164,8 +164,8 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) ACA_Message_Pulsar_Consumer consumer(mq_update_topic, mq_broker_ip, mq_subscription); consumer.unicastConsumerDispatched(mq_hash); - consumer.unicastResubscribe(false); - consumer.unicastResubscribe(true,mq_test_topic, to_string(mq_hash)); + consumer.unicastResubscribe(true); + consumer.unicastResubscribe(false,mq_test_topic, to_string(mq_hash)); pause(); g_demo_mode = previous_demo_mode; @@ -173,8 +173,8 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) // This case tests the pulsar producer implementation and publishes a GoalState to the subscribed topic. // First run pulsar_consumer_test then execute -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_hash_producer_test -TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_test +TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) { int retcode = 0; int overall_rc=0; @@ -215,48 +215,4 @@ TEST(pulsar_test_cases, DISABLED_pulsar_hash_producer_test) EXPECT_EQ(overall_rc, EXIT_SUCCESS); overall_rc = EXIT_SUCCESS; -} - -// This case tests the pulsar producer implementation and publishes a GoalStateV2 to the subscribed topic. -// First run pulsar_consumer_test then execute -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_testv2 - -TEST(pulsar_test_cases, DISABLED_pulsar_producer_testv2) -{ - int retcode=0; - int overall_rc=0; - ulong not_care_culminative_time; - string cmd_string; - string GoalStateString; - - aca_test_reset_environment(); - - GoalStateV2 GoalState_builder; - PortState new_port_states; - SubnetState new_subnet_states; - - aca_test_create_default_port_state(&new_port_states); - auto &port_states_map = *GoalState_builder.mutable_port_states(); - port_states_map[port_id_1] = new_port_states; - - aca_test_create_default_subnet_state(&new_subnet_states); - auto &subnet_states_map = *GoalState_builder.mutable_subnet_states(); - subnet_states_map[subnet_id_1] = new_subnet_states; - - if(GoalState_builder.SerializeToString(&GoalStateString)){ - ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); - } - - ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); - retcode = producer.publish(GoalStateString); - EXPECT_EQ(retcode, EXIT_SUCCESS); - - ACA_LOG_INFO("%s","Waiting for GoalStateV2 update.\n"); - sleep(2); - - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; - } \ No newline at end of file From 7ab25434d022f7c4f292a0c67729ee94ae690737 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 30 Dec 2021 11:14:51 +0800 Subject: [PATCH 26/37] replace construct function with init function --- include/aca_message_pulsar_consumer.h | 5 +- src/comm/aca_message_pulsar_consumer.cpp | 69 ++++++++---------------- 2 files changed, 24 insertions(+), 50 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 393bb6e2..18abc804 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -63,13 +63,12 @@ class ACA_Message_Pulsar_Consumer { public: - static string recovered_topic; static ACA_Message_Pulsar_Consumer &get_instance(); ACA_Message_Pulsar_Consumer(); - ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); +// ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); ~ACA_Message_Pulsar_Consumer(); @@ -95,7 +94,7 @@ class ACA_Message_Pulsar_Consumer { bool unicastResubscribe(string topic, int stickyHash); - bool unicastResubscribe(bool isSubscribe, string topic="", string stickHash=""); + bool unicastResubscribe(bool isUnSubscribe, string topic="", string stickHash=""); }; } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index dc9626a6..240f1abb 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -32,9 +32,6 @@ namespace aca_message_pulsar { string aca_message_pulsar::ACA_Message_Pulsar_Consumer::empty_topic=""; -string aca_message_pulsar::ACA_Message_Pulsar_Consumer::recovered_topic= - ACA_Message_Pulsar_Consumer::getRecoveredTopicName(); - void listener(Consumer consumer, const Message& message){ alcor::schema::GoalStateV2 deserialized_GoalState; alcor::schema::GoalStateOperationReply gsOperationalReply; @@ -67,26 +64,6 @@ void listener(Consumer consumer, const Message& message){ ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer() { - string default_brokers = "pulsar://localhost:6650"; - string default_topic = "Host-ts-1"; - string default_subscription_name = "test_subscription"; - - setUnicastTopicName(default_topic); - recovered_topic=default_topic; - setMulticastTopicName(default_topic); - setBrokers(default_brokers); - setUnicastSubscriptionName(default_subscription_name); - setMulticastSubscriptionName(default_subscription_name); - - ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); - ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); - ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); - ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); - ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); - - // Create the clients - this->ptr_multicast_client= new Client(default_brokers); - this->ptr_unicast_client = new Client(default_brokers); } ACA_Message_Pulsar_Consumer &ACA_Message_Pulsar_Consumer::get_instance() @@ -96,7 +73,6 @@ ACA_Message_Pulsar_Consumer &ACA_Message_Pulsar_Consumer::get_instance() } void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subscription_name){ setUnicastTopicName(topic); - recovered_topic=topic; setMulticastTopicName(topic); setBrokers(brokers); setUnicastSubscriptionName(subscription_name); @@ -112,25 +88,25 @@ void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subs this->ptr_multicast_client= new Client(brokers); this->ptr_unicast_client = new Client(brokers); } -ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) -{ - setUnicastTopicName(topic); - recovered_topic=topic; - setMulticastTopicName(topic); - setBrokers(brokers); - setUnicastSubscriptionName(subscription_name); - setMulticastSubscriptionName(subscription_name); - - ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); - ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); - ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); - ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); - ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); - - // Create the clients - this->ptr_multicast_client= new Client(brokers); - this->ptr_unicast_client = new Client(brokers); -} +//ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) +//{ +// setUnicastTopicName(topic); +// recovered_topic=topic; +// setMulticastTopicName(topic); +// setBrokers(brokers); +// setUnicastSubscriptionName(subscription_name); +// setMulticastSubscriptionName(subscription_name); +// +// ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); +// ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); +// ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); +// ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); +// ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); +// +// // Create the clients +// this->ptr_multicast_client= new Client(brokers); +// this->ptr_unicast_client = new Client(brokers); +//} ACA_Message_Pulsar_Consumer::~ACA_Message_Pulsar_Consumer() { @@ -208,7 +184,7 @@ bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() { Result result; if(this->unicast_topic_name==empty_topic){ - ACA_LOG_INFO("The consumer already unsubscribe the unicast topic."); + ACA_LOG_INFO("The consumer already unsubscribe the unicast topic.\n"); return EXIT_SUCCESS; } @@ -229,7 +205,6 @@ bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHas if (result==EXIT_SUCCESS){ setUnicastTopicName(topic); - recovered_topic=topic; result = unicastConsumerDispatched(stickyHash); if (result==EXIT_SUCCESS) { return EXIT_SUCCESS; @@ -240,9 +215,9 @@ bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHas } -bool ACA_Message_Pulsar_Consumer::unicastResubscribe(bool isSubscribe, string topic, string stickHash) +bool ACA_Message_Pulsar_Consumer::unicastResubscribe(bool isUnSubscribe, string topic, string stickHash) { - if(!isSubscribe){ + if(isUnSubscribe){ return unicastUnsubcribe(); } else{ From 886059ecf079d863f42ac34781df1d6222083939 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 30 Dec 2021 11:15:55 +0800 Subject: [PATCH 27/37] add subscribe topic info test --- test/func_tests/gs_tests.cpp | 110 ++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/test/func_tests/gs_tests.cpp b/test/func_tests/gs_tests.cpp index 1b6a3bdf..8e2941ae 100644 --- a/test/func_tests/gs_tests.cpp +++ b/test/func_tests/gs_tests.cpp @@ -18,7 +18,9 @@ #include "aca_comm_mgr.h" #include "aca_grpc.h" #include "aca_grpc_client.h" +#include "aca_message_pulsar_producer.h" #include "goalstateprovisioner.grpc.pb.h" +#include "subscribeinfoprovisioner.grpc.pb.h" #include "goalstate.pb.h" #include "cppkafka/buffer.h" #include /* for getopt */ @@ -38,6 +40,7 @@ static char EMPTY_STRING[] = ""; static char LOCALHOST[] = "localhost"; static char GRPC_PORT[] = "50001"; +static char SUBSCRIBE_PORT[] = "50002"; using namespace std; using namespace alcor::schema; @@ -46,6 +49,7 @@ using aca_comm_manager::Aca_Comm_Manager; // Global variables string g_grpc_server_ip = EMPTY_STRING; string g_grpc_port = EMPTY_STRING; +string g_subscribe_port = EMPTY_STRING; string g_ofctl_command = EMPTY_STRING; string g_ofctl_target = EMPTY_STRING; string g_ofctl_options = EMPTY_STRING; @@ -79,6 +83,7 @@ std::atomic_ulong g_total_vpcs_table_mutex_time(0); std::atomic_ulong g_total_update_GS_time(0); // total time for ACA message in microseconds std::atomic_ulong g_total_ACA_Message_time(0); + bool g_demo_mode = false; bool g_debug_mode = false; @@ -88,6 +93,7 @@ static string subnet_id_1 = "27330ae4-b718-11ea-b3de-111111111111"; static string subnet1_gw_ip = "10.10.0.1"; static string subnet1_gw_mac = "fa:16:3e:d7:f2:11"; static string vmac_address_1 = "fa:16:3e:d7:f2:6c"; +static string broker_list= "pulsar://localhost:6650"; using grpc::Channel; using grpc::ClientAsyncResponseReader; @@ -446,6 +452,50 @@ class GoalStateProvisionerClient { std::unique_ptr stub_; }; +class SubscribeInfoProvisionerClient { +public: + explicit SubscribeInfoProvisionerClient(std::shared_ptr channel) + : stub_(SubscribeInfoProvisioner::NewStub(channel)) + { + } + + void push_info(NodeSubscribeInfo &subscribeInfo, SubscribeOperationReply &reply) + { + ClientContext context; + + auto before_sync_call = std::chrono::steady_clock::now(); + + Status status = stub_->PushNodeSubscribeInfo(&context, subscribeInfo, &reply); + + auto after_sync_call = std::chrono::steady_clock::now(); + + auto sync_call_time = + cast_to_microseconds(after_sync_call - before_sync_call).count(); + + ACA_LOG_INFO("[METRICS] PushNodeSubscribeInfo sync call took: %ld microseconds or %ld milliseconds\n", + sync_call_time, us_to_ms(sync_call_time)); + + if (!status.ok()) { + ACA_LOG_ERROR("%s", "Subscribe info update failed\n"); + } + } + + void update_subscribe_info(const SubscribeOperation &operation, const string &key, const string &topic){ + + SubscribeOperationReply reply; + + NodeSubscribeInfo info; + info.set_subscribe_operation(operation); + info.set_key(key); + info.set_topic(topic); + + push_info(info,reply); + } + +private: + std::unique_ptr stub_; +}; + // function to handle ctrl-c and kill process static void aca_signal_handler(int sig_num) { @@ -704,6 +754,56 @@ int run_as_client() return rc; } +int run_as_topic_client() { + int rc=1; + string hashValue="49775"; + string key="9192a4d4-ffff-4ece-b3f0-8d36e3d88001"; + string updateTopic="update topic"; + SubscribeOperation operation=alcor::schema::Subscribe; + + ACA_LOG_INFO("%s", "-------------- setup local subscribe info client --------------\n"); + ACA_LOG_INFO("operation is %s\n","Subscribe"); + ACA_LOG_INFO("subscribe key is %s\n",key.c_str()); + ACA_LOG_INFO("subscribe topic is %s\n",updateTopic.c_str()); + ACA_LOG_INFO("subscribe server is %s\n",string (g_grpc_server_ip + ":" + g_subscribe_port).c_str()); + + auto before_subscribe_client = std::chrono::steady_clock::now(); + + SubscribeInfoProvisionerClient subscribe_client(grpc::CreateChannel( + g_grpc_server_ip + ":" + g_subscribe_port, grpc::InsecureChannelCredentials())); + + auto after_subscribe_client = std::chrono::steady_clock::now(); + auto client_time = + cast_to_microseconds(after_subscribe_client-before_subscribe_client).count(); + ACA_LOG_INFO("[METRICS] create subscribe client took: %ld microseconds or %ld milliseconds\n", + client_time, us_to_ms(client_time)); + + ACA_LOG_INFO("%s", "-------------- sending one subscribe info --------------\n"); + + GoalStateOperationReply reply; + auto before_send_info = std::chrono::steady_clock::now(); + + subscribe_client.update_subscribe_info(operation, hashValue, updateTopic); + + auto after_send_info = std::chrono::steady_clock::now(); + auto send_info_time = + cast_to_microseconds(after_send_info-before_send_info).count(); + ACA_LOG_INFO("[METRICS] send_info call took: %ld microseconds or %ld milliseconds\n", + send_info_time, us_to_ms(send_info_time)); + + ACA_LOG_INFO("%s", "-------------- sending one empty goalstate message --------------\n"); + GoalStateV2 emptyGoalState; + string GoalStateString; + + if(emptyGoalState.SerializeToString(&GoalStateString)){ + ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); + } + + aca_message_pulsar::ACA_Message_Pulsar_Producer producer(broker_list, updateTopic); + rc = producer.publish(GoalStateString,key); + return rc; +} + int main(int argc, char *argv[]) { int option; @@ -749,11 +849,15 @@ int main(int argc, char *argv[]) if (g_grpc_port == EMPTY_STRING) { g_grpc_port = GRPC_PORT; } + if(g_subscribe_port == EMPTY_STRING){ + g_subscribe_port = SUBSCRIBE_PORT; + } if (g_run_as_server) { rc = RunServer(); } else { - rc = run_as_client(); +// rc = run_as_client(); + rc = run_as_topic_client(); } // Verify that the version of the library that we linked against is // compatible with the version of the headers we compiled against. @@ -762,4 +866,6 @@ int main(int argc, char *argv[]) aca_cleanup(); return rc; -} \ No newline at end of file +} + + From fb76dda4d7ea775537e39618bb5cae0273af9329 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 30 Dec 2021 11:18:07 +0800 Subject: [PATCH 28/37] use get_instance function to init pulsar consumer --- src/aca_main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/aca_main.cpp b/src/aca_main.cpp index 3a7bf953..d0e12f69 100644 --- a/src/aca_main.cpp +++ b/src/aca_main.cpp @@ -46,7 +46,7 @@ using std::string; static char EMPTY_STRING[] = ""; static char BROKER_LIST[] = "pulsar://localhost:6650"; static char PULSAR_TOPIC[] = "Host-ts-1"; -static char PULSAR_SUBSCRIPTION_NAME[] = "Test-Subscription"; +static char PULSAR_SUBSCRIPTION_NAME[] = "test-subscription"; static char GRPC_SERVER_PORT[] = "50001"; static char GRPC_SUBSCRIBE_SERVER_PORT[] = "50002"; static char OFCTL_COMMAND[] = "monitor"; @@ -64,7 +64,7 @@ GoalStateProvisionerClientImpl *g_grpc_client = NULL; string g_broker_list = EMPTY_STRING; string g_pulsar_topic = EMPTY_STRING; string g_pulsar_subsription_name = EMPTY_STRING; -string g_pulsar_hashed_key = "0"; +string g_pulsar_hashed_key = "49775"; string g_grpc_server_port = EMPTY_STRING; string g_grpc_subscribe_server_port = EMPTY_STRING; string g_ofctl_command = EMPTY_STRING; @@ -325,9 +325,8 @@ int main(int argc, char *argv[]) //// monitor br-tun for arp request message //ACA_OVS_Control::get_instance().monitor("br-tun", "resume"); - ACA_Message_Pulsar_Consumer network_config_consumer(g_pulsar_topic, g_broker_list, g_pulsar_subsription_name); - //network_config_consumer.multicastConsumerDispatched(); - network_config_consumer.unicastConsumerDispatched(atoi(g_pulsar_hashed_key.c_str())); + ACA_Message_Pulsar_Consumer::get_instance().init(g_pulsar_topic, g_broker_list, g_pulsar_subsription_name); + ACA_Message_Pulsar_Consumer::get_instance().unicastConsumerDispatched(atoi(g_pulsar_hashed_key.c_str())); pause(); aca_cleanup(); From 2921c0db604ae23ad4d5c65b3c76d307b6038b6d Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 30 Dec 2021 11:31:39 +0800 Subject: [PATCH 29/37] remove multicast test and recovered test --- test/gtest/aca_test_mq.cpp | 47 ++++---------------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index 52fd459d..c279d751 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -90,25 +90,9 @@ static int mq_hash=49775; // 21485 49775 // This case tests the pulsar consumer implementation. // First run this case by executing: -// ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_consumer_test +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_test // Then run the following producer test cases. -TEST(pulsar_test_cases, DISABLED_pulsar_consumer_test) -{ - bool previous_demo_mode = g_demo_mode; - g_demo_mode = true; - - aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer=ACA_Message_Pulsar_Consumer::get_instance(); - consumer.init(mq_test_topic, mq_broker_ip, mq_subscription); -// ACA_Message_Pulsar_Consumer consumer(mq_test_topic, mq_broker_ip, mq_subscription); - consumer.multicastConsumerDispatched(); - pause(); - - g_demo_mode = previous_demo_mode; -} - -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_test TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) { string cmd_string; @@ -127,31 +111,6 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) g_demo_mode = previous_demo_mode; } -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_recover_test -TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_recover_test) -{ - string cmd_string; - string mq_update_topic="update topic"; - bool previous_demo_mode = g_demo_mode; - g_demo_mode = true; - - aca_test_reset_environment(); - - auto* pt= - new ACA_Message_Pulsar_Consumer(mq_test_topic,mq_broker_ip,mq_subscription); - pt->unicastConsumerDispatched(mq_hash); - pt->unicastResubscribe(mq_update_topic,mq_hash); - delete pt; - - pt= - new ACA_Message_Pulsar_Consumer(ACA_Message_Pulsar_Consumer::recovered_topic,mq_broker_ip,mq_subscription); - pt->unicastConsumerDispatched(mq_hash); - - pause(); - - g_demo_mode = previous_demo_mode; -} - // sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) { @@ -162,7 +121,9 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer(mq_update_topic, mq_broker_ip, mq_subscription); + ACA_Message_Pulsar_Consumer consumer= + ACA_Message_Pulsar_Consumer::get_instance(); + consumer.init(mq_update_topic, mq_broker_ip, mq_subscription); consumer.unicastConsumerDispatched(mq_hash); consumer.unicastResubscribe(true); consumer.unicastResubscribe(false,mq_test_topic, to_string(mq_hash)); From 014c8029ef1dc99579f14173b5691b4a0b7d3c5d Mon Sep 17 00:00:00 2001 From: lly00 Date: Thu, 30 Dec 2021 15:53:46 +0800 Subject: [PATCH 30/37] merge for subscribe info test --- include/aca_message_pulsar_consumer.h | 2 -- src/comm/aca_message_pulsar_consumer.cpp | 20 +------------------- test/func_tests/gs_tests.cpp | 12 +++++------- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 18abc804..97fe3ca4 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -68,8 +68,6 @@ class ACA_Message_Pulsar_Consumer { ACA_Message_Pulsar_Consumer(); -// ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name); - ~ACA_Message_Pulsar_Consumer(); void init(string topic, string brokers, string subscription_name); diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 240f1abb..8d6c3e3f 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -88,25 +88,6 @@ void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subs this->ptr_multicast_client= new Client(brokers); this->ptr_unicast_client = new Client(brokers); } -//ACA_Message_Pulsar_Consumer::ACA_Message_Pulsar_Consumer(string topic, string brokers, string subscription_name) -//{ -// setUnicastTopicName(topic); -// recovered_topic=topic; -// setMulticastTopicName(topic); -// setBrokers(brokers); -// setUnicastSubscriptionName(subscription_name); -// setMulticastSubscriptionName(subscription_name); -// -// ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); -// ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); -// ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); -// ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); -// ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); -// -// // Create the clients -// this->ptr_multicast_client= new Client(brokers); -// this->ptr_unicast_client = new Client(brokers); -//} ACA_Message_Pulsar_Consumer::~ACA_Message_Pulsar_Consumer() { @@ -139,6 +120,7 @@ string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const return this->unicast_subscription_name; } +//TODO: get recovered topic from database? string ACA_Message_Pulsar_Consumer::getRecoveredTopicName() { return "recovered topic test"; diff --git a/test/func_tests/gs_tests.cpp b/test/func_tests/gs_tests.cpp index 8e2941ae..8bf71378 100644 --- a/test/func_tests/gs_tests.cpp +++ b/test/func_tests/gs_tests.cpp @@ -480,16 +480,14 @@ class SubscribeInfoProvisionerClient { } } - void update_subscribe_info(const SubscribeOperation &operation, const string &key, const string &topic){ - - SubscribeOperationReply reply; - + void update_subscribe_info(const SubscribeOperation operation, const string key, const string topic, SubscribeOperationReply &reply) + { NodeSubscribeInfo info; info.set_subscribe_operation(operation); info.set_key(key); info.set_topic(topic); - push_info(info,reply); + push_info(info, reply); } private: @@ -780,10 +778,10 @@ int run_as_topic_client() { ACA_LOG_INFO("%s", "-------------- sending one subscribe info --------------\n"); - GoalStateOperationReply reply; + SubscribeOperationReply reply; auto before_send_info = std::chrono::steady_clock::now(); - subscribe_client.update_subscribe_info(operation, hashValue, updateTopic); + subscribe_client.update_subscribe_info(operation, hashValue, updateTopic, reply); auto after_send_info = std::chrono::steady_clock::now(); auto send_info_time = From 31019affe20d2ef4f986653b54f28282eeda8127 Mon Sep 17 00:00:00 2001 From: lly00 Date: Thu, 30 Dec 2021 19:46:03 +0800 Subject: [PATCH 31/37] fix an error in cmakelists --- src/grpc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grpc/CMakeLists.txt b/src/grpc/CMakeLists.txt index 928740b3..6334d721 100644 --- a/src/grpc/CMakeLists.txt +++ b/src/grpc/CMakeLists.txt @@ -30,7 +30,7 @@ set(aca_proto_sub_hdrs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.pb. set(aca_grpc_sub_srcs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.grpc.pb.cc") set(aca_grpc_sub_hdrs "${CMAKE_CURRENT_BINARY_DIR}/subscribeinfoprovisioner.grpc.pb.h") add_custom_command( - OUTPUT "${aca_proto_srcs}" "${aca_proto_hdrs}" "${aca_grpc_srcs}" "${aca_grpc_hdrs}" "${aca_proto_sub_srcs}" "${aca_proto__sub_hdrs}" "${aca_grpc_sub_srcs}" "${aca_grpc_sub_hdrs}" + OUTPUT "${aca_proto_srcs}" "${aca_proto_hdrs}" "${aca_grpc_srcs}" "${aca_grpc_hdrs}" "${aca_proto_sub_srcs}" "${aca_proto_sub_hdrs}" "${aca_grpc_sub_srcs}" "${aca_grpc_sub_hdrs}" COMMAND ${_PROTOBUF_PROTOC} ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" From 4228bee2484ce647bc7576a8c16786da39e32e0a Mon Sep 17 00:00:00 2001 From: lly00 Date: Thu, 6 Jan 2022 09:31:47 +0800 Subject: [PATCH 32/37] change topic name type string to vector --- include/aca_message_pulsar_consumer.h | 5 ++--- src/comm/aca_message_pulsar_consumer.cpp | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 97fe3ca4..85429be5 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -26,6 +26,7 @@ using namespace pulsar; using std::string; +using std::vector; namespace aca_message_pulsar { @@ -37,7 +38,7 @@ class ACA_Message_Pulsar_Consumer { string unicast_subscription_name; // Subscription name of the unicast pulsar consumer string multicast_topic_name; //A string representation of the topic to be consumed, for example: /hostid/00000000-0000-0000-0000-000000000000/netwconf/ - string unicast_topic_name; + vector unicast_topic_name = vector(); ConsumerConfiguration multicast_consumer_config; //Configuration of the mulitcast pulsar consumer ConsumerConfiguration unicast_consumer_config; //Configuration of the unicast pulsar consumer @@ -48,8 +49,6 @@ class ACA_Message_Pulsar_Consumer { Consumer multicast_consumer; Consumer unicast_consumer; - static string empty_topic; - private: void setMulticastSubscriptionName(string subscription_name); diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 8d6c3e3f..b0dff641 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -30,8 +30,6 @@ using pulsar::StickyRange; namespace aca_message_pulsar { -string aca_message_pulsar::ACA_Message_Pulsar_Consumer::empty_topic=""; - void listener(Consumer consumer, const Message& message){ alcor::schema::GoalStateV2 deserialized_GoalState; alcor::schema::GoalStateOperationReply gsOperationalReply; @@ -79,7 +77,7 @@ void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subs setMulticastSubscriptionName(subscription_name); ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); - ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", this->unicast_topic_name.c_str()); + ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", topic); ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); @@ -112,7 +110,10 @@ string ACA_Message_Pulsar_Consumer::getMulticastSubscriptionName() const string ACA_Message_Pulsar_Consumer::getUnicastTopicName() const { - return this->unicast_topic_name; + string topic = ""; + for (auto t: this->unicast_topic_name) + topic += t; + return topic; } string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const @@ -139,10 +140,10 @@ bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ //Use key shared mode this->unicast_consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(keySharedPolicy).setMessageListener(listener); - ACA_LOG_INFO("%s\n",this->unicast_topic_name.c_str()); + //ACA_LOG_INFO("%s\n",this->unicast_topic_name.c_str()); result = this->ptr_unicast_client->subscribe(this->unicast_topic_name,this->unicast_subscription_name,this->unicast_consumer_config,this->unicast_consumer); if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to subscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); + ACA_LOG_ERROR("Failed to subscribe unicast topic: %s\n", this->getUnicastTopicName().c_str()); return EXIT_FAILURE; } @@ -165,17 +166,17 @@ bool ACA_Message_Pulsar_Consumer::multicastConsumerDispatched(){ bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() { Result result; - if(this->unicast_topic_name==empty_topic){ + if(this->unicast_topic_name.empty()){ ACA_LOG_INFO("The consumer already unsubscribe the unicast topic.\n"); return EXIT_SUCCESS; } result=this->unicast_consumer.unsubscribe(); if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->unicast_topic_name.c_str()); + ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->getUnicastTopicName().c_str()); return EXIT_FAILURE; } - this->unicast_topic_name=empty_topic; + this->unicast_topic_name.clear(); return EXIT_SUCCESS; } @@ -224,7 +225,7 @@ void ACA_Message_Pulsar_Consumer::setMulticastSubscriptionName(string subscripti void ACA_Message_Pulsar_Consumer::setUnicastTopicName(string topic) { - this->unicast_topic_name = topic; + this->unicast_topic_name.push_back(topic); } void ACA_Message_Pulsar_Consumer::setUnicastSubscriptionName(string subscription_name) From 76e014b617525a6434b0cde7c522df6400002f1f Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 7 Jan 2022 15:53:27 +0800 Subject: [PATCH 33/37] add an option to launch topic client --- test/func_tests/gs_tests.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/func_tests/gs_tests.cpp b/test/func_tests/gs_tests.cpp index 8bf71378..3a883cf5 100644 --- a/test/func_tests/gs_tests.cpp +++ b/test/func_tests/gs_tests.cpp @@ -58,6 +58,8 @@ string g_ncm_port = EMPTY_STRING; string g_grpc_server_port = EMPTY_STRING; // by default, this should run as GRCP client, unless specified by the corresponding flag. bool g_run_as_server = false; +bool g_run_as_topic_client = false; + GoalStateProvisionerAsyncServer *g_grpc_server = NULL; GoalStateProvisionerClientImpl *g_grpc_client = NULL; // GoalStateProvisionerServer *g_test_grcp_server = NULL; @@ -812,7 +814,7 @@ int main(int argc, char *argv[]) signal(SIGINT, aca_signal_handler); signal(SIGTERM, aca_signal_handler); - while ((option = getopt(argc, argv, "s:p:dm")) != -1) { + while ((option = getopt(argc, argv, "s:p:dmt")) != -1) { switch (option) { case 's': g_grpc_server_ip = optarg; @@ -826,6 +828,9 @@ int main(int argc, char *argv[]) case 'm': g_run_as_server = true; break; + case 't': + g_run_as_topic_client = true; + break; default: /* the '?' case when the option is not recognized */ /* specifying port not avaiable for now */ fprintf(stderr, @@ -833,7 +838,8 @@ int main(int argc, char *argv[]) "\t\t[-s grpc server]\n" "\t\t[-p grpc port]\n" "\t\t[-d enable debug mode]\n" - "\t\t[-m If this flag is passed in, gs test runs as grpc server, which listens on localhost:54321; otherwise it runs as a grpc client]\n", + "\t\t[-m If this flag is passed in, gs test runs as grpc server, which listens on localhost:54321;]\n", + "\t\t[-t If this flag is passed in, gs test runs as grpc topic client, which publishes topic subscribe requests to localhost:50002; otherwise it runs as a grpc client]\n", argv[0]); exit(EXIT_FAILURE); } @@ -853,9 +859,12 @@ int main(int argc, char *argv[]) if (g_run_as_server) { rc = RunServer(); - } else { -// rc = run_as_client(); - rc = run_as_topic_client(); + } + else if (g_run_as_topic_client){ + rc = run_as_topic_client(); + } + else { + rc = run_as_client(); } // Verify that the version of the library that we linked against is // compatible with the version of the headers we compiled against. From 652ddef70f63b1ff03df1c68ebc0ae6200a628a1 Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 7 Jan 2022 15:58:01 +0800 Subject: [PATCH 34/37] remove static topic string --- src/comm/aca_message_pulsar_consumer.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index b0dff641..828c1df2 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -77,7 +77,7 @@ void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subs setMulticastSubscriptionName(subscription_name); ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); - ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", topic); + ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", topic.c_str()); ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); @@ -121,12 +121,6 @@ string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const return this->unicast_subscription_name; } -//TODO: get recovered topic from database? -string ACA_Message_Pulsar_Consumer::getRecoveredTopicName() -{ - return "recovered topic test"; -} - bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ Result result; Consumer consumer; From 34062d8b544ffd8f06dc1f937518770acd313357 Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 7 Jan 2022 16:49:35 +0800 Subject: [PATCH 35/37] add pulsar consumer multi-subscribe test --- src/comm/aca_message_pulsar_consumer.cpp | 16 ++- test/gtest/aca_test_mq.cpp | 138 +++++++++++++++++------ 2 files changed, 113 insertions(+), 41 deletions(-) diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 828c1df2..cce8b934 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -36,7 +36,7 @@ void listener(Consumer consumer, const Message& message){ int rc; Result result; - ACA_LOG_DEBUG("\n<=====incoming message: %s\n", + ACA_LOG_DEBUG("\n<=====incoming message: %s =====>\n", message.getDataAsString().c_str()); rc = Aca_Comm_Manager::get_instance().deserialize( @@ -112,7 +112,7 @@ string ACA_Message_Pulsar_Consumer::getUnicastTopicName() const { string topic = ""; for (auto t: this->unicast_topic_name) - topic += t; + topic += (t+" "); return topic; } @@ -178,14 +178,12 @@ bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHas { bool result; - result = unicastUnsubcribe(); - if (result==EXIT_SUCCESS){ - setUnicastTopicName(topic); - result = unicastConsumerDispatched(stickyHash); - if (result==EXIT_SUCCESS) { - return EXIT_SUCCESS; - } + setUnicastTopicName(topic); + this->unicast_consumer.unsubscribe(); // unsubscribe the pulsar topics to avoid warning. + result = unicastConsumerDispatched(stickyHash); + if (result==EXIT_SUCCESS) { + return EXIT_SUCCESS; } ACA_LOG_ERROR("Failed to resubscribe unicast topic: %s\n", topic.c_str()); return EXIT_FAILURE; diff --git a/test/gtest/aca_test_mq.cpp b/test/gtest/aca_test_mq.cpp index c279d751..c2ce57a2 100644 --- a/test/gtest/aca_test_mq.cpp +++ b/test/gtest/aca_test_mq.cpp @@ -77,21 +77,26 @@ static string mq_test_topic = "Host-ts-1"; static string mq_subscription = "test_subscription"; static string mq_key="9192a4d4-ffff-4ece-b3f0-8d36e3d88001"; // 3dda2801-d675-4688-a63f-dcda8d327f50 9192a4d4-ffff-4ece-b3f0-8d36e3d88001 static int mq_hash=49775; // 21485 49775 +static string mq_update_topics[6] = + {"update-topic","update-topic2","update-topic3","update-topic4","update-topic5","update-topic6"}; // // Test suite: pulsar_test_cases -// +// This test suite contains three tests: +// 1. basic pulsar consumer and producer test. +// 2. pulsar consumer multi-subscribe test. +// 3. pulsar consumer resubscribe test. // Note: it requires a pulsar setup on localhost therefore this test is DISABLED by default. // You will need three terminals: // Terminal(1): run pulsar standalone. // Terminal(2): run pulsar consumer test case. -// Terminal(3): run pulsar producer test cases. +// Terminal(3): run pulsar producer test case. -// This case tests the pulsar consumer implementation. -// First run this case by executing: -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_test -// Then run the following producer test cases. +// 1. Basic pulsar consumer and producer test. +// Ensure you launched the pulsar then executing: +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_test +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_test TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) { @@ -103,19 +108,65 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_test) aca_test_reset_environment(); - ACA_Message_Pulsar_Consumer consumer = ACA_Message_Pulsar_Consumer::get_instance(); - consumer.init(mq_test_topic, mq_broker_ip, mq_subscription); - consumer.unicastConsumerDispatched(mq_hash); + ACA_Message_Pulsar_Consumer::get_instance().init(mq_test_topic, mq_broker_ip, mq_subscription); + ACA_Message_Pulsar_Consumer::get_instance().unicastConsumerDispatched(mq_hash); pause(); g_demo_mode = previous_demo_mode; } -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test -TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) +TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) { + int retcode = 0; + int overall_rc=0; + int length=1000; + ulong not_care_culminative_time; string cmd_string; - string mq_update_topic="update topic"; + string GoalStateString; + unsigned char serializedGoalState[length]; + + GoalStateV2 GoalState_builder; + PortState new_port_states; + SubnetState new_subnet_states; + + aca_test_reset_environment(); + + aca_test_create_default_port_state(&new_port_states); + auto &port_states_map = *GoalState_builder.mutable_port_states(); + port_states_map[port_id_1] = new_port_states; + + aca_test_create_default_subnet_state(&new_subnet_states); + auto &subnet_states_map = *GoalState_builder.mutable_subnet_states(); + subnet_states_map[subnet_id_1] = new_subnet_states; + + + if(GoalState_builder.SerializeToString(&GoalStateString)){ + ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); + } + + ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); + retcode = producer.publish(GoalStateString,mq_key); + EXPECT_EQ(retcode, EXIT_SUCCESS); + + ACA_LOG_INFO("%s","Waiting for GoalStateV2 update.\n"); + sleep(1); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; + +} + +// 2. Pulsar consumer multi-subscribe test. +// Ensure you launched the pulsar then executing: +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_multisubscribe_test +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_multisubscribe_test + +TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_multisubscribe_test) +{ + string cmd_string; + bool previous_demo_mode = g_demo_mode; g_demo_mode = true; @@ -123,19 +174,18 @@ TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) ACA_Message_Pulsar_Consumer consumer= ACA_Message_Pulsar_Consumer::get_instance(); - consumer.init(mq_update_topic, mq_broker_ip, mq_subscription); + consumer.init(mq_test_topic, mq_broker_ip, mq_subscription); consumer.unicastConsumerDispatched(mq_hash); - consumer.unicastResubscribe(true); - consumer.unicastResubscribe(false,mq_test_topic, to_string(mq_hash)); + for(int i = 0; i < size(mq_update_topics); i++){ + consumer.unicastResubscribe(false, mq_update_topics[i], to_string(mq_hash)); + } + ACA_LOG_INFO("Current subscribe topics are: %s\n",consumer.getUnicastTopicName().c_str()); pause(); g_demo_mode = previous_demo_mode; } -// This case tests the pulsar producer implementation and publishes a GoalState to the subscribed topic. -// First run pulsar_consumer_test then execute -// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_producer_test -TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) +TEST(pulsar_test_cases, DISABLED_pulsar_producer_multisubscribe_test) { int retcode = 0; int overall_rc=0; @@ -149,8 +199,6 @@ TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) PortState new_port_states; SubnetState new_subnet_states; - aca_test_reset_environment(); - aca_test_create_default_port_state(&new_port_states); auto &port_states_map = *GoalState_builder.mutable_port_states(); port_states_map[port_id_1] = new_port_states; @@ -159,21 +207,47 @@ TEST(pulsar_test_cases, DISABLED_pulsar_producer_test) auto &subnet_states_map = *GoalState_builder.mutable_subnet_states(); subnet_states_map[subnet_id_1] = new_subnet_states; + for(int i=0; i< size(mq_update_topics); i++){ + aca_test_reset_environment(); - if(GoalState_builder.SerializeToString(&GoalStateString)){ - ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); + if(GoalState_builder.SerializeToString(&GoalStateString)){ + ACA_LOG_INFO("%s","Successfully covert GoalStateV2 to message\n"); + } + + ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_update_topics[i]); + retcode = producer.publish(GoalStateString,mq_key); + EXPECT_EQ(retcode, EXIT_SUCCESS); + + ACA_LOG_INFO("%s","Waiting for GoalStateV2 update.\n"); + sleep(1); + + ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( + "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); + EXPECT_EQ(overall_rc, EXIT_SUCCESS); + overall_rc = EXIT_SUCCESS; } +} - ACA_Message_Pulsar_Producer producer(mq_broker_ip, mq_test_topic); - retcode = producer.publish(GoalStateString,mq_key); - EXPECT_EQ(retcode, EXIT_SUCCESS); +// 3. Pulsar consumer resubscribe test. +// Ensure you launched the pulsar then executing: +// sudo ./aca_tests --gtest_also_run_disabled_tests --gtest_filter=*DISABLED_pulsar_unicast_consumer_resubscribe_test - ACA_LOG_INFO("%s","Waiting for GoalStateV2 update.\n"); - sleep(1); +TEST(pulsar_test_cases, DISABLED_pulsar_unicast_consumer_resubscribe_test) +{ + string cmd_string; + string mq_update_topic="update topic"; + bool previous_demo_mode = g_demo_mode; + g_demo_mode = true; - ACA_OVS_L2_Programmer::get_instance().execute_ovsdb_command( - "get Interface " + port_name_1 + " ofport", not_care_culminative_time, overall_rc); - EXPECT_EQ(overall_rc, EXIT_SUCCESS); - overall_rc = EXIT_SUCCESS; + aca_test_reset_environment(); + ACA_Message_Pulsar_Consumer consumer= + ACA_Message_Pulsar_Consumer::get_instance(); + consumer.init(mq_update_topic, mq_broker_ip, mq_subscription); + consumer.unicastConsumerDispatched(mq_hash); + consumer.unicastResubscribe(true); + consumer.unicastResubscribe(false,mq_test_topic, to_string(mq_hash)); + pause(); + + g_demo_mode = previous_demo_mode; } \ No newline at end of file From 80eac63b46ab4822aeb86e8406e9074c9f7ab3e4 Mon Sep 17 00:00:00 2001 From: Joey Date: Mon, 7 Mar 2022 21:53:17 +0800 Subject: [PATCH 36/37] add specific logs to mq --- include/aca_message_pulsar_consumer.h | 6 +- src/comm/aca_message_pulsar_consumer.cpp | 82 ++++++++++-------------- src/comm/aca_message_pulsar_producer.cpp | 56 ++++++++-------- 3 files changed, 63 insertions(+), 81 deletions(-) diff --git a/include/aca_message_pulsar_consumer.h b/include/aca_message_pulsar_consumer.h index 85429be5..04db7881 100644 --- a/include/aca_message_pulsar_consumer.h +++ b/include/aca_message_pulsar_consumer.h @@ -87,11 +87,9 @@ class ACA_Message_Pulsar_Consumer { bool unicastConsumerDispatched(int stickyHash); - bool unicastUnsubcribe(); + bool unicastUnsubscribeAll(); - bool unicastResubscribe(string topic, int stickyHash); - - bool unicastResubscribe(bool isUnSubscribe, string topic="", string stickHash=""); + bool unicastResubscribe(bool unSubscribe, string topic="", string stickHash=""); }; } // namespace aca_message_pulsar diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index cce8b934..1344a729 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -36,24 +36,26 @@ void listener(Consumer consumer, const Message& message){ int rc; Result result; - ACA_LOG_DEBUG("\n<=====incoming message: %s =====>\n", - message.getDataAsString().c_str()); - + ACA_LOG_DEBUG("%s","ACA_PULSAR_MQ: Successfully received the incoming message.\n"); + ACA_LOG_DEBUG("%s","ACA_PULSAR_MQ: Start deserializing the message to GoalState...\n"); + ACA_LOG_DEBUG("%s","<====================================================>\n"); rc = Aca_Comm_Manager::get_instance().deserialize( (unsigned char *)message.getData(), message.getLength(), deserialized_GoalState); + ACA_LOG_DEBUG("%s","<====================================================>\n"); if (rc == EXIT_SUCCESS) { + ACA_LOG_DEBUG("%s","ACA_PULSAR_MQ: Start updating GoalState...\n"); + ACA_LOG_DEBUG("%s","<====================================================>\n"); rc = Aca_Comm_Manager::get_instance().update_goal_state( deserialized_GoalState, gsOperationalReply); - - + ACA_LOG_DEBUG("%s","<====================================================>\n"); if (rc != EXIT_SUCCESS) { - ACA_LOG_ERROR("Failed to update host with latest goal state, rc=%d.\n", rc); + ACA_LOG_ERROR("ACA_PULSAR_MQ: ERROR, failed to update host with latest goal state, rc=%d.\n", rc); } else { - ACA_LOG_INFO("Successfully updated host with latest goal state %d.\n", rc); + ACA_LOG_INFO("ACA_PULSAR_MQ: Successfully updated host with latest goal state, rc=%d.\n", rc); } } else { - ACA_LOG_ERROR("Deserialization failed with error code %d.\n", rc); + ACA_LOG_ERROR("ACA_PULSAR_MQ: ERROR, failed to deserialize the message with error code %d.\n", rc); } // Now acknowledge message @@ -76,11 +78,11 @@ void ACA_Message_Pulsar_Consumer::init(string topic, string brokers, string subs setUnicastSubscriptionName(subscription_name); setMulticastSubscriptionName(subscription_name); - ACA_LOG_DEBUG("Broker list: %s\n", this->brokers_list.c_str()); - ACA_LOG_DEBUG("Unicast consumer topic name: %s\n", topic.c_str()); - ACA_LOG_DEBUG("Unicast consumer subscription name: %s\n", this->unicast_subscription_name.c_str()); - ACA_LOG_DEBUG("Multicast consumer topic name: %s\n", this->multicast_topic_name.c_str()); - ACA_LOG_DEBUG("Multicast consumer subscription name: %s\n", this->multicast_subscription_name.c_str()); + ACA_LOG_DEBUG("ACA_PULSAR_MQ: Broker list -> %s\n", this->brokers_list.c_str()); + ACA_LOG_DEBUG("ACA_PULSAR_MQ: Unicast consumer topic name -> %s\n", this->unicast_topic_name[0].c_str()); + ACA_LOG_DEBUG("ACA_PULSAR_MQ: Unicast consumer subscription name -> %s\n", this->unicast_subscription_name.c_str()); + ACA_LOG_DEBUG("ACA_PULSAR_MQ: Multicast consumer topic name -> %s\n", this->multicast_topic_name.c_str()); + ACA_LOG_DEBUG("ACA_PULSAR_MQ: Multicast consumer subscription name -> %s\n", this->multicast_subscription_name.c_str()); // Create the clients this->ptr_multicast_client= new Client(brokers); @@ -122,8 +124,6 @@ string ACA_Message_Pulsar_Consumer::getUnicastSubscriptionName() const } bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ - Result result; - Consumer consumer; KeySharedPolicy keySharedPolicy; keySharedPolicy.setKeySharedMode(STICKY); @@ -134,10 +134,9 @@ bool ACA_Message_Pulsar_Consumer::unicastConsumerDispatched(int stickyHash){ //Use key shared mode this->unicast_consumer_config.setConsumerType(ConsumerKeyShared).setKeySharedPolicy(keySharedPolicy).setMessageListener(listener); - //ACA_LOG_INFO("%s\n",this->unicast_topic_name.c_str()); - result = this->ptr_unicast_client->subscribe(this->unicast_topic_name,this->unicast_subscription_name,this->unicast_consumer_config,this->unicast_consumer); + Result result = this->ptr_unicast_client->subscribe(this->unicast_topic_name,this->unicast_subscription_name,this->unicast_consumer_config,this->unicast_consumer); if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to subscribe unicast topic: %s\n", this->getUnicastTopicName().c_str()); + ACA_LOG_ERROR("ACA_PULSAR_MQ: ERROR, failed to subscribe unicast topic -> %s\n", this->getUnicastTopicName().c_str()); return EXIT_FAILURE; } @@ -151,52 +150,41 @@ bool ACA_Message_Pulsar_Consumer::multicastConsumerDispatched(){ this->multicast_consumer_config.setMessageListener(listener); result = this->ptr_multicast_client->subscribe(this->multicast_topic_name,this->multicast_subscription_name,this->multicast_consumer_config,this->multicast_consumer); if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to subscribe multicast topic: %s\n", this->multicast_topic_name.c_str()); + ACA_LOG_ERROR("ACA_PULSAR_MQ: ERROR, failed to subscribe multicast topic -> %s\n", this->multicast_topic_name.c_str()); return EXIT_FAILURE; } return EXIT_SUCCESS; } -bool ACA_Message_Pulsar_Consumer::unicastUnsubcribe() +bool ACA_Message_Pulsar_Consumer::unicastUnsubscribeAll() { - Result result; if(this->unicast_topic_name.empty()){ - ACA_LOG_INFO("The consumer already unsubscribe the unicast topic.\n"); + ACA_LOG_INFO("ACA_PULSAR_MQ: Successfully to unsubscribe all the unicast topics.\n"); return EXIT_SUCCESS; } - result=this->unicast_consumer.unsubscribe(); - if (result != Result::ResultOk){ - ACA_LOG_ERROR("Failed to unsubscribe unicast topic: %s\n", this->getUnicastTopicName().c_str()); - return EXIT_FAILURE; - } - this->unicast_topic_name.clear(); - return EXIT_SUCCESS; -} - -bool ACA_Message_Pulsar_Consumer::unicastResubscribe(string topic, int stickyHash) -{ - bool result; - - - setUnicastTopicName(topic); - this->unicast_consumer.unsubscribe(); // unsubscribe the pulsar topics to avoid warning. - result = unicastConsumerDispatched(stickyHash); - if (result==EXIT_SUCCESS) { + if (this->unicast_consumer.unsubscribe() == Result::ResultOk){ + ACA_LOG_INFO("ACA_PULSAR_MQ: Successfully to unsubscribe all the unicast topics.\n"); + this->unicast_topic_name.clear(); return EXIT_SUCCESS; } - ACA_LOG_ERROR("Failed to resubscribe unicast topic: %s\n", topic.c_str()); - return EXIT_FAILURE; + else{ + ACA_LOG_ERROR("ACA_PULSAR_MQ: ERROR, failed to unsubscribe unicast topics -> %s.\n", this->getUnicastTopicName().c_str()); + return EXIT_FAILURE; + } } - -bool ACA_Message_Pulsar_Consumer::unicastResubscribe(bool isUnSubscribe, string topic, string stickHash) +bool ACA_Message_Pulsar_Consumer::unicastResubscribe(bool unSubscribe, string topic, string stickHash) { - if(isUnSubscribe){ - return unicastUnsubcribe(); + if(!unSubscribe){ + if(this->unicast_consumer.unsubscribe() == Result::ResultOk){ // this unsubscribes topics in pulsar, but doesn't clean the topic list of Consumer. + setUnicastTopicName(topic); + return unicastConsumerDispatched(stoi(stickHash)); + } + return EXIT_FAILURE; } else{ - return unicastResubscribe(topic, std::stoi(stickHash)); + return unicastUnsubscribeAll(); } } diff --git a/src/comm/aca_message_pulsar_producer.cpp b/src/comm/aca_message_pulsar_producer.cpp index 115e50d0..39303d82 100644 --- a/src/comm/aca_message_pulsar_producer.cpp +++ b/src/comm/aca_message_pulsar_producer.cpp @@ -55,60 +55,56 @@ void ACA_Message_Pulsar_Producer::setTopicName(string topic) bool ACA_Message_Pulsar_Producer::publish(string message) { - Result result; - // Create a producer Producer producer; - result = this->ptr_client->createProducer(this->topic_name,producer); - if(result != ResultOk){ - ACA_LOG_ERROR("Failed to create producer, result=%d.\n", result); + Result createProducerResult = this->ptr_client->createProducer(this->topic_name,producer); + if(createProducerResult != ResultOk){ + ACA_LOG_ERROR("ACA_PULSAR_MQ: Failed to create producer, result=%d.\n", createProducerResult); return EXIT_FAILURE; } // Create a message Message msg = MessageBuilder().setContent(message).build(); - result = producer.send(msg); - if(result != ResultOk){ - ACA_LOG_ERROR("Failed to send message %s.\n", message.c_str()); + + if(producer.send(msg) != ResultOk){ + ACA_LOG_ERROR("ACA_PULSAR_MQ: Failed to send message -> %s.\n", message.c_str()); return EXIT_FAILURE; } + else{ + ACA_LOG_INFO("ACA_PULSAR_MQ: Successfully send message %s.\n", message.c_str()); - ACA_LOG_INFO("Successfully send message %s\n", message.c_str()); - - // Flush all produced messages - producer.flush(); - producer.close(); - return EXIT_SUCCESS; - + // Flush all produced messages + producer.flush(); + producer.close(); + return EXIT_SUCCESS; + } } bool ACA_Message_Pulsar_Producer::publish(string message, string orderingKey) { - Result result; - // Create a producer Producer producer; - result = this->ptr_client->createProducer(this->topic_name,producer); - if(result != ResultOk){ - ACA_LOG_ERROR("Failed to create producer, result=%d.\n", result); + Result createProducerResult = this->ptr_client->createProducer(this->topic_name,producer); + if(createProducerResult != ResultOk){ + ACA_LOG_ERROR("ACA_PULSAR_MQ: Failed to create producer, result=%d.\n", createProducerResult); return EXIT_FAILURE; } // Create a message Message msg = MessageBuilder().setContent(message).setOrderingKey(orderingKey).build(); - result = producer.send(msg); - if(result != ResultOk){ - ACA_LOG_ERROR("Failed to send message %s.\n", message.c_str()); + + if(producer.send(msg) != ResultOk){ + ACA_LOG_ERROR("ACA_PULSAR_MQ: Failed to send message %s.\n", message.c_str()); return EXIT_FAILURE; } + else{ + ACA_LOG_INFO("ACA_PULSAR_MQ: Successfully send message %s.\n", message.c_str()); - ACA_LOG_INFO("Successfully send message %s\n", message.c_str()); - - // Flush all produced messages - producer.flush(); - producer.close(); - return EXIT_SUCCESS; - + // Flush all produced messages + producer.flush(); + producer.close(); + return EXIT_SUCCESS; + } } void ACA_Message_Pulsar_Producer::setBrokers(string brokers) { From 244ec448de6825f2b790d49d7ba61b447e2dc211 Mon Sep 17 00:00:00 2001 From: Joey Date: Mon, 7 Mar 2022 22:56:19 +0800 Subject: [PATCH 37/37] add logs distinguish grpc and mq. --- src/comm/aca_grpc.cpp | 10 ++++++---- src/comm/aca_message_pulsar_consumer.cpp | 14 +++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/comm/aca_grpc.cpp b/src/comm/aca_grpc.cpp index 4c4c06cd..77af3745 100644 --- a/src/comm/aca_grpc.cpp +++ b/src/comm/aca_grpc.cpp @@ -174,7 +174,8 @@ void GoalStateProvisionerAsyncServer::ProcessPushGoalStatesStreamAsyncCall( // process goalstateV2 in the thread pool // It has read from the stream, now to GoalStateV2 should not be empty // and we need to process it. - ACA_LOG_DEBUG("%s\n", "This call has already read from the stream, now we process the gsv2..."); + ACA_LOG_DEBUG("%s\n", "ACA_GRPC: This call has already read from the stream, now we process the gsv2..."); + if (streamingCall->goalStateV2_.neighbor_states_size() == 1) { // if there's only one neighbor state, it means that it is pushed @@ -189,16 +190,17 @@ void GoalStateProvisionerAsyncServer::ProcessPushGoalStatesStreamAsyncCall( } std::chrono::_V2::steady_clock::time_point start = std::chrono::steady_clock::now(); + ACA_LOG_INFO("%s\n", "ACA_GRPC: Start updating GoalStateV2..."); int rc = Aca_Comm_Manager::get_instance().update_goal_state( streamingCall->goalStateV2_, streamingCall->gsOperationReply_); if (rc == EXIT_SUCCESS) { - ACA_LOG_INFO("Control Fast Path streaming - Successfully updated host with latest goal state %d.\n", + ACA_LOG_INFO("ACA_GRPC: Control Fast Path streaming - Successfully updated host with latest goal state %d.\n", rc); } else if (rc == EINPROGRESS) { - ACA_LOG_INFO("Control Fast Path streaming - Update host with latest goal state returned pending, rc=%d.\n", + ACA_LOG_INFO("ACA_GRPC: Control Fast Path streaming - Update host with latest goal state returned pending, rc=%d.\n", rc); } else { - ACA_LOG_ERROR("Control Fast Path streaming - Failed to update host with latest goal state, rc=%d.\n", + ACA_LOG_ERROR("ACA_GRPC: Control Fast Path streaming - Failed to update host with latest goal state, rc=%d.\n", rc); } std::chrono::_V2::steady_clock::time_point end = diff --git a/src/comm/aca_message_pulsar_consumer.cpp b/src/comm/aca_message_pulsar_consumer.cpp index 1344a729..1517486d 100644 --- a/src/comm/aca_message_pulsar_consumer.cpp +++ b/src/comm/aca_message_pulsar_consumer.cpp @@ -36,18 +36,18 @@ void listener(Consumer consumer, const Message& message){ int rc; Result result; - ACA_LOG_DEBUG("%s","ACA_PULSAR_MQ: Successfully received the incoming message.\n"); - ACA_LOG_DEBUG("%s","ACA_PULSAR_MQ: Start deserializing the message to GoalState...\n"); - ACA_LOG_DEBUG("%s","<====================================================>\n"); + ACA_LOG_INFO("%s","ACA_PULSAR_MQ: Successfully received the incoming message.\n"); + ACA_LOG_INFO("%s","ACA_PULSAR_MQ: Start deserializing the message to GoalState...\n"); + ACA_LOG_INFO("%s","<====================================================>\n"); rc = Aca_Comm_Manager::get_instance().deserialize( (unsigned char *)message.getData(), message.getLength(), deserialized_GoalState); - ACA_LOG_DEBUG("%s","<====================================================>\n"); + ACA_LOG_INFO("%s","<====================================================>\n"); if (rc == EXIT_SUCCESS) { - ACA_LOG_DEBUG("%s","ACA_PULSAR_MQ: Start updating GoalState...\n"); - ACA_LOG_DEBUG("%s","<====================================================>\n"); + ACA_LOG_INFO("%s","ACA_PULSAR_MQ: Start updating GoalState...\n"); + ACA_LOG_INFO("%s","<====================================================>\n"); rc = Aca_Comm_Manager::get_instance().update_goal_state( deserialized_GoalState, gsOperationalReply); - ACA_LOG_DEBUG("%s","<====================================================>\n"); + ACA_LOG_INFO("%s","<====================================================>\n"); if (rc != EXIT_SUCCESS) { ACA_LOG_ERROR("ACA_PULSAR_MQ: ERROR, failed to update host with latest goal state, rc=%d.\n", rc); } else {