Skip to content

Commit 3a167ad

Browse files
authored
PAC changs to receive config updates (#18620)
1 parent 2e55c75 commit 3a167ad

File tree

9 files changed

+1086
-0
lines changed

9 files changed

+1086
-0
lines changed

src/sonic-pac/paccfg/Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
INCLUDES = -I $(top_srcdir)/fpinfra/inc -I $(top_srcdir)/authmgr/common -I $(top_srcdir)/authmgr/mapping/include -I $(top_srcdir)/authmgr/protocol/include
2+
3+
lib_LTLIBRARIES = libpaccfg.la
4+
5+
if DEBUG
6+
DBGFLAGS = -ggdb -DDEBUG
7+
else
8+
DBGFLAGS = -g -DNDEBUG
9+
endif
10+
11+
AM_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(SONIC_COMMON_CFLAGS)
12+
13+
libpaccfg_la_SOURCES = $(top_srcdir)/paccfg/pac_cfg_authmgr.cpp $(top_srcdir)/paccfg/pac_authmgrcfg.cpp $(top_srcdir)/paccfg/pac_cfg_vlan.cpp $(top_srcdir)/paccfg/pac_vlancfg.cpp
14+
15+
libpaccfg_la_LIBADD = -lswsscommon -lnl-3 -lnl-route-3 -lhiredis $(SONIC_COMMON_LDFLAGS)
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* Copyright 2019 Broadcom Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include <swss/logger.h>
17+
#include <swss/dbconnector.h>
18+
#include <swss/producerstatetable.h>
19+
#include <swss/macaddress.h>
20+
#include <swss/tokenize.h>
21+
#include "pac_authmgrcfg.h"
22+
23+
using namespace std;
24+
using namespace swss;
25+
26+
// PAC SONIC config engine
27+
PacCfg::PacCfg(DBConnector *db, DBConnector *cfgDb, DBConnector *stateDb) :
28+
m_cfgFdbTable(cfgDb, CFG_FDB_TABLE_NAME),
29+
m_stateOperFdbTable(stateDb, STATE_OPER_FDB_TABLE_NAME),
30+
m_stateOperPortTable(stateDb, STATE_OPER_PORT_TABLE_NAME)
31+
{
32+
Logger::linkToDbNative("paccfg");
33+
SWSS_LOG_NOTICE("PAC: config object");
34+
35+
/* FDB flush notification producer */
36+
m_flushFdb = std::make_shared<swss::NotificationProducer>(db, "FLUSHFDBREQUEST");
37+
}
38+
39+
PacCfg::~PacCfg()
40+
{
41+
42+
}
43+
44+
// Set learning mode for a port
45+
bool PacCfg::intfLearningSet(string port, string learning)
46+
{
47+
string key(port);
48+
vector<FieldValueTuple> fvVector;
49+
50+
// Configure port learning mode for FDB manager
51+
fvVector.emplace_back("learn_mode", learning);
52+
m_stateOperPortTable.set(key, fvVector);
53+
54+
return true;
55+
}
56+
57+
// Get learning mode of a port
58+
bool PacCfg::intfLearningGet(string port, string *learning)
59+
{
60+
return true;
61+
}
62+
63+
// Add a static MAC address to FDB
64+
bool PacCfg::intfStaticMacAdd(string port, MacAddress mac, int vlan)
65+
{
66+
string key = VLAN_PREFIX + to_string(vlan);
67+
key += STATE_DB_SEPARATOR;
68+
key += mac.to_string();
69+
70+
vector<FieldValueTuple> fvVector;
71+
72+
fvVector.push_back(FieldValueTuple("port", port));
73+
fvVector.push_back(FieldValueTuple("type", "static"));
74+
m_stateOperFdbTable.set(key, fvVector);
75+
76+
return true;
77+
}
78+
79+
// Remove an added static MAC address.
80+
bool PacCfg::intfStaticMacRemove(string port, MacAddress mac, int vlan)
81+
{
82+
string key = VLAN_PREFIX + to_string(vlan);
83+
key += STATE_DB_SEPARATOR;
84+
key += mac.to_string();
85+
86+
m_stateOperFdbTable.del(key);
87+
88+
return true;
89+
}
90+
91+
// for now, blindly delete all entries.
92+
// Ideally we need to delete only the entries owned by PAC.
93+
void PacCfg::intfStaticMacCleanup(void)
94+
{
95+
vector<string> keys;
96+
m_stateOperFdbTable.getKeys(keys);
97+
for (const auto key : keys)
98+
{
99+
m_stateOperFdbTable.del(key);
100+
}
101+
}
102+
103+
// Acquire/Release port.
104+
bool PacCfg::intfAcquireSet(string port, bool acquire)
105+
{
106+
vector<FieldValueTuple> fvVector;
107+
108+
// Configure port acquire config for port.
109+
if (acquire == true)
110+
{
111+
fvVector.emplace_back("acquired", "true");
112+
}
113+
else
114+
{
115+
fvVector.emplace_back("acquired", "false");
116+
}
117+
m_stateOperPortTable.set(port, fvVector);
118+
119+
return true;
120+
}
121+
122+
// Block a client
123+
bool PacCfg::intfClientBlock(string port, MacAddress mac, int vlan)
124+
{
125+
// Add a static MAC entry with discard bits set.
126+
string key = VLAN_PREFIX + to_string(vlan);
127+
key += STATE_DB_SEPARATOR;
128+
key += mac.to_string();
129+
130+
vector<FieldValueTuple> fvVector;
131+
fvVector.push_back(FieldValueTuple("discard", "true"));
132+
fvVector.push_back(FieldValueTuple("port", port));
133+
fvVector.push_back(FieldValueTuple("type", "static"));
134+
135+
m_stateOperFdbTable.set(key, fvVector);
136+
137+
return true;
138+
}
139+
140+
bool PacCfg::intfFdbFlush(string port)
141+
{
142+
vector<FieldValueTuple> values;
143+
144+
SWSS_LOG_DEBUG("send fdb flush by port %s notification ", port.c_str());
145+
146+
// Send FDB flush notification.
147+
m_flushFdb->send("PORT", port, values);
148+
149+
return true;
150+
}
151+
152+
bool PacCfg::intfMacVlanTranslationAdd(string port, MacAddress mac, int vlan)
153+
{
154+
// Add MAC-VLAN translation for given MAC-VLAN pair.
155+
return true;
156+
}
157+
158+
bool PacCfg::intfMacVlanTranslationRemove(string port, MacAddress mac, int vlan)
159+
{
160+
// Remove MAC-VLAN translation for given MAC-VLAN pair.
161+
return true;
162+
}
163+
164+
bool PacCfg::sendFdbNotification(string op, string port)
165+
{
166+
vector<string> keys;
167+
vector<FieldValueTuple> entry;
168+
const char delimiter = '|';
169+
170+
/* Retrieve static MAC entries configure on port and
171+
* send a notification to add/remove those entries on port.
172+
*/
173+
m_cfgFdbTable.getKeys(keys);
174+
175+
for (auto id : keys)
176+
{
177+
m_cfgFdbTable.get(id, entry);
178+
for (auto i : entry)
179+
{
180+
if (fvField(i) == "port")
181+
{
182+
if (fvValue(i) == port)
183+
{
184+
vector<FieldValueTuple> values;
185+
186+
/* Get MAC and VLAN from key */
187+
vector <string> tokens = tokenize(id, delimiter, 1);
188+
189+
/* tokens[0] is VLAN (Vlan20) and tokens[1] is mac (00:01:02:03:04:05). */
190+
values.push_back(FieldValueTuple("mac", tokens[1]));
191+
values.push_back(FieldValueTuple("Vlan", tokens[0]));
192+
m_fdbCfgNotificationProducer->send(op, port, values);
193+
}
194+
}
195+
}
196+
}
197+
198+
return true;
199+
}

src/sonic-pac/paccfg/pac_authmgrcfg.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2019 Broadcom Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef _PAC_AUTHMGR_CFG_H
18+
#define _PAC_AUTHMGR_CFG_H
19+
20+
#include <string.h>
21+
#include <swss/dbconnector.h>
22+
#include <swss/schema.h>
23+
#include <swss/table.h>
24+
#include <swss/macaddress.h>
25+
#include <swss/notificationproducer.h>
26+
#include <swss/subscriberstatetable.h>
27+
#include <swss/producerstatetable.h>
28+
#include <swss/table.h>
29+
#include <swss/select.h>
30+
#include <swss/timestamp.h>
31+
32+
using namespace std;
33+
34+
#define STATE_DB_SEPARATOR "|"
35+
#define CONFIG_DB_SEPARATOR "|"
36+
37+
namespace swss {
38+
39+
class PacCfg {
40+
public:
41+
PacCfg(DBConnector *appDb, DBConnector *cfgDb, DBConnector *stateDb);
42+
~PacCfg();
43+
44+
/* Update learning mode of a port. */
45+
bool intfLearningSet(std::string port, std::string learning);
46+
47+
/* Get learning mode of a port. */
48+
bool intfLearningGet(std::string port, std::string *learning);
49+
50+
/* Acquire/Release port. */
51+
bool intfAcquireSet(std::string port, bool acquire);
52+
53+
/* Block a client's traffic. */
54+
bool intfClientBlock(std::string port, MacAddress mac, int vlan);
55+
56+
/* Add a static MAC entry. */
57+
bool intfStaticMacAdd(std::string port, MacAddress mac, int vlan);
58+
59+
/* Add a static MAC entry. */
60+
bool intfStaticMacRemove(std::string port, MacAddress mac, int vlan);
61+
62+
/* Clean up all static MAC entries. */
63+
void intfStaticMacCleanup(void);
64+
65+
/* Flush FDB entries on a port. */
66+
bool intfFdbFlush(std::string port);
67+
68+
/* Add MAC-VLAN translation config. */
69+
bool intfMacVlanTranslationAdd(std::string port, MacAddress mac, int vlan);
70+
71+
/* Remove MAC-VLAN translation config. */
72+
bool intfMacVlanTranslationRemove(std::string port, MacAddress mac, int vlan);
73+
74+
/* Send notification to FDB mgr. */
75+
bool sendFdbNotification(std::string op, std::string port);
76+
77+
private:
78+
/* Tables for writing config */
79+
Table m_cfgFdbTable;
80+
Table m_stateOperFdbTable;
81+
Table m_stateOperPortTable;
82+
83+
std::shared_ptr<swss::NotificationProducer> m_flushFdb;
84+
std::shared_ptr<swss::NotificationProducer> m_fdbCfgNotificationProducer;
85+
86+
};
87+
}
88+
89+
#endif /* _PAC_AUTHMGR_CFG_H */

0 commit comments

Comments
 (0)