Skip to content

Commit

Permalink
Add enable config option for startup section
Browse files Browse the repository at this point in the history
    "opflex": {
       "startup": {
            "enabled": "true",

with default being false. If false none of the startup related code
will be executed.

Also create a startup subdir ${VARDIR}/lib/opflex-agent-ovs/startup

Signed-off-by: Madhu Challa <challa@gmail.com>
  • Loading branch information
mchalla committed May 21, 2024
1 parent 0402fb3 commit 75d3721
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
13 changes: 11 additions & 2 deletions agent-ovs/lib/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ Agent::Agent(OFFramework& framework_, const LogParams& _logParams)
prometheusExposeLocalHostOnly(false),
prometheusExposeEpSvcNan(false),
behaviorL34FlowsWithoutSubnet(true),
logParams(_logParams) {
logParams(_logParams),
startupPolicyEnabled(false) {
std::random_device rng;
std::mt19937 urng(rng());
uuid = to_string(basic_random_generator<std::mt19937>(urng)());
Expand Down Expand Up @@ -189,6 +190,7 @@ void Agent::setProperties(const boost::property_tree::ptree& properties) {
static const std::string BEHAVIOR_L34FLOWS_WITHOUT_SUBNET("behavior.l34flows-without-subnet");
static const std::string OPFLEX_ASYC_JSON("opflex.asyncjson.enabled");
static const std::string OVS_ASYNC_JSON("ovs.asyncjson.enabled");
static const std::string OPFLEX_STARTUP_POLICY_ENABLED("opflex.startup.enabled");
static const std::string OPFLEX_POLICY_FILE("opflex.startup.policy-file");
static const std::string OPFLEX_LOCAL_RESOLVE_AFTER_CONNECTION("opflex.startup.resolve-aft-conn");
static const std::string OPFLEX_STARTUP_POLICY_DURATION("opflex.startup.policy-duration");
Expand Down Expand Up @@ -527,6 +529,13 @@ void Agent::setProperties(const boost::property_tree::ptree& properties) {
setenv("OVS_USE_ASYNC_JSON", "", true);
}

optional<bool> startupPolicy =
properties.get_optional<bool>(OPFLEX_STARTUP_POLICY_ENABLED);
if (startupPolicy && startupPolicy.get() == true) {
startupPolicyEnabled = true;
LOG(INFO) << "Startup policy is enabled";
}

optional<std::string> policyFile =
properties.get_optional<std::string>(OPFLEX_POLICY_FILE);
if (policyFile) {
Expand Down Expand Up @@ -606,7 +615,7 @@ void Agent::applyProperties() {
framework.setHandshakeTimeout(peerHandshakeTimeout);
framework.setKeepaliveTimeout(keepaliveTimeout);
framework.setStartupPolicy(opflexPolicyFile, modelgbp::getMetadata(),
startupPolicyDuration,
startupPolicyDuration, startupPolicyEnabled,
localResolveAftConn);
}

Expand Down
1 change: 1 addition & 0 deletions agent-ovs/lib/include/opflexagent/Agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ typedef opflex::ofcore::OFConstants::OpflexElementMode opflex_elem_t;
bool behaviorL34FlowsWithoutSubnet;
LogParams logParams;
/* Persistent policy from disk */
bool startupPolicyEnabled;
boost::optional<std::string> opflexPolicyFile;
};

Expand Down
1 change: 1 addition & 0 deletions docker/travis/launch-opflexagent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if [ -w ${PREFIX} ]; then
mkdir -p ${VARDIR}/lib/opflex-agent-ovs/reboot-conf.d
mkdir -p ${VARDIR}/lib/opflex-agent-ovs/droplog
mkdir -p ${VARDIR}/lib/opflex-agent-ovs/faults
mkdir -p ${VARDIR}/lib/opflex-agent-ovs/startup
fi

if [ -d ${OPFLEXAGENT_CONF_PATH} ]; then
Expand Down
15 changes: 13 additions & 2 deletions libopflex/engine/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ void Processor::sendToRole(const item& i, uint64_t& newexp,
}

bool Processor::shouldResolveLocal() {
if (!startupPolicyEnabled) return false;

uint64_t curtime = now(proc_loop);
// check >= for duration 0 because now wont update till next uv_loop
if (!opflexPolicyFile
Expand Down Expand Up @@ -698,7 +700,14 @@ bool Processor::waitForPendingItems(uint32_t& wait) {
void Processor::setStartupPolicy(boost::optional<std::string>& file,
const modb::ModelMetadata& model,
uint64_t& duration,
bool& enabled,
bool& resolve_after_connection) {
if (enabled == false) {
LOG(INFO) << "Startup policy disabled";
return;
}

startupPolicyEnabled = enabled;
opflexPolicyFile = file;
if (file) {
startupdb.init(model);
Expand Down Expand Up @@ -733,8 +742,10 @@ void Processor::start(ofcore::OFConstants::OpflexElementMode agent_mode) {

LOG(DEBUG) << "Starting OpFlex Processor";

size_t objs = readStartupPolicy();
LOG(DEBUG) << "Read " << objs << " objects from startup policy";
if (startupPolicyEnabled) {
size_t objs = readStartupPolicy();
LOG(DEBUG) << "Read " << objs << " objects from startup policy";
}

client = &store->getStoreClient("_SYSTEM_");
store->forEachClass(&register_listeners, this);
Expand Down
8 changes: 8 additions & 0 deletions libopflex/engine/include/opflex/engine/Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ class Processor : public internal::AbstractObjectListener,
* @param model the model for initializing startupdb
* @param duration the amount of time in ms from new
* connection to continue using startupdb
* @param enabled if the feature is enabled
* @param resolve_after_connection resolve after leaf connection
*/
void setStartupPolicy(boost::optional<std::string>& file,
const modb::ModelMetadata& model,
uint64_t& duration,
bool& enabled,
bool& resolve_after_connection);
/**
* Enable/Disable reporting of observable changes to registered observers
Expand Down Expand Up @@ -592,6 +595,11 @@ class Processor : public internal::AbstractObjectListener,
*/
volatile int64_t newConnectiontime = 0;

/**
* is startup policy enabled
*/
volatile bool startupPolicyEnabled = false;

/**
* local resolves only after a new connection till startupPolicyDuration
*/
Expand Down
2 changes: 2 additions & 0 deletions libopflex/include/opflex/ofcore/OFFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,13 @@ class OFFramework : private boost::noncopyable {
* @param file startup policy file name or boost::none
* @param model the model to use for startupdb
* @param duration in ms how long from new connection to use startupdb
* @pararm enabled if the startup policy is enabled
* @param resolve_after_connection delay local resolves till connection
*/
void setStartupPolicy(boost::optional<std::string>& file,
const modb::ModelMetadata& model,
uint64_t& duration,
bool& enabled,
bool& resolve_after_connection);

/**
Expand Down
5 changes: 3 additions & 2 deletions libopflex/ofcore/OFFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ bool OFFramework::waitForPendingItems(uint32_t& wait) {
void OFFramework::setStartupPolicy(boost::optional<std::string>& file,
const modb::ModelMetadata& model,
uint64_t& duration,
bool& enabled,
bool& resolve_after_connection) {
pimpl->processor.setStartupPolicy(file, model,
duration, resolve_after_connection);
pimpl->processor.setStartupPolicy(file, model, duration,
enabled, resolve_after_connection);
}

void OFFramework::start() {
Expand Down

0 comments on commit 75d3721

Please sign in to comment.