Skip to content

Commit

Permalink
# This is a combination of 5 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

fix multi-vlan relay issue

# This is the commit message sonic-net#2:

issue fix

# This is the commit message sonic-net#3:

code refine in UT

# This is the commit message sonic-net#4:

fix counter rollback issue

# This is the commit message sonic-net#5:

Use github code scanning instead of LGTM (sonic-net#26)

* Use github code scanning instead of LGTM

* fi libyang libyang1

* remove libyang1

* add python

* add libpython
  • Loading branch information
jcaiMR committed Dec 14, 2022
1 parent 1e846f6 commit 8ffbe8a
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 268 deletions.
4 changes: 4 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "CodeQL config"
queries:
- uses: security-and-quality
- uses: security-extended
80 changes: 80 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# For more infomation, please visit: https://github.com/github/codeql-action

name: "CodeQL"

on:
push:
branches:
- 'master'
- '202[0-9][0-9][0-9]'
pull_request_target:
branches:
- 'master'
- '202[0-9][0-9][0-9]'
workflow_dispatch:

jobs:
analyze:
name: Analyze
runs-on: ubuntu-20.04
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2.1.29
with:
config-file: ./.github/codeql/codeql-config.yml
languages: ${{ matrix.language }}

- name: prepare
run: |
sudo apt-get update
sudo apt-get install -y libboost-system-dev \
libboost-thread-dev \
libevent-dev \
libhiredis-dev \
libnl-3-dev \
libnl-route-3-dev \
libnl-nf-3-dev \
libnl-genl-3-dev \
libgmock-dev \
dh-exec \
swig3.0 \
uuid-dev \
libzmq3-dev \
libyang-dev \
libpython2.7-dev \
python
- name: build-swss-common
run: |
set -x
cd ..
git clone https://github.com/sonic-net/sonic-swss-common
pushd sonic-swss-common
./autogen.sh
fakeroot dpkg-buildpackage -us -uc -b
popd
dpkg-deb -x libswsscommon_1.0.0_amd64.deb $(dirname $GITHUB_WORKSPACE)
dpkg-deb -x libswsscommon-dev_1.0.0_amd64.deb $(dirname $GITHUB_WORKSPACE)
- name: build
run: |
make all LDFLAGS="-L$(dirname $GITHUB_WORKSPACE)/usr/lib/x86_64-linux-gnu" CPPFLAGS="-I$(dirname $GITHUB_WORKSPACE)/usr/include -I$(dirname $GITHUB_WORKSPACE)/usr/include/swss"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2.1.29
with:
category: "/language:${{matrix.language}}"
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 @@ -48,13 +48,14 @@ void deinitialize_swss()


/**
* @code void get_dhcp(std::vector<relay_config> *vlans)
* @code void get_dhcp(std::unordered_map<std::string, relay_config> vlans)
*
* @brief initialize and get vlan table information from DHCP_RELAY
*
* @return none
*/
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable) {
void get_dhcp(std::unordered_map<std::string, relay_config> &vlans, swss::SubscriberStateTable *ipHelpersTable)
{
swss::Selectable *selectable;
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC);
if (ret == swss::Select::ERROR) {
Expand All @@ -70,7 +71,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 @@ -82,16 +83,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 @@ -100,16 +101,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 @@ -143,7 +144,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
22 changes: 12 additions & 10 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,13 +30,13 @@ void initialize_swss(std::vector<relay_config> *vlans);
void deinitialize_swss();

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

/**
* @code void swssNotification test
Expand All @@ -48,28 +50,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 8ffbe8a

Please sign in to comment.