Skip to content

Commit

Permalink
Out of band config handling
Browse files Browse the repository at this point in the history
Change frequency of tunnel ep advertisement timer,
based on out-of-band-config file inserted by host-agent.

Signed-off-by: Kiran Shastri <[email protected]>
  • Loading branch information
shastrinator committed Sep 2, 2024
1 parent 39090f8 commit 8326f7e
Show file tree
Hide file tree
Showing 21 changed files with 370 additions and 7 deletions.
3 changes: 3 additions & 0 deletions agent-ovs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ libopflex_agent_la_include_HEADERS = \
lib/include/opflexagent/FSNetpolSource.h \
lib/include/opflexagent/FSPacketDropLogConfigSource.h \
lib/include/opflexagent/PacketDropLogConfig.h \
lib/include/opflexagent/FSOutOfBandConfigSource.h \
lib/include/opflexagent/OutOfBandConfig.h \
lib/include/opflexagent/Faults.h \
lib/include/opflexagent/PrometheusManager.h

Expand Down Expand Up @@ -231,6 +233,7 @@ libopflex_agent_la_SOURCES = \
lib/SnatSource.cpp \
lib/FSNetpolSource.cpp \
lib/FSPacketDropLogConfigSource.cpp \
lib/FSOutOfBandConfigSource.cpp \
lib/AgentPrometheusManager.cpp

libopflex_agent_la_LDFLAGS = -shared -version-info ${VERSION_INFO}
Expand Down
20 changes: 20 additions & 0 deletions agent-ovs/lib/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void Agent::setProperties(const boost::property_tree::ptree& properties) {
static const std::string SNAT_SOURCE_PATH("snat-sources.filesystem");
static const std::string NETPOL_SOURCE_PATH("netpol-sources.filesystem");
static const std::string DROP_LOG_CFG_SOURCE_FSPATH("drop-log-config-sources.filesystem");
static const std::string OUT_OF_BAND_CFG_SOURCE_FSPATH("out-of-band-config-sources.filesystem");
static const std::string FAULT_SOURCE_FSPATH("host-agent-fault-sources.filesystem");
static const std::string PACKET_EVENT_NOTIF_SOCK("packet-event-notif.socket-name");
static const std::string OPFLEX_PEERS("opflex.peers");
Expand Down Expand Up @@ -346,6 +347,16 @@ void Agent::setProperties(const boost::property_tree::ptree& properties) {
for (const ptree::value_type &v : dropLogCfgSrc.get())
dropLogCfgSourcePath = v.second.data();
}

optional<const ptree&> outOfBandCfgSrc =
properties.get_child_optional(OUT_OF_BAND_CFG_SOURCE_FSPATH);

if (outOfBandCfgSrc) {
for (const ptree::value_type &v : outOfBandCfgSrc.get())
oobCfgSourcePath = v.second.data();
} else {
oobCfgSourcePath = "/usr/local/var/lib/opflex-agent-ovs/outofband";
}

optional<const ptree&> hostAgentFaultSrc =
properties.get_child_optional(FAULT_SOURCE_FSPATH);
Expand Down Expand Up @@ -740,6 +751,14 @@ void Agent::start() {
dropLogCfgSource.reset(new FSPacketDropLogConfigSource(&extraConfigManager,
fsWatcher, dropLogCfgSourcePath, uri));
}
if(!oobCfgSourcePath.empty()) {
opflex::modb::URI uri = (opflex::modb::URIBuilder()
.addElement("PolicyUniverse").addElement("ObserverOutOfBandConfig")
.build());
oobCfgSource.reset(new FSOutOfBandConfigSource(&extraConfigManager,
fsWatcher, oobCfgSourcePath, uri));
}

for (const std::string& path : hostAgentFaultPaths) {
FaultSource* source =
new FSFaultSource(&faultManager, fsWatcher, path, *this);
Expand Down Expand Up @@ -857,6 +876,7 @@ void Agent::createUniverse (std::shared_ptr<modelgbp::dmtree::Root> root)
root->addObserverSvcStatUniverse();
root->addObserverPolicyStatUniverse();
root->addObserverDropFlowConfigUniverse();
root->addObserverOutOfBandConfigUniverse();
root->addSpanUniverse();
root->addEpdrExternalDiscovered();
root->addEpdrLocalRouteDiscovered();
Expand Down
38 changes: 38 additions & 0 deletions agent-ovs/lib/ExtraConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <modelgbp/observer/DropFlowConfigUniverse.hpp>
#include <modelgbp/observer/DropFlowConfig.hpp>
#include <modelgbp/observer/DropPruneConfig.hpp>
#include <modelgbp/observer/OutOfBandConfigUniverse.hpp>
#include <modelgbp/observer/OutOfBandConfig.hpp>
#include <opflex/modb/Mutator.h>

#include <memory>
Expand Down Expand Up @@ -102,6 +104,42 @@ void ExtraConfigManager::notifyPacketDropPruneConfigListeners(const std::string
}
}

void ExtraConfigManager::notifyOutOfBandConfigListeners(std::shared_ptr<OutOfBandConfigSpec> &oobSptr) {
unique_lock<mutex> guard(listener_mutex);
for (ExtraConfigListener* listener : extraConfigListeners) {
listener->outOfBandConfigUpdated(oobSptr);
}
}

void ExtraConfigManager::outOfBandConfigUpdated(const OutOfBandConfigSpec &outOfBandCfg) {
using modelgbp::observer::OutOfBandConfigUniverse;
using modelgbp::observer::OutOfBandConfig;
Mutator mutator(framework, "policyelement");
optional<shared_ptr<OutOfBandConfigUniverse>> oobCfgUni =
OutOfBandConfigUniverse::resolve(framework);
shared_ptr<OutOfBandConfig> oobCfg =
oobCfgUni.get()->addObserverOutOfBandConfig();
oobCfg->setTunnelEpAdvertisementInterval(outOfBandCfg.tunnelEpAdvInterval);
mutator.commit();
shared_ptr<OutOfBandConfigSpec> oobSptr(new OutOfBandConfigSpec(outOfBandCfg.tunnelEpAdvInterval));
notifyOutOfBandConfigListeners(oobSptr);
}

void ExtraConfigManager::outOfBandConfigDeleted() {
using modelgbp::observer::OutOfBandConfigUniverse;
using modelgbp::observer::OutOfBandConfig;
Mutator mutator(framework, "policyelement");
optional<shared_ptr<OutOfBandConfigUniverse>> oobCfgUni =
OutOfBandConfigUniverse::resolve(framework);
opflex::modb::URI oobCfgURI =
opflex::modb::URIBuilder(oobCfgUni.get()->getURI())
.addElement("ObserverOutOfBandConfig").build();
OutOfBandConfig::remove(framework, oobCfgURI);
mutator.commit();
shared_ptr<OutOfBandConfigSpec> oobSptr;
notifyOutOfBandConfigListeners(oobSptr);
}

void ExtraConfigManager::packetDropLogConfigUpdated(PacketDropLogConfig &dropCfg) {
using modelgbp::observer::DropLogConfig;

Expand Down
87 changes: 87 additions & 0 deletions agent-ovs/lib/FSOutOfBandConfigSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
* Implementation for FSOutOfBandConfigSource 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
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(HAVE_SYS_INOTIFY_H) && defined(HAVE_SYS_EVENTFD_H)
#define USE_INOTIFY
#endif

#include <stdexcept>
#include <sstream>

#include <boost/property_tree/json_parser.hpp>
#include <boost/algorithm/string.hpp>
#include <opflex/modb/URIBuilder.h>
#include <boost/algorithm/string/predicate.hpp>
#include <opflexagent/FSOutOfBandConfigSource.h>
#include <modelgbp/observer/DropLogModeEnumT.hpp>
#include <opflexagent/ExtraConfigManager.h>
#include <opflexagent/logging.h>

namespace opflexagent {

using boost::optional;
namespace fs = boost::filesystem;
using std::string;
using std::make_pair;
using std::runtime_error;
using opflex::modb::URI;
using boost::asio::ip::address;
using modelgbp::observer::DropLogModeEnumT;

FSOutOfBandConfigSource::FSOutOfBandConfigSource(ExtraConfigManager* manager_,
FSWatcher& listener,
const std::string& serviceDir,
const opflex::modb::URI &uri)
: manager(manager_) {
listener.addWatch(serviceDir, *this);
}

static bool isOutOfBandConfig(const fs::path& filePath) {
string fstr = filePath.filename().string();
return (fstr == "aci-containers-system.oob");
}

void FSOutOfBandConfigSource::updated(const fs::path& filePath) {
using boost::property_tree::ptree;
ptree properties;
try {
if (isOutOfBandConfig(filePath)) {
const string& pathStr = filePath.string();
read_json(pathStr, properties);
const std::string TUNNEL_ADV_INTVL("tunnel-ep-advertisement-interval");
OutOfBandConfigSpec oobSpec(properties.get<long>(TUNNEL_ADV_INTVL, 300));
manager->outOfBandConfigUpdated(oobSpec);
}
} catch (const std::exception& ex) {
LOG(ERROR) << "Could not update out of band config for "
<< filePath << ": "
<< ex.what();
}

}

void FSOutOfBandConfigSource::deleted(const fs::path& filePath) {
try {
string pathStr = filePath.string();
if (isOutOfBandConfig(filePath)) {
manager->outOfBandConfigDeleted();
}
} catch (const std::exception& ex) {
LOG(ERROR) << "Could not delete out of band config for "
<< filePath << ": "
<< ex.what();
}
}

} /* namespace opflexagent */
4 changes: 3 additions & 1 deletion agent-ovs/lib/include/opflexagent/Agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <opflexagent/NetFlowManager.h>
#include <opflexagent/QosManager.h>
#include <opflexagent/SysStatsManager.h>
#include <opflexagent/FSOutOfBandConfigSource.h>

#include <opflexagent/PrometheusManager.h>

Expand Down Expand Up @@ -396,10 +397,11 @@ typedef opflex::ofcore::OFConstants::OpflexElementMode opflex_elem_t;
std::vector<std::unique_ptr<FSRDConfigSource>> rdConfigSources;
std::vector<std::unique_ptr<LearningBridgeSource>> learningBridgeSources;
std::string dropLogCfgSourcePath;
std::string oobCfgSourcePath;
std::set<std::string> hostAgentFaultPaths;
std::string packetEventNotifSockPath;
std::unique_ptr<FSPacketDropLogConfigSource> dropLogCfgSource;

std::unique_ptr<FSOutOfBandConfigSource> oobCfgSource;
std::set<std::string> serviceSourcePaths;
std::vector<std::unique_ptr<ServiceSource>> serviceSources;

Expand Down
9 changes: 9 additions & 0 deletions agent-ovs/lib/include/opflexagent/ExtraConfigListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define OPFLEXAGENT_EXTRACONFIGLISTENER_H

#include <opflex/modb/URI.h>
#include <opflexagent/OutOfBandConfig.h>

namespace opflexagent {

Expand Down Expand Up @@ -60,6 +61,14 @@ class ExtraConfigListener {
* @param filterName Prune filter name
*/
virtual void packetDropPruneConfigUpdated(const std::string &filterName) = 0;

/**
* Called when an out of band config is updated
*
* @param oobSptr out of band config shared pointer
*/
virtual void outOfBandConfigUpdated(std::shared_ptr<OutOfBandConfigSpec> &oobSptr) = 0;

};

} /* namespace opflexagent */
Expand Down
20 changes: 20 additions & 0 deletions agent-ovs/lib/include/opflexagent/ExtraConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ class ExtraConfigManager : private boost::noncopyable {
*/
void notifyPacketDropPruneConfigListeners(const std::string &dropPruneFilterName);

/**
* Notify listeners for out of band config object
*
* @param oobSptr shared ptr to OutOfBandConfig
*/
void notifyOutOfBandConfigListeners(std::shared_ptr<OutOfBandConfigSpec> &oobSptr);

/**
* Add or update an out of band config object
*
* @param oobCfg Out Of Band Config object
*/
void outOfBandConfigUpdated(const OutOfBandConfigSpec &oobCfg);

/**
* Delete an out of band config object
*/
void outOfBandConfigDeleted();

/**
* Add or update a packet drop log config object
*
Expand Down Expand Up @@ -167,6 +186,7 @@ class ExtraConfigManager : private boost::noncopyable {

friend class FSRDConfigSource;
friend class FSPacketDropLogConfigSource;
friend class FSOutOfBandConfigSource;
};

} /* namespace opflexagent */
Expand Down
58 changes: 58 additions & 0 deletions agent-ovs/lib/include/opflexagent/FSOutOfBandConfigSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
* Include file for filesystem out of band config source
*
* 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
*/

#pragma once
#ifndef OPFLEXAGENT_OUTOFBANDCONFIGSOURCE_H
#define OPFLEXAGENT_OUTOFBANDCONFIGSOURCE_H

#include <opflexagent/FSWatcher.h>
#include <boost/filesystem.hpp>

#include <opflexagent/OutOfBandConfig.h>

#include <string>

namespace opflexagent {

class ExtraConfigManager;

/**
* An out of band config source that gets information for
* out of band config from the filesystem.
*/
class FSOutOfBandConfigSource : public FSWatcher::Watcher {
public:
/**
* Instantiate a new out of band config source. It will set a
* watch on the given path.
*/
FSOutOfBandConfigSource(ExtraConfigManager* manager,
FSWatcher& listener,
const std::string& OutOfBandConfigDir,
const opflex::modb::URI& uri);

/**
* Destroy the out of band config source and clean up all state
*/
virtual ~FSOutOfBandConfigSource() {}

// See Watcher
virtual void updated(const boost::filesystem::path& filePath);
// See Watcher
virtual void deleted(const boost::filesystem::path& filePath);

private:
ExtraConfigManager* manager;
};

} /* namespace opflexagent */

#endif /* OPFLEXAGENT_OUTOFBANDCONFIGSOURCE_H */
24 changes: 24 additions & 0 deletions agent-ovs/lib/include/opflexagent/OutOfBandConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
* Include file for out of band config
*
* Copyright (c) 2020 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
*/

#pragma once
#ifndef OPFLEXAGENT_OUTOFBANDCONFIG_H
#define OPFLEXAGENT_OUTOFBANDCONFIG_H

namespace opflexagent {
class OutOfBandConfigSpec {
public:
OutOfBandConfigSpec(long intvl):tunnelEpAdvInterval(intvl) {};
long tunnelEpAdvInterval;
};
} /* namespace opflexagent */

#endif /* OPFLEXAGENT_OUTOFBANDCONFIG_H */
8 changes: 8 additions & 0 deletions agent-ovs/lib/include/opflexagent/TunnelEpManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ class TunnelEpManager : private boost::noncopyable {
return (uuid == tunnelEpUUID);
}

/**
* Get TunnelEp's UUID
* @return TunnelEp's UUID
*/
std::string getTunnelEpUUID() {
return tunnelEpUUID;
}

private:
Agent* agent;
Renderer* renderer;
Expand Down
Loading

0 comments on commit 8326f7e

Please sign in to comment.