diff --git a/agent-ovs/Makefile.am b/agent-ovs/Makefile.am index 5812e142..d10a342e 100644 --- a/agent-ovs/Makefile.am +++ b/agent-ovs/Makefile.am @@ -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 \ @@ -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 \ @@ -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 \ @@ -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) \ diff --git a/agent-ovs/lib/EndpointTenantMapper.cpp b/agent-ovs/lib/EndpointTenantMapper.cpp deleted file mode 100644 index 29f84294..00000000 --- a/agent-ovs/lib/EndpointTenantMapper.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Implementation of EndpointTenantMapper class - * Copyright (c) 2014 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 - - -namespace opflexagent { - -EndpointTenantMapper::EndpointTenantMapper() { - endpointTenantMap = {}; -} - -void EndpointTenantMapper::UpdateMapping(uint32_t key, std::string value){ - endpointTenantMap[key] = value; -} - -void EndpointTenantMapper::UpdateMappingFromURI(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); - UpdateMapping(key, tenant); -} - -std::string EndpointTenantMapper::GetMapping(uint32_t key){ - if(endpointTenantMap.find(key) == endpointTenantMap.end()) - return ""; - return endpointTenantMap[key]; -} -} \ No newline at end of file diff --git a/agent-ovs/lib/include/opflexagent/EndpointTenantMapper.h b/agent-ovs/lib/include/opflexagent/EndpointTenantMapper.h deleted file mode 100644 index 3c2bf6ef..00000000 --- a/agent-ovs/lib/include/opflexagent/EndpointTenantMapper.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */ -/* - * Definition of EndpointTenantMapper class - * Copyright (c) 2014 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 - */ - -#ifndef OPFLEXAGENT_ENDPOINTTENANTMAPPER_H_ -#define OPFLEXAGENT_ENDPOINTTENANTMAPPER_H_ - -#include - -#include - -#include -#include -#include -#include -#include -#include - -using std::unordered_map; - -namespace opflexagent { - -/** - * Class to keep track of EPG vnid to tenant ID translation. -*/ -class EndpointTenantMapper : private boost::noncopyable { -public: - EndpointTenantMapper(); - /** - * Update or create a mapping between the given key - * and value - */ - void UpdateMapping(uint32_t key, std::string value); - /** - * Update or create a mapping between the given key - * and tenant, which is extracted from the EPG URI. - */ - void UpdateMappingFromURI(uint32_t key, std::string uri); - /** - * Get the mapping for the given key, if available. - * If no mapping exists, returns an empty string. - */ - std::string GetMapping(uint32_t key); - /** - * If the drop log should print the source/destination - * tenant. - */ - bool shouldPrintTenant; -private: - unordered_map endpointTenantMap; -}; - -} /* namespace opflexagent */ - -#endif // OPFLEXAGENT_ENDPOINTTENANTMAPPER_H_ \ No newline at end of file diff --git a/agent-ovs/ovs/EndpointTenantMapper.cpp b/agent-ovs/ovs/EndpointTenantMapper.cpp new file mode 100644 index 00000000..3e6b219f --- /dev/null +++ b/agent-ovs/ovs/EndpointTenantMapper.cpp @@ -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 epWrapper = epMgr.getEndpoint(uuid); + + if (!epWrapper) { // EP removed + return; + } + optional epgURI = epMgr.getComputedEPG(uuid); + + // IntFlowManager mapping + if(epMgr.localExternalDomainExists(epgURI.get())) { + optional epgVnid = ((1<< 30) + epMgr.getExtEncapId(epgURI.get())); + if (epgVnid) UpdateVNIDMappingFromURI(epgVnid.get(), epgURI.get().toString()); + }else{ + PolicyManager& polMgr = agent->getPolicyManager(); + optional 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& accessIface = epWrapper->getAccessInterface(); + const optional& 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 iface = lbMgr.getLBIface(uuid); + + if (!iface) + return; + + if (iface->getInterfaceName()) { + EndpointManager& epMgr = agent->getEndpointManager(); + std::unordered_set 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> 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 eps; + agent->getEndpointManager().getEndpointsByAccessIface(portName, eps); + agent->getEndpointManager().getEndpointsByAccessUplink(portName, eps); + for (const std::string& ep : eps) + endpointUpdated(ep); +} +} \ No newline at end of file diff --git a/agent-ovs/ovs/IntFlowManager.cpp b/agent-ovs/ovs/IntFlowManager.cpp index 8117de2d..6af0132a 100644 --- a/agent-ovs/ovs/IntFlowManager.cpp +++ b/agent-ovs/ovs/IntFlowManager.cpp @@ -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()), @@ -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; @@ -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) == @@ -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); @@ -641,7 +636,6 @@ bool IntFlowManager::getGroupForwardingInfo(const URI& epgURI, uint32_t& vnid, return false; } vnid = epgVnid.get(); - endpointTenantMapper.UpdateMappingFromURI(vnid, epgURI.toString()); optional > epgRd = polMgr.getRDForGroup(epgURI); optional > epgBd = polMgr.getBDForGroup(epgURI); diff --git a/agent-ovs/ovs/OVSRenderer.cpp b/agent-ovs/ovs/OVSRenderer.cpp index 0c9712f3..e04b4902 100644 --- a/agent-ovs/ovs/OVSRenderer.cpp +++ b/agent-ovs/ovs/OVSRenderer.cpp @@ -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()), @@ -167,6 +167,7 @@ void OVSRenderer::start() { if (accessBridgeName != "") { accessFlowManager.start(); } + endpointTenantMapper.start(); dnsManager.setCacheDir(dnsCacheDir); dnsManager.start(); @@ -295,6 +296,7 @@ void OVSRenderer::stop() { intSwitchManager.stop(); accessSwitchManager.stop(); + endpointTenantMapper.stop(); if (getAgent().isFeatureEnabled(FeatureList::ERSPAN)) spanRenderer.stop(); netflowRendererIntBridge.stop(); diff --git a/agent-ovs/ovs/PacketDecoder.cpp b/agent-ovs/ovs/PacketDecoder.cpp index ca448dd3..c1a67ab7 100644 --- a/agent-ovs/ovs/PacketDecoder.cpp +++ b/agent-ovs/ovs/PacketDecoder.cpp @@ -477,6 +477,10 @@ int PacketDecoder::configure() { sptrGeneveOptDestinationEPGLayerVariant(new GeneveOptDestinationEPGLayerVariant()); sptrGeneveOptDestinationEPGLayerVariant->configure(); registerLayer(sptrGeneveOptDestinationEPGLayerVariant); + shared_ptr + sptrGeneveOptOutputPortLayerVariant(new GeneveOptOutputPortLayerVariant()); + sptrGeneveOptOutputPortLayerVariant->configure(); + registerLayer(sptrGeneveOptOutputPortLayerVariant); /*Set the base layer id*/ baseLayerId = sptrGeneve->getId(); return 0; diff --git a/agent-ovs/ovs/PacketDecoderLayers.cpp b/agent-ovs/ovs/PacketDecoderLayers.cpp index 2fdf3c74..63571d64 100644 --- a/agent-ovs/ovs/PacketDecoderLayers.cpp +++ b/agent-ovs/ovs/PacketDecoderLayers.cpp @@ -200,6 +200,21 @@ void GeneveOptDestinationEPGLayerVariant::reParse(ParseInfo &p) { p.meta[ParseInfoMetaType::DESTINATION_EPG] = p.scratchpad[3]; } +int GeneveOptOutputPortLayerVariant::configure() { + addKeyData(65535); + addKeyData(7); + return 0; +} + +void GeneveOptOutputPortLayerVariant::getFormatString(boost::format &fmtStr) { + //Format string to print the layer goes here + fmtStr = boost::format(""); +} + +void GeneveOptOutputPortLayerVariant::reParse(ParseInfo &p) { + p.meta[ParseInfoMetaType::OUTPUT_PORT] = p.scratchpad[3]; +} + int ARPLayer::configure() { addField("hwType", 16, 0, PDF::FLDTYPE_BYTES, 0, 0, -1, 0, 0); addField("eType", 16, 16, PDF::FLDTYPE_BYTES, 0, 0, -1, 0, 0); diff --git a/agent-ovs/ovs/PacketLogHandler.cpp b/agent-ovs/ovs/PacketLogHandler.cpp index 4a1eb113..f8d00289 100644 --- a/agent-ovs/ovs/PacketLogHandler.cpp +++ b/agent-ovs/ovs/PacketLogHandler.cpp @@ -200,12 +200,19 @@ bool PacketLogHandler::getDropReason(ParseInfo &p, std::string &dropReason) { if(endpointTenantMap.shouldPrintTenant == false) return isPermit; - std::string sourceTenant = endpointTenantMap.GetMapping(p.meta[PIM::SOURCE_EPG]); - std::string destinationTenant = endpointTenantMap.GetMapping(p.meta[PIM::DESTINATION_EPG]); + std::string sourceTenant = ""; + std::string destinationTenant = ""; + if(p.meta[PIM::SOURCE_BRIDGE] == 1){ + sourceTenant = endpointTenantMap.GetVNIDMapping(p.meta[PIM::SOURCE_EPG]); + destinationTenant = endpointTenantMap.GetVNIDMapping(p.meta[PIM::DESTINATION_EPG]); + }else{ + sourceTenant = endpointTenantMap.GetPortMapping(endpointTenantMap.GetMatchingPort(p.meta[PIM::OUTPUT_PORT])); + destinationTenant = endpointTenantMap.GetPortMapping(p.meta[PIM::OUTPUT_PORT]); + } if(sourceTenant.empty()) sourceTenant = "N/A"; if(destinationTenant.empty()) destinationTenant = "N/A"; - dropReason += " "+sourceTenant; - dropReason += " "+destinationTenant; + dropReason += " STID="+sourceTenant; + dropReason += " DTID="+destinationTenant; return isPermit; } diff --git a/agent-ovs/ovs/include/EndpointTenantMapper.h b/agent-ovs/ovs/include/EndpointTenantMapper.h new file mode 100644 index 00000000..e1c00e41 --- /dev/null +++ b/agent-ovs/ovs/include/EndpointTenantMapper.h @@ -0,0 +1,121 @@ +/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */ +/* + * Definition 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 + */ + +#ifndef OPFLEXAGENT_ENDPOINTTENANTMAPPER_H_ +#define OPFLEXAGENT_ENDPOINTTENANTMAPPER_H_ + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "SwitchManager.h" + +using std::unordered_map; + +namespace opflexagent { + +/** + * Class to keep track of EPG vnid -> Tenant ID + * and Output Port -> Tenant ID mapping. +*/ +class EndpointTenantMapper : public EndpointListener, + public ExtraConfigListener, + public LearningBridgeListener, + public PortStatusListener, + private boost::noncopyable { +public: + EndpointTenantMapper(Agent* agent_, SwitchManager* accessSwitchManager_, boost::asio::io_service& ioService_); + void start(); + void stop(); + /** + * Update or create a mapping between the given vnid + * and value. + */ + void UpdateVNIDMapping(uint32_t key, std::string value); + /** + * Update or create a mapping between the given key + * and tenant, which is extracted from the EPG URI. + */ + void UpdateVNIDMappingFromURI(uint32_t key, std::string uri); + /** + * Update or creating a mapping between the given port + * and tenant. + */ + void UpdatePortMapping(uint32_t key, std::string value); + /** + * Update or create a mapping between the given key + * and tenant, which is extracted from the EPG URI. + */ + void UpdatePortMappingFromURI(uint32_t key, std::string uri); + /** + * Create a mapping between an access and uplink port. + */ + void SetPortToPortMapping(uint32_t inPort, uint32_t outPort); + /** + * Get the mapping for the given key, if available. + * If no mapping exists, returns an empty string. + */ + std::string GetVNIDMapping(uint32_t key); + /** + * Get the mapping for the given key, if available. + * If no mapping exists, returns an empty string. + */ + std::string GetPortMapping(uint32_t key); + /** + * Get the port opposite of the one given. + */ + uint32_t GetMatchingPort(uint32_t port); + /** + * If the drop log should include the source/destination + * tenant. + */ + bool shouldPrintTenant; + + /* Interface: EndpointListener */ + virtual void endpointUpdated(const std::string& uuid); + virtual void secGroupSetUpdated(const EndpointListener::uri_set_t& secGrps){} + + /* Interface: LearningBridgeListener */ + virtual void lbIfaceUpdated(const std::string& uuid); + + /* Interface: ExtraConfigListener */ + virtual void rdConfigUpdated(const opflex::modb::URI& rdURI){} + virtual void packetDropLogConfigUpdated(const opflex::modb::URI& dropLogCfgURI); + virtual void packetDropFlowConfigUpdated(const opflex::modb::URI& dropFlowCfgURI){} + virtual void packetDropPruneConfigUpdated(const std::string& pruneFilter){} + + /* Interface: PortStatusListener */ + virtual void portStatusUpdate(const std::string& portName, + uint32_t portNo, bool fromDesc); +private: + void handleEndpointUpdate(const string& uuid); + void handlePortStatusUpdate(const std::string& portName, uint32_t portNo); + + Agent* agent; + SwitchManager* accessSwitchManager; + unordered_map endpointTenantMap; + unordered_map portTenantMap; + unordered_map portToPortMap; + TaskQueue taskQueue; + std::atomic stopping; +}; + +} /* namespace opflexagent */ + +#endif // OPFLEXAGENT_ENDPOINTTENANTMAPPER_H_ \ No newline at end of file diff --git a/agent-ovs/ovs/include/IntFlowManager.h b/agent-ovs/ovs/include/IntFlowManager.h index 89929131..5beb8e35 100644 --- a/agent-ovs/ovs/include/IntFlowManager.h +++ b/agent-ovs/ovs/include/IntFlowManager.h @@ -17,7 +17,6 @@ #include #include "SwitchManager.h" #include -#include #include "ActionBuilder.h" #include "AdvertManager.h" #include @@ -75,8 +74,7 @@ class IntFlowManager : public SwitchStateHandler, SwitchManager& switchManager, IdGenerator& idGen, CtZoneManager& ctZoneManager, - TunnelEpManager& tnlEpManager, - EndpointTenantMapper& endpointTenantMapper); + TunnelEpManager& tnlEpManager); ~IntFlowManager() {} /** @@ -1064,8 +1062,6 @@ class IntFlowManager : public SwitchStateHandler, typedef std::unordered_map natFlowMatchKey; natFlowMatchKey natEpMap; - - EndpointTenantMapper& endpointTenantMapper; }; } // namespace opflexagent diff --git a/agent-ovs/ovs/include/OVSRenderer.h b/agent-ovs/ovs/include/OVSRenderer.h index 2a07a0a4..6280b95d 100644 --- a/agent-ovs/ovs/include/OVSRenderer.h +++ b/agent-ovs/ovs/include/OVSRenderer.h @@ -21,7 +21,7 @@ #include "SecGrpStatsManager.h" #include "TableDropStatsManager.h" #include -#include +#include "EndpointTenantMapper.h" #include "PacketInHandler.h" #include "CtZoneManager.h" #include "SpanRenderer.h" @@ -69,7 +69,6 @@ class OVSRenderer : public Renderer, private: IdGenerator idGen; - EndpointTenantMapper endpointTenantMapper; CtZoneManager ctZoneManager; FlowExecutor intFlowExecutor; @@ -85,6 +84,7 @@ class OVSRenderer : public Renderer, SwitchManager accessSwitchManager; AccessFlowManager accessFlowManager; + EndpointTenantMapper endpointTenantMapper; PacketInHandler pktInHandler; InterfaceStatsManager interfaceStatsManager; diff --git a/agent-ovs/ovs/include/PacketDecoder.h b/agent-ovs/ovs/include/PacketDecoder.h index 9cfe6458..3f7c7250 100644 --- a/agent-ovs/ovs/include/PacketDecoder.h +++ b/agent-ovs/ovs/include/PacketDecoder.h @@ -141,7 +141,8 @@ typedef enum { CAPTURE_REASON, POLICY_TRIGGERED_DROP, SOURCE_EPG, - DESTINATION_EPG + DESTINATION_EPG, + OUTPUT_PORT } ParseInfoMetaType; /** @@ -231,9 +232,11 @@ struct ParseInfo { */ PacketTuple packetTuple; /** - * Source Bridge,TableId,CaptureReason,Policies triggered the drop,sourceEPG,destinationEPG + * Source Bridge, TableId, CaptureReason, + * Policies triggered the drop, + * sourceEPG, destinationEPG, Output Port */ - uint32_t meta[6]; + uint32_t meta[7]; /** * Prune logs for this packet */ diff --git a/agent-ovs/ovs/include/PacketDecoderLayers.h b/agent-ovs/ovs/include/PacketDecoderLayers.h index 1742e2b6..e8d7b8fb 100644 --- a/agent-ovs/ovs/include/PacketDecoderLayers.h +++ b/agent-ovs/ovs/include/PacketDecoderLayers.h @@ -136,6 +136,18 @@ class GeneveOptDestinationEPGLayerVariant: public PacketDecoderLayerVariant { virtual void reParse(ParseInfo &p); }; +/** + * Variant implementing output port + */ +class GeneveOptOutputPortLayerVariant: public PacketDecoderLayerVariant { +public: + GeneveOptOutputPortLayerVariant():PacketDecoderLayerVariant("GeneveOpt", "OutputPort", 5, 6){}; + virtual ~GeneveOptOutputPortLayerVariant() {}; + virtual int configure(); + virtual void getFormatString(boost::format &fmtStr); + virtual void reParse(ParseInfo &p); +}; + /** * Layer implementing ARP */ diff --git a/agent-ovs/ovs/include/PacketLogHandler.h b/agent-ovs/ovs/include/PacketLogHandler.h index e49cda56..b4b966ea 100644 --- a/agent-ovs/ovs/include/PacketLogHandler.h +++ b/agent-ovs/ovs/include/PacketLogHandler.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include "EndpointTenantMapper.h" #include "PacketDecoderLayers.h" #include #include diff --git a/agent-ovs/ovs/test/AccessFlowManager_test.cpp b/agent-ovs/ovs/test/AccessFlowManager_test.cpp index d125959e..5be64077 100644 --- a/agent-ovs/ovs/test/AccessFlowManager_test.cpp +++ b/agent-ovs/ovs/test/AccessFlowManager_test.cpp @@ -39,7 +39,7 @@ using opflex::modb::Mutator; class AccessFlowManagerFixture : public FlowManagerFixture { public: AccessFlowManagerFixture() - : accessFlowManager(agent, switchManager, idGen, ctZoneManager) { + : accessFlowManager(agent, switchManager, idGen, ctZoneManager){ expTables.resize(AccessFlowManager::NUM_FLOW_TABLES); switchManager.registerStateHandler(&accessFlowManager); idGen.initNamespace("l24classifierRule"); diff --git a/agent-ovs/ovs/test/AdvertManager_test.cpp b/agent-ovs/ovs/test/AdvertManager_test.cpp index 39ec4910..a78888fd 100644 --- a/agent-ovs/ovs/test/AdvertManager_test.cpp +++ b/agent-ovs/ovs/test/AdvertManager_test.cpp @@ -41,8 +41,7 @@ class AdvertManagerFixture : public ModbFixture { : ModbFixture(), ctZoneManager(idGen), switchManager(agent, flowExecutor, flowReader, portMapper), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), advertManager(agent, intFlowManager), dnsManager(agent), pktInHandler(agent, intFlowManager, dnsManager) { @@ -161,7 +160,6 @@ class AdvertManagerFixture : public ModbFixture { DnsManager dnsManager; PacketInHandler pktInHandler; ofputil_protocol proto; - EndpointTenantMapper endpointTenantMapper; }; class EpAdvertFixtureGU : public AdvertManagerFixture { diff --git a/agent-ovs/ovs/test/ContractStatsManager_test.cpp b/agent-ovs/ovs/test/ContractStatsManager_test.cpp index d5bb1ebf..dde9b3ce 100644 --- a/agent-ovs/ovs/test/ContractStatsManager_test.cpp +++ b/agent-ovs/ovs/test/ContractStatsManager_test.cpp @@ -63,8 +63,7 @@ class ContractStatsManagerFixture : public PolicyStatsManagerFixture { public: ContractStatsManagerFixture() : PolicyStatsManagerFixture(), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), contractStatsManager(&agent, idGen, switchManager, 300), policyManager(agent.getPolicyManager()) { diff --git a/agent-ovs/ovs/test/DnsManager_test.cpp b/agent-ovs/ovs/test/DnsManager_test.cpp index 4072512c..bc36e64b 100644 --- a/agent-ovs/ovs/test/DnsManager_test.cpp +++ b/agent-ovs/ovs/test/DnsManager_test.cpp @@ -167,8 +167,7 @@ class DnsManagerFixture : public ModbFixture ModbFixture(), ctZoneManager(idGen), switchManager(agent, flowExecutor, flowReader, intPortMapper), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), dnsManager(agent), pktInHandler(agent, intFlowManager, dnsManager), proto(ofputil_protocol_from_ofp_version @@ -194,7 +193,6 @@ class DnsManagerFixture : public ModbFixture MockPortMapper accPortMapper; MockSwitchManager switchManager; IntFlowManager intFlowManager; - EndpointTenantMapper endpointTenantMapper; protected: DnsManager dnsManager; PacketInHandler pktInHandler; diff --git a/agent-ovs/ovs/test/IntFlowManager_test.cpp b/agent-ovs/ovs/test/IntFlowManager_test.cpp index 394f8f0d..d8329bf5 100644 --- a/agent-ovs/ovs/test/IntFlowManager_test.cpp +++ b/agent-ovs/ovs/test/IntFlowManager_test.cpp @@ -78,8 +78,7 @@ class BaseIntFlowManagerFixture : public FlowManagerFixture { BaseIntFlowManagerFixture() : FlowManagerFixture(), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), dnsManager(agent), pktInHandler(agent, intFlowManager,dnsManager), policyMgr(agent.getPolicyManager()), diff --git a/agent-ovs/ovs/test/NatStatsManager_test.cpp b/agent-ovs/ovs/test/NatStatsManager_test.cpp index 18ce77ea..e311eae8 100644 --- a/agent-ovs/ovs/test/NatStatsManager_test.cpp +++ b/agent-ovs/ovs/test/NatStatsManager_test.cpp @@ -52,8 +52,7 @@ class NatStatsManagerFixture : public PolicyStatsManagerFixture { public: NatStatsManagerFixture() : PolicyStatsManagerFixture(), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), dnsManager(agent), pktInHandler(agent, intFlowManager, dnsManager), policyMgr(agent.getPolicyManager()), diff --git a/agent-ovs/ovs/test/PacketDecoder_test.cpp b/agent-ovs/ovs/test/PacketDecoder_test.cpp index 080e2922..640e44e9 100644 --- a/agent-ovs/ovs/test/PacketDecoder_test.cpp +++ b/agent-ovs/ovs/test/PacketDecoder_test.cpp @@ -10,23 +10,23 @@ #include #include "MockPacketLogHandler.h" #include -#include +#include "EndpointTenantMapper.h" BOOST_AUTO_TEST_SUITE(PacketDecoder_test) using namespace std; using namespace opflexagent; /*Dummy io_service objects for constructor*/ -static boost::asio::io_service io_1,io_2; +static boost::asio::io_service io_1,io_2,io_3; class PacketDecoderFixture { public: - PacketDecoderFixture():pktLogger(io_1,io_2,idGen,endpointTenantMapper){ + PacketDecoderFixture(): endpointTenantMapper(NULL, NULL, io_3), pktLogger(io_1,io_2,idGen,endpointTenantMapper){ pktLogger.startListener(); endpointTenantMapper.shouldPrintTenant = false; }; + EndpointTenantMapper endpointTenantMapper; MockPacketLogHandler pktLogger; opflexagent::IdGenerator idGen; - opflexagent::EndpointTenantMapper endpointTenantMapper; }; static const uint8_t arp_buf[] = { @@ -276,7 +276,7 @@ BOOST_FIXTURE_TEST_CASE(enhanceDropReason_test, PacketDecoderFixture) { u1_id = idGen.getId(nmspc, u1); BOOST_CHECK(u1_id != 0); BOOST_CHECK(u1_id == idGen.getId(nmspc, u1)); - std::string expected("Int-POL_TABLE DENY /PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/ N/A N/A"); + std::string expected("Int-POL_TABLE DENY /PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/ STID=N/A DTID=N/A"); auto pktDecoder = pktLogger.getDecoder(); ParseInfo p(&pktDecoder); int ret = pktDecoder.decode(arp_stream, 186, p); @@ -292,14 +292,14 @@ BOOST_FIXTURE_TEST_CASE(printSourceTenant_test, PacketDecoderFixture) { string nmspc("l24classifierRule"); string u1("/PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/"); uint32_t u1_id; - endpointTenantMapper.UpdateMapping(4660, "tenantA"); - endpointTenantMapper.UpdateMapping(12288, "tenantB"); + endpointTenantMapper.UpdateVNIDMapping(4660, "tenantA"); + endpointTenantMapper.UpdateVNIDMapping(12288, "tenantB"); idGen.setPersistLocation(dir); idGen.initNamespace(nmspc); u1_id = idGen.getId(nmspc, u1); BOOST_CHECK(u1_id != 0); BOOST_CHECK(u1_id == idGen.getId(nmspc, u1)); - std::string expected("Int-POL_TABLE DENY /PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/ tenantA tenantB"); + std::string expected("Int-POL_TABLE DENY /PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/ STID=tenantA DTID=tenantB"); auto pktDecoder = pktLogger.getDecoder(); ParseInfo p(&pktDecoder); int ret = pktDecoder.decode(arp_stream, 186, p); diff --git a/agent-ovs/ovs/test/PacketInHandler_test.cpp b/agent-ovs/ovs/test/PacketInHandler_test.cpp index 5812eba9..9c4462ef 100644 --- a/agent-ovs/ovs/test/PacketInHandler_test.cpp +++ b/agent-ovs/ovs/test/PacketInHandler_test.cpp @@ -37,8 +37,7 @@ class PacketInHandlerFixture : public ModbFixture { : ModbFixture(), ctZoneManager(idGen), switchManager(agent, flowExecutor, flowReader, intPortMapper), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), dnsManager(agent), pktInHandler(agent, intFlowManager, dnsManager), proto(ofputil_protocol_from_ofp_version @@ -103,7 +102,6 @@ class PacketInHandlerFixture : public ModbFixture { DnsManager dnsManager; PacketInHandler pktInHandler; ofputil_protocol proto; - EndpointTenantMapper endpointTenantMapper; }; static const uint8_t pkt_dhcpv4_discover[] = diff --git a/agent-ovs/ovs/test/ServiceStatsManager_test.cpp b/agent-ovs/ovs/test/ServiceStatsManager_test.cpp index 6df4e632..dcbd1850 100644 --- a/agent-ovs/ovs/test/ServiceStatsManager_test.cpp +++ b/agent-ovs/ovs/test/ServiceStatsManager_test.cpp @@ -63,8 +63,7 @@ class ServiceStatsManagerFixture : public PolicyStatsManagerFixture { public: ServiceStatsManagerFixture() : PolicyStatsManagerFixture(), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), dnsManager(agent), pktInHandler(agent, intFlowManager, dnsManager), serviceStatsManager(&agent, idGen, diff --git a/agent-ovs/ovs/test/TableDropStatsManager_test.cpp b/agent-ovs/ovs/test/TableDropStatsManager_test.cpp index 5733a1c5..6fa7523e 100644 --- a/agent-ovs/ovs/test/TableDropStatsManager_test.cpp +++ b/agent-ovs/ovs/test/TableDropStatsManager_test.cpp @@ -118,8 +118,7 @@ class TableDropStatsManagerFixture : public PolicyStatsManagerFixture { accBr(agent, exec, reader, accPortMapper), intFlowManager(agent, switchManager, idGen, - ctZoneManager, tunnelEpManager, - endpointTenantMapper), + ctZoneManager, tunnelEpManager), accFlowManager(agent, accBr, idGen, ctZoneManager), dnsManager(agent), diff --git a/agent-ovs/ovs/test/include/FlowManagerFixture.h b/agent-ovs/ovs/test/include/FlowManagerFixture.h index 2035c3da..1f05847a 100644 --- a/agent-ovs/ovs/test/include/FlowManagerFixture.h +++ b/agent-ovs/ovs/test/include/FlowManagerFixture.h @@ -58,7 +58,6 @@ class FlowManagerFixture : public ModbFixture { } IdGenerator idGen; - EndpointTenantMapper endpointTenantMapper; CtZoneManager ctZoneManager; MockFlowExecutor exec; MockFlowReader reader;