Skip to content

Commit

Permalink
[VS] Add support for context and multiple switches (sonic-net#830)
Browse files Browse the repository at this point in the history
So far virtual switch supported only 1 switch to be created and only default hwinfo which was empty string. This change allows to reuse context_config.json to allow multiple switches to be created in virtual switch and each can have different hwinfo. This scenario can be useful when running VS test with multiple swss containers running.
  • Loading branch information
kcudnik authored Jun 1, 2021
1 parent 4f4d583 commit ce764f1
Show file tree
Hide file tree
Showing 19 changed files with 467 additions and 31 deletions.
6 changes: 6 additions & 0 deletions lib/src/ContextConfigContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ std::shared_ptr<ContextConfigContainer> ContextConfigContainer::loadFromFile(
auto sc = std::make_shared<SwitchConfig>(switchIndex, hwinfo);

cc->insert(sc);

SWSS_LOG_NOTICE("insert into context '%s' config for hwinfo '%s'", cc->m_name.c_str(), hwinfo.c_str());
}

ccc->insert(cc);

SWSS_LOG_NOTICE("insert context '%s' into container list", cc->m_name.c_str());
}
}
catch (const std::exception& e)
Expand All @@ -144,6 +148,8 @@ std::shared_ptr<ContextConfigContainer> ContextConfigContainer::loadFromFile(
return getDefault();
}

SWSS_LOG_NOTICE("loaded %zu context configs", ccc->m_map.size());

return ccc;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/SwitchConfigContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void SwitchConfigContainer::insert(
config->m_hardwareInfo.c_str());
}

SWSS_LOG_NOTICE("added switch: %u:%s",
SWSS_LOG_NOTICE("added switch: idx %u, hwinfo '%s'",
config->m_switchIndex,
config->m_hardwareInfo.c_str());

Expand Down
6 changes: 6 additions & 0 deletions syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "meta/sai_serialize.h"

#include "vslib/inc/saivs.h"

#include <unistd.h>
#include <inttypes.h>

Expand Down Expand Up @@ -2671,6 +2673,10 @@ void Syncd::loadProfileMap()
{
SWSS_LOG_ENTER();

// in case of virtual switch, populate context config
m_profileMap[SAI_KEY_VS_GLOBAL_CONTEXT] = std::to_string(m_commandLineOptions->m_globalContext);
m_profileMap[SAI_KEY_VS_CONTEXT_CONFIG] = m_commandLineOptions->m_contextConfig;

if (m_commandLineOptions->m_profileMapFile.size() == 0)
{
SWSS_LOG_NOTICE("profile map file not specified");
Expand Down
5 changes: 3 additions & 2 deletions tests/aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ getVid
github
GRE
gSwitchId
GUID
hardcoded
hasEqualAttribute
hostif
Expand All @@ -120,10 +121,10 @@ ini
init
INIT
inout
INSEG
inseg
Inseg
INSEG
insegs
inseg
ip
IP
ipc
Expand Down
24 changes: 24 additions & 0 deletions vslib/inc/Context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "ContextConfig.h"

namespace saivs
{
class Context
{
public:

Context(
_In_ std::shared_ptr<ContextConfig> contextConfig);

virtual ~Context();

public:

std::shared_ptr<ContextConfig> getContextConfig() const;

private:

std::shared_ptr<ContextConfig> m_contextConfig;
};
}
31 changes: 31 additions & 0 deletions vslib/inc/ContextConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "SwitchConfigContainer.h"

namespace saivs
{
class ContextConfig
{
public:

ContextConfig(
_In_ uint32_t guid,
_In_ const std::string& name);

virtual ~ContextConfig();

public:

void insert(
_In_ std::shared_ptr<SwitchConfig> config);


public: // TODO to private

uint32_t m_guid;

std::string m_name;

std::shared_ptr<SwitchConfigContainer> m_scc;
};
}
43 changes: 43 additions & 0 deletions vslib/inc/ContextConfigContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "ContextConfig.h"

#include "swss/sal.h"

#include <memory>
#include <map>
#include <set>

namespace saivs
{
class ContextConfigContainer
{
public:

ContextConfigContainer();

virtual ~ContextConfigContainer();

public:

void insert(
_In_ std::shared_ptr<ContextConfig> contextConfig);

std::shared_ptr<ContextConfig> get(
_In_ uint32_t guid);

std::set<std::shared_ptr<ContextConfig>> getAllContextConfigs();

public:

static std::shared_ptr<ContextConfigContainer> loadFromFile(
_In_ const char* contextConfig);

static std::shared_ptr<ContextConfigContainer> getDefault();

private:

std::map<uint32_t, std::shared_ptr<ContextConfig>> m_map;

};
}
8 changes: 8 additions & 0 deletions vslib/inc/Sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "EventPayloadNotification.h"
#include "ResourceLimiterContainer.h"
#include "CorePortIndexMapContainer.h"
#include "Context.h"

#include "meta/Meta.h"

Expand Down Expand Up @@ -401,6 +402,11 @@ namespace saivs

std::shared_ptr<Signal> m_signal;

private:

std::shared_ptr<Context> getContext(
_In_ uint32_t globalContext) const;

private:

bool m_apiInitialized;
Expand All @@ -424,5 +430,7 @@ namespace saivs
std::shared_ptr<ResourceLimiterContainer> m_resourceLimiterContainer;

std::shared_ptr<CorePortIndexMapContainer> m_corePortIndexMapContainer;

std::map<uint32_t, std::shared_ptr<Context>> m_contextMap;
};
}
4 changes: 3 additions & 1 deletion vslib/inc/SwitchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ namespace saivs
{
public:

SwitchConfig();
SwitchConfig(
_In_ uint32_t switchIndex,
_In_ const std::string& hwinfo);

virtual ~SwitchConfig() = default;

Expand Down
3 changes: 3 additions & 0 deletions vslib/inc/SwitchConfigContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "SwitchConfig.h"

#include <map>
#include <set>
#include <memory>

namespace saivs
Expand All @@ -26,6 +27,8 @@ namespace saivs
std::shared_ptr<SwitchConfig> getConfig(
_In_ const std::string& hardwareInfo) const;

std::set<std::shared_ptr<SwitchConfig>> getSwitchConfigs() const;

private:

std::map<uint32_t, std::shared_ptr<SwitchConfig>> m_indexToConfig;
Expand Down
17 changes: 17 additions & 0 deletions vslib/inc/saivs.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ extern "C" {
*/
#define SAI_KEY_VS_CORE_PORT_INDEX_MAP_FILE "SAI_VS_CORE_PORT_INDEX_MAP_FILE"

/**
* @brief Context config.
*
* Optional. Should point to a context_config.json which will contain how many
* contexts (syncd) we have in the system globally and each context how many
* switches it manages. Only one of this contexts will be used in VS.
*/
#define SAI_KEY_VS_CONTEXT_CONFIG "SAI_VS_CONTEXT_CONFIG"

/**
* @brief Global context.
*
* Optional. Should point to GUID value which is provided in context_config.json
* by SAI_KEY_VS_CONTEXT_CONFIG. Default is 0.
*/
#define SAI_KEY_VS_GLOBAL_CONTEXT "SAI_VS_GLOBAL_CONTEXT"

#define SAI_VALUE_VS_SWITCH_TYPE_BCM56850 "SAI_VS_SWITCH_TYPE_BCM56850"
#define SAI_VALUE_VS_SWITCH_TYPE_BCM81724 "SAI_VS_SWITCH_TYPE_BCM81724"
#define SAI_VALUE_VS_SWITCH_TYPE_MLNX2700 "SAI_VS_SWITCH_TYPE_MLNX2700"
Expand Down
28 changes: 28 additions & 0 deletions vslib/src/Context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "Context.h"

#include "swss/logger.h"

using namespace saivs;

Context::Context(
_In_ std::shared_ptr<ContextConfig> contextConfig):
m_contextConfig(contextConfig)
{
SWSS_LOG_ENTER();

// empty
}

Context::~Context()
{
SWSS_LOG_ENTER();

// empty
}

std::shared_ptr<ContextConfig> Context::getContextConfig() const
{
SWSS_LOG_ENTER();

return m_contextConfig;
}
31 changes: 31 additions & 0 deletions vslib/src/ContextConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "ContextConfig.h"

#include "swss/logger.h"

using namespace saivs;

ContextConfig::ContextConfig(
_In_ uint32_t guid,
_In_ const std::string& name):
m_guid(guid),
m_name(name)
{
SWSS_LOG_ENTER();

m_scc = std::make_shared<SwitchConfigContainer>();
}

ContextConfig::~ContextConfig()
{
SWSS_LOG_ENTER();

// empty
}

void ContextConfig::insert(
_In_ std::shared_ptr<SwitchConfig> config)
{
SWSS_LOG_ENTER();

m_scc->insert(config);
}
Loading

0 comments on commit ce764f1

Please sign in to comment.