<commit_before>/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#include <string>
#include <vector>
#include <base/logging.h>
#include <base/lifetime.h>
#include <base/misc_utils.h>
#include <io/event_manager.h>
#include <ifmap/ifmap_link.h>

#include <cmn/agent_cmn.h>
#include <vnc_cfg_types.h>
#include <agent_types.h>

#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh.h>
#include <base/sandesh/task_types.h>

#include <init/agent_param.h>
#include <cmn/agent_signal.h>
#include <cfg/cfg_init.h>
#include <cfg/cfg_mirror.h>
#include <cfg/discovery_agent.h>
#include <cmn/agent.h>

#include <oper/operdb_init.h>
#include <oper/config_manager.h>
#include <oper/interface_common.h>
#include <oper/health_check.h>
#include <oper/metadata_ip.h>
#include <oper/multicast.h>
#include <oper/nexthop.h>
#include <oper/mirror_table.h>
#include <oper/mpls.h>
#include <oper/peer.h>

#include <filter/acl.h>

#include <cmn/agent_factory.h>
#include <base/task_tbbkeepawake.h>

const std::string Agent::null_string_ = "";
const std::set<std::string> Agent::null_string_list_;
const std::string Agent::fabric_vn_name_ =
    "default-domain:default-project:ip-fabric";
std::string Agent::fabric_vrf_name_ =
    "default-domain:default-project:ip-fabric:__default__";
const std::string Agent::link_local_vn_name_ =
    "default-domain:default-project:__link_local__";
const std::string Agent::link_local_vrf_name_ =
    "default-domain:default-project:__link_local__:__link_local__";
const MacAddress Agent::vrrp_mac_(0x00, 0x00, 0x5E, 0x00, 0x01, 0x00);
const MacAddress Agent::pkt_interface_mac_(0x00, 0x00, 0x00, 0x00, 0x00, 0x01);
const std::string Agent::bcast_mac_ = "FF:FF:FF:FF:FF:FF";
const std::string Agent::config_file_ = "/etc/contrail/contrail-vrouter-agent.conf";
const std::string Agent::log_file_ = "/var/log/contrail/vrouter.log";
const std::string Agent::xmpp_dns_server_connection_name_prefix_ = "dns-server:";
const std::string Agent::xmpp_control_node_connection_name_prefix_ = "control-node:";

SandeshTraceBufferPtr TaskTraceBuf(SandeshTraceBufferCreate("TaskTrace", 5000));
Agent *Agent::singleton_;

IpAddress Agent::GetMirrorSourceIp(const IpAddress &dest) {
    IpAddress sip;
    if (dest.is_v4()) {
        if (router_id() == dest) {
            // If source IP and dest IP are same,
            // linux kernel will drop the packet.
            // Hence we will use link local IP address as sip.
            sip = Ip4Address(METADATA_IP_ADDR);
        } else {
            sip = router_id();
        }
    } else if (dest.is_v6()) {
        sip = Ip6Address::v4_mapped(router_id());
    }
    return sip;
}

const string &Agent::GetHostInterfaceName() const {
    // There is single host interface.  Its addressed by type and not name
    return Agent::null_string_;
};

std::string Agent::GetUuidStr(boost::uuids::uuid uuid_val) const {
    std::ostringstream str;
    str << uuid_val;
    return str.str();
}

const string &Agent::vhost_interface_name() const {
    return vhost_interface_name_;
};

bool Agent::isXenMode() {
    return params_->isXenMode();
}

bool Agent::isKvmMode() {
    return params_->isKvmMode();
}

bool Agent::isDockerMode() {
    return params_->isDockerMode();
}

static void SetTaskPolicyOne(const char *task, const char *exclude_list[],
                             int count) {
    TaskScheduler *scheduler = TaskScheduler::GetInstance();
    TaskPolicy policy;
    for (int i = 0; i < count; ++i) {
        int task_id = scheduler->GetTaskId(exclude_list[i]);
        policy.push_back(TaskExclusion(task_id));
    }
    scheduler->SetPolicy(scheduler->GetTaskId(task), policy);
}

void Agent::SetAgentTaskPolicy() {
    /*
     * TODO(roque): this method should not be called by the agent constructor.
     */
    static bool initialized = false;
    if (initialized) {
        return;
    }
    initialized = true;

    const char *db_exclude_list[] = {
        kTaskFlowEvent,
        kTaskFlowKSync,
        kTaskFlowUpdate,
        kTaskFlowDelete,
        kTaskFlowAudit,
        "Agent::Services",
        "Agent::StatsCollector",
        kTaskFlowStatsCollector,
        "sandesh::RecvQueue",
        "Agent::Uve",
        "Agent::KSync",
        "Agent::PktFlowResponder",
        "Agent::Profile",
        "Agent::PktHandler",
        kTaskHealthCheck,
        kTaskDBExclude,<commit_msg>Agent::Diag task policy to be updated<commit_after>/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#include <string>
#include <vector>
#include <base/logging.h>
#include <base/lifetime.h>
#include <base/misc_utils.h>
#include <io/event_manager.h>
#include <ifmap/ifmap_link.h>

#include <cmn/agent_cmn.h>
#include <vnc_cfg_types.h>
#include <agent_types.h>

#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh.h>
#include <base/sandesh/task_types.h>

#include <init/agent_param.h>
#include <cmn/agent_signal.h>
#include <cfg/cfg_init.h>
#include <cfg/cfg_mirror.h>
#include <cfg/discovery_agent.h>
#include <cmn/agent.h>

#include <oper/operdb_init.h>
#include <oper/config_manager.h>
#include <oper/interface_common.h>
#include <oper/health_check.h>
#include <oper/metadata_ip.h>
#include <oper/multicast.h>
#include <oper/nexthop.h>
#include <oper/mirror_table.h>
#include <oper/mpls.h>
#include <oper/peer.h>

#include <filter/acl.h>

#include <cmn/agent_factory.h>
#include <base/task_tbbkeepawake.h>

const std::string Agent::null_string_ = "";
const std::set<std::string> Agent::null_string_list_;
const std::string Agent::fabric_vn_name_ =
    "default-domain:default-project:ip-fabric";
std::string Agent::fabric_vrf_name_ =
    "default-domain:default-project:ip-fabric:__default__";
const std::string Agent::link_local_vn_name_ =
    "default-domain:default-project:__link_local__";
const std::string Agent::link_local_vrf_name_ =
    "default-domain:default-project:__link_local__:__link_local__";
const MacAddress Agent::vrrp_mac_(0x00, 0x00, 0x5E, 0x00, 0x01, 0x00);
const MacAddress Agent::pkt_interface_mac_(0x00, 0x00, 0x00, 0x00, 0x00, 0x01);
const std::string Agent::bcast_mac_ = "FF:FF:FF:FF:FF:FF";
const std::string Agent::config_file_ = "/etc/contrail/contrail-vrouter-agent.conf";
const std::string Agent::log_file_ = "/var/log/contrail/vrouter.log";
const std::string Agent::xmpp_dns_server_connection_name_prefix_ = "dns-server:";
const std::string Agent::xmpp_control_node_connection_name_prefix_ = "control-node:";

SandeshTraceBufferPtr TaskTraceBuf(SandeshTraceBufferCreate("TaskTrace", 5000));
Agent *Agent::singleton_;

IpAddress Agent::GetMirrorSourceIp(const IpAddress &dest) {
    IpAddress sip;
    if (dest.is_v4()) {
        if (router_id() == dest) {
            // If source IP and dest IP are same,
            // linux kernel will drop the packet.
            // Hence we will use link local IP address as sip.
            sip = Ip4Address(METADATA_IP_ADDR);
        } else {
            sip = router_id();
        }
    } else if (dest.is_v6()) {
        sip = Ip6Address::v4_mapped(router_id());
    }
    return sip;
}

const string &Agent::GetHostInterfaceName() const {
    // There is single host interface.  Its addressed by type and not name
    return Agent::null_string_;
};

std::string Agent::GetUuidStr(boost::uuids::uuid uuid_val) const {
    std::ostringstream str;
    str << uuid_val;
    return str.str();
}

const string &Agent::vhost_interface_name() const {
    return vhost_interface_name_;
};

bool Agent::isXenMode() {
    return params_->isXenMode();
}

bool Agent::isKvmMode() {
    return params_->isKvmMode();
}

bool Agent::isDockerMode() {
    return params_->isDockerMode();
}

static void SetTaskPolicyOne(const char *task, const char *exclude_list[],
                             int count) {
    TaskScheduler *scheduler = TaskScheduler::GetInstance();
    TaskPolicy policy;
    for (int i = 0; i < count; ++i) {
        int task_id = scheduler->GetTaskId(exclude_list[i]);
        policy.push_back(TaskExclusion(task_id));
    }
    scheduler->SetPolicy(scheduler->GetTaskId(task), policy);
}

void Agent::SetAgentTaskPolicy() {
    /*
     * TODO(roque): this method should not be called by the agent constructor.
     */
    static bool initialized = false;
    if (initialized) {
        return;
    }
    initialized = true;

    const char *db_exclude_list[] = {
        kTaskFlowEvent,
        kTaskFlowKSync,
        kTaskFlowUpdate,
        kTaskFlowDelete,
        kTaskFlowAudit,
        "Agent::Services",
        "Agent::StatsCollector",
        kTaskFlowStatsCollector,
        "sandesh::RecvQueue",
        "Agent::Uve",
        "Agent::KSync",
        "Agent::PktFlowResponder",
        "Agent::Profile",
        "Agent::PktHandler",
        "Agent::Diag",
        kTaskHealthCheck,
        kTaskDBExclude,
{'fraction_non_alphanumeric': 0.1352761084023132, 'fraction_numerical': 0.011112371017122123, 'mean_word_length': 3.913649025069638, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7291614', 'n_tokens_mistral': 3143, 'n_tokens_neox': 3046, 'n_words': 601}