Skip to content

Commit

Permalink
Fix multiple vlan issue (sonic-net#27)
Browse files Browse the repository at this point in the history
* # This is a combination of 5 commits.
# This is the 1st commit message:

fix multi-vlan relay issue
  • Loading branch information
jcaiMR authored and qiluo-msft committed Feb 2, 2023
1 parent 5ec1f5b commit ed86546
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 293 deletions.
25 changes: 14 additions & 11 deletions src/configInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ swss::Select swssSelect;
*
* @return none
*/
void initialize_swss(std::vector<relay_config> *vlans)
void initialize_swss(std::unordered_map<std::string, relay_config> &vlans)
{
try {
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
Expand Down Expand Up @@ -50,13 +50,14 @@ void deinitialize_swss()


/**
* @code void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic)
* @code void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic)
*
* @brief initialize and get vlan table information from DHCP_RELAY
*
* @return none
*/
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic) {
void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic) {
swss::Selectable *selectable;
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC);
if (ret == swss::Select::ERROR) {
Expand All @@ -77,7 +78,7 @@ void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHe
*
* @brief main thread for handling SWSS notification
*
* @param context list of vlans/argument config that contains strings of server and option
* @param context map of vlans/argument config that contains strings of server and option
*
* @return none
*/
Expand All @@ -89,16 +90,16 @@ void handleSwssNotification(swssNotification test)
}

/**
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans)
*
* @brief handles DHCPv6 relay configuration change notification
*
* @param ipHelpersTable DHCP table
* @param vlans list of vlans/argument config that contains strings of server and option
* @param vlans map of vlans/argument config that contains strings of server and option
*
* @return none
*/
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans)
{
std::deque<swss::KeyOpFieldsValuesTuple> entries;

Expand All @@ -107,16 +108,16 @@ void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::ve
}

/**
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> vlans)
*
* @brief process DHCPv6 relay servers and options configuration change notification
*
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table
* @param vlans list of vlans/argument config that contains strings of server and option
* @param vlans map of vlans/argument config that contains strings of server and option
*
* @return none
*/
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans)
{
std::vector<std::string> servers;

Expand Down Expand Up @@ -150,7 +151,9 @@ void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries,
intf.is_interface_id = true;
}
}
vlans->push_back(intf);
syslog(LOG_INFO, "add %s relay config, option79 %s interface-id %s\n", vlan.c_str(),
intf.is_option_79 ? "enable" : "disable", intf.is_interface_id ? "enable" : "disable");
vlans[vlan] = intf;
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/configInterface.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <string>
#include <unordered_map>
#include <boost/thread.hpp>
#include "subscriberstatetable.h"
#include "select.h"
#include "relay.h"

struct swssNotification {
std::vector<relay_config> *vlans;
std::unordered_map<std::string, relay_config> vlans;
swss::SubscriberStateTable *ipHelpersTable;
};
/**
Expand All @@ -16,7 +18,7 @@ struct swssNotification {
*
* @return none
*/
void initialize_swss(std::vector<relay_config> *vlans);
void initialize_swss(std::unordered_map<std::string, relay_config> &vlans);

/**
* @code void deinitialize_swss()
Expand All @@ -28,14 +30,13 @@ void initialize_swss(std::vector<relay_config> *vlans);
void deinitialize_swss();

/**
* @code void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic)
* @code void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic)
*
* @brief initialize and get vlan information from DHCP_RELAY
*
* @return none
*/
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic);

void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable, bool dynamic);
/**
* @code void swssNotification test
*
Expand All @@ -48,28 +49,28 @@ void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHe
void handleSwssNotification(swssNotification test);

/**
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans)
*
* @brief handles DHCPv6 relay configuration change notification
*
* @param ipHelpersTable DHCP table
* @param vlans list of vlans/argument config that contains strings of server and option
* @param vlans map of vlans/argument config that contains strings of server and option
*
* @return none
*/
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans);
void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::unordered_map<std::string, relay_config> &vlans);

/**
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans)
* @code void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans)
*
* @brief process DHCPv6 relay servers and options configuration change notification
*
* @param entries queue of std::tuple<std::string, std::string, std::vector<FieldValueTuple>> entries in DHCP table
* @param context list of vlans/argument config that contains strings of server and option
* @param context map of vlans/argument config that contains strings of server and option
*
* @return none
*/
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::vector<relay_config> *vlans);
void processRelayNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries, std::unordered_map<std::string, relay_config> &vlans);

/**
*@code stopSwssNotificationPoll
Expand Down
7 changes: 4 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <syslog.h>
#include <unordered_map>
#include "configInterface.h"

bool dual_tor_sock = false;
Expand All @@ -23,9 +24,9 @@ int main(int argc, char *argv[]) {
}
}
try {
std::vector<relay_config> vlans;
initialize_swss(&vlans);
loop_relay(&vlans);
std::unordered_map<std::string, relay_config> vlans;
initialize_swss(vlans);
loop_relay(vlans);
}
catch (std::exception &e)
{
Expand Down
Loading

0 comments on commit ed86546

Please sign in to comment.