From f5351d65e194da83d75006a2a9d2b8909efea813 Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Wed, 23 Mar 2016 14:04:34 -0700 Subject: [PATCH] packaging: Move common and tests to sonic-common repo Signed-off-by: Shuotian Cheng --- Makefile.am | 6 +- common/Makefile.am | 30 ---- common/consumertable.cpp | 149 -------------------- common/consumertable.h | 38 ----- common/dbconnector.cpp | 74 ---------- common/dbconnector.h | 38 ----- common/ipaddress.cpp | 39 ------ common/ipaddress.h | 74 ---------- common/ipaddresses.cpp | 46 ------ common/ipaddresses.h | 56 -------- common/ipprefix.cpp | 44 ------ common/ipprefix.h | 62 --------- common/json.cpp | 82 ----------- common/json.h | 20 --- common/linkcache.cpp | 77 ---------- common/linkcache.h | 31 ----- common/logger.cpp | 32 ----- common/logger.h | 40 ------ common/macaddress.cpp | 59 -------- common/macaddress.h | 63 --------- common/netdispatcher.cpp | 45 ------ common/netdispatcher.h | 45 ------ common/netlink.cpp | 94 ------------- common/netlink.h | 31 ----- common/netmsg.h | 20 --- common/producertable.cpp | 69 --------- common/producertable.h | 34 ----- common/redisreply.cpp | 72 ---------- common/redisreply.h | 44 ------ common/scheme.h | 24 ---- common/select.cpp | 81 ----------- common/select.h | 44 ------ common/selectable.h | 37 ----- common/table.cpp | 232 ------------------------------- common/table.h | 84 ----------- configure.ac | 16 +-- debian/control | 12 -- debian/libswsscommon-dev.dirs | 2 - debian/libswsscommon-dev.install | 1 - debian/libswsscommon-dev.links | 2 - debian/libswsscommon.dirs | 1 - debian/libswsscommon.install | 1 - debian/swss.dirs | 1 - debian/swss.install | 1 - fpmsyncd/Makefile.am | 3 +- fpmsyncd/fpmlink.cpp | 6 +- fpmsyncd/fpmlink.h | 2 +- fpmsyncd/fpmsyncd.cpp | 6 +- fpmsyncd/routesync.cpp | 14 +- fpmsyncd/routesync.h | 6 +- intfsyncd/Makefile.am | 3 +- intfsyncd/intfsync.cpp | 12 +- intfsyncd/intfsync.h | 6 +- intfsyncd/intfsyncd.cpp | 8 +- neighsyncd/Makefile.am | 3 +- neighsyncd/neighsync.cpp | 12 +- neighsyncd/neighsync.h | 6 +- neighsyncd/neighsyncd.cpp | 8 +- orchagent/Makefile.am | 5 +- orchagent/intfsorch.cpp | 4 +- orchagent/intfsorch.h | 4 +- orchagent/main.cpp | 2 +- orchagent/neighorch.cpp | 2 +- orchagent/orch.cpp | 2 +- orchagent/orch.h | 6 +- orchagent/orchdaemon.cpp | 2 +- orchagent/orchdaemon.h | 8 +- orchagent/portsorch.cpp | 2 +- orchagent/portsorch.h | 2 +- orchagent/routeorch.cpp | 2 +- orchagent/routeorch.h | 6 +- orchagent/routeresync.cpp | 4 +- portsyncd/Makefile.am | 3 +- portsyncd/linksync.cpp | 12 +- portsyncd/linksync.h | 6 +- portsyncd/portsyncd.cpp | 10 +- tests/Makefile.am | 21 --- tests/redis_ut.cpp | 223 ----------------------------- 78 files changed, 88 insertions(+), 2386 deletions(-) delete mode 100644 common/Makefile.am delete mode 100644 common/consumertable.cpp delete mode 100644 common/consumertable.h delete mode 100644 common/dbconnector.cpp delete mode 100644 common/dbconnector.h delete mode 100644 common/ipaddress.cpp delete mode 100644 common/ipaddress.h delete mode 100644 common/ipaddresses.cpp delete mode 100644 common/ipaddresses.h delete mode 100644 common/ipprefix.cpp delete mode 100644 common/ipprefix.h delete mode 100644 common/json.cpp delete mode 100644 common/json.h delete mode 100644 common/linkcache.cpp delete mode 100644 common/linkcache.h delete mode 100644 common/logger.cpp delete mode 100644 common/logger.h delete mode 100644 common/macaddress.cpp delete mode 100644 common/macaddress.h delete mode 100644 common/netdispatcher.cpp delete mode 100644 common/netdispatcher.h delete mode 100644 common/netlink.cpp delete mode 100644 common/netlink.h delete mode 100644 common/netmsg.h delete mode 100644 common/producertable.cpp delete mode 100644 common/producertable.h delete mode 100644 common/redisreply.cpp delete mode 100644 common/redisreply.h delete mode 100644 common/scheme.h delete mode 100644 common/select.cpp delete mode 100644 common/select.h delete mode 100644 common/selectable.h delete mode 100644 common/table.cpp delete mode 100644 common/table.h delete mode 100644 debian/libswsscommon-dev.dirs delete mode 100644 debian/libswsscommon-dev.install delete mode 100755 debian/libswsscommon-dev.links delete mode 100644 debian/libswsscommon.dirs delete mode 100644 debian/libswsscommon.install delete mode 100644 debian/swss.dirs delete mode 100644 debian/swss.install delete mode 100644 tests/Makefile.am delete mode 100644 tests/redis_ut.cpp diff --git a/Makefile.am b/Makefile.am index 7b7cf06f3b..6f8ccc0485 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,4 @@ -SUBDIRS = common neighsyncd intfsyncd portsyncd orchagent - -if TESTS -SUBDIRS += tests -endif +SUBDIRS = neighsyncd intfsyncd portsyncd orchagent if FPM SUBDIRS += fpmsyncd diff --git a/common/Makefile.am b/common/Makefile.am deleted file mode 100644 index f8be9e3f9c..0000000000 --- a/common/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -INCLUDES = -I $(top_srcdir) - -lib_LTLIBRARIES = libswsscommon.la - -if DEBUG -DBGFLAGS = -ggdb -DDEBUG -else -DBGFLAGS = -g -endif - -libswsscommon_la_SOURCES = \ - logger.cpp \ - redisreply.cpp \ - dbconnector.cpp \ - table.cpp \ - json.cpp \ - producertable.cpp \ - select.cpp \ - consumertable.cpp \ - ipaddress.cpp \ - ipprefix.cpp \ - ipaddresses.cpp \ - macaddress.cpp \ - netdispatcher.cpp \ - netlink.cpp \ - linkcache.cpp - -libswsscommon_la_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -libswsscommon_la_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -libswsscommon_la_LIBADD = -lnl-3 -lnl-route-3 -lhiredis diff --git a/common/consumertable.cpp b/common/consumertable.cpp deleted file mode 100644 index c3ed28ab74..0000000000 --- a/common/consumertable.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "common/redisreply.h" -#include "common/consumertable.h" -#include "common/json.h" -#include -#include -#include -#include -#include -#include - -/* The database is already alive and kicking, no need for more than a second */ -#define SUBSCRIBE_TIMEOUT (1000) - -using namespace std; - -namespace swss { - -ConsumerTable::ConsumerTable(DBConnector *db, string tableName) : - Table(db, tableName), - m_subscribe(NULL), - m_queueLength(0) -{ - bool again = true; - - while (again) - { - try - { - RedisReply watch(m_db, string("WATCH ") + getKeyQueueTableName(), REDIS_REPLY_STATUS); - watch.checkStatusOK(); - multi(); - enqueue(string("LLEN ") + getKeyQueueTableName(), REDIS_REPLY_INTEGER); - subsribe(); - enqueue(string("LLEN ") + getKeyQueueTableName(), REDIS_REPLY_INTEGER); - exec(); - again = false; - } - catch (...) - { - delete m_subscribe; - } - } - - m_queueLength = queueResultsFront()->integer; - /* No need for that since we have WATCH gurantee on the transaction */ -} - -ConsumerTable::~ConsumerTable() -{ - delete m_subscribe; -} - -static string pop_front(queue &q) -{ - string ret(q.front()->getContext()->str); - delete q.front(); - q.pop(); - return ret; -} - -void ConsumerTable::pop(KeyOpFieldsValuesTuple &kco) -{ - string rpop_key("RPOP "); - string rpop_value = rpop_key; - string rpop_op = rpop_key; - - multi(); - - rpop_key += getKeyQueueTableName(); - enqueue(rpop_key, REDIS_REPLY_STRING); - - rpop_op += getOpQueueTableName(); - enqueue(rpop_op, REDIS_REPLY_STRING); - - rpop_value += getValueQueueTableName(); - enqueue(rpop_value, REDIS_REPLY_STRING); - - exec(); - - vector fieldsValues; - string key = pop_front(m_results); - string op = pop_front(m_results); - JSon::readJson(pop_front(m_results), fieldsValues); - - kco = std::make_tuple(key, op, fieldsValues); -} - -void ConsumerTable::addFd(fd_set *fd) -{ - FD_SET(m_subscribe->getContext()->fd, fd); -} - -int ConsumerTable::readCache() -{ - redisReply *reply = NULL; - - /* Read the messages in queue before subsribe command execute */ - if (m_queueLength) { - m_queueLength--; - return ConsumerTable::DATA; - } - - if (redisGetReplyFromReader(m_subscribe->getContext(), - (void**)&reply) != REDIS_OK) - { - return Selectable::ERROR; - } else if (reply != NULL) - { - freeReplyObject(reply); - return Selectable::DATA; - } - - return Selectable::NODATA; -} - -void ConsumerTable::readMe() -{ - redisReply *reply = NULL; - - if (redisGetReply(m_subscribe->getContext(), (void**)&reply) != REDIS_OK) - throw "Unable to read redis reply"; - - freeReplyObject(reply); -} - -bool ConsumerTable::isMe(fd_set *fd) -{ - return FD_ISSET(m_subscribe->getContext()->fd, fd); -} - -void ConsumerTable::subsribe() -{ - /* Create new new context to DB */ - if (m_db->getContext()->connection_type == REDIS_CONN_TCP) - m_subscribe = new DBConnector(m_db->getDB(), - m_db->getContext()->tcp.host, - m_db->getContext()->tcp.port, - SUBSCRIBE_TIMEOUT); - else - m_subscribe = new DBConnector(m_db->getDB(), - m_db->getContext()->unix_sock.path, - SUBSCRIBE_TIMEOUT); - /* Send SUBSCRIBE #channel command */ - string s("SUBSCRIBE "); - s+= getChannelTableName(); - RedisReply r(m_subscribe, s, REDIS_REPLY_ARRAY); -} - -} diff --git a/common/consumertable.h b/common/consumertable.h deleted file mode 100644 index 59deed1d20..0000000000 --- a/common/consumertable.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __CONSUMERTABLE__ -#define __CONSUMERTABLE__ - -#include -#include -#include -#include -#include "dbconnector.h" -#include "table.h" -#include "selectable.h" - -namespace swss { - -class ConsumerTable : public Table, public Selectable -{ -public: - ConsumerTable(DBConnector *db, std::string tableName); - virtual ~ConsumerTable(); - - /* Get a singlesubsribe channel rpop */ - void pop(KeyOpFieldsValuesTuple &kco); - - virtual void addFd(fd_set *fd); - virtual bool isMe(fd_set *fd); - virtual int readCache(); - virtual void readMe(); - -private: - /* Create a new redisContext, SELECT DB and SUBSRIBE */ - void subsribe(); - - DBConnector *m_subscribe; - unsigned int m_queueLength; -}; - -} - -#endif diff --git a/common/dbconnector.cpp b/common/dbconnector.cpp deleted file mode 100644 index 967ff08537..0000000000 --- a/common/dbconnector.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "common/dbconnector.h" -#include "common/redisreply.h" - -using namespace std; - -namespace swss { - -void DBConnector::select(DBConnector *db) -{ - string select("SELECT "); - select += to_string(db->getDB()); - - RedisReply r(db, select, REDIS_REPLY_STATUS); - r.checkStatusOK(); -} - -DBConnector::~DBConnector() -{ - redisFree(m_conn); -} - -DBConnector::DBConnector(int db, string hostname, int port, - unsigned int timeout) : - m_db(db) -{ - struct timeval tv = {0, (suseconds_t)timeout * 1000}; - - if (timeout) - m_conn = redisConnectWithTimeout(hostname.c_str(), port, tv); - else - m_conn = redisConnect(hostname.c_str(), port); - - if (m_conn->err) - throw system_error(make_error_code(errc::address_not_available), - "Unable to connect to redis"); - - select(this); -} - -DBConnector::DBConnector(int db, string unixPath, unsigned int timeout) : - m_db(db) -{ - struct timeval tv = {0, (suseconds_t)timeout * 1000}; - - if (timeout) - m_conn = redisConnectUnixWithTimeout(unixPath.c_str(), tv); - else - m_conn = redisConnectUnix(unixPath.c_str()); - - if (m_conn->err) - throw system_error(make_error_code(errc::address_not_available), - "Unable to connect to redis (unixs-socket)"); - - select(this); -} - -redisContext *DBConnector::getContext() -{ - return m_conn; -} - -int DBConnector::getDB() -{ - return m_db; -} - -} diff --git a/common/dbconnector.h b/common/dbconnector.h deleted file mode 100644 index f239d814da..0000000000 --- a/common/dbconnector.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __DBCONNECTOR__ -#define __DBCONNECTOR__ - -#include -#include - -#include - - -namespace swss { - -class DBConnector -{ -public: - /* - * Connect to Redis DB wither with a hostname:port or unix socket - * Select the database index provided by "db" - * - * Timeout - The time in milisecond until exception is been thrown. For - * infinite wait, set this value to 0 - */ - DBConnector(int db, std::string hostname, int port, unsigned int timeout); - DBConnector(int db, std::string unixPath, unsigned int timeout); - - ~DBConnector(); - - redisContext *getContext(); - int getDB(); - - static void select(DBConnector *db); - -private: - redisContext *m_conn; - int m_db; -}; - -} -#endif diff --git a/common/ipaddress.cpp b/common/ipaddress.cpp deleted file mode 100644 index 0b9b4c441a..0000000000 --- a/common/ipaddress.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -#include "ipaddress.h" - -using namespace swss; - -IpAddress::IpAddress(uint32_t ip) -{ - m_ip.family = AF_INET; - m_ip.ip_addr.ipv4_addr = ip; -} - -IpAddress::IpAddress(const std::string &ipStr) -{ - if (ipStr.find(":") != std::string::npos) - { - m_ip.family = AF_INET6; - } - else - { - m_ip.family = AF_INET; - } - - if (inet_pton(m_ip.family, ipStr.c_str(), &m_ip.ip_addr) != 1) - { - std::string err = "Error converting " + ipStr + " to IP address"; - throw std::invalid_argument(err); - } -} - -const std::string IpAddress::to_string() const -{ - char buf[INET6_ADDRSTRLEN]; - - std::string ipStr(inet_ntop(m_ip.family, &m_ip.ip_addr, buf, INET6_ADDRSTRLEN)); - - return ipStr; -} diff --git a/common/ipaddress.h b/common/ipaddress.h deleted file mode 100644 index f8c9e9ebda..0000000000 --- a/common/ipaddress.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef __IPADDRESS__ -#define __IPADDRESS__ - -#include -#include -#include -#include - -namespace swss { - -struct ip_addr_t { - uint8_t family; - union { - uint32_t ipv4_addr; - unsigned char ipv6_addr[16]; - } ip_addr; -}; - -class IpAddress -{ -public: - IpAddress() {} - IpAddress(ip_addr_t ip) { m_ip = ip; } - IpAddress(uint32_t ip); - IpAddress(const std::string &ipStr); - - inline bool isV4() const - { - return m_ip.family == AF_INET; - } - - inline const ip_addr_t getIp() const - { - return m_ip; - } - - inline const uint32_t getV4Addr() const - { - return m_ip.ip_addr.ipv4_addr; - } - - inline bool operator<(const IpAddress &o) const - { - if (m_ip.family < o.m_ip.family) - return true; - - if (m_ip.family == AF_INET) - return m_ip.ip_addr.ipv4_addr < - o.m_ip.ip_addr.ipv4_addr; - - return (memcmp(&m_ip.ip_addr.ipv6_addr, &o.m_ip.ip_addr.ipv6_addr, 16) < 0); - } - - inline bool operator==(const IpAddress &o) const - { - return m_ip.family == o.m_ip.family && - ((m_ip.family == AF_INET && m_ip.ip_addr.ipv4_addr == o.m_ip.ip_addr.ipv4_addr) || - (m_ip.family == AF_INET6 && memcmp(&m_ip.ip_addr.ipv6_addr, o.m_ip.ip_addr.ipv6_addr, 16))); - } - - inline bool operator!=(const IpAddress &o) const - { - return !(*this == o); - } - - const std::string to_string() const; - -private: - struct ip_addr_t m_ip; -}; - -} - -#endif diff --git a/common/ipaddresses.cpp b/common/ipaddresses.cpp deleted file mode 100644 index f76168eb8a..0000000000 --- a/common/ipaddresses.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "ipaddresses.h" - -#include - -using namespace std; -using namespace swss; - -IpAddresses::IpAddresses(const string &ipsStr) -{ - string ip_str; - istringstream iss(ipsStr); - - while (getline(iss, ip_str, ',')) - { - IpAddress ip(ip_str); - m_ips.insert(ip); - } -} - -void IpAddresses::add(const string &ipStr) -{ - IpAddress ip(ipStr); - m_ips.insert(ip); -} - -void IpAddresses::add(const IpAddress &ip) -{ - m_ips.insert(ip); -} - -const string IpAddresses::to_string() const -{ - string ips_str; - - for (auto it = m_ips.begin(); it != m_ips.end(); ++it) - { - if (it != m_ips.begin()) - { - ips_str += ","; - } - - ips_str += it->to_string(); - } - - return ips_str; -} diff --git a/common/ipaddresses.h b/common/ipaddresses.h deleted file mode 100644 index 9c010a5d6b..0000000000 --- a/common/ipaddresses.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __IPADDRESSES__ -#define __IPADDRESSES__ - -#include - -#include "ipaddress.h" - -namespace swss { - -class IpAddresses -{ -public: - IpAddresses() {} - - /* A list of IpAddresses separated by ',' */ - IpAddresses(const std::string &ips); - - inline const std::set &getIpAddresses() const - { - return m_ips; - } - - inline size_t getSize() const - { - return m_ips.size(); - } - - inline bool operator<(const IpAddresses &o) const - { - return m_ips < o.m_ips; - } - - inline bool operator==(const IpAddresses &o) const - { - return m_ips == o.m_ips; - } - - inline bool operator!=(const IpAddresses &o) const - { - return !(*this == o); - } - - void add(const std::string &ip); - - void add(const IpAddress &ip); - - const std::string to_string() const; - - -private: - std::set m_ips; -}; - -} - -#endif diff --git a/common/ipprefix.cpp b/common/ipprefix.cpp deleted file mode 100644 index d2a68b22fe..0000000000 --- a/common/ipprefix.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include - -#include "ipprefix.h" - -using namespace swss; - -IpPrefix::IpPrefix( - const std::string &ipPrefixStr) -{ - size_t pos = ipPrefixStr.find('/'); - std::string ipStr = ipPrefixStr.substr(0, pos); - if (ipStr.empty()) - { - m_ip = IpAddress(0); - } - else - { - m_ip = IpAddress(ipStr); - } - - if (pos == std::string::npos) - { - if (m_ip.isV4()) - m_mask = 32; - else - m_mask = 128; - } - else - { - m_mask = std::stoi(ipPrefixStr.substr(pos + 1)); - } -} - -IpPrefix::IpPrefix(uint32_t ipPrefix, int mask) -{ - m_ip = IpAddress(ipPrefix); - m_mask = mask; -} - -const std::string IpPrefix::to_string() const -{ - return (m_ip.to_string() + "/" + std::to_string(m_mask)); -} diff --git a/common/ipprefix.h b/common/ipprefix.h deleted file mode 100644 index 1a981956b1..0000000000 --- a/common/ipprefix.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef __IPPREFIX__ -#define __IPPREFIX__ - -#include "ipaddress.h" - -namespace swss { - -class IpPrefix -{ -public: - IpPrefix() {} - IpPrefix(const std::string &ipPrefixStr); - IpPrefix(uint32_t addr, int mask); - - inline bool isV4() const - { - return m_ip.isV4(); - } - - inline const IpAddress getIp() const - { - return m_ip; - } - - inline const IpAddress getMask() const - { - return IpAddress(htonl((0xFFFFFFFFLL << (32 - m_mask)) & 0xFFFFFFFF)); - } - - inline const int getMaskLength() const - { - return m_mask; - } - - inline bool operator<(const IpPrefix &o) const - { - if (m_mask != o.m_mask) - return m_mask < o.m_mask; - else - return m_ip < o.m_ip; - } - - inline bool operator==(const IpPrefix &o) const - { - return m_ip == o.m_ip && m_mask == o.m_mask; - } - - inline bool operator!=(const IpPrefix &o) const - { - return !(*this == o); - } - - const std::string to_string() const; - -private: - IpAddress m_ip; - int m_mask; -}; - -} - -#endif diff --git a/common/json.cpp b/common/json.cpp deleted file mode 100644 index 6a39b8a227..0000000000 --- a/common/json.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "common/json.h" -#include -#include - -using namespace std; - -namespace swss { - -static const string gHex = "0123456789ABCDEF"; -static bool shouldEncode(char ch) -{ - return ch == '{' || ch == '}' || ch == '\"' || ch == '\'' || ch == '%'; -} - -static string escape(const string &a) -{ - string ret; - for (char i : a) - { - if (shouldEncode(i)) - ret += string("%") + gHex[i >> 4] + gHex[i & 0xF]; - else - ret += i; - } - return ret; -} - -static string descape(const string &a) -{ - string ret; - for (auto i = a.begin(); i != a.end(); i++) - { - if (*i != '%') - { - ret+= *i; - continue; - } - - i++; - ret += char(((gHex.find(*i++)) << 4) | gHex.find(*i)); - } - return ret; -} - -string JSon::buildJson(const vector &fv) -{ - string tab = " "; - string json = "{" + tab; - - //for (FieldValueTuple &i : fv) - for (auto i = fv.begin(); i != fv.end();) - { - json+= tab + "\"" + escape(fvField(*i)) + "\" : \"" + - escape(fvValue(*i)) + "\""; - if (++i != fv.end()) - json += "," + tab; - } - json += tab + "}"; - return json; -} - -void JSon::readJson(const string &json, vector &fv) -{ - istringstream f(json); - string field, value, tmp; - FieldValueTuple e; - - /* Read the spaces and charactes until { "field" = "value", */ - while (getline(f, tmp, '\"')) { - /* Read field name */ - if (!getline(f, field, '\"')) break; - fvField(e) = descape(field); - /* Read " = " */ - if (!getline(f, tmp, '\"')) break; - /* Read value name */ - if (!getline(f, value, '\"')) break; - fvValue(e) = descape(value); - fv.push_back(e); - } -} - -} diff --git a/common/json.h b/common/json.h deleted file mode 100644 index cab880b644..0000000000 --- a/common/json.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __JSON__ -#define __JSON__ - -#include -#include - -#include "table.h" - -namespace swss { - -class JSon { -public: - static std::string buildJson(const std::vector &fv); - - static void readJson(const std::string &json, std::vector &fv); -}; - -} - -#endif diff --git a/common/linkcache.cpp b/common/linkcache.cpp deleted file mode 100644 index c34ae4d180..0000000000 --- a/common/linkcache.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include -#include -#include "common/logger.h" -#include "common/linkcache.h" - -using namespace std; -using namespace swss; - -LinkCache::LinkCache() -{ - m_nl_sock = nl_socket_alloc(); - if (!m_nl_sock) - { - SWSS_LOG_ERROR("Unable to allocated netlink socket"); - throw system_error(make_error_code(errc::address_not_available), - "Unable to allocated netlink socket"); - } - - int err = nl_connect(m_nl_sock, NETLINK_ROUTE); - if (err < 0) - { - SWSS_LOG_ERROR("Unable to connect netlink socket: %s", nl_geterror(err)); - nl_socket_free(m_nl_sock); - m_nl_sock = NULL; - throw system_error(make_error_code(errc::address_not_available), - "Unable to connect netlink socket"); - } - - err = rtnl_link_alloc_cache(m_nl_sock, AF_UNSPEC, &m_link_cache); - if (err < 0) - { - SWSS_LOG_ERROR("Unable to allocate link cache: %s", nl_geterror(err)); - nl_close(m_nl_sock); - nl_socket_free(m_nl_sock); - m_nl_sock = NULL; - throw system_error(make_error_code(errc::address_not_available), - "Unable to connect netlink socket"); - } -} - -LinkCache::~LinkCache() -{ - if (m_nl_sock != NULL) - { - nl_close(m_nl_sock); - nl_socket_free(m_nl_sock); - } -} - -LinkCache &LinkCache::getInstance() -{ - static LinkCache linkCache; - return linkCache; -} - -string LinkCache::ifindexToName(int ifindex) -{ -#define MAX_ADDR_SIZE 128 - char addrStr[MAX_ADDR_SIZE + 1] = {0}; - - if (rtnl_link_i2name(m_link_cache, ifindex, addrStr, MAX_ADDR_SIZE) == NULL) - { - /* Trying to refill cache */ - nl_cache_refill(m_nl_sock ,m_link_cache); - if (rtnl_link_i2name(m_link_cache, ifindex, - addrStr, MAX_ADDR_SIZE) == NULL) - { - /* Returns ifindex as string / */ - return to_string(ifindex); - } - - } - - return string(addrStr); -} diff --git a/common/linkcache.h b/common/linkcache.h deleted file mode 100644 index ce64b7778e..0000000000 --- a/common/linkcache.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __LINKCACHE__ -#define __LINKCACHE__ - -#include -#include -#include -#include -#include -#include -#include - -namespace swss { - -class LinkCache { -public: - static LinkCache &getInstance(); - - /* Translate ifindex to name */ - std::string ifindexToName(int ifindex); - -private: - LinkCache(); - ~LinkCache(); - - nl_cache *m_link_cache; - nl_sock *m_nl_sock; -}; - -} - -#endif diff --git a/common/logger.cpp b/common/logger.cpp deleted file mode 100644 index 4eff954c7d..0000000000 --- a/common/logger.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "logger.h" - -#include -#include -#include - -using namespace swss; - -Logger::Priority Logger::m_minPrio = Logger::SWSS_NOTICE; - -Logger &Logger::getInstance() -{ - static Logger m_logger; - return m_logger; -} - -void Logger::setMinPrio(Priority prio) -{ - m_minPrio = prio; -} - -void Logger::write(Priority prio, const char *fmt, ...) -{ - - if (prio > m_minPrio) - return; - - va_list ap; - va_start(ap, fmt); - vsyslog(prio, fmt, ap); - va_end(ap); -} diff --git a/common/logger.h b/common/logger.h deleted file mode 100644 index dd354cebe7..0000000000 --- a/common/logger.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef SWSS_COMMON_LOGGER_H -#define SWSS_COMMON_LOGGER_H - -namespace swss { - -#define SWSS_LOG_ERROR(MSG, ...) Logger::getInstance().write(Logger::SWSS_ERROR, MSG, ##__VA_ARGS__) -#define SWSS_LOG_WARN(MSG, ...) Logger::getInstance().write(Logger::SWSS_WARN, MSG, ##__VA_ARGS__) -#define SWSS_LOG_NOTICE(MSG, ...) Logger::getInstance().write(Logger::SWSS_NOTICE, MSG, ##__VA_ARGS__) -#define SWSS_LOG_INFO(MSG, ...) Logger::getInstance().write(Logger::SWSS_INFO, MSG, ##__VA_ARGS__) -#define SWSS_LOG_DEBUG(MSG, ...) Logger::getInstance().write(Logger::SWSS_DEBUG, MSG, ##__VA_ARGS__) - -class Logger -{ -public: - enum Priority - { - SWSS_EMERG, - SWSS_ALERT, - SWSS_CRIT, - SWSS_ERROR, - SWSS_WARN, - SWSS_NOTICE, - SWSS_INFO, - SWSS_DEBUG - }; - - static Logger &getInstance(); - static void setMinPrio(Priority prio); - void write(Priority prio, const char *fmt, ...); -private: - Logger() {}; - Logger(const Logger&); - Logger &operator=(const Logger&); - - static Priority m_minPrio; -}; - -} - -#endif /* SWSS_COMMON_LOGGER_H */ diff --git a/common/macaddress.cpp b/common/macaddress.cpp deleted file mode 100644 index 864dd357c2..0000000000 --- a/common/macaddress.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "macaddress.h" - -#include - -using namespace swss; -using namespace std; - -MacAddress::MacAddress() -{ - memset(m_mac, 0, 6); -} - -MacAddress::MacAddress(const uint8_t *mac) -{ - memcpy(m_mac, mac, 6); -} - -MacAddress::MacAddress(const std::string& macStr) -{ - MacAddress::parseMacString(macStr, m_mac); -} - -const std::string MacAddress::to_string() const -{ - char tmp_mac[32]; - sprintf(tmp_mac, "%02x:%02x:%02x:%02x:%02x:%02x", m_mac[0], m_mac[1], m_mac[2], m_mac[3], m_mac[4], m_mac[5]); - return std::string(tmp_mac); -} - -std::string MacAddress::to_string(const uint8_t* mac) -{ - uint8_t tmp_mac[32]; - sprintf((char*)tmp_mac, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return std::string((char*)tmp_mac); -} - -bool MacAddress::parseMacString(const string& macStr, uint8_t* mac) -{ - int i, value; - char ignore; - istringstream iss(macStr); - - if (mac == NULL) - { - return false; - } - - iss >> hex; - - for (i = 0; i < 5; i++) - { - iss >> value >> ignore; - mac[i] = value; - } - iss >> value; - mac[5] = value; - - return true; -} diff --git a/common/macaddress.h b/common/macaddress.h deleted file mode 100644 index d5bad6c6b1..0000000000 --- a/common/macaddress.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __MACADDRESS__ -#define __MACADDRESS__ - -#include -#include -#include - -namespace swss { - -class MacAddress -{ -public: - - MacAddress(); - - MacAddress(const uint8_t *mac); - - MacAddress(const std::string& macStr); - - inline void getMac(uint8_t *mac) const - { - memcpy(mac, m_mac, 6); - } - - inline const uint8_t *getMac() const - { - return m_mac; - } - - inline bool operator==(const MacAddress &o) const - { - return !memcmp(m_mac, o.m_mac, 6); - } - - inline bool operator!=(const MacAddress &o) const - { - return !(*this == o); - } - - inline bool operator!() const - { - return (!m_mac[0] && !m_mac[1] && !m_mac[2] && - !m_mac[3] && !m_mac[4] && !m_mac[5]); - } - - inline operator bool() const - { - return !!(*this); - } - - const std::string to_string() const; - - static std::string to_string(const uint8_t* mac); - - static bool parseMacString(const std::string& strmac, uint8_t* mac); - -private: - uint8_t m_mac[6]; -}; - -} - -#endif \ No newline at end of file diff --git a/common/netdispatcher.cpp b/common/netdispatcher.cpp deleted file mode 100644 index dc181ff10f..0000000000 --- a/common/netdispatcher.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include "common/netdispatcher.h" -#include "common/netmsg.h" - -using namespace swss; - -NetDispatcher::NetDispatcher() -{ -} - -NetDispatcher::~NetDispatcher() -{ -} - -NetDispatcher& NetDispatcher::getInstance() -{ - static NetDispatcher gInstance; - return gInstance; -} - -void NetDispatcher::registerMessageHandler(int nlmsg_type, NetMsg *callback) -{ - if (m_handlers.find(nlmsg_type) != m_handlers.end()) - throw "Trying to registered on already registerd netlink message"; - - m_handlers[nlmsg_type] = callback; -} - -void NetDispatcher::nlCallback(struct nl_object *obj, void *context) -{ - NetMsg *callback = (NetMsg *)context; - callback->onMsg(nl_object_get_msgtype(obj), obj); -} - -void NetDispatcher::onNetlinkMessage(struct nl_msg *msg) -{ - struct nlmsghdr *nlmsghdr = nlmsg_hdr(msg); - auto callback = m_handlers.find(nlmsghdr->nlmsg_type); - - /* Drop not registered messages */ - if (callback == m_handlers.end()) - return; - - nl_msg_parse(msg, NetDispatcher::nlCallback, (void *)(callback->second)); -} diff --git a/common/netdispatcher.h b/common/netdispatcher.h deleted file mode 100644 index 591b898e54..0000000000 --- a/common/netdispatcher.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __NETDISPATCHER__ -#define __NETDISPATCHER__ - -#include -#include -#include -#include -#include - -#include - -#include "netmsg.h" - -namespace swss { - -class NetDispatcher { -public: - /**/ - static NetDispatcher& getInstance(); - - /* - * Register callback class according to message-type. - * - * Throw exception if - */ - void registerMessageHandler(int nlmsg_type, NetMsg *callback); - - /* - * Called by NetLink or FpmLink classes as indication of new packet arrival - */ - void onNetlinkMessage(struct nl_msg *msg); - -private: - NetDispatcher(); - ~NetDispatcher(); - - /* nl_msg_parse callback API */ - static void nlCallback(struct nl_object *obj, void *context); - - std::map m_handlers; -}; - -} - -#endif diff --git a/common/netlink.cpp b/common/netlink.cpp deleted file mode 100644 index 76ecc3f578..0000000000 --- a/common/netlink.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include "common/logger.h" -#include "common/netmsg.h" -#include "common/netdispatcher.h" -#include "common/netlink.h" - -using namespace swss; -using namespace std; - -NetLink::NetLink() : - m_socket(NULL) -{ - m_socket = nl_socket_alloc(); - if (!m_socket) - { - SWSS_LOG_ERROR("Unable to allocated netlink socket"); - throw system_error(make_error_code(errc::address_not_available), - "Unable to allocated netlink socket"); - } - - nl_socket_disable_seq_check(m_socket); - nl_socket_modify_cb(m_socket, NL_CB_VALID, NL_CB_CUSTOM, onNetlinkMsg, this); - - int err = nl_connect(m_socket, NETLINK_ROUTE); - if (err < 0) - { - SWSS_LOG_ERROR("Unable to connect netlink socket: %s", nl_geterror(err)); - nl_socket_free(m_socket); - m_socket = NULL; - throw system_error(make_error_code(errc::address_not_available), - "Unable to connect netlink socket"); - } -} - -NetLink::~NetLink() -{ - if (m_socket != NULL) - { - nl_close(m_socket); - nl_socket_free(m_socket); - } -} - -void NetLink::registerGroup(int rtnlGroup) -{ - int err = nl_socket_add_membership(m_socket, rtnlGroup); - if (err < 0) - { - SWSS_LOG_ERROR("Unable to register to group %d: %s", rtnlGroup, - nl_geterror(err)); - throw system_error(make_error_code(errc::address_not_available), - "Unable to register group"); - } -} - -void NetLink::dumpRequest(int rtmGetCommand) -{ - int err = nl_rtgen_request(m_socket, rtmGetCommand, AF_UNSPEC, NLM_F_DUMP); - if (err < 0) - { - SWSS_LOG_ERROR("Unable to request dump on group %d: %s", rtmGetCommand, - nl_geterror(err)); - throw system_error(make_error_code(errc::address_not_available), - "Unable to request dump"); - } -} - -void NetLink::addFd(fd_set *fd) -{ - FD_SET(nl_socket_get_fd(m_socket), fd); -} - -bool NetLink::isMe(fd_set *fd) -{ - return FD_ISSET(nl_socket_get_fd(m_socket), fd); -} - -int NetLink::readCache() -{ - return NODATA; -} - -void NetLink::readMe() -{ - nl_recvmsgs_default(m_socket); -} - -int NetLink::onNetlinkMsg(struct nl_msg *msg, void *arg) -{ - NetDispatcher::getInstance().onNetlinkMessage(msg); - return NL_OK; -} diff --git a/common/netlink.h b/common/netlink.h deleted file mode 100644 index 4ff1614e94..0000000000 --- a/common/netlink.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __NETLINK__ -#define __NETLINK__ - -#include -#include -#include "selectable.h" - -namespace swss { - -class NetLink : public Selectable { -public: - NetLink(); - virtual ~NetLink(); - - void registerGroup(int rtnlGroup); - void dumpRequest(int rtmGetCommand); - - virtual void addFd(fd_set *fd); - virtual bool isMe(fd_set *fd); - virtual int readCache(); - virtual void readMe(); - -private: - static int onNetlinkMsg(struct nl_msg *msg, void *arg); - - nl_sock *m_socket; -}; - -} - -#endif diff --git a/common/netmsg.h b/common/netmsg.h deleted file mode 100644 index f77d881895..0000000000 --- a/common/netmsg.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __NETMSG__ -#define __NETMSG__ - -#include -#include -#include -#include -#include - -namespace swss { - -class NetMsg { -public: - /* Called by NetDispatcher when netmsg matches filters */ - virtual void onMsg(int nlmsg_type, struct nl_object *obj) = 0; -}; - -} - -#endif diff --git a/common/producertable.cpp b/common/producertable.cpp deleted file mode 100644 index 603c298c5a..0000000000 --- a/common/producertable.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "common/redisreply.h" -#include "common/producertable.h" -#include "common/json.h" -#include -#include - -using namespace std; - -namespace swss { - -ProducerTable::ProducerTable(DBConnector *db, string tableName) : - Table(db, tableName) -{ -} - -void ProducerTable::enqueueDbChange(string key, string value, string op) -{ - string lpush_value; - string lpush_key("LPUSH "); - string lpush_op = lpush_key; - char *temp; - int len; - - lpush_key += getKeyQueueTableName(); - lpush_key += " "; - lpush_key += key; - enqueue(lpush_key, REDIS_REPLY_INTEGER); - - len = redisFormatCommand(&temp, "LPUSH %s %s", getValueQueueTableName().c_str(), value.c_str()); - lpush_value = string(temp, len); - free(temp); - enqueue(lpush_value, REDIS_REPLY_INTEGER, true); - - lpush_op += getOpQueueTableName(); - lpush_op += " "; - lpush_op += op; - enqueue(lpush_op, REDIS_REPLY_INTEGER); - - string publish("PUBLISH "); - publish += getChannelTableName(); - publish += " G"; - enqueue(publish, REDIS_REPLY_INTEGER); -} - -void ProducerTable::set(string key, vector &values, string op) -{ - multi(); - for (FieldValueTuple &i : values) - enqueue(formatHSET(getKeyName(key), fvField(i), fvValue(i)), - REDIS_REPLY_INTEGER, true); - - enqueueDbChange(key, JSon::buildJson(values), op); - exec(); -} - -void ProducerTable::del(string key, string op) -{ - string del("DEL "); - del += getKeyName(key); - - multi(); - - enqueueDbChange(key, "{}", op); - enqueue(del, REDIS_REPLY_INTEGER); - - exec(); -} - -} diff --git a/common/producertable.h b/common/producertable.h deleted file mode 100644 index 7f7a870ce5..0000000000 --- a/common/producertable.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __PRODUCERTABLE__ -#define __PRODUCERTABLE__ - -#include -#include - -#include -#include "dbconnector.h" -#include "table.h" -#include "scheme.h" - -namespace swss { - -class ProducerTable : public Table -{ -public: - ProducerTable(DBConnector *db, std::string tableName); - - /* Implements set() and del() commands using notification messages */ - virtual void set(std::string key, std::vector &values, - std::string op = SET_COMMAND); - virtual void del(std::string key, std::string op = DEL_COMMAND); - -private: - /* Disable copy-constructor and operator = */ - ProducerTable(const ProducerTable &other); - ProducerTable & operator = (const ProducerTable &other); - - void enqueueDbChange(std::string key, std::string value, std::string op); -}; - -} - -#endif diff --git a/common/redisreply.cpp b/common/redisreply.cpp deleted file mode 100644 index 07776ee8a4..0000000000 --- a/common/redisreply.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include - -#include "common/logger.h" -#include "common/redisreply.h" - -using namespace std; - -namespace swss { - -RedisReply::RedisReply(DBConnector *db, string command, int exepectedType, bool isFormatted) -{ - if (isFormatted) - { - redisAppendFormattedCommand(db->getContext(), command.c_str(), command.length()); - redisGetReply(db->getContext(), (void**)&m_reply); - } else - { - m_reply = (redisReply *)redisCommand(db->getContext(), command.c_str()); - } - - if (!m_reply) - throw system_error(make_error_code(errc::not_enough_memory), - "Memory exception"); - - if (m_reply->type != exepectedType) { - SWSS_LOG_INFO("Except to get redis type %d got type %d\n", - exepectedType, m_reply->type); - freeReplyObject(m_reply); - m_reply = NULL; /* Some compilers call destructor in this case */ - throw system_error(make_error_code(errc::io_error), - "Wrong expected type of result"); - } -} - -RedisReply::RedisReply(redisReply *reply) : - m_reply(reply) -{ -} - -RedisReply::~RedisReply() -{ - if (m_reply) - freeReplyObject(m_reply); -} - -redisReply *RedisReply::getContext() -{ - return m_reply; -} - -void RedisReply::checkStatus(char *status) -{ - if (strcmp(m_reply->str, status) != 0) - throw system_error(make_error_code(errc::io_error), - "Invalid return code"); -} - -void RedisReply::checkStatusOK() -{ - checkStatus("OK"); -} - -void RedisReply::checkStatusQueued() -{ - checkStatus("QUEUED"); -} - -} diff --git a/common/redisreply.h b/common/redisreply.h deleted file mode 100644 index aacdbaa65f..0000000000 --- a/common/redisreply.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __REDISREPLY__ -#define __REDISREPLY__ - -#include -#include "dbconnector.h" - -namespace swss { - -class RedisReply -{ -public: - /* - * Send a new command to redis and waits for reply - * The reply must be one of REDIS_REPLY_* format (e.g. REDIS_REPLY_STATUS, - * REDIS_REPLY_INTEGER, ...) - * isFormatted - Set to true if the command is already formatted in redis - * protocol - */ - RedisReply(DBConnector *db, std::string command, int exepectedType, - bool isFormatted = false); - - /* auto_ptr for native structue (Free the memory on destructor) */ - RedisReply(redisReply *reply); - - /* Free the resources */ - ~RedisReply(); - - /* Return the actual reply object */ - redisReply *getContext(); - - /* Check that the staus is OK, throw exception otherwise */ - void checkStatusOK(); - - /* Check that the staus is QUEUED, throw exception otherwise */ - void checkStatusQueued(); - -private: - void checkStatus(char *status); - - redisReply *m_reply; -}; - -} -#endif diff --git a/common/scheme.h b/common/scheme.h deleted file mode 100644 index 30fb74de93..0000000000 --- a/common/scheme.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __SCHEME__ -#define __SCHEME__ - -namespace swss { - -#define APPL_DB 0 -#define ASIC_DB 1 - -#define APP_PORT_TABLE_NAME "PORT_TABLE" -#define APP_VLAN_TABLE_NAME "VLAN_TABLE" -#define APP_LAG_TABLE_NAME "LAG_TABLE" -#define APP_INTF_TABLE_NAME "INTF_TABLE" -#define APP_NEIGH_TABLE_NAME "NEIGH_TABLE" -#define APP_ROUTE_TABLE_NAME "ROUTE_TABLE" - -#define IPV4_NAME "IPv4" -#define IPV6_NAME "IPv6" - -#define SET_COMMAND "SET" -#define DEL_COMMAND "DEL" - -} - -#endif diff --git a/common/select.cpp b/common/select.cpp deleted file mode 100644 index 0c43123082..0000000000 --- a/common/select.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "common/selectable.h" -#include "common/select.h" -#include -#include -#include - -using namespace std; - -namespace swss { - -void Select::addSelectable(Selectable *c) -{ - m_objects.push_back(c); -} - -void Select::addFd(int fd) -{ - m_fds.push_back(fd); -} - -int Select::select(Selectable **c, int *fd, unsigned int timeout) -{ - struct timeval t = {0, (suseconds_t)(timeout)*1000}; - struct timeval *pTimeout = NULL; - fd_set fs; - int err; - - FD_ZERO(&fs); - *c = NULL; - *fd = 0; - if (timeout != std::numeric_limits::max()) - pTimeout = &t; - - /* Checking caching from reader */ - for (Selectable *i : m_objects) - { - err = i->readCache(); - if (err == Selectable::ERROR) - return Select::ERROR; - else if (err == Selectable::DATA) { - *c = i; - return Select::OBJECT; - } - /* else, timeout = no data */ - - i->addFd(&fs); - } - - for (int fd : m_fds) - { - FD_SET(fd, &fs); - } - - err = ::select(FD_SETSIZE, &fs, NULL, NULL, pTimeout); - if (err < 0) - return Select::ERROR; - if (err == 0) - return Select::TIMEOUT; - - /* Check other consumer-table */ - for (Selectable *i : m_objects) - if (i->isMe(&fs)) - { - i->readMe(); - *c = i; - return Select::OBJECT; - } - - /* Check other FDs */ - for (int f : m_fds) - if (FD_ISSET(f, &fs)) - { - *fd = f; - return Select::FD; - } - - /* Shouldn't reach here */ - return Select::ERROR; -} - -}; diff --git a/common/select.h b/common/select.h deleted file mode 100644 index 76617cbecb..0000000000 --- a/common/select.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __CONSUMERSELECT__ -#define __CONSUMERSELECT__ - -#include -#include -#include -#include -#include "selectable.h" - -namespace swss { - -class Select -{ -public: - /* Add object for select */ - void addSelectable(Selectable *c); - - /* Add file-descriptor for select */ - void addFd(int fd); - - /* - * Wait until data will arrived, returns the object on which select() - * was signaled. - */ - enum { - OBJECT = 0, - FD = 1, - ERROR = 2, - TIMEOUT = 3 - }; - int select(Selectable **c, int *fd, - unsigned int timeout = std::numeric_limits::max()); - -private: - /* Create a new redisContext, SELECT DB and SUBSRIBE */ - void subsribe(); - - std::vector m_objects; - std::vector m_fds; -}; - -} - -#endif diff --git a/common/selectable.h b/common/selectable.h deleted file mode 100644 index b269ce4d17..0000000000 --- a/common/selectable.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __SELECT__ -#define __SELECT__ - -#include -#include -#include -#include -#include "dbconnector.h" -#include "table.h" - -namespace swss { - -class Selectable -{ -public: - virtual ~Selectable() {}; - - enum { - DATA = 0, - ERROR = 1, - NODATA = 2 - }; - - /* Implements FD_SET */ - virtual void addFd(fd_set *fd) = 0; - virtual bool isMe(fd_set *fd) = 0; - - /* Read and empty socket caching (if exists) */ - virtual int readCache() = 0; - - /* Read a message from the socket */ - virtual void readMe() = 0; -}; - -} - -#endif diff --git a/common/table.cpp b/common/table.cpp deleted file mode 100644 index 1fccae1791..0000000000 --- a/common/table.cpp +++ /dev/null @@ -1,232 +0,0 @@ -#include -#include - -#include "common/table.h" -#include "common/logger.h" -#include "common/redisreply.h" - -using namespace std; - -namespace swss { - -Table::Table(DBConnector *db, string tableName) : - m_db(db), - m_tableName(tableName) -{ -} - -string Table::getKeyName(string key) -{ - return m_tableName + ':' + key; -} - -string Table::getKeyQueueTableName() -{ - return m_tableName + "_KEY_QUEUE"; -} - -string Table::getValueQueueTableName() -{ - return m_tableName + "_VALUE_QUEUE"; -} - -string Table::getOpQueueTableName() -{ - return m_tableName + "_OP_QUEUE"; -} - -string Table::getChannelTableName() -{ - return m_tableName + "_CHANNEL"; -} - -bool Table::get(std::string key, vector &values) -{ - string hgetall_key("HGETALL "); - hgetall_key += getKeyName(key); - - RedisReply r(m_db, hgetall_key, REDIS_REPLY_ARRAY); - redisReply *reply = r.getContext(); - values.clear(); - - if (!reply->elements) - return false; - - if (reply->elements & 1) - throw system_error(make_error_code(errc::address_not_available), - "Unable to connect netlink socket"); - - for (unsigned int i = 0; i < reply->elements; i += 2) - values.push_back(make_tuple(reply->element[i]->str, - reply->element[i + 1]->str)); - - return true; -} - -void Table::set(std::string key, std::vector &values, - std::string /*op*/) -{ - /* We are doing transaction for AON (All or nothing) */ - multi(); - for (FieldValueTuple &i : values) - enqueue(formatHSET(getKeyName(key), fvField(i), fvValue(i)), - REDIS_REPLY_INTEGER, true); - - exec(); -} - -void Table::del(std::string key, std::string /* op */) -{ - RedisReply r(m_db, string("DEL ") + getKeyName(key), REDIS_REPLY_INTEGER); - if (r.getContext()->type != REDIS_REPLY_INTEGER) - throw system_error(make_error_code(errc::io_error), - "DEL operation failed"); -} - -bool Table::getField(std::string key, std::string field, std::string &value) -{ - std::string hget = formatHGET(getKeyName(key).c_str(), - field.c_str()); - - RedisReply r(m_db, hget, REDIS_REPLY_INTEGER); - - if (r.getContext()->type != REDIS_REPLY_STRING) - { - return false; - } - - value = std::string(r.getContext()->str); - - return true; -} - -void Table::setField(std::string key, std::string field, std::string value) -{ - FieldValueTuple entry(field, value); - - std::vector values { entry }; - - set(key, values); -} - -void Table::delField(std::string key, std::string field) -{ - std::string hdel = formatHDEL(getKeyName(key), field); - - RedisReply r(m_db, hdel, REDIS_REPLY_INTEGER); - - if (r.getContext()->type != REDIS_REPLY_INTEGER) - throw system_error(make_error_code(errc::io_error), - "DEL operation failed"); -} - -Table::~Table() -{ -} - -void Table::multi() -{ - while (!m_expectedResults.empty()) - m_expectedResults.pop(); - RedisReply r(m_db, "MULTI", REDIS_REPLY_STATUS); - r.checkStatusOK(); -} - -redisReply *Table::queueResultsFront() -{ - return m_results.front()->getContext(); -} - -void Table::queueResultsPop() -{ - delete m_results.front(); - m_results.pop(); -} - -void Table::exec() -{ - redisReply *reply = (redisReply *)redisCommand(m_db->getContext(), "EXEC"); - unsigned int size = reply->elements; - - try - { - if (reply->type != REDIS_REPLY_ARRAY) - throw system_error(make_error_code(errc::io_error), - "Error in transaction"); - - if (size != m_expectedResults.size()) - throw system_error(make_error_code(errc::io_error), - "Got to different nuber of answers!"); - - while (!m_results.empty()) - queueResultsPop(); - - for (unsigned int i = 0; i < size; i++) - { - int expectedType = m_expectedResults.front(); - m_expectedResults.pop(); - if (expectedType != reply->element[i]->type) - { - SWSS_LOG_INFO("Except to get redis type %d got type %d\n", - expectedType, reply->element[i]->type); - throw system_error(make_error_code(errc::io_error), - "Got unexpected result"); - } - } - } - catch (...) { - freeReplyObject(reply); - throw; - } - - for (unsigned int i = 0; i < size; i++) - m_results.push(new RedisReply(reply->element[i])); - - /* Free only the array memory */ - free(reply->element); - free(reply); -} - -void Table::enqueue(std::string command, int exepectedResult, bool isFormatted) -{ - RedisReply r(m_db, command, REDIS_REPLY_STATUS, isFormatted); - r.checkStatusQueued(); - m_expectedResults.push(exepectedResult); -} - -string Table::formatHSET(const string& key, const string& field, - const string& value) -{ - char *temp; - int len = redisFormatCommand(&temp, "HSET %s %s %s", - key.c_str(), - field.c_str(), - value.c_str()); - string hset(temp, len); - free(temp); - return hset; -} - -string Table::formatHGET(const string& key, const string& field) -{ - char *temp; - int len = redisFormatCommand(&temp, "HGET %s %s", - key.c_str(), - field.c_str()); - string hget(temp, len); - free(temp); - return hget; -} - -string Table::formatHDEL(const string& key, const string& field) -{ - char *temp; - int len = redisFormatCommand(&temp, "HDEL %s %s", - key.c_str(), - field.c_str()); - string hdel(temp, len); - free(temp); - return hdel; -} - -} diff --git a/common/table.h b/common/table.h deleted file mode 100644 index d079341ff2..0000000000 --- a/common/table.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef __TABLE__ -#define __TABLE__ - -#include -#include -#include -#include "hiredis/hiredis.h" -#include "dbconnector.h" -#include "redisreply.h" -#include "scheme.h" - -namespace swss { - -typedef std::tuple FieldValueTuple; -#define fvField std::get<0> -#define fvValue std::get<1> -typedef std::tuple > KeyOpFieldsValuesTuple; -#define kfvKey std::get<0> -#define kfvOp std::get<1> -#define kfvFieldsValues std::get<2> - -class Table { -public: - Table(DBConnector *db, std::string tableName); - - /* Read a value from the DB directly */ - /* Returns false if the key doesn't exists */ - bool get(std::string key, std::vector &values); - - /* Set an entry in the DB directly (op not in used) */ - virtual void set(std::string key, std::vector &values, - std::string op = ""); - /* Delete an entry in the DB directly (op not in used) */ - virtual void del(std::string key, std::string op = ""); - - bool getField(std::string key, std::string field, std::string &value); - void setField(std::string key, std::string field, std::string value); - void delField(std::string key, std::string field); - - virtual ~Table(); - -protected: - /* Return the actual key name as a comibation of tableName:key */ - std::string getKeyName(std::string key); - - std::string getKeyQueueTableName(); - std::string getValueQueueTableName(); - std::string getOpQueueTableName(); - std::string getChannelTableName(); - - /* Start a transaction */ - void multi(); - /* Execute a transaction and get results */ - void exec(); - - /* Send a command within a transaction */ - void enqueue(std::string command, int exepectedResult, bool isFormatted = false); - redisReply* queueResultsFront(); - void queueResultsPop(); - - /* Format HSET key field value command */ - static std::string formatHSET(const std::string &key, - const std::string &field, - const std::string &value); - - /* Format HGET key field command */ - static std::string formatHGET(const std::string& key, - const std::string& field); - - /* Format HDEL key field command */ - static std::string formatHDEL(const std::string& key, - const std::string& field); - - DBConnector *m_db; - std::string m_tableName; - - /* Remember the expected results for the transaction */ - std::queue m_expectedResults; - std::queue m_results; -}; - -} - -#endif diff --git a/configure.ac b/configure.ac index 7cdb456f26..7559689136 100644 --- a/configure.ac +++ b/configure.ac @@ -23,18 +23,6 @@ esac],[debug=false]) AM_CONDITIONAL(DEBUG, test x$debug = xtrue) -AC_ARG_WITH(gtest, -[ --with-gtest= Compiles tests using the location of google tests], -AC_MSG_NOTICE(Using gtest path from:$with_gtest), with_gtest="none") - -GTEST_PATH= -if test "x$with_gtest" != xnone; then -GTEST_PATH=$with_gtest -fi -AC_SUBST(GTEST_PATH) -AM_CONDITIONAL(TESTS, test "x$with_gtest" != xnone) - - AC_ARG_WITH(fpm, [ --with-fpm= Compiles using qauggas fpm library], AC_MSG_NOTICE(Using fpmi path from:$with_fpm), with_fpm="none") @@ -47,14 +35,12 @@ AC_SUBST(FPM_PATH) AM_CONDITIONAL(FPM, test "x$with_fpm" != xnone) -CFLAGS_COMMON="-std=c++11 -Wall -fPIC -Wno-write-strings -I/usr/include/libnl3" +CFLAGS_COMMON="-std=c++11 -Wall -fPIC -Wno-write-strings -I/usr/include/libnl3 -I/usr/include/swss" AC_SUBST(CFLAGS_COMMON) AC_CONFIG_FILES([ Makefile - common/Makefile orchagent/Makefile - tests/Makefile fpmsyncd/Makefile neighsyncd/Makefile intfsyncd/Makefile diff --git a/debian/control b/debian/control index 58d120ed47..f2bee6994a 100644 --- a/debian/control +++ b/debian/control @@ -9,15 +9,3 @@ Package: swss Architecture: any Depends: ${shlibs:Depends} Description: This package contains Switch State Service for SONiC project. - -Package: libswsscommon -Architecture: any -Section: libs -Description: Tihs package contains Switch State Service common library. - -Package: libswsscommon-dev -Architecture: any -Depends: libswsscommon (= ${binary:Version}) -Section: libdevel -Description: This package contains development files for Switch State Service. - diff --git a/debian/libswsscommon-dev.dirs b/debian/libswsscommon-dev.dirs deleted file mode 100644 index 44188162ec..0000000000 --- a/debian/libswsscommon-dev.dirs +++ /dev/null @@ -1,2 +0,0 @@ -usr/lib -usr/include diff --git a/debian/libswsscommon-dev.install b/debian/libswsscommon-dev.install deleted file mode 100644 index 173abf58e7..0000000000 --- a/debian/libswsscommon-dev.install +++ /dev/null @@ -1 +0,0 @@ -common/*.h usr/include/swss diff --git a/debian/libswsscommon-dev.links b/debian/libswsscommon-dev.links deleted file mode 100755 index 7fc4c02c29..0000000000 --- a/debian/libswsscommon-dev.links +++ /dev/null @@ -1,2 +0,0 @@ -#! /usr/bin/dh-exec -/usr/lib/${DEB_HOST_MULTIARCH}/libswsscommon.so.0 /usr/lib/${DEB_HOST_MULTIARCH}/libswsscommon.so diff --git a/debian/libswsscommon.dirs b/debian/libswsscommon.dirs deleted file mode 100644 index 68457717bd..0000000000 --- a/debian/libswsscommon.dirs +++ /dev/null @@ -1 +0,0 @@ -usr/lib diff --git a/debian/libswsscommon.install b/debian/libswsscommon.install deleted file mode 100644 index 3ddde58419..0000000000 --- a/debian/libswsscommon.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/*/lib*.so.* diff --git a/debian/swss.dirs b/debian/swss.dirs deleted file mode 100644 index e772481755..0000000000 --- a/debian/swss.dirs +++ /dev/null @@ -1 +0,0 @@ -usr/bin diff --git a/debian/swss.install b/debian/swss.install deleted file mode 100644 index 1df36c612f..0000000000 --- a/debian/swss.install +++ /dev/null @@ -1 +0,0 @@ -usr/bin/* diff --git a/fpmsyncd/Makefile.am b/fpmsyncd/Makefile.am index 54b7b76d35..579c2d0135 100644 --- a/fpmsyncd/Makefile.am +++ b/fpmsyncd/Makefile.am @@ -12,6 +12,5 @@ fpmsyncd_SOURCES = fpmsyncd.cpp fpmlink.cpp routesync.cpp fpmsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) fpmsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -fpmsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis \ - -L$(top_srcdir)/common -lswsscommon +fpmsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon diff --git a/fpmsyncd/fpmlink.cpp b/fpmsyncd/fpmlink.cpp index 39c226b894..a111ff2c4e 100644 --- a/fpmsyncd/fpmlink.cpp +++ b/fpmsyncd/fpmlink.cpp @@ -1,9 +1,9 @@ #include #include #include -#include "common/logger.h" -#include "common/netmsg.h" -#include "common/netdispatcher.h" +#include "logger.h" +#include "netmsg.h" +#include "netdispatcher.h" #include "fpmsyncd/fpmlink.h" using namespace swss; diff --git a/fpmsyncd/fpmlink.h b/fpmsyncd/fpmlink.h index f1ab87a269..ce682041ab 100644 --- a/fpmsyncd/fpmlink.h +++ b/fpmsyncd/fpmlink.h @@ -11,7 +11,7 @@ #include #include -#include "common/selectable.h" +#include "selectable.h" #include "fpm/fpm.h" namespace swss { diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index f94a07a717..8308b1df7a 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -1,7 +1,7 @@ #include -#include "common/logger.h" -#include "common/select.h" -#include "common/netdispatcher.h" +#include "logger.h" +#include "select.h" +#include "netdispatcher.h" #include "fpmsyncd/fpmlink.h" #include "fpmsyncd/routesync.h" diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index b8403ec80d..8cdb05e826 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -1,13 +1,13 @@ #include #include #include -#include "common/logger.h" -#include "common/select.h" -#include "common/netmsg.h" -#include "common/ipprefix.h" -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/scheme.h" +#include "logger.h" +#include "select.h" +#include "netmsg.h" +#include "ipprefix.h" +#include "dbconnector.h" +#include "producertable.h" +#include "scheme.h" #include "fpmsyncd/fpmlink.h" #include "fpmsyncd/routesync.h" diff --git a/fpmsyncd/routesync.h b/fpmsyncd/routesync.h index 118935bb77..ba30f681b1 100644 --- a/fpmsyncd/routesync.h +++ b/fpmsyncd/routesync.h @@ -1,9 +1,9 @@ #ifndef __ROUTESYNC__ #define __ROUTESYNC__ -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "netmsg.h" namespace swss { diff --git a/intfsyncd/Makefile.am b/intfsyncd/Makefile.am index 8b7c3b49b2..d79a2646a7 100644 --- a/intfsyncd/Makefile.am +++ b/intfsyncd/Makefile.am @@ -12,6 +12,5 @@ intfsyncd_SOURCES = intfsyncd.cpp intfsync.cpp intfsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) intfsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -intfsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis \ - -L$(top_srcdir)/common -lswsscommon +intfsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon diff --git a/intfsyncd/intfsync.cpp b/intfsyncd/intfsync.cpp index cf4566dc19..d9e3bc480a 100644 --- a/intfsyncd/intfsync.cpp +++ b/intfsyncd/intfsync.cpp @@ -3,12 +3,12 @@ #include #include #include -#include "common/logger.h" -#include "common/netmsg.h" -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/scheme.h" -#include "common/linkcache.h" +#include "logger.h" +#include "netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "scheme.h" +#include "linkcache.h" #include "intfsyncd/intfsync.h" using namespace std; diff --git a/intfsyncd/intfsync.h b/intfsyncd/intfsync.h index 364fb78c75..ebafee6db8 100644 --- a/intfsyncd/intfsync.h +++ b/intfsyncd/intfsync.h @@ -1,9 +1,9 @@ #ifndef __INTFSYNC__ #define __INTFSYNC__ -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "netmsg.h" namespace swss { diff --git a/intfsyncd/intfsyncd.cpp b/intfsyncd/intfsyncd.cpp index 53ccb9cec2..9b4e553a38 100644 --- a/intfsyncd/intfsyncd.cpp +++ b/intfsyncd/intfsyncd.cpp @@ -1,8 +1,8 @@ #include -#include "common/logger.h" -#include "common/select.h" -#include "common/netdispatcher.h" -#include "common/netlink.h" +#include "logger.h" +#include "select.h" +#include "netdispatcher.h" +#include "netlink.h" #include "intfsyncd/intfsync.h" using namespace std; diff --git a/neighsyncd/Makefile.am b/neighsyncd/Makefile.am index de50384770..4c02526ebb 100644 --- a/neighsyncd/Makefile.am +++ b/neighsyncd/Makefile.am @@ -12,6 +12,5 @@ neighsyncd_SOURCES = neighsyncd.cpp neighsync.cpp neighsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) neighsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -neighsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis \ - -L$(top_srcdir)/common -lswsscommon +neighsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon diff --git a/neighsyncd/neighsync.cpp b/neighsyncd/neighsync.cpp index e4364ce03f..31d2cbbb19 100644 --- a/neighsyncd/neighsync.cpp +++ b/neighsyncd/neighsync.cpp @@ -3,12 +3,12 @@ #include #include #include -#include "common/logger.h" -#include "common/netmsg.h" -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/scheme.h" -#include "common/linkcache.h" +#include "logger.h" +#include "netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "scheme.h" +#include "linkcache.h" #include "neighsyncd/neighsync.h" using namespace std; diff --git a/neighsyncd/neighsync.h b/neighsyncd/neighsync.h index 999977d917..9578a5edf6 100644 --- a/neighsyncd/neighsync.h +++ b/neighsyncd/neighsync.h @@ -1,9 +1,9 @@ #ifndef __NEIGHSYNC__ #define __NEIGHSYNC__ -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "netmsg.h" namespace swss { diff --git a/neighsyncd/neighsyncd.cpp b/neighsyncd/neighsyncd.cpp index 603edba92f..7a39152f11 100644 --- a/neighsyncd/neighsyncd.cpp +++ b/neighsyncd/neighsyncd.cpp @@ -1,8 +1,8 @@ #include -#include "common/logger.h" -#include "common/select.h" -#include "common/netdispatcher.h" -#include "common/netlink.h" +#include "logger.h" +#include "select.h" +#include "netdispatcher.h" +#include "netlink.h" #include "neighsyncd/neighsync.h" using namespace std; diff --git a/orchagent/Makefile.am b/orchagent/Makefile.am index 317367abcf..c227ee71d0 100644 --- a/orchagent/Makefile.am +++ b/orchagent/Makefile.am @@ -14,10 +14,9 @@ orchagent_SOURCES = main.cpp orchdaemon.cpp orch.cpp routeorch.cpp neighorch.cpp orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -orchagent_LDADD = -lnl-3 -lnl-route-3 -lpthread -lhiredis -lsai\ - -L$(top_srcdir)/common -lswsscommon +orchagent_LDADD = -lnl-3 -lnl-route-3 -lpthread -lhiredis -lsairedis -lswsscommon routeresync_SOURCES = routeresync.cpp routeresync_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) routeresync_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -routeresync_LDADD = -L$(top_srcdir)/common -lswsscommon +routeresync_LDADD = -lswsscommon diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 67f6e87393..a4ff2c662b 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -1,7 +1,7 @@ #include "intfsorch.h" -#include "common/ipprefix.h" -#include "common/logger.h" +#include "ipprefix.h" +#include "logger.h" #include #include diff --git a/orchagent/intfsorch.h b/orchagent/intfsorch.h index c3b3e0c40a..4b7a3ada43 100644 --- a/orchagent/intfsorch.h +++ b/orchagent/intfsorch.h @@ -4,8 +4,8 @@ #include "orch.h" #include "portsorch.h" -#include "common/ipaddress.h" -#include "common/macaddress.h" +#include "ipaddress.h" +#include "macaddress.h" #include diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 11f39cf717..8492cd45b6 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -1,6 +1,6 @@ #include "orchdaemon.h" -#include "common/logger.h" +#include "logger.h" extern "C" { #include "sai.h" diff --git a/orchagent/neighorch.cpp b/orchagent/neighorch.cpp index 744ccc05be..83dcde6c4e 100644 --- a/orchagent/neighorch.cpp +++ b/orchagent/neighorch.cpp @@ -1,6 +1,6 @@ #include "neighorch.h" -#include "common/logger.h" +#include "logger.h" extern sai_neighbor_api_t* sai_neighbor_api; extern sai_next_hop_api_t* sai_next_hop_api; diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index c5eeba5378..2b2c59d6b1 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -1,6 +1,6 @@ #include "orch.h" -#include "common/logger.h" +#include "logger.h" Orch::Orch(DBConnector *db, string tableName) : m_db(db), m_name(tableName) diff --git a/orchagent/orch.h b/orchagent/orch.h index 24b9c4b4fa..0209771354 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -6,9 +6,9 @@ extern "C" { #include "saistatus.h" } -#include "common/dbconnector.h" -#include "common/consumertable.h" -#include "common/producertable.h" +#include "dbconnector.h" +#include "consumertable.h" +#include "producertable.h" #include diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index b400480bfb..a3bf3ee790 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -2,7 +2,7 @@ #include "routeorch.h" #include "neighorch.h" -#include "common/logger.h" +#include "logger.h" #include diff --git a/orchagent/orchdaemon.h b/orchagent/orchdaemon.h index 0c50041941..7656021515 100644 --- a/orchagent/orchdaemon.h +++ b/orchagent/orchdaemon.h @@ -1,10 +1,10 @@ #ifndef SWSS_ORCHDAEMON_H #define SWSS_ORCHDAEMON_H -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/consumertable.h" -#include "common/select.h" +#include "dbconnector.h" +#include "producertable.h" +#include "consumertable.h" +#include "select.h" #include "portsorch.h" #include "intfsorch.h" diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index ec1172dae7..93fbf76415 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -8,7 +8,7 @@ #include "net/if.h" -#include "common/logger.h" +#include "logger.h" extern sai_switch_api_t *sai_switch_api; extern sai_vlan_api_t *sai_vlan_api; diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 40ea5103c0..0f1394b3a3 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -4,7 +4,7 @@ #include "orch.h" #include "port.h" -#include "common/macaddress.h" +#include "macaddress.h" #include diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 7153df7728..e05dae8cb7 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1,6 +1,6 @@ #include "routeorch.h" -#include "common/logger.h" +#include "logger.h" extern sai_route_api_t* sai_route_api; extern sai_next_hop_group_api_t* sai_next_hop_group_api; diff --git a/orchagent/routeorch.h b/orchagent/routeorch.h index 737194ee8f..550accd4b4 100644 --- a/orchagent/routeorch.h +++ b/orchagent/routeorch.h @@ -4,9 +4,9 @@ #include "orch.h" #include "intfsorch.h" -#include "common/ipaddress.h" -#include "common/ipaddresses.h" -#include "common/ipprefix.h" +#include "ipaddress.h" +#include "ipaddresses.h" +#include "ipprefix.h" #include diff --git a/orchagent/routeresync.cpp b/orchagent/routeresync.cpp index d1729730b8..f4845850e0 100644 --- a/orchagent/routeresync.cpp +++ b/orchagent/routeresync.cpp @@ -1,8 +1,8 @@ #include #include #include -#include "common/dbconnector.h" -#include "common/producertable.h" +#include "dbconnector.h" +#include "producertable.h" using namespace std; using namespace swss; diff --git a/portsyncd/Makefile.am b/portsyncd/Makefile.am index 5330ec125f..547583316c 100644 --- a/portsyncd/Makefile.am +++ b/portsyncd/Makefile.am @@ -12,6 +12,5 @@ portsyncd_SOURCES = portsyncd.cpp linksync.cpp portsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) portsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -portsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis \ - -L$(top_srcdir)/common -lswsscommon +portsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon diff --git a/portsyncd/linksync.cpp b/portsyncd/linksync.cpp index fd9aeb9c78..85759b3e8d 100644 --- a/portsyncd/linksync.cpp +++ b/portsyncd/linksync.cpp @@ -4,12 +4,12 @@ #include #include #include -#include "common/logger.h" -#include "common/netmsg.h" -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/scheme.h" -#include "common/linkcache.h" +#include "logger.h" +#include "netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "scheme.h" +#include "linkcache.h" #include "portsyncd/linksync.h" #include diff --git a/portsyncd/linksync.h b/portsyncd/linksync.h index e3578f95f9..1a22ab7de6 100644 --- a/portsyncd/linksync.h +++ b/portsyncd/linksync.h @@ -1,9 +1,9 @@ #ifndef __LINKSYNC__ #define __LINKSYNC__ -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/netmsg.h" +#include "dbconnector.h" +#include "producertable.h" +#include "netmsg.h" namespace swss { diff --git a/portsyncd/portsyncd.cpp b/portsyncd/portsyncd.cpp index 9b92fb2750..240f20c84e 100644 --- a/portsyncd/portsyncd.cpp +++ b/portsyncd/portsyncd.cpp @@ -1,8 +1,8 @@ -#include "common/dbconnector.h" -#include "common/select.h" -#include "common/netdispatcher.h" -#include "common/netlink.h" -#include "common/producertable.h" +#include "dbconnector.h" +#include "select.h" +#include "netdispatcher.h" +#include "netlink.h" +#include "producertable.h" #include "portsyncd/linksync.h" #include diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index 7a59093746..0000000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -INCLUDES = -I $(top_srcdir) - -bin_PROGRAMS = tests - -if DEBUG -DBGFLAGS = -ggdb -DDEBUG -else -DBGFLAGS = -g -endif - -CFLAGS_GTEST = -I $(GTEST_PATH)/googletest/include -LDADD_GTEST = $(GTEST_PATH)/build/googletest/libgtest_main.a \ - $(GTEST_PATH)/build/googletest/libgtest.a - -tests_SOURCES = redis_ut.cpp - -tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) -tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) -tests_LDADD = -lnl-genl-3 -lhiredis -lhiredis -lpthread \ - -L$(top_srcdir)/common -lswsscommon $(LDADD_GTEST) - diff --git a/tests/redis_ut.cpp b/tests/redis_ut.cpp deleted file mode 100644 index 51cdca934c..0000000000 --- a/tests/redis_ut.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include "common/dbconnector.h" -#include "common/producertable.h" -#include "common/consumertable.h" -#include "common/select.h" -#include -#include -#include -#include -#include "gtest/gtest.h" - -using namespace std; -using namespace swss; - -#define TEST_VIEW (7) -#define NUMBER_OF_THREADS (64) // Spawning more than 256 threads causes libc++ to except -#define NUMBER_OF_OPS (1000) -#define MAX_FIELDS_DIV (30) // Testing up to 30 fields objects -#define PRINT_SKIP (10) // Print + for Producer and - for Consumer for every 100 ops - -int getMaxFields(int i) -{ - return (i/MAX_FIELDS_DIV) + 1; -} - -string key(int i) -{ - return string("key") + to_string(i); -} - -string field(int i) -{ - return string("field") + to_string(i); -} - -string value(int i) -{ - return string("value") + to_string(i); -} - -bool IsDigit(char ch) -{ - return (ch >= '0') && (ch <= '9'); -} - -int readNumberAtEOL(const string& str) -{ - auto pos = find_if(str.begin(), str.end(), IsDigit); - istringstream is(str.substr(pos - str.begin())); - int ret; - - is >> ret; - return ret; -} - -void validateFields(const string& key, const vector& f) -{ - unsigned int maxNumOfFields = getMaxFields(readNumberAtEOL(key)); - int i = 0; - EXPECT_EQ(maxNumOfFields, f.size()); - - for (auto fv : f) - { - EXPECT_EQ(i, readNumberAtEOL(fvField(fv))); - EXPECT_EQ(i, readNumberAtEOL(fvValue(fv))); - i++; - } -} - -void producerWorker(int index) -{ - string tableName = "UT_REDIS_THREAD_" + to_string(index); - DBConnector db(TEST_VIEW, "localhost", 6379, 0); - ProducerTable p(&db, tableName); - - for (int i = 0; i < NUMBER_OF_OPS; i++) - { - vector fields; - int maxNumOfFields = getMaxFields(i); - for (int j = 0; j < maxNumOfFields; j++) - { - FieldValueTuple t(field(j), value(j)); - fields.push_back(t); - } - if ((i % 100) == 0) - cout << "+" << flush; - - p.set(key(i), fields); - } - - for (int i = 0; i < NUMBER_OF_OPS; i++) - { - p.del(key(i)); - } -} - -void consumerWorker(int index) -{ - string tableName = "UT_REDIS_THREAD_" + to_string(index); - DBConnector db(TEST_VIEW, "localhost", 6379, 0); - ConsumerTable c(&db, tableName); - Select cs; - Selectable *selectcs; - int tmpfd; - int numberOfKeysSet = 0; - int numberOfKeyDeleted = 0; - int ret, i = 0; - KeyOpFieldsValuesTuple kco; - - cs.addSelectable(&c); - while ((ret = cs.select(&selectcs, &tmpfd)) == Select::OBJECT) - { - c.pop(kco); - if (kfvOp(kco) == "SET") - { - numberOfKeysSet++; - validateFields(kfvKey(kco), kfvFieldsValues(kco)); - } else - { - numberOfKeyDeleted++; - } - - if ((i++ % 100) == 0) - cout << "-" << flush; - - if ((numberOfKeysSet == NUMBER_OF_OPS) && - (numberOfKeyDeleted == NUMBER_OF_OPS)) - break; - } - - EXPECT_EQ(ret, Selectable::DATA); -} - -void clearDB() -{ - DBConnector db(TEST_VIEW, "localhost", 6379, 0); - RedisReply r(&db, "FLUSHALL", REDIS_REPLY_STATUS); - r.checkStatusOK(); -} - -TEST(DBConnector, test) -{ - std::thread *producerThreads, *consumerThreads; - producerThreads = new std::thread[NUMBER_OF_THREADS]; - consumerThreads = new std::thread[NUMBER_OF_THREADS]; - - clearDB(); - - cout << "Starting " << NUMBER_OF_THREADS*2 << " producers and consumers on redis" << endl; - /* Starting the consumer before the producer */ - for (int i = 0; i < NUMBER_OF_THREADS; i++) - { - consumerThreads[i] = std::thread(consumerWorker, i); - producerThreads[i] = std::thread(producerWorker, i); - } - - cout << "Done. Waiting for all job to finish " << NUMBER_OF_OPS << " jobs." << endl; - - for (int i = 0; i < NUMBER_OF_THREADS; i++) - { - producerThreads[i].join(); - consumerThreads[i].join(); - } -} - -TEST(DBConnector, multitable) -{ - DBConnector db(TEST_VIEW, "localhost", 6379, 0); - ConsumerTable *consumers[NUMBER_OF_THREADS]; - thread producerThreads[NUMBER_OF_THREADS]; - KeyOpFieldsValuesTuple kco; - Select cs; - int numberOfKeysSet = 0; - int numberOfKeyDeleted = 0; - int ret = 0, i; - - clearDB(); - - cout << "Starting " << NUMBER_OF_THREADS*2 << " producers and consumers on redis, using single thread for consumers and thread per producer" << endl; - - /* Starting the consumer before the producer */ - for (i = 0; i < NUMBER_OF_THREADS; i++) - { - consumers[i] = new ConsumerTable(&db, string("UT_REDIS_THREAD_") + - to_string(i)); - producerThreads[i] = thread(producerWorker, i); - } - - for (i = 0; i < NUMBER_OF_THREADS; i++) - cs.addSelectable(consumers[i]); - - while (1) - { - Selectable *i; - int fd; - - ret = cs.select(&i, &fd); - EXPECT_EQ(ret, Select::OBJECT); - - ((ConsumerTable *)i)->pop(kco); - if (kfvOp(kco) == "SET") - { - numberOfKeysSet++; - validateFields(kfvKey(kco), kfvFieldsValues(kco)); - } else - { - numberOfKeyDeleted++; - } - - if ((numberOfKeysSet == NUMBER_OF_OPS * NUMBER_OF_THREADS) && - (numberOfKeyDeleted == NUMBER_OF_OPS * NUMBER_OF_THREADS)) - break; - } - - /* Making sure threads stops execution */ - for (i = 0; i < NUMBER_OF_THREADS; i++) - { - producerThreads[i].join(); - delete consumers[i]; - } - - cout << endl << "Done." << endl; -} -