Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Droplog print tenant for br-int Drops #543

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions agent-ovs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ libopflex_agent_la_include_HEADERS = \
lib/include/opflexagent/Fault.h \
lib/include/opflexagent/Agent.h \
lib/include/opflexagent/IdGenerator.h \
lib/include/opflexagent/EndpointTenantMapper.h \
lib/include/opflexagent/KeyedRateLimiter.h \
lib/include/opflexagent/MulticastListener.h \
lib/include/opflexagent/TaskQueue.h \
Expand Down Expand Up @@ -183,7 +182,8 @@ noinst_HEADERS = \
ovs/include/OvsdbTransactMessage.h \
ovs/include/OvsdbState.h \
ovs/include/DnsManager.h \
ovs/include/NatStatsManager.h
ovs/include/NatStatsManager.h \
ovs/include/EndpointTenantMapper.h

libopflex_agent_la_SOURCES = \
lib/AgentLogHandler.cpp \
Expand Down Expand Up @@ -218,7 +218,6 @@ libopflex_agent_la_SOURCES = \
lib/Fault.cpp \
lib/Agent.cpp \
lib/IdGenerator.cpp \
lib/EndpointTenantMapper.cpp \
lib/NotifServer.cpp \
lib/MulticastListener.cpp \
lib/TaskQueue.cpp \
Expand Down Expand Up @@ -294,8 +293,9 @@ if RENDERER_OVS
ovs/OvsdbMessage.cpp \
ovs/OvsdbMonitorMessage.cpp \
ovs/CtZoneManager.cpp \
ovs/DnsManager.cpp \
ovs/NatStatsManager.cpp
ovs/DnsManager.cpp \
ovs/NatStatsManager.cpp \
ovs/EndpointTenantMapper.cpp

librenderer_openvswitch_la_CFLAGS = \
$(libopenvswitch_CFLAGS) \
Expand Down
35 changes: 0 additions & 35 deletions agent-ovs/lib/EndpointTenantMapper.cpp

This file was deleted.

61 changes: 0 additions & 61 deletions agent-ovs/lib/include/opflexagent/EndpointTenantMapper.h

This file was deleted.

176 changes: 176 additions & 0 deletions agent-ovs/ovs/EndpointTenantMapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Implemencletion of EndpointTenantMapper class
* Copyright (c) 2024 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/

#include "EndpointTenantMapper.h"
#include "SwitchManager.h"


namespace opflexagent {

using std::string;
typedef EndpointListener::uri_set_t uri_set_t;

EndpointTenantMapper::EndpointTenantMapper(Agent* agent_, SwitchManager* accessSwitchManager_, boost::asio::io_service& ioService_)
: agent(agent_), accessSwitchManager(accessSwitchManager_), taskQueue(ioService_) {
endpointTenantMap = {};
portTenantMap = {};
portToPortMap = {};
}

void EndpointTenantMapper::start() {
LOG(DEBUG) << "Starting EndpointTenantMapper";
accessSwitchManager->getPortMapper().registerPortStatusListener(this);
agent->getEndpointManager().registerListener(this);
agent->getExtraConfigManager().registerListener(this);
agent->getLearningBridgeManager().registerListener(this);
}

void EndpointTenantMapper::stop() {
LOG(DEBUG) << "Stopping EndpointTenantMapper";
stopping = true;
accessSwitchManager->getPortMapper().unregisterPortStatusListener(this);
agent->getEndpointManager().unregisterListener(this);
agent->getExtraConfigManager().unregisterListener(this);
agent->getLearningBridgeManager().unregisterListener(this);
}

void EndpointTenantMapper::UpdateVNIDMapping(uint32_t key, std::string value){
endpointTenantMap[key] = value;
}

void EndpointTenantMapper::UpdateVNIDMappingFromURI(uint32_t key, std::string uri){
size_t tLow = uri.find("PolicySpace") + 12;
size_t gEpGStart = uri.rfind("GbpEpGroup");
std::string tenant = uri.substr(tLow,gEpGStart-tLow-1);
UpdateVNIDMapping(key, std::move(tenant));
}

void EndpointTenantMapper::UpdatePortMapping(uint32_t key, std::string value){
portTenantMap[key] = value;
}

void EndpointTenantMapper::UpdatePortMappingFromURI(uint32_t key, std::string uri){
size_t tLow = uri.find("PolicySpace") + 12;
size_t gEpGStart = uri.rfind("GbpEpGroup");
std::string tenant = uri.substr(tLow,gEpGStart-tLow-1);
UpdatePortMapping(key, std::move(tenant));
}

void EndpointTenantMapper::SetPortToPortMapping(uint32_t inPort, uint32_t outPort){
portToPortMap[inPort] = outPort;
portToPortMap[outPort] = inPort;
}

std::string EndpointTenantMapper::GetVNIDMapping(uint32_t key){
if(endpointTenantMap.find(key) == endpointTenantMap.end())
return "";
return endpointTenantMap[key];
}

std::string EndpointTenantMapper::GetPortMapping(uint32_t key){
if(portTenantMap.find(key) == portTenantMap.end())
return "";
return portTenantMap[key];
}

uint32_t EndpointTenantMapper::GetMatchingPort(uint32_t port){
if(portToPortMap.find(port) == portToPortMap.end())
return OFPP_NONE;
return portToPortMap[port];
}

void EndpointTenantMapper::handleEndpointUpdate(const string& uuid) {
EndpointManager& epMgr = agent->getEndpointManager();
shared_ptr<const Endpoint> epWrapper = epMgr.getEndpoint(uuid);

if (!epWrapper) { // EP removed
return;
}
optional<URI> epgURI = epMgr.getComputedEPG(uuid);

// IntFlowManager mapping
if(epMgr.localExternalDomainExists(epgURI.get())) {
optional<uint32_t> epgVnid = ((1<< 30) + epMgr.getExtEncapId(epgURI.get()));
if (epgVnid) UpdateVNIDMappingFromURI(epgVnid.get(), epgURI.get().toString());
}else{
PolicyManager& polMgr = agent->getPolicyManager();
optional<uint32_t> epgVnid = polMgr.getVnidForGroup(epgURI.get());
if(epgVnid) UpdateVNIDMappingFromURI(epgVnid.get(), epgURI.get().toString());
}

// AccessFlowManager mapping
uint32_t accessPort = OFPP_NONE;
uint32_t uplinkPort = OFPP_NONE;
const optional<string>& accessIface = epWrapper->getAccessInterface();
const optional<string>& uplinkIface = epWrapper->getAccessUplinkInterface();
if (accessIface){
accessPort = accessSwitchManager->getPortMapper().FindPort(accessIface.get());
if(epgURI) UpdatePortMappingFromURI(accessPort, epgURI.get().toString());
}
if (uplinkIface) {
uplinkPort = accessSwitchManager->getPortMapper().FindPort(uplinkIface.get());
}

if(accessIface && uplinkIface){
SetPortToPortMapping(accessPort, uplinkPort);
}
}

void EndpointTenantMapper::endpointUpdated(const string& uuid) {
if (stopping) return;
taskQueue.dispatch(uuid, [=](){ handleEndpointUpdate(uuid); });
}

void EndpointTenantMapper::lbIfaceUpdated(const std::string& uuid) {
if(stopping) return;
LearningBridgeManager& lbMgr = agent->getLearningBridgeManager();
shared_ptr<const LearningBridgeIface> iface = lbMgr.getLBIface(uuid);

if (!iface)
return;

if (iface->getInterfaceName()) {
EndpointManager& epMgr = agent->getEndpointManager();
std::unordered_set<std::string> epUuids;
epMgr.getEndpointsByIface(iface->getInterfaceName().get(), epUuids);

for (auto& epUuid : epUuids) {
endpointUpdated(epUuid);
}
}
}

void EndpointTenantMapper::packetDropLogConfigUpdated(const URI& dropLogCfgURI) {
if(stopping) return;
using modelgbp::observer::DropLogConfig;
optional<shared_ptr<DropLogConfig>> dropLogCfg =
DropLogConfig::resolve(agent->getFramework(), dropLogCfgURI);
if(!dropLogCfg) {
LOG(INFO) << "Defaulting to droplog tenant printing disabled";
return;
}
shouldPrintTenant = dropLogCfg.get()->getDropLogPrintTenant(0) != 0;
LOG(INFO) << "Droplog tenant printing set to " + std::to_string(dropLogCfg.get()->getDropLogPrintTenant(0));
}

void EndpointTenantMapper::portStatusUpdate(const string& portName,
uint32_t portNo, bool) {
if (stopping) return;
agent->getAgentIOService().dispatch([=]() { handlePortStatusUpdate(portName, portNo); });
}

void EndpointTenantMapper::handlePortStatusUpdate(const string& portName,
uint32_t) {
unordered_set<std::string> eps;
agent->getEndpointManager().getEndpointsByAccessIface(portName, eps);
agent->getEndpointManager().getEndpointsByAccessUplink(portName, eps);
for (const std::string& ep : eps)
endpointUpdated(ep);
}
}
10 changes: 2 additions & 8 deletions agent-ovs/ovs/IntFlowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ IntFlowManager::IntFlowManager(Agent& agent_,
SwitchManager& switchManager_,
IdGenerator& idGen_,
CtZoneManager& ctZoneManager_,
TunnelEpManager& tunnelEpManager_,
EndpointTenantMapper& endpointTenantMapper_) :
TunnelEpManager& tunnelEpManager_) :
agent(agent_), switchManager(switchManager_), idGen(idGen_),
ctZoneManager(ctZoneManager_), tunnelEpManager(tunnelEpManager_),
prometheusManager(agent.getPrometheusManager()),
Expand All @@ -149,8 +148,7 @@ IntFlowManager::IntFlowManager(Agent& agent_,
serviceStatsFlowDisabled(false), isNatStatsEnabled(false),
advertManager(agent, *this), isSyncing(false), stopping(false),
faultmanager(agent.getFaultManager()),
svcStatsTaskQueue(svcStatsIOService),
endpointTenantMapper(endpointTenantMapper_) {
svcStatsTaskQueue(svcStatsIOService) {
// set up flow tables
switchManager.setMaxFlowTables(NUM_FLOW_TABLES);
SwitchManager::TableDescriptionMap fwdTblDescr;
Expand Down Expand Up @@ -432,8 +430,6 @@ void IntFlowManager::packetDropLogConfigUpdated(const URI& dropLogCfgURI) {
LOG(INFO) << "Defaulting to droplog disabled";
return;
}
endpointTenantMapper.shouldPrintTenant = dropLogCfg.get()->getDropLogPrintTenant(0) != 0;
LOG(INFO) << "Droplog tenant printing set to " + dropLogCfg.get()->getDropLogPrintTenant(0);
if(dropLogCfg.get()->getDropLogEnable(0) != 0) {
if(dropLogCfg.get()->getDropLogMode(
DropLogModeEnumT::CONST_UNFILTERED_DROP_LOG) ==
Expand Down Expand Up @@ -623,7 +619,6 @@ bool IntFlowManager::getGroupForwardingInfo(const URI& epgURI, uint32_t& vnid,
return false;
}
vnid = epgVnid.get();
endpointTenantMapper.UpdateMappingFromURI(vnid, epgURI.toString());

bdStr = "extbd:" + epgURI.toString();
bdURI = URI(bdStr);
Expand All @@ -641,7 +636,6 @@ bool IntFlowManager::getGroupForwardingInfo(const URI& epgURI, uint32_t& vnid,
return false;
}
vnid = epgVnid.get();
endpointTenantMapper.UpdateMappingFromURI(vnid, epgURI.toString());

optional<shared_ptr<RoutingDomain> > epgRd = polMgr.getRDForGroup(epgURI);
optional<shared_ptr<BridgeDomain> > epgBd = polMgr.getBDForGroup(epgURI);
Expand Down
6 changes: 4 additions & 2 deletions agent-ovs/ovs/OVSRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ OVSRenderer::OVSRenderer(Agent& agent_)
intPortMapper),
tunnelEpManager(&agent_),
intFlowManager(agent_, intSwitchManager, idGen,
ctZoneManager, tunnelEpManager,
endpointTenantMapper),
ctZoneManager, tunnelEpManager),
accessSwitchManager(agent_, accessFlowExecutor,
accessFlowReader, accessPortMapper),
accessFlowManager(agent_, accessSwitchManager, idGen, ctZoneManager),
endpointTenantMapper(&agent_, &accessSwitchManager, agent_.getAgentIOService()),
pktInHandler(agent_, intFlowManager, dnsManager),
interfaceStatsManager(&agent_, intSwitchManager.getPortMapper(),
accessSwitchManager.getPortMapper()),
Expand Down Expand Up @@ -167,6 +167,7 @@ void OVSRenderer::start() {
if (accessBridgeName != "") {
accessFlowManager.start();
}
endpointTenantMapper.start();
dnsManager.setCacheDir(dnsCacheDir);
dnsManager.start();

Expand Down Expand Up @@ -295,6 +296,7 @@ void OVSRenderer::stop() {

intSwitchManager.stop();
accessSwitchManager.stop();
endpointTenantMapper.stop();
if (getAgent().isFeatureEnabled(FeatureList::ERSPAN))
spanRenderer.stop();
netflowRendererIntBridge.stop();
Expand Down
Loading
Loading