vxlan: vxlan/vxlan.api API cleanup
Use consistent API types. Type: fix Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: I7f6f37ec6eed780322e2488d6eb0f5681945ba09 Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
This commit is contained in:
@ -33,8 +33,7 @@ const vxlan_tunnel::mode_t vxlan_tunnel::mode_t::GPE(3, "GPE");
|
||||
|
||||
vxlan_tunnel::mode_t::mode_t(int v, const std::string s)
|
||||
: enum_base<vxlan_tunnel::mode_t>(v, s)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
vxlan_tunnel::endpoint_t::endpoint_t(const boost::asio::ip::address& src,
|
||||
const boost::asio::ip::address& dst,
|
||||
@ -42,15 +41,13 @@ vxlan_tunnel::endpoint_t::endpoint_t(const boost::asio::ip::address& src,
|
||||
: src(src)
|
||||
, dst(dst)
|
||||
, vni(vni)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
vxlan_tunnel::endpoint_t::endpoint_t()
|
||||
: src()
|
||||
, dst()
|
||||
, vni(0)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool
|
||||
vxlan_tunnel::endpoint_t::operator==(const endpoint_t& other) const
|
||||
@ -96,8 +93,7 @@ vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
|
||||
, m_mcast_itf()
|
||||
, m_rd()
|
||||
, m_table_id(route::DEFAULT_TABLE)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
|
||||
const boost::asio::ip::address& dst,
|
||||
@ -112,8 +108,7 @@ vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
|
||||
, m_mcast_itf(mcast_itf.singular())
|
||||
, m_rd()
|
||||
, m_table_id(route::DEFAULT_TABLE)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
|
||||
const boost::asio::ip::address& dst,
|
||||
@ -128,8 +123,7 @@ vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
|
||||
, m_mcast_itf()
|
||||
, m_rd(rd.singular())
|
||||
, m_table_id(m_rd->table_id())
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
vxlan_tunnel::vxlan_tunnel(const vxlan_tunnel& o)
|
||||
: interface(o)
|
||||
@ -138,8 +132,7 @@ vxlan_tunnel::vxlan_tunnel(const vxlan_tunnel& o)
|
||||
, m_mcast_itf(o.m_mcast_itf)
|
||||
, m_rd(o.m_rd)
|
||||
, m_table_id(o.m_table_id)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool
|
||||
vxlan_tunnel::operator==(const vxlan_tunnel& other) const
|
||||
@ -178,15 +171,23 @@ vxlan_tunnel::replay()
|
||||
if (m_hdl) {
|
||||
if (mode_t::STANDARD == m_mode)
|
||||
HW::enqueue(new vxlan_tunnel_cmds::create_cmd(
|
||||
m_hdl, name(), m_tep,
|
||||
m_hdl,
|
||||
name(),
|
||||
m_tep,
|
||||
(m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
|
||||
else if (mode_t::GBP_L2 == m_mode)
|
||||
HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(
|
||||
m_hdl, name(), m_tep, true,
|
||||
m_hdl,
|
||||
name(),
|
||||
m_tep,
|
||||
true,
|
||||
(m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
|
||||
else if (mode_t::GBP_L3 == m_mode)
|
||||
HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(
|
||||
m_hdl, name(), m_tep, false,
|
||||
m_hdl,
|
||||
name(),
|
||||
m_tep,
|
||||
false,
|
||||
(m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
|
||||
}
|
||||
if (m_rd && (m_rd->table_id() != route::DEFAULT_TABLE)) {
|
||||
@ -224,15 +225,23 @@ vxlan_tunnel::update(const vxlan_tunnel& desired)
|
||||
if (rc_t::OK != m_hdl.rc()) {
|
||||
if (mode_t::STANDARD == m_mode)
|
||||
HW::enqueue(new vxlan_tunnel_cmds::create_cmd(
|
||||
m_hdl, name(), m_tep,
|
||||
m_hdl,
|
||||
name(),
|
||||
m_tep,
|
||||
(m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
|
||||
else if (mode_t::GBP_L2 == m_mode)
|
||||
HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(
|
||||
m_hdl, name(), m_tep, true,
|
||||
m_hdl,
|
||||
name(),
|
||||
m_tep,
|
||||
true,
|
||||
(m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
|
||||
else if (mode_t::GBP_L3 == m_mode)
|
||||
HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(
|
||||
m_hdl, name(), m_tep, false,
|
||||
m_hdl,
|
||||
name(),
|
||||
m_tep,
|
||||
false,
|
||||
(m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
|
||||
}
|
||||
if (!m_table_id && m_rd) {
|
||||
@ -272,9 +281,9 @@ vxlan_tunnel::event_handler::handle_populate(const client_db::key_t& key)
|
||||
auto& payload = record.get_payload();
|
||||
handle_t hdl(payload.sw_if_index);
|
||||
boost::asio::ip::address src =
|
||||
from_bytes(payload.is_ipv6, payload.src_address);
|
||||
from_bytes(payload.src_address.af, (uint8_t*)&payload.src_address.un);
|
||||
boost::asio::ip::address dst =
|
||||
from_bytes(payload.is_ipv6, payload.dst_address);
|
||||
from_bytes(payload.dst_address.af, (uint8_t*)&payload.dst_address.un);
|
||||
|
||||
std::shared_ptr<vxlan_tunnel> vt =
|
||||
vxlan_tunnel(src, dst, payload.vni).singular();
|
||||
@ -299,7 +308,9 @@ vxlan_tunnel::event_handler::handle_populate(const client_db::key_t& key)
|
||||
boost::asio::ip::address dst = from_api(payload.tunnel.dst);
|
||||
|
||||
std::shared_ptr<vxlan_tunnel> vt =
|
||||
vxlan_tunnel(src, dst, payload.tunnel.vni,
|
||||
vxlan_tunnel(src,
|
||||
dst,
|
||||
payload.tunnel.vni,
|
||||
(payload.tunnel.mode == VXLAN_GBP_API_TUNNEL_MODE_L2
|
||||
? mode_t::GBP_L2
|
||||
: mode_t::GBP_L3))
|
||||
|
@ -27,8 +27,7 @@ create_cmd::create_cmd(HW::item<handle_t>& item,
|
||||
: interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
|
||||
, m_ep(ep)
|
||||
, m_mcast_itf(mcast_itf)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool
|
||||
create_cmd::operator==(const create_cmd& other) const
|
||||
@ -43,9 +42,12 @@ create_cmd::issue(connection& con)
|
||||
|
||||
auto& payload = req.get_request().get_payload();
|
||||
payload.is_add = 1;
|
||||
payload.is_ipv6 = 0;
|
||||
to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
|
||||
to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
|
||||
to_bytes(m_ep.src,
|
||||
(uint8_t*)&payload.src_address.af,
|
||||
(uint8_t*)&payload.src_address.un);
|
||||
to_bytes(m_ep.dst,
|
||||
(uint8_t*)&payload.dst_address.af,
|
||||
(uint8_t*)&payload.dst_address.un);
|
||||
payload.mcast_sw_if_index = m_mcast_itf.value();
|
||||
payload.encap_vrf_id = 0;
|
||||
payload.decap_next_index = ~0;
|
||||
@ -76,8 +78,7 @@ delete_cmd::delete_cmd(HW::item<handle_t>& item,
|
||||
const vxlan_tunnel::endpoint_t& ep)
|
||||
: interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item)
|
||||
, m_ep(ep)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool
|
||||
delete_cmd::operator==(const delete_cmd& other) const
|
||||
@ -92,9 +93,12 @@ delete_cmd::issue(connection& con)
|
||||
|
||||
auto payload = req.get_request().get_payload();
|
||||
payload.is_add = 0;
|
||||
payload.is_ipv6 = 0;
|
||||
to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
|
||||
to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
|
||||
to_bytes(m_ep.src,
|
||||
(uint8_t*)&payload.src_address.af,
|
||||
(uint8_t*)&payload.src_address.un);
|
||||
to_bytes(m_ep.dst,
|
||||
(uint8_t*)&payload.dst_address.af,
|
||||
(uint8_t*)&payload.dst_address.un);
|
||||
payload.mcast_sw_if_index = ~0;
|
||||
payload.encap_vrf_id = 0;
|
||||
payload.decap_next_index = ~0;
|
||||
@ -118,9 +122,7 @@ delete_cmd::to_string() const
|
||||
return (s.str());
|
||||
}
|
||||
|
||||
dump_cmd::dump_cmd()
|
||||
{
|
||||
}
|
||||
dump_cmd::dump_cmd() {}
|
||||
|
||||
bool
|
||||
dump_cmd::operator==(const dump_cmd& other) const
|
||||
|
@ -11733,14 +11733,16 @@ api_vxlan_add_del_tunnel (vat_main_t * vam)
|
||||
|
||||
if (ipv6_set)
|
||||
{
|
||||
clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
|
||||
clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
|
||||
clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
|
||||
clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
|
||||
}
|
||||
else
|
||||
{
|
||||
clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
|
||||
clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
|
||||
clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
|
||||
clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
|
||||
}
|
||||
mp->src_address.af = ipv6_set;
|
||||
mp->dst_address.af = ipv6_set;
|
||||
|
||||
mp->instance = htonl (instance);
|
||||
mp->encap_vrf_id = ntohl (encap_vrf_id);
|
||||
@ -11748,7 +11750,6 @@ api_vxlan_add_del_tunnel (vat_main_t * vam)
|
||||
mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
|
||||
mp->vni = ntohl (vni);
|
||||
mp->is_add = is_add;
|
||||
mp->is_ipv6 = ipv6_set;
|
||||
|
||||
S (mp);
|
||||
W (ret);
|
||||
@ -11759,8 +11760,10 @@ static void vl_api_vxlan_tunnel_details_t_handler
|
||||
(vl_api_vxlan_tunnel_details_t * mp)
|
||||
{
|
||||
vat_main_t *vam = &vat_main;
|
||||
ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
|
||||
ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
|
||||
ip46_address_t src =
|
||||
to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
|
||||
ip46_address_t dst =
|
||||
to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
|
||||
|
||||
print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
|
||||
ntohl (mp->sw_if_index),
|
||||
@ -11790,29 +11793,28 @@ static void vl_api_vxlan_tunnel_details_t_handler_json
|
||||
|
||||
vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
|
||||
|
||||
if (mp->is_ipv6)
|
||||
if (mp->src_address.af)
|
||||
{
|
||||
struct in6_addr ip6;
|
||||
|
||||
clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
|
||||
clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
|
||||
vat_json_object_add_ip6 (node, "src_address", ip6);
|
||||
clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
|
||||
clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
|
||||
vat_json_object_add_ip6 (node, "dst_address", ip6);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct in_addr ip4;
|
||||
|
||||
clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
|
||||
clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
|
||||
vat_json_object_add_ip4 (node, "src_address", ip4);
|
||||
clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
|
||||
clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
|
||||
vat_json_object_add_ip4 (node, "dst_address", ip4);
|
||||
}
|
||||
vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
|
||||
vat_json_object_add_uint (node, "decap_next_index",
|
||||
ntohl (mp->decap_next_index));
|
||||
vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
|
||||
vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
|
||||
vat_json_object_add_uint (node, "mcast_sw_if_index",
|
||||
ntohl (mp->mcast_sw_if_index));
|
||||
}
|
||||
|
@ -13,31 +13,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
option version = "1.1.0";
|
||||
option version = "2.0.0";
|
||||
|
||||
import "vnet/interface_types.api";
|
||||
import "vnet/ip/ip_types.api";
|
||||
|
||||
/** \brief Create or delete a VXLAN tunnel
|
||||
@param client_index - opaque cookie to identify the sender
|
||||
@param context - sender context, to match reply w/ request
|
||||
@param is_add - Use 1 to create the tunnel, 0 to remove it
|
||||
@param is_ipv6 - Use 0 for IPv4, 1 for IPv6
|
||||
@param instance - optional unique custom device instance, else ~0.
|
||||
@param src_address - Source IP address
|
||||
@param dst_address - Destination IP address, can be multicast
|
||||
@param mcast_sw_if_index - Interface for multicast destination
|
||||
@param encap_vrf_id - Encap route table FIB index
|
||||
@param decap_next_index - Name of decap next graph node
|
||||
@param decap_next_index - index of decap next graph node
|
||||
@param vni - The VXLAN Network Identifier, uint24
|
||||
*/
|
||||
define vxlan_add_del_tunnel
|
||||
{
|
||||
u32 client_index;
|
||||
u32 context;
|
||||
u8 is_add;
|
||||
u8 is_ipv6;
|
||||
bool is_add [default=true];
|
||||
u32 instance; /* If non-~0, specifies a custom dev instance */
|
||||
u8 src_address[16];
|
||||
u8 dst_address[16];
|
||||
u32 mcast_sw_if_index;
|
||||
vl_api_address_t src_address;
|
||||
vl_api_address_t dst_address;
|
||||
vl_api_interface_index_t mcast_sw_if_index;
|
||||
u32 encap_vrf_id;
|
||||
u32 decap_next_index;
|
||||
u32 vni;
|
||||
@ -47,28 +48,27 @@ define vxlan_add_del_tunnel_reply
|
||||
{
|
||||
u32 context;
|
||||
i32 retval;
|
||||
u32 sw_if_index;
|
||||
vl_api_interface_index_t sw_if_index;
|
||||
};
|
||||
|
||||
define vxlan_tunnel_dump
|
||||
{
|
||||
u32 client_index;
|
||||
u32 context;
|
||||
u32 sw_if_index;
|
||||
vl_api_interface_index_t sw_if_index;
|
||||
};
|
||||
|
||||
define vxlan_tunnel_details
|
||||
{
|
||||
u32 context;
|
||||
u32 sw_if_index;
|
||||
vl_api_interface_index_t sw_if_index;
|
||||
u32 instance;
|
||||
u8 src_address[16];
|
||||
u8 dst_address[16];
|
||||
u32 mcast_sw_if_index;
|
||||
vl_api_address_t src_address;
|
||||
vl_api_address_t dst_address;
|
||||
vl_api_interface_index_t mcast_sw_if_index;
|
||||
u32 encap_vrf_id;
|
||||
u32 decap_next_index;
|
||||
u32 vni;
|
||||
u8 is_ipv6;
|
||||
};
|
||||
|
||||
/** \brief Interface set vxlan-bypass request
|
||||
@ -82,9 +82,9 @@ autoreply define sw_interface_set_vxlan_bypass
|
||||
{
|
||||
u32 client_index;
|
||||
u32 context;
|
||||
u32 sw_if_index;
|
||||
u8 is_ipv6;
|
||||
u8 enable;
|
||||
vl_api_interface_index_t sw_if_index;
|
||||
bool is_ipv6;
|
||||
bool enable [default=true];
|
||||
};
|
||||
|
||||
/** \brief Offload vxlan rx request
|
||||
@ -98,7 +98,7 @@ autoreply define vxlan_offload_rx
|
||||
{
|
||||
u32 client_index;
|
||||
u32 context;
|
||||
u32 hw_if_index;
|
||||
u32 sw_if_index;
|
||||
u8 enable;
|
||||
vl_api_interface_index_t hw_if_index;
|
||||
vl_api_interface_index_t sw_if_index;
|
||||
bool enable [default=true];
|
||||
};
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <vnet/vxlan/vxlan.h>
|
||||
#include <vnet/fib/fib_table.h>
|
||||
|
||||
#include <vnet/ip/ip_types_api.h>
|
||||
|
||||
#include <vnet/vnet_msg_enum.h>
|
||||
|
||||
#define vl_typedefs /* define message structures */
|
||||
@ -124,9 +126,22 @@ static void vl_api_vxlan_add_del_tunnel_t_handler
|
||||
{
|
||||
vl_api_vxlan_add_del_tunnel_reply_t *rmp;
|
||||
int rv = 0;
|
||||
bool is_ipv6;
|
||||
u32 fib_index;
|
||||
ip46_address_t src, dst;
|
||||
|
||||
fib_index = fib_table_find (fib_ip_proto (mp->is_ipv6),
|
||||
ip_address_decode (&mp->src_address, &src);
|
||||
ip_address_decode (&mp->dst_address, &dst);
|
||||
|
||||
if (ip46_address_is_ip4 (&src) != ip46_address_is_ip4 (&dst))
|
||||
{
|
||||
rv = VNET_API_ERROR_INVALID_VALUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
is_ipv6 = !ip46_address_is_ip4 (&src);
|
||||
|
||||
fib_index = fib_table_find (fib_ip_proto (is_ipv6),
|
||||
ntohl (mp->encap_vrf_id));
|
||||
if (fib_index == ~0)
|
||||
{
|
||||
@ -136,14 +151,14 @@ static void vl_api_vxlan_add_del_tunnel_t_handler
|
||||
|
||||
vnet_vxlan_add_del_tunnel_args_t a = {
|
||||
.is_add = mp->is_add,
|
||||
.is_ip6 = mp->is_ipv6,
|
||||
.is_ip6 = is_ipv6,
|
||||
.instance = ntohl (mp->instance),
|
||||
.mcast_sw_if_index = ntohl (mp->mcast_sw_if_index),
|
||||
.encap_fib_index = fib_index,
|
||||
.decap_next_index = ntohl (mp->decap_next_index),
|
||||
.vni = ntohl (mp->vni),
|
||||
.dst = to_ip46 (mp->is_ipv6, mp->dst_address),
|
||||
.src = to_ip46 (mp->is_ipv6, mp->src_address),
|
||||
.dst = dst,
|
||||
.src = src,
|
||||
};
|
||||
|
||||
/* Check src & dst are different */
|
||||
@ -177,30 +192,24 @@ static void send_vxlan_tunnel_details
|
||||
vl_api_vxlan_tunnel_details_t *rmp;
|
||||
ip4_main_t *im4 = &ip4_main;
|
||||
ip6_main_t *im6 = &ip6_main;
|
||||
u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
|
||||
|
||||
rmp = vl_msg_api_alloc (sizeof (*rmp));
|
||||
clib_memset (rmp, 0, sizeof (*rmp));
|
||||
rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
|
||||
if (is_ipv6)
|
||||
{
|
||||
memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
|
||||
memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
|
||||
rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
|
||||
}
|
||||
|
||||
ip_address_encode (&t->src, IP46_TYPE_ANY, &rmp->src_address);
|
||||
ip_address_encode (&t->dst, IP46_TYPE_ANY, &rmp->dst_address);
|
||||
|
||||
if (ip46_address_is_ip4 (&t->dst))
|
||||
rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
|
||||
else
|
||||
{
|
||||
memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
|
||||
memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
|
||||
rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
|
||||
}
|
||||
rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
|
||||
|
||||
rmp->instance = htonl (t->user_instance);
|
||||
rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
|
||||
rmp->vni = htonl (t->vni);
|
||||
rmp->decap_next_index = htonl (t->decap_next_index);
|
||||
rmp->sw_if_index = htonl (t->sw_if_index);
|
||||
rmp->is_ipv6 = is_ipv6;
|
||||
rmp->context = context;
|
||||
|
||||
vl_api_send_msg (reg, (u8 *) rmp);
|
||||
|
@ -1484,8 +1484,10 @@ static void *vl_api_vxlan_add_del_tunnel_t_print
|
||||
u8 *s;
|
||||
s = format (0, "SCRIPT: vxlan_add_del_tunnel ");
|
||||
|
||||
ip46_address_t src = to_ip46 (mp->is_ipv6, mp->src_address);
|
||||
ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->dst_address);
|
||||
ip46_address_t src =
|
||||
to_ip46 (mp->src_address.af, (u8 *) & mp->src_address.un);
|
||||
ip46_address_t dst =
|
||||
to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
|
||||
|
||||
u8 is_grp = ip46_address_is_multicast (&dst);
|
||||
char *dst_name = is_grp ? "group" : "dst";
|
||||
|
@ -11,6 +11,7 @@ from framework import VppTestCase, VppTestRunner
|
||||
from util import Host, ppp
|
||||
from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint, VppDot1ADSubint
|
||||
from vpp_gre_interface import VppGreInterface
|
||||
from vpp_vxlan_tunnel import VppVxlanTunnel
|
||||
from collections import namedtuple
|
||||
from vpp_papi import VppEnum
|
||||
|
||||
@ -53,12 +54,11 @@ class TestSpan(VppTestCase):
|
||||
i.config_ip4()
|
||||
i.resolve_arp()
|
||||
|
||||
cls.vxlan = cls.vapi.vxlan_add_del_tunnel(
|
||||
src_address=cls.pg2.local_ip4n, dst_address=cls.pg2.remote_ip4n,
|
||||
is_add=1, vni=1111)
|
||||
|
||||
def setUp(self):
|
||||
super(TestSpan, self).setUp()
|
||||
self.vxlan = VppVxlanTunnel(self, src=self.pg2.local_ip4,
|
||||
dst=self.pg2.remote_ip4, vni=1111)
|
||||
self.vxlan.add_vpp_config()
|
||||
self.reset_packet_infos()
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -12,6 +12,7 @@ from scapy.layers.inet import IP, UDP
|
||||
from scapy.layers.vxlan import VXLAN
|
||||
from scapy.utils import atol
|
||||
from vpp_ip_route import VppIpRoute, VppRoutePath
|
||||
from vpp_vxlan_tunnel import VppVxlanTunnel
|
||||
from vpp_ip import INVALID_INDEX
|
||||
|
||||
|
||||
@ -98,8 +99,9 @@ class TestVxlan(BridgeDomain, VppTestCase):
|
||||
rip.add_vpp_config()
|
||||
dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4)
|
||||
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n,
|
||||
dst_address=dest_ip4n, vni=vni)
|
||||
r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
|
||||
dst=dest_ip4, vni=vni)
|
||||
r.add_vpp_config()
|
||||
cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni)
|
||||
|
||||
@classmethod
|
||||
@ -112,12 +114,14 @@ class TestVxlan(BridgeDomain, VppTestCase):
|
||||
vni_start = 10000
|
||||
vni_end = vni_start + n_shared_dst_tunnels
|
||||
for vni in range(vni_start, vni_end):
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n,
|
||||
dst_address=cls.mcast_ip4n,
|
||||
mcast_sw_if_index=1,
|
||||
is_add=is_add, vni=vni)
|
||||
if r.sw_if_index == 0xffffffff:
|
||||
raise ValueError("bad sw_if_index: ~0")
|
||||
r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
|
||||
dst=cls.mcast_ip4, mcast_sw_if_index=1, vni=vni)
|
||||
if is_add:
|
||||
r.add_vpp_config()
|
||||
if r.sw_if_index == 0xffffffff:
|
||||
raise ValueError("bad sw_if_index: ~0")
|
||||
else:
|
||||
r.remove_vpp_config()
|
||||
|
||||
@classmethod
|
||||
def add_shared_mcast_dst_load(cls):
|
||||
@ -135,13 +139,15 @@ class TestVxlan(BridgeDomain, VppTestCase):
|
||||
n_distinct_dst_tunnels = 200
|
||||
ip_range_start = 10
|
||||
ip_range_end = ip_range_start + n_distinct_dst_tunnels
|
||||
for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start,
|
||||
ip_range_end):
|
||||
vni = bytearray(dest_ip4n)[3]
|
||||
cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n,
|
||||
dst_address=dest_ip4n,
|
||||
mcast_sw_if_index=1, is_add=is_add,
|
||||
vni=vni)
|
||||
for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start,
|
||||
ip_range_end):
|
||||
vni = bytearray(socket.inet_pton(socket.AF_INET, dest_ip4))[3]
|
||||
r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
|
||||
dst=dest_ip4, mcast_sw_if_index=1, vni=vni)
|
||||
if is_add:
|
||||
r.add_vpp_config()
|
||||
else:
|
||||
r.remove_vpp_config()
|
||||
|
||||
@classmethod
|
||||
def add_mcast_tunnels_load(cls):
|
||||
@ -182,43 +188,6 @@ class TestVxlan(BridgeDomain, VppTestCase):
|
||||
cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % (
|
||||
(iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF)
|
||||
|
||||
# Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
|
||||
# into BD.
|
||||
cls.single_tunnel_bd = 1
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n,
|
||||
dst_address=cls.pg0.remote_ip4n,
|
||||
vni=cls.single_tunnel_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=cls.single_tunnel_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd)
|
||||
|
||||
# Setup vni 2 to test multicast flooding
|
||||
cls.n_ucast_tunnels = 10
|
||||
cls.mcast_flood_bd = 2
|
||||
cls.create_vxlan_flood_test_bd(cls.mcast_flood_bd,
|
||||
cls.n_ucast_tunnels)
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n,
|
||||
dst_address=cls.mcast_ip4n,
|
||||
mcast_sw_if_index=1,
|
||||
vni=cls.mcast_flood_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=cls.mcast_flood_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=cls.pg2.sw_if_index, bd_id=cls.mcast_flood_bd)
|
||||
|
||||
# Add and delete mcast tunnels to check stability
|
||||
cls.add_shared_mcast_dst_load()
|
||||
cls.add_mcast_tunnels_load()
|
||||
cls.del_shared_mcast_dst_load()
|
||||
cls.del_mcast_tunnels_load()
|
||||
|
||||
# Setup vni 3 to test unicast flooding
|
||||
cls.ucast_flood_bd = 3
|
||||
cls.create_vxlan_flood_test_bd(cls.ucast_flood_bd,
|
||||
cls.n_ucast_tunnels)
|
||||
cls.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd)
|
||||
except Exception:
|
||||
super(TestVxlan, cls).tearDownClass()
|
||||
raise
|
||||
@ -227,6 +196,51 @@ class TestVxlan(BridgeDomain, VppTestCase):
|
||||
def tearDownClass(cls):
|
||||
super(TestVxlan, cls).tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
super(TestVxlan, self).setUp()
|
||||
# Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
|
||||
# into BD.
|
||||
self.single_tunnel_bd = 1
|
||||
r = VppVxlanTunnel(self, src=self.pg0.local_ip4,
|
||||
dst=self.pg0.remote_ip4, vni=self.single_tunnel_bd)
|
||||
r.add_vpp_config()
|
||||
self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=self.single_tunnel_bd)
|
||||
self.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd)
|
||||
|
||||
# Setup vni 2 to test multicast flooding
|
||||
self.n_ucast_tunnels = 10
|
||||
self.mcast_flood_bd = 2
|
||||
self.create_vxlan_flood_test_bd(self.mcast_flood_bd,
|
||||
self.n_ucast_tunnels)
|
||||
r = VppVxlanTunnel(self, src=self.pg0.local_ip4, dst=self.mcast_ip4,
|
||||
mcast_sw_if_index=1, vni=self.mcast_flood_bd)
|
||||
r.add_vpp_config()
|
||||
self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=self.mcast_flood_bd)
|
||||
self.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd)
|
||||
|
||||
# Add and delete mcast tunnels to check stability
|
||||
self.add_shared_mcast_dst_load()
|
||||
self.add_mcast_tunnels_load()
|
||||
self.del_shared_mcast_dst_load()
|
||||
self.del_mcast_tunnels_load()
|
||||
|
||||
# Setup vni 3 to test unicast flooding
|
||||
self.ucast_flood_bd = 3
|
||||
self.create_vxlan_flood_test_bd(self.ucast_flood_bd,
|
||||
self.n_ucast_tunnels)
|
||||
self.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd)
|
||||
|
||||
def test_decap(self):
|
||||
""" Decapsulation test
|
||||
from BridgeDoman
|
||||
"""
|
||||
super(TestVxlan, self).test_decap()
|
||||
|
||||
def test_encap_big_packet(self):
|
||||
""" Encapsulation test send big frame from pg1
|
||||
Verify receipt of encapsulated frames on pg0
|
||||
|
@ -10,6 +10,7 @@ from scapy.layers.inet6 import IPv6, UDP
|
||||
from scapy.layers.vxlan import VXLAN
|
||||
from scapy.utils import atol
|
||||
from vpp_ip_route import VppIpRoute, VppRoutePath
|
||||
from vpp_vxlan_tunnel import VppVxlanTunnel
|
||||
from vpp_ip import INVALID_INDEX
|
||||
|
||||
|
||||
@ -88,15 +89,14 @@ class TestVxlan6(BridgeDomain, VppTestCase):
|
||||
start = 10
|
||||
end = start + n_ucast_tunnels
|
||||
for dest_ip6 in cls.ip_range(start, end):
|
||||
dest_ip6n = socket.inet_pton(socket.AF_INET6, dest_ip6)
|
||||
# add host route so dest ip will not be resolved
|
||||
rip = VppIpRoute(cls, dest_ip6, 128,
|
||||
[VppRoutePath(cls.pg0.remote_ip6, INVALID_INDEX)],
|
||||
register=False)
|
||||
rip.add_vpp_config()
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip6n,
|
||||
dst_address=dest_ip6n, is_ipv6=1,
|
||||
vni=vni)
|
||||
r = VppVxlanTunnel(cls, src=cls.pg0.local_ip6,
|
||||
dst=dest_ip6, vni=vni)
|
||||
r.add_vpp_config()
|
||||
cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni)
|
||||
|
||||
@classmethod
|
||||
@ -135,38 +135,6 @@ class TestVxlan6(BridgeDomain, VppTestCase):
|
||||
cls.mcast_ip6n = socket.inet_pton(socket.AF_INET6, cls.mcast_ip6)
|
||||
cls.mcast_mac = "33:33:00:00:00:%02x" % (1)
|
||||
|
||||
# Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
|
||||
# into BD.
|
||||
cls.single_tunnel_bd = 1
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip6n,
|
||||
dst_address=cls.pg0.remote_ip6n,
|
||||
is_ipv6=1,
|
||||
vni=cls.single_tunnel_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=cls.single_tunnel_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd)
|
||||
|
||||
# Setup vni 2 to test multicast flooding
|
||||
cls.n_ucast_tunnels = 10
|
||||
cls.mcast_flood_bd = 2
|
||||
cls.create_vxlan_flood_test_bd(cls.mcast_flood_bd,
|
||||
cls.n_ucast_tunnels)
|
||||
r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip6n,
|
||||
dst_address=cls.mcast_ip6n,
|
||||
mcast_sw_if_index=1, is_ipv6=1,
|
||||
vni=cls.mcast_flood_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=cls.mcast_flood_bd)
|
||||
cls.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=cls.pg2.sw_if_index, bd_id=cls.mcast_flood_bd)
|
||||
|
||||
# Setup vni 3 to test unicast flooding
|
||||
cls.ucast_flood_bd = 3
|
||||
cls.create_vxlan_flood_test_bd(cls.ucast_flood_bd,
|
||||
cls.n_ucast_tunnels)
|
||||
cls.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd)
|
||||
except Exception:
|
||||
super(TestVxlan6, cls).tearDownClass()
|
||||
raise
|
||||
@ -175,6 +143,39 @@ class TestVxlan6(BridgeDomain, VppTestCase):
|
||||
def tearDownClass(cls):
|
||||
super(TestVxlan6, cls).tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
super(TestVxlan6, self).setUp()
|
||||
# Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
|
||||
# into BD.
|
||||
self.single_tunnel_bd = 1
|
||||
r = VppVxlanTunnel(self, src=self.pg0.local_ip6,
|
||||
dst=self.pg0.remote_ip6, vni=self.single_tunnel_bd)
|
||||
r.add_vpp_config()
|
||||
self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=self.single_tunnel_bd)
|
||||
self.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd)
|
||||
|
||||
# Setup vni 2 to test multicast flooding
|
||||
self.n_ucast_tunnels = 10
|
||||
self.mcast_flood_bd = 2
|
||||
self.create_vxlan_flood_test_bd(self.mcast_flood_bd,
|
||||
self.n_ucast_tunnels)
|
||||
r = VppVxlanTunnel(self, src=self.pg0.local_ip6, dst=self.mcast_ip6,
|
||||
mcast_sw_if_index=1, vni=self.mcast_flood_bd)
|
||||
r.add_vpp_config()
|
||||
self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
|
||||
bd_id=self.mcast_flood_bd)
|
||||
self.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd)
|
||||
|
||||
# Setup vni 3 to test unicast flooding
|
||||
self.ucast_flood_bd = 3
|
||||
self.create_vxlan_flood_test_bd(self.ucast_flood_bd,
|
||||
self.n_ucast_tunnels)
|
||||
self.vapi.sw_interface_set_l2_bridge(
|
||||
rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd)
|
||||
|
||||
# Method to define VPP actions before tear down of the test case.
|
||||
# Overrides tearDown method in VppTestCase class.
|
||||
# @param self The object pointer.
|
||||
|
65
test/vpp_vxlan_tunnel.py
Normal file
65
test/vpp_vxlan_tunnel.py
Normal file
@ -0,0 +1,65 @@
|
||||
from vpp_interface import VppInterface
|
||||
from vpp_papi import VppEnum
|
||||
|
||||
|
||||
INDEX_INVALID = 0xffffffff
|
||||
|
||||
|
||||
def find_vxlan_tunnel(test, src, dst, vni):
|
||||
ts = test.vapi.vxlan_tunnel_dump(INDEX_INVALID)
|
||||
for t in ts:
|
||||
if src == str(t.src_address) and \
|
||||
dst == str(t.dst_address) and \
|
||||
t.vni == vni:
|
||||
return t.sw_if_index
|
||||
return INDEX_INVALID
|
||||
|
||||
|
||||
class VppVxlanTunnel(VppInterface):
|
||||
"""
|
||||
VPP VXLAN interface
|
||||
"""
|
||||
|
||||
def __init__(self, test, src, dst, vni, mcast_itf=None,
|
||||
mcast_sw_if_index=INDEX_INVALID,
|
||||
decap_next_index=INDEX_INVALID,
|
||||
encap_vrf_id=None, instance=0xffffffff):
|
||||
""" Create VXLAN Tunnel interface """
|
||||
super(VppVxlanTunnel, self).__init__(test)
|
||||
self.src = src
|
||||
self.dst = dst
|
||||
self.vni = vni
|
||||
self.mcast_itf = mcast_itf
|
||||
self.mcast_sw_if_index = mcast_sw_if_index
|
||||
self.encap_vrf_id = encap_vrf_id
|
||||
self.decap_next_index = decap_next_index
|
||||
self.instance = instance
|
||||
|
||||
if (self.mcast_itf):
|
||||
self.mcast_sw_if_index = self.mcast_itf.sw_if_index
|
||||
|
||||
def add_vpp_config(self):
|
||||
reply = self.test.vapi.vxlan_add_del_tunnel(
|
||||
is_add=1, src_address=self.src, dst_address=self.dst, vni=self.vni,
|
||||
mcast_sw_if_index=self.mcast_sw_if_index,
|
||||
encap_vrf_id=self.encap_vrf_id,
|
||||
instance=self.instance, decap_next_index=self.decap_next_index)
|
||||
self.set_sw_if_index(reply.sw_if_index)
|
||||
self._test.registry.register(self, self._test.logger)
|
||||
|
||||
def remove_vpp_config(self):
|
||||
self.test.vapi.vxlan_add_del_tunnel(
|
||||
is_add=0, src_address=self.src, dst_address=self.dst, vni=self.vni,
|
||||
mcast_sw_if_index=self.mcast_sw_if_index,
|
||||
encap_vrf_id=self.encap_vrf_id, instance=self.instance,
|
||||
decap_next_index=self.decap_next_index)
|
||||
|
||||
def query_vpp_config(self):
|
||||
return (INDEX_INVALID != find_vxlan_tunnel(self._test,
|
||||
self.src,
|
||||
self.dst,
|
||||
self.vni))
|
||||
|
||||
def object_id(self):
|
||||
return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
|
||||
self.src, self.dst)
|
Reference in New Issue
Block a user