<commit_before>/*
 * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
 */
#include <string>
#include <sandesh/sandesh_trace.h>
#include <port_ipc/port_ipc_types.h>
#include <cmn/agent_cmn.h>
#include <init/agent_param.h>
#include <oper/interface_common.h>
#include <controller/controller_init.h>
#include "port_subscribe_table.h"
#include "port_ipc_handler.h"

using namespace autogen;

/////////////////////////////////////////////////////////////////////////////
// Init/Shutdown routines
/////////////////////////////////////////////////////////////////////////////
void PortSubscribeTable::InitDone() {
    // Register with config DB table for vm-port UUID to IFNode mapping
    vmi_config_table_ = (static_cast<IFMapAgentTable *>
                         (IFMapTable::FindTable(agent_->db(),
                                                "virtual-machine-interface")));
    vmi_config_listener_id_ = vmi_config_table_->Register
        (boost::bind(&PortSubscribeTable::Notify, this, _1, _2));
}

void PortSubscribeTable::Shutdown() {
    DBTable::DBStateClear(vmi_config_table_, vmi_config_listener_id_);
    vmi_config_table_->Unregister(vmi_config_listener_id_);
}

/////////////////////////////////////////////////////////////////////////////
// PortSubscribeEntry routines
/////////////////////////////////////////////////////////////////////////////
PortSubscribeEntry::PortSubscribeEntry(Type type, const std::string &ifname,
                                       int32_t version) :
    type_(type), ifname_(ifname), version_(version) {
}

PortSubscribeEntry::~PortSubscribeEntry() {
}

// Only version number is modifiable
void PortSubscribeEntry::Update(const PortSubscribeEntry *rhs) {
    version_ = rhs->version_;
}

const char *PortSubscribeEntry::TypeToString(Type type) {
    switch (type) {
    case VMPORT:
        return "VM Port";
        break;

    case NAMESPACE:
        return "Namespace Port";
        break;

    case REMOTE_PORT:
        return "Remote Port";
        break;

    default:
        break;
    }

    return "Invalid";
}

/////////////////////////////////////////////////////////////////////////////
// VmiSubscribeEntry routines
/////////////////////////////////////////////////////////////////////////////
VmiSubscribeEntry::VmiSubscribeEntry(PortSubscribeEntry::Type type,
                                     const std::string &ifname,
                                     uint32_t version,
                                     const boost::uuids::uuid &vmi_uuid,
                                     const boost::uuids::uuid vm_uuid,
                                     const std::string &vm_name,
                                     const boost::uuids::uuid &vn_uuid,
                                     const boost::uuids::uuid &project_uuid,
                                     const Ip4Address &ip4_addr,
                                     const Ip6Address &ip6_addr,
                                     const std::string &mac_addr,
                                     uint16_t tx_vlan_id, uint16_t rx_vlan_id,
                                     uint8_t vhostuser_mode) :
    PortSubscribeEntry(type, ifname, version), vmi_uuid_(vmi_uuid),
    vm_uuid_(vm_uuid), vm_name_(vm_name), vn_uuid_(vn_uuid),
    project_uuid_(project_uuid), ip4_addr_(ip4_addr), ip6_addr_(ip6_addr),
    mac_addr_(mac_addr), tx_vlan_id_(tx_vlan_id), rx_vlan_id_(rx_vlan_id),
    vhostuser_mode_(vhostuser_mode) {
}

VmiSubscribeEntry::~VmiSubscribeEntry() {
}

void VmiSubscribeEntry::Update(const PortSubscribeEntry *rhs) {
    PortSubscribeEntry::Update(rhs);
}

void VmiSubscribeEntry::OnAdd(Agent *agent, PortSubscribeTable *table) const {
    uint16_t tx_vlan_id_p = VmInterface::kInvalidVlanId;
    uint16_t rx_vlan_id_p = VmInterface::kInvalidVlanId;
    string port = Agent::NullString();
    Interface::Transport transport = Interface::TRANSPORT_ETHERNET;
    if (agent->params()->isVmwareMode()) {
        tx_vlan_id_p = tx_vlan_id_;
        rx_vlan_id_p = rx_vlan_id_;
        port = agent->params()->vmware_physical_port();
        transport = Interface::TRANSPORT_VIRTUAL;
    }

    if ((agent->vrouter_on_nic_mode() == true ||
         agent->vrouter_on_host_dpdk() == true) &&
        type_ == PortSubscribeEntry::VMPORT) {
        transport = Interface::TRANSPORT_PMD;
    }
<commit_msg>* Support interface addition without vlan tag in vcenter<commit_after>/*
 * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
 */
#include <string>
#include <sandesh/sandesh_trace.h>
#include <port_ipc/port_ipc_types.h>
#include <cmn/agent_cmn.h>
#include <init/agent_param.h>
#include <oper/interface_common.h>
#include <controller/controller_init.h>
#include "port_subscribe_table.h"
#include "port_ipc_handler.h"

using namespace autogen;

/////////////////////////////////////////////////////////////////////////////
// Init/Shutdown routines
/////////////////////////////////////////////////////////////////////////////
void PortSubscribeTable::InitDone() {
    // Register with config DB table for vm-port UUID to IFNode mapping
    vmi_config_table_ = (static_cast<IFMapAgentTable *>
                         (IFMapTable::FindTable(agent_->db(),
                                                "virtual-machine-interface")));
    vmi_config_listener_id_ = vmi_config_table_->Register
        (boost::bind(&PortSubscribeTable::Notify, this, _1, _2));
}

void PortSubscribeTable::Shutdown() {
    DBTable::DBStateClear(vmi_config_table_, vmi_config_listener_id_);
    vmi_config_table_->Unregister(vmi_config_listener_id_);
}

/////////////////////////////////////////////////////////////////////////////
// PortSubscribeEntry routines
/////////////////////////////////////////////////////////////////////////////
PortSubscribeEntry::PortSubscribeEntry(Type type, const std::string &ifname,
                                       int32_t version) :
    type_(type), ifname_(ifname), version_(version) {
}

PortSubscribeEntry::~PortSubscribeEntry() {
}

// Only version number is modifiable
void PortSubscribeEntry::Update(const PortSubscribeEntry *rhs) {
    version_ = rhs->version_;
}

const char *PortSubscribeEntry::TypeToString(Type type) {
    switch (type) {
    case VMPORT:
        return "VM Port";
        break;

    case NAMESPACE:
        return "Namespace Port";
        break;

    case REMOTE_PORT:
        return "Remote Port";
        break;

    default:
        break;
    }

    return "Invalid";
}

/////////////////////////////////////////////////////////////////////////////
// VmiSubscribeEntry routines
/////////////////////////////////////////////////////////////////////////////
VmiSubscribeEntry::VmiSubscribeEntry(PortSubscribeEntry::Type type,
                                     const std::string &ifname,
                                     uint32_t version,
                                     const boost::uuids::uuid &vmi_uuid,
                                     const boost::uuids::uuid vm_uuid,
                                     const std::string &vm_name,
                                     const boost::uuids::uuid &vn_uuid,
                                     const boost::uuids::uuid &project_uuid,
                                     const Ip4Address &ip4_addr,
                                     const Ip6Address &ip6_addr,
                                     const std::string &mac_addr,
                                     uint16_t tx_vlan_id, uint16_t rx_vlan_id,
                                     uint8_t vhostuser_mode) :
    PortSubscribeEntry(type, ifname, version), vmi_uuid_(vmi_uuid),
    vm_uuid_(vm_uuid), vm_name_(vm_name), vn_uuid_(vn_uuid),
    project_uuid_(project_uuid), ip4_addr_(ip4_addr), ip6_addr_(ip6_addr),
    mac_addr_(mac_addr), tx_vlan_id_(tx_vlan_id), rx_vlan_id_(rx_vlan_id),
    vhostuser_mode_(vhostuser_mode) {
}

VmiSubscribeEntry::~VmiSubscribeEntry() {
}

void VmiSubscribeEntry::Update(const PortSubscribeEntry *rhs) {
    PortSubscribeEntry::Update(rhs);
}

void VmiSubscribeEntry::OnAdd(Agent *agent, PortSubscribeTable *table) const {
    uint16_t tx_vlan_id_p = VmInterface::kInvalidVlanId;
    uint16_t rx_vlan_id_p = VmInterface::kInvalidVlanId;
    string port = Agent::NullString();
    Interface::Transport transport = Interface::TRANSPORT_ETHERNET;
    if (agent->params()->isVmwareMode()) {
        tx_vlan_id_p = tx_vlan_id_;
        rx_vlan_id_p = rx_vlan_id_;
        if (tx_vlan_id_p != VmInterface::kInvalidVlanId ||
            rx_vlan_id_p != VmInterface::kInvalidVlanId) {
            // In case of netns instance transport mode and
            // parent interface shouldnt be set
            port = agent->params()->vmware_physical_port();
            transport = Interface::TRANSPORT_VIRTUAL;
        }
    }

    if ((agent->vrouter_on_nic_mode() == true ||
         agent->vrouter_on_host_dpdk() == true) &&
        type_ == PortSubscribeEntry::VMPORT) {
        transport = Interface::TRANSPORT_PMD;
    }

{'fraction_non_alphanumeric': 0.1918765952724448, 'fraction_numerical': 0.00599267561868827, 'mean_word_length': 1.7695144437615242, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3099792', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2433, 'n_words': 444}