Skip to content

Commit

Permalink
add src_ip needed by tunnel creation (sonic-net#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
lguohan authored Jan 4, 2017
1 parent 4c753eb commit 9be6620
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
37 changes: 31 additions & 6 deletions orchagent/tunneldecaporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
string op = kfvOp(t);

IpAddresses ip_addresses;
IpAddress src_ip;
string tunnel_type;
string dscp_mode;
string ecn_mode;
Expand All @@ -55,7 +56,7 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
break;
}
}
if (fvField(i) == "dst_ip")
else if (fvField(i) == "dst_ip")
{
try
{
Expand All @@ -72,7 +73,24 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
setIpAttribute(key, ip_addresses, tunnelTable.find(key)->second.tunnel_id);
}
}
if (fvField(i) == "dscp_mode")
else if (fvField(i) == "src_ip")
{
try
{
src_ip = IpAddress(fvValue(i));
}
catch (const std::invalid_argument &e)
{
SWSS_LOG_ERROR("%s", e.what());
valid = false;
break;
}
if (exists)
{
SWSS_LOG_ERROR("cannot modify src ip for existing tunnel");
}
}
else if (fvField(i) == "dscp_mode")
{
dscp_mode = fvValue(i);
if (dscp_mode != "uniform" && dscp_mode != "pipe")
Expand All @@ -86,7 +104,7 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
setTunnelAttribute(fvField(i), dscp_mode, tunnelTable.find(key)->second.tunnel_id);
}
}
if (fvField(i) == "ecn_mode")
else if (fvField(i) == "ecn_mode")
{
ecn_mode = fvValue(i);
if (ecn_mode != "copy_from_outer" && ecn_mode != "standard")
Expand All @@ -100,7 +118,7 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
setTunnelAttribute(fvField(i), ecn_mode, tunnelTable.find(key)->second.tunnel_id);
}
}
if (fvField(i) == "ttl_mode")
else if (fvField(i) == "ttl_mode")
{
ttl_mode = fvValue(i);
if (ttl_mode != "uniform" && ttl_mode != "pipe")
Expand All @@ -115,10 +133,11 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
}
}
}

// create new tunnel if it doesn't exists already
if (valid && !exists)
{
if (addDecapTunnel(key, tunnel_type, ip_addresses, dscp_mode, ecn_mode, ttl_mode))
if (addDecapTunnel(key, tunnel_type, ip_addresses, src_ip, dscp_mode, ecn_mode, ttl_mode))
{
SWSS_LOG_NOTICE("Tunnel(s) added to ASIC_DB.");
}
Expand Down Expand Up @@ -152,14 +171,15 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
* Arguments:
* @param[in] type - type of tunnel
* @param[in] dst_ip - destination ip address to decap
* @param[in] src_ip - source ip address to decap
* @param[in] dscp - dscp mode (uniform/pipe)
* @param[in] ecn - ecn mode (copy_from_outer/standard)
* @param[in] ttl - ttl mode (uniform/pipe)
*
* Return Values:
* @return true on success and false if there's an error
*/
bool TunnelDecapOrch::addDecapTunnel(string key, string type, IpAddresses dst_ip, string dscp, string ecn, string ttl)
bool TunnelDecapOrch::addDecapTunnel(string key, string type, IpAddresses dst_ip, IpAddress src_ip, string dscp, string ecn, string ttl)
{

SWSS_LOG_ENTER();
Expand Down Expand Up @@ -198,6 +218,11 @@ bool TunnelDecapOrch::addDecapTunnel(string key, string type, IpAddresses dst_ip
attr.value.oid = gUnderlayIfId;
tunnel_attrs.push_back(attr);

// tunnel src ip
attr.id = SAI_TUNNEL_ATTR_ENCAP_SRC_IP;
copy(attr.value.ipaddr, src_ip.to_string());
tunnel_attrs.push_back(attr);

// decap ecn mode (copy from outer/standard)
attr.id = SAI_TUNNEL_ATTR_DECAP_ECN_MODE;
if (ecn == "copy_from_outer")
Expand Down
2 changes: 1 addition & 1 deletion orchagent/tunneldecaporch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TunnelDecapOrch : public Orch
TunnelTable tunnelTable;
ExistingIps existingIps;

bool addDecapTunnel(string key, string type, IpAddresses dst_ip, string dscp, string ecn, string ttl);
bool addDecapTunnel(string key, string type, IpAddresses dst_ip, IpAddress src_ip, string dscp, string ecn, string ttl);
bool removeDecapTunnel(string key);

bool addDecapTunnelTermEntries(string tunnelKey, IpAddresses dst_ip, sai_object_id_t tunnel_id);
Expand Down
1 change: 1 addition & 0 deletions swssconfig/sample/netbouncer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"TUNNEL_DECAP_TABLE:NETBOUNCER" : {
"tunnel_type":"IPINIP",
"src_ip":"10.0.0.1",
"dst_ip":"10.0.0.1",
"dscp_mode":"pipe",
"ecn_mode":"copy_from_outer",
Expand Down

0 comments on commit 9be6620

Please sign in to comment.