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

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangml committed Dec 21, 2020
1 parent 19a01b6 commit 787fecf
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 71 deletions.
10 changes: 1 addition & 9 deletions include/aca_zeta_programming.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ class ACA_Zeta_Programming {

uint get_group_id(string zeta_gateway_id);

void set_zeta_gateway(uint tunnel_id, const string auxGateway_id);

int remove_zeta_gateway(uint tunnel_id);

string get_zeta_gateway_id(uint tunnel_id);

bool is_exist_zeta_gateway(const string auxGateway_id);

private:
int _create_oam_ofp(uint port_number);
int _delete_oam_ofp(uint port_number);
Expand All @@ -76,7 +68,7 @@ class ACA_Zeta_Programming {

// hashtable <key: zeta_gateway_id, value: zeta_config>
CTSL::HashMap<string, zeta_config *> _zeta_config_table;
mutex _zeta_config_table_mutex;
mutex _zeta_config_operation_mutex;
};

} // namespace aca_zeta_programming
Expand Down
Binary file removed include/hashmap/HashMap
Binary file not shown.
4 changes: 2 additions & 2 deletions src/ovs/aca_vlan_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ string ACA_Vlan_Manager::get_zeta_gateway_id(uint tunnel_id)
zeta_gateway_id = current_vpc_table_entry->zeta_gateway_id;
}

ACA_LOG_DEBUG("%s", "ACA_Vlan_Manager::get_zeta_gateway_id ---> Entering\n");
ACA_LOG_DEBUG("%s", "ACA_Vlan_Manager::get_zeta_gateway_id <--- Entering\n");
return zeta_gateway_id;
}

Expand Down Expand Up @@ -335,7 +335,7 @@ bool ACA_Vlan_Manager::is_exist_zeta_gateway(string zeta_gateway_id)
}
}

ACA_LOG_DEBUG("%s", "ACA_Vlan_Manager::get_aux_gateway_id ---> Entering\n");
ACA_LOG_DEBUG("%s", "ACA_Vlan_Manager::get_aux_gateway_id <--- Entering\n");

return zeta_gateway_id_found;
}
Expand Down
33 changes: 12 additions & 21 deletions src/zeta/aca_zeta_oam_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "aca_ovs_control.h"
#include "aca_vlan_manager.h"
#include "aca_zeta_programming.h"
#include <math.h>

using namespace std;
using namespace aca_ovs_control;
Expand All @@ -46,19 +47,14 @@ ACA_Zeta_Oam_Server &ACA_Zeta_Oam_Server::get_instance()

bool ACA_Zeta_Oam_Server::_validate_oam_message(oam_message *oammsg)
{
int retcode = 0;

if (!oammsg) {
ACA_LOG_ERROR("%s", "OAM message is null!\n");
return false;
}

if (OAM_MSG_FLOW_INJECTION != oammsg->op_code && OAM_MSG_FLOW_DELETION != oammsg->op_code) {
retcode = -1;
uint op_code = ntohl(oammsg->op_code);
if (op_code != OAM_MSG_FLOW_INJECTION && op_code != OAM_MSG_FLOW_DELETION) {
ACA_LOG_ERROR("%s", "Invalid 'op_code' field for OAM message!\n");
}

if (0 != retcode) {
return false;
}

Expand Down Expand Up @@ -104,11 +100,13 @@ uint8_t ACA_Zeta_Oam_Server::_get_message_type(oam_message *oammsg)
return OAM_MSG_NONE;
}

if (oammsg->op_code != OAM_MSG_FLOW_INJECTION && oammsg->op_code != OAM_MSG_FLOW_DELETION) {
uint8_t op_code = (uint8_t)(ntohl(oammsg->op_code));

if (op_code != OAM_MSG_FLOW_INJECTION && op_code != OAM_MSG_FLOW_DELETION) {
return OAM_MSG_NONE;
}

return (uint8_t)(ntohl(oammsg->op_code));
return op_code;
}

string ACA_Zeta_Oam_Server::_get_mac_addr(uint8_t *mac)
Expand All @@ -129,20 +127,13 @@ string ACA_Zeta_Oam_Server::_get_mac_addr(uint8_t *mac)
return mac_string;
}

uint ACA_Zeta_Oam_Server::_get_tunnel_id(uint8_t vni[3])
uint ACA_Zeta_Oam_Server::_get_tunnel_id(uint8_t *vni)
{
string tunnel_id;
stringstream ss;

for (int i = 0; i < 3; i++) {
ss << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<unsigned int>(vni[i]);
}
uint tunnel_id;

ss >> tunnel_id;
tunnel_id.pop_back();
tunnel_id = ((uint)vni[0]) | ((uint)vni[1]) << 8 | ((uint) vni[2]) << 16;

return strtoul(tunnel_id.c_str(), NULL, 10);
return tunnel_id;
}

//extract data for flow table matching from the oam message
Expand All @@ -157,7 +148,7 @@ oam_match ACA_Zeta_Oam_Server::_get_oam_match_field(oam_message *oammsg)
match.sport = to_string(ntohs(msg_data.src_port));
match.dport = to_string(ntohs(msg_data.dst_port));
match.proto = to_string(msg_data.proto);
// TODO: figure out the conversion from 3 bytes VNI to tunnel_id string
// TODO: figure out the conversion from 3 bytes VNI to tunnel_id
match.vni = _get_tunnel_id(msg_data.vni);

return match;
Expand Down
90 changes: 68 additions & 22 deletions src/zeta/aca_zeta_programming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ void ACA_Zeta_Programming::clear_all_data()

int ACA_Zeta_Programming::_create_group_punt_rule(uint tunnel_id, uint group_id)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::_create_group_punt_rule ---> Entering\n");

unsigned long not_care_culminative_time;
int overall_rc = EXIT_SUCCESS;

Expand All @@ -91,15 +93,18 @@ int ACA_Zeta_Programming::_create_group_punt_rule(uint tunnel_id, uint group_id)
ACA_LOG_ERROR("_create_group_punt_rule failed!!! overrall_rc: %d\n", overall_rc);
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::_create_group_punt_rule <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

int ACA_Zeta_Programming::_delete_group_punt_rule(uint tunnel_id)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::_delete_group_punt_rule ---> Entering\n");
int overall_rc;

uint vlan_id = ACA_Vlan_Manager::get_instance().get_or_create_vlan_id(tunnel_id);
string opt = "table=22,priority=50,dl_vlan" + to_string(vlan_id);
string opt = "table=22,priority=50,dl_vlan=" + to_string(vlan_id);

overall_rc = ACA_OVS_Control::get_instance().del_flows("br-tun", opt.c_str());

Expand All @@ -108,12 +113,16 @@ int ACA_Zeta_Programming::_delete_group_punt_rule(uint tunnel_id)
} else {
ACA_LOG_ERROR("_delete_group_punt_rule failed!!! overrall_rc: %d\n", overall_rc);
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::_delete_group_punt_rule <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

// add the OAM punt rule
int ACA_Zeta_Programming::_create_oam_ofp(uint port_number)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::_create_oam_ofp ---> Entering\n");
int overall_rc;

string opt = "table=0,priority=25,udp,udp_dst=" + to_string(port_number) + ",actions=CONTROLLER";
Expand All @@ -125,12 +134,15 @@ int ACA_Zeta_Programming::_create_oam_ofp(uint port_number)
ACA_LOG_ERROR("creat_oam_ofp failed!!! overrall_rc: %d\n", overall_rc);
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::_create_oam_ofp <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

// delete the OAM punt rule
int ACA_Zeta_Programming::_delete_oam_ofp(uint port_number)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::_delete_oam_ofp ---> Entering\n");
int overall_rc;

string opt = "udp,udp_dst=" + to_string(port_number);
Expand All @@ -142,30 +154,41 @@ int ACA_Zeta_Programming::_delete_oam_ofp(uint port_number)
} else {
ACA_LOG_ERROR("delete_oam_ofp failed!!! overrall_rc: %d\n", overall_rc);
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::_delete_oam_ofp <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

uint ACA_Zeta_Programming::get_oam_port(string zeta_gateway_id)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::get_oam_port ---> Entering\n");
zeta_config *current_zeta_cfg;
uint oam_port = 0;
if (_zeta_config_table.find(zeta_gateway_id, current_zeta_cfg)) {
oam_port = current_zeta_cfg->oam_port;
} else {
ACA_LOG_ERROR("zeta_gateway_id %s not found in zeta_config_table\n",
zeta_gateway_id.c_str());
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::get_oam_port <--- Exiting, oam_port = %d\n", oam_port);
return oam_port;
}

int ACA_Zeta_Programming::create_zeta_config(const alcor::schema::AuxGateway current_AuxGateway,
uint tunnel_id)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::create_zeta_config ---> Entering\n");
int overall_rc = EXIT_SUCCESS;
zeta_config *new_zeta_cfg;
bool bucket_not_found = false;
unordered_set<string> new_zeta_buckets;

uint oam_port = current_AuxGateway.zeta_info().port_inband_operation();

_zeta_config_table_mutex.lock();
_zeta_config_operation_mutex.lock();
// -----critical section starts-----
if (!_zeta_config_table.find(current_AuxGateway.id(), new_zeta_cfg)) {
create_entry(current_AuxGateway.id(), oam_port);
_create_oam_ofp(oam_port);
Expand Down Expand Up @@ -200,50 +223,62 @@ int ACA_Zeta_Programming::create_zeta_config(const alcor::schema::AuxGateway cur
} else {
ACA_LOG_INFO("%s", "The vpc currently has an auxgateway set!\n");
}
_zeta_config_table_mutex.unlock();
// -----critical section ends-----
_zeta_config_operation_mutex.unlock();

ACA_LOG_DEBUG("ACA_Zeta_Programming::create_zeta_config <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

int ACA_Zeta_Programming::delete_zeta_config(const alcor::schema::AuxGateway current_AuxGateway,
uint tunnel_id)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::delete_zeta_config ---> Entering\n");
zeta_config stZetaCfg;
int overall_rc = EXIT_SUCCESS;

zeta_config *current_zeta_cfg;

_zeta_config_table_mutex.lock();
_zeta_config_operation_mutex.lock();
// -----critical section starts-----
if (!_zeta_config_table.find(current_AuxGateway.id(), current_zeta_cfg)) {
return overall_rc;
}

string current_zeta_gateway_id =
ACA_Vlan_Manager::get_instance().get_zeta_gateway_id(tunnel_id);

if (current_zeta_gateway_id.empty()) {
ACA_LOG_INFO("%s", "No auxgateway is currently set for this vpc!\n");
ACA_LOG_ERROR("zeta_gateway_id %s not found in zeta_config_table\n",
current_AuxGateway.id().c_str());
} else {
if (current_zeta_gateway_id != current_AuxGateway.id()) {
ACA_LOG_ERROR("%s", "The auxgateway_id is inconsistent with the auxgateway_id currently set by the vpc!\n");
string current_zeta_gateway_id =
ACA_Vlan_Manager::get_instance().get_zeta_gateway_id(tunnel_id);

if (current_zeta_gateway_id.empty()) {
ACA_LOG_INFO("%s", "No auxgateway is currently set for this vpc!\n");
} else {
ACA_LOG_INFO("%s", "Reset auxGateway to empty!\n");
_delete_group_punt_rule(tunnel_id);
overall_rc = ACA_Vlan_Manager::get_instance().remove_zeta_gateway(tunnel_id);
if (current_zeta_gateway_id != current_AuxGateway.id()) {
ACA_LOG_ERROR("%s", "The auxgateway_id is inconsistent with the auxgateway_id currently set by the vpc!\n");
} else {
ACA_LOG_INFO("%s", "Reset auxGateway to empty!\n");
_delete_group_punt_rule(tunnel_id);
overall_rc = ACA_Vlan_Manager::get_instance().remove_zeta_gateway(tunnel_id);
}
}
}

if (!ACA_Vlan_Manager::get_instance().is_exist_zeta_gateway(current_AuxGateway.id())) {
_delete_oam_ofp(current_zeta_cfg->oam_port);
_zeta_config_table.erase(current_AuxGateway.id());
if (!ACA_Vlan_Manager::get_instance().is_exist_zeta_gateway(
current_AuxGateway.id())) {
_delete_oam_ofp(current_zeta_cfg->oam_port);
_zeta_config_table.erase(current_AuxGateway.id());
}
}
_zeta_config_table_mutex.unlock();

// -----critical section ends-----
_zeta_config_operation_mutex.unlock();

ACA_LOG_DEBUG("ACA_Zeta_Programming::delete_zeta_config <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

int ACA_Zeta_Programming::_create_zeta_group_entry(zeta_config *zeta_cfg)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::_create_zeta_group_entry ---> Entering\n");
unsigned long not_care_culminative_time;
int overall_rc = EXIT_SUCCESS;

Expand All @@ -265,11 +300,14 @@ int ACA_Zeta_Programming::_create_zeta_group_entry(zeta_config *zeta_cfg)
ACA_LOG_ERROR("update_zeta_group_entry failed!!! overrall_rc: %d\n", overall_rc);
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::_create_zeta_group_entry <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

int ACA_Zeta_Programming::_delete_zeta_group_entry(zeta_config *zeta_cfg)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::_delete_zeta_group_entry ---> Entering\n");
unsigned long not_care_culminative_time;
int overall_rc = EXIT_SUCCESS;

Expand All @@ -284,6 +322,8 @@ int ACA_Zeta_Programming::_delete_zeta_group_entry(zeta_config *zeta_cfg)
ACA_LOG_ERROR("delete_zeta_group_entry failed!!! overrall_rc: %d\n", overall_rc);
}

ACA_LOG_DEBUG("ACA_Zeta_Programming::_delete_zeta_group_entry <--- Exiting, overall_rc = %d\n",
overall_rc);
return overall_rc;
}

Expand Down Expand Up @@ -325,14 +365,20 @@ bool ACA_Zeta_Programming::oam_port_rule_exists(uint port_number)

uint ACA_Zeta_Programming::get_group_id(string zeta_gateway_id)
{
ACA_LOG_DEBUG("%s", "ACA_Zeta_Programming::get_group_id ---> Entering\n");
uint group_id = 0;
zeta_config *current_zeta_cfg;

if (!_zeta_config_table.find(zeta_gateway_id, current_zeta_cfg)) {
group_id = current_zeta_cfg->group_id;
} else {
ACA_LOG_ERROR("zeta_gateway_id %s not found in zeta_config_table\n",
zeta_gateway_id.c_str());
}

return group_id;

ACA_LOG_DEBUG("ACA_Zeta_Programming::get_group_id <--- Exiting, overall_rc = %u\n", group_id);
}

} // namespace aca_zeta_programming
Loading

0 comments on commit 787fecf

Please sign in to comment.