Skip to content

Commit

Permalink
VNET Vxlan - Initial commit (#7)
Browse files Browse the repository at this point in the history
* VNET Vxlan - Initial commit

* Generic code to handle BRIDGE to VNI mapping

* Seperated Vnet function from common code

* Test case update for vxlan, log level changes

* Modified NH Tunnel create, integrated vxlan and vnet

* Code alignment, logs updated
  • Loading branch information
prsunny authored Oct 16, 2018
1 parent 1f8e499 commit 106f7b3
Show file tree
Hide file tree
Showing 6 changed files with 630 additions and 106 deletions.
3 changes: 3 additions & 0 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ bool OrchDaemon::init()
gDirectory.set(vxlan_tunnel_orch);
VxlanTunnelMapOrch *vxlan_tunnel_map_orch = new VxlanTunnelMapOrch(m_configDb, CFG_VXLAN_TUNNEL_MAP_TABLE_NAME);
gDirectory.set(vxlan_tunnel_map_orch);
VxlanVrfMapOrch *vxlan_vrf_orch = new VxlanVrfMapOrch(m_applDb, APP_VXLAN_VRF_TABLE_NAME);
gDirectory.set(vxlan_vrf_orch);

vector<string> qos_tables = {
CFG_TC_TO_QUEUE_MAP_TABLE_NAME,
Expand Down Expand Up @@ -192,6 +194,7 @@ bool OrchDaemon::init()
m_orchList.push_back(vrf_orch);
m_orchList.push_back(vxlan_tunnel_orch);
m_orchList.push_back(vxlan_tunnel_map_orch);
m_orchList.push_back(vxlan_vrf_orch);

m_select = new Select();

Expand Down
37 changes: 27 additions & 10 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
#include "portsorch.h"
#include "request_parser.h"
#include "vnetorch.h"
#include "vxlanorch.h"
#include "directory.h"
#include "swssnet.h"

extern sai_virtual_router_api_t* sai_virtual_router_api;
extern sai_route_api_t* sai_route_api;
extern sai_object_id_t gSwitchId;
extern Directory<Orch*> gDirectory;
extern PortsOrch *gPortsOrch;

/*
Expand Down Expand Up @@ -291,29 +294,32 @@ VNetRouteOrch::VNetRouteOrch(DBConnector *db, vector<string> &tableNames, VNetOr
handler_map_.insert(handler_pair(APP_VNET_RT_TUNNEL_TABLE_NAME, &VNetRouteOrch::handleTunnel));
}

sai_object_id_t VNetRouteOrch::getNextHop(const string& vnet, IpAddress& ipAddr)
sai_object_id_t VNetRouteOrch::getNextHop(const string& vnet, endpoint& endp)
{
auto it = nh_tunnels_.find(vnet);
if (it != nh_tunnels_.end())
{
if (it->second.find(ipAddr) != it->second.end())
if (it->second.find(endp.ip) != it->second.end())
{
return it->second.at(ipAddr);
return it->second.at(endp.ip);
}
}

sai_object_id_t nh_id = SAI_NULL_OBJECT_ID;
VxlanVrfMapOrch* vxlan_orch = gDirectory.get<VxlanVrfMapOrch*>();

/*
* @FIXEME createNextHopTunnel(vnet, ipAddr, nh_id) , throw if failed
*/
nh_id = vxlan_orch->createNextHopTunnel(vnet, endp.ip, endp.mac, endp.vni);
if (nh_id == SAI_NULL_OBJECT_ID)
{
throw std::runtime_error("NH Tunnel create failed");
}

nh_tunnels_[vnet].insert({ipAddr, nh_id});
nh_tunnels_[vnet].insert({endp.ip, nh_id});
return nh_id;
}

template<>
bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipPrefix, IpAddress& endIp)
bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipPrefix, endpoint& endp)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -345,7 +351,7 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP

sai_ip_prefix_t pfx;
copy(pfx, ipPrefix);
sai_object_id_t nh_id = getNextHop(vnet, endIp);
sai_object_id_t nh_id = getNextHop(vnet, endp);

for (auto vr_id : vr_set)
{
Expand Down Expand Up @@ -450,13 +456,23 @@ void VNetRouteOrch::handleTunnel(const Request& request)
SWSS_LOG_ENTER();

IpAddress ip;
MacAddress mac;
uint32_t vni = 0;

for (const auto& name: request.getAttrFieldNames())
{
if (name == "endpoint")
{
ip = request.getAttrIP(name);
}
else if (name == "vni")
{
vni = static_cast<uint32_t>(request.getAttrUint(name));
}
else if (name == "mac_address")
{
mac = request.getAttrMacAddress(name);
}
else
{
SWSS_LOG_WARN("Logic error: Unknown attribute: %s", name.c_str());
Expand All @@ -469,9 +485,10 @@ void VNetRouteOrch::handleTunnel(const Request& request)

SWSS_LOG_INFO("VNET-RT '%s' add for endpoint %s", vnet_name.c_str(), ip_pfx.to_string().c_str());

endpoint endp = { ip, mac, vni };
if (vnet_orch_->isVnetExecVrf())
{
if (!doRouteTask<VNetVrfObject>(vnet_name, ip_pfx, ip))
if (!doRouteTask<VNetVrfObject>(vnet_name, ip_pfx, endp))
{
throw std::runtime_error("Route add failed");
}
Expand Down
17 changes: 13 additions & 4 deletions orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ class VNetOrch : public Orch2
const request_description_t vnet_route_description = {
{ REQ_T_STRING, REQ_T_IP_PREFIX },
{
{ "endpoint", REQ_T_IP },
{ "ifname", REQ_T_STRING },
{ "endpoint", REQ_T_IP },
{ "ifname", REQ_T_STRING },
{ "vni", REQ_T_UINT },
{ "mac_address", REQ_T_MAC_ADDRESS },
},
{ }
};
Expand All @@ -192,6 +194,13 @@ class VNetRouteRequest : public Request
using NextHopMap = map<IpAddress, sai_object_id_t>;
using NextHopTunnels = map<string, NextHopMap>;

struct endpoint
{
IpAddress ip;
MacAddress mac;
uint32_t vni;
};

class VNetRouteOrch : public Orch2
{
public:
Expand All @@ -207,12 +216,12 @@ class VNetRouteOrch : public Orch2
void handleTunnel(const Request&);

template<typename T>
bool doRouteTask(const string& vnet, IpPrefix& ipPrefix, IpAddress& ipAddr);
bool doRouteTask(const string& vnet, IpPrefix& ipPrefix, endpoint& endp);

template<typename T>
bool doRouteTask(const string& vnet, IpPrefix& ipPrefix, string& ifname);

sai_object_id_t getNextHop(const string& vnet, IpAddress& ipAddr);
sai_object_id_t getNextHop(const string& vnet, endpoint& endp);

VNetOrch *vnet_orch_;
VNetRouteRequest request_;
Expand Down
Loading

0 comments on commit 106f7b3

Please sign in to comment.