Skip to content

Commit f931ae4

Browse files
authored
[VS] Add support for context and multiple switches (#830)
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.
1 parent 59208de commit f931ae4

19 files changed

+467
-31
lines changed

lib/src/ContextConfigContainer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,13 @@ std::shared_ptr<ContextConfigContainer> ContextConfigContainer::loadFromFile(
132132
auto sc = std::make_shared<SwitchConfig>(switchIndex, hwinfo);
133133

134134
cc->insert(sc);
135+
136+
SWSS_LOG_NOTICE("insert into context '%s' config for hwinfo '%s'", cc->m_name.c_str(), hwinfo.c_str());
135137
}
136138

137139
ccc->insert(cc);
140+
141+
SWSS_LOG_NOTICE("insert context '%s' into container list", cc->m_name.c_str());
138142
}
139143
}
140144
catch (const std::exception& e)
@@ -144,6 +148,8 @@ std::shared_ptr<ContextConfigContainer> ContextConfigContainer::loadFromFile(
144148
return getDefault();
145149
}
146150

151+
SWSS_LOG_NOTICE("loaded %zu context configs", ccc->m_map.size());
152+
147153
return ccc;
148154
}
149155

lib/src/SwitchConfigContainer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void SwitchConfigContainer::insert(
2424
config->m_hardwareInfo.c_str());
2525
}
2626

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

syncd/Syncd.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "meta/sai_serialize.h"
2727

28+
#include "vslib/inc/saivs.h"
29+
2830
#include <unistd.h>
2931
#include <inttypes.h>
3032

@@ -2671,6 +2673,10 @@ void Syncd::loadProfileMap()
26712673
{
26722674
SWSS_LOG_ENTER();
26732675

2676+
// in case of virtual switch, populate context config
2677+
m_profileMap[SAI_KEY_VS_GLOBAL_CONTEXT] = std::to_string(m_commandLineOptions->m_globalContext);
2678+
m_profileMap[SAI_KEY_VS_CONTEXT_CONFIG] = m_commandLineOptions->m_contextConfig;
2679+
26742680
if (m_commandLineOptions->m_profileMapFile.size() == 0)
26752681
{
26762682
SWSS_LOG_NOTICE("profile map file not specified");

tests/aspell.en.pws

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ getVid
102102
github
103103
GRE
104104
gSwitchId
105+
GUID
105106
hardcoded
106107
hasEqualAttribute
107108
hostif
@@ -120,10 +121,10 @@ ini
120121
init
121122
INIT
122123
inout
123-
INSEG
124+
inseg
124125
Inseg
126+
INSEG
125127
insegs
126-
inseg
127128
ip
128129
IP
129130
ipc

vslib/inc/Context.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "ContextConfig.h"
4+
5+
namespace saivs
6+
{
7+
class Context
8+
{
9+
public:
10+
11+
Context(
12+
_In_ std::shared_ptr<ContextConfig> contextConfig);
13+
14+
virtual ~Context();
15+
16+
public:
17+
18+
std::shared_ptr<ContextConfig> getContextConfig() const;
19+
20+
private:
21+
22+
std::shared_ptr<ContextConfig> m_contextConfig;
23+
};
24+
}

vslib/inc/ContextConfig.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include "SwitchConfigContainer.h"
4+
5+
namespace saivs
6+
{
7+
class ContextConfig
8+
{
9+
public:
10+
11+
ContextConfig(
12+
_In_ uint32_t guid,
13+
_In_ const std::string& name);
14+
15+
virtual ~ContextConfig();
16+
17+
public:
18+
19+
void insert(
20+
_In_ std::shared_ptr<SwitchConfig> config);
21+
22+
23+
public: // TODO to private
24+
25+
uint32_t m_guid;
26+
27+
std::string m_name;
28+
29+
std::shared_ptr<SwitchConfigContainer> m_scc;
30+
};
31+
}

vslib/inc/ContextConfigContainer.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include "ContextConfig.h"
4+
5+
#include "swss/sal.h"
6+
7+
#include <memory>
8+
#include <map>
9+
#include <set>
10+
11+
namespace saivs
12+
{
13+
class ContextConfigContainer
14+
{
15+
public:
16+
17+
ContextConfigContainer();
18+
19+
virtual ~ContextConfigContainer();
20+
21+
public:
22+
23+
void insert(
24+
_In_ std::shared_ptr<ContextConfig> contextConfig);
25+
26+
std::shared_ptr<ContextConfig> get(
27+
_In_ uint32_t guid);
28+
29+
std::set<std::shared_ptr<ContextConfig>> getAllContextConfigs();
30+
31+
public:
32+
33+
static std::shared_ptr<ContextConfigContainer> loadFromFile(
34+
_In_ const char* contextConfig);
35+
36+
static std::shared_ptr<ContextConfigContainer> getDefault();
37+
38+
private:
39+
40+
std::map<uint32_t, std::shared_ptr<ContextConfig>> m_map;
41+
42+
};
43+
}

vslib/inc/Sai.h

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "EventPayloadNotification.h"
77
#include "ResourceLimiterContainer.h"
88
#include "CorePortIndexMapContainer.h"
9+
#include "Context.h"
910

1011
#include "meta/Meta.h"
1112

@@ -401,6 +402,11 @@ namespace saivs
401402

402403
std::shared_ptr<Signal> m_signal;
403404

405+
private:
406+
407+
std::shared_ptr<Context> getContext(
408+
_In_ uint32_t globalContext) const;
409+
404410
private:
405411

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

426432
std::shared_ptr<CorePortIndexMapContainer> m_corePortIndexMapContainer;
433+
434+
std::map<uint32_t, std::shared_ptr<Context>> m_contextMap;
427435
};
428436
}

vslib/inc/SwitchConfig.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ namespace saivs
4040
{
4141
public:
4242

43-
SwitchConfig();
43+
SwitchConfig(
44+
_In_ uint32_t switchIndex,
45+
_In_ const std::string& hwinfo);
4446

4547
virtual ~SwitchConfig() = default;
4648

vslib/inc/SwitchConfigContainer.h

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "SwitchConfig.h"
44

55
#include <map>
6+
#include <set>
67
#include <memory>
78

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

30+
std::set<std::shared_ptr<SwitchConfig>> getSwitchConfigs() const;
31+
2932
private:
3033

3134
std::map<uint32_t, std::shared_ptr<SwitchConfig>> m_indexToConfig;

vslib/inc/saivs.h

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ extern "C" {
6969
*/
7070
#define SAI_KEY_VS_CORE_PORT_INDEX_MAP_FILE "SAI_VS_CORE_PORT_INDEX_MAP_FILE"
7171

72+
/**
73+
* @brief Context config.
74+
*
75+
* Optional. Should point to a context_config.json which will contain how many
76+
* contexts (syncd) we have in the system globally and each context how many
77+
* switches it manages. Only one of this contexts will be used in VS.
78+
*/
79+
#define SAI_KEY_VS_CONTEXT_CONFIG "SAI_VS_CONTEXT_CONFIG"
80+
81+
/**
82+
* @brief Global context.
83+
*
84+
* Optional. Should point to GUID value which is provided in context_config.json
85+
* by SAI_KEY_VS_CONTEXT_CONFIG. Default is 0.
86+
*/
87+
#define SAI_KEY_VS_GLOBAL_CONTEXT "SAI_VS_GLOBAL_CONTEXT"
88+
7289
#define SAI_VALUE_VS_SWITCH_TYPE_BCM56850 "SAI_VS_SWITCH_TYPE_BCM56850"
7390
#define SAI_VALUE_VS_SWITCH_TYPE_BCM81724 "SAI_VS_SWITCH_TYPE_BCM81724"
7491
#define SAI_VALUE_VS_SWITCH_TYPE_MLNX2700 "SAI_VS_SWITCH_TYPE_MLNX2700"

vslib/src/Context.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "Context.h"
2+
3+
#include "swss/logger.h"
4+
5+
using namespace saivs;
6+
7+
Context::Context(
8+
_In_ std::shared_ptr<ContextConfig> contextConfig):
9+
m_contextConfig(contextConfig)
10+
{
11+
SWSS_LOG_ENTER();
12+
13+
// empty
14+
}
15+
16+
Context::~Context()
17+
{
18+
SWSS_LOG_ENTER();
19+
20+
// empty
21+
}
22+
23+
std::shared_ptr<ContextConfig> Context::getContextConfig() const
24+
{
25+
SWSS_LOG_ENTER();
26+
27+
return m_contextConfig;
28+
}

vslib/src/ContextConfig.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "ContextConfig.h"
2+
3+
#include "swss/logger.h"
4+
5+
using namespace saivs;
6+
7+
ContextConfig::ContextConfig(
8+
_In_ uint32_t guid,
9+
_In_ const std::string& name):
10+
m_guid(guid),
11+
m_name(name)
12+
{
13+
SWSS_LOG_ENTER();
14+
15+
m_scc = std::make_shared<SwitchConfigContainer>();
16+
}
17+
18+
ContextConfig::~ContextConfig()
19+
{
20+
SWSS_LOG_ENTER();
21+
22+
// empty
23+
}
24+
25+
void ContextConfig::insert(
26+
_In_ std::shared_ptr<SwitchConfig> config)
27+
{
28+
SWSS_LOG_ENTER();
29+
30+
m_scc->insert(config);
31+
}

0 commit comments

Comments
 (0)