aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Kozemcak <akozemca@cisco.com>2016-07-27 10:33:38 +0200
committerFlorin Coras <florin.coras@gmail.com>2016-07-27 13:23:24 +0000
commita8691754d2f7cdd960c3d8dc5fbff6367e9c36b8 (patch)
treeb1715a03db89657278630c21b6e4363a905e55e4
parent683d3ee1b136060ef38290b6ab3a21c9a4730c4f (diff)
VAT add_locator_set api support multiple locators
Change-Id: I22df3d4407bd7fdd953783f00605380a2d6fb46e Signed-off-by: Andrej Kozemcak <akozemca@cisco.com>
-rw-r--r--vnet/vnet/lisp-cp/control.c13
-rw-r--r--vpp-api-test/vat/api_format.c33
-rw-r--r--vpp/vpp-api/api.c27
-rw-r--r--vpp/vpp-api/vpe.api2
4 files changed, 70 insertions, 5 deletions
diff --git a/vnet/vnet/lisp-cp/control.c b/vnet/vnet/lisp-cp/control.c
index 78e730f5a5d..fb4c8397d2d 100644
--- a/vnet/vnet/lisp-cp/control.c
+++ b/vnet/vnet/lisp-cp/control.c
@@ -1562,8 +1562,8 @@ is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls,
vec_foreach(locit, ls->locator_indices)
{
itloc = pool_elt_at_index(lcm->locator_pool, locit[0]);
- if (itloc->sw_if_index == loc->sw_if_index ||
- !gid_address_cmp(&itloc->address, &loc->address))
+ if ((ls->local && itloc->sw_if_index == loc->sw_if_index) ||
+ (!ls->local && !gid_address_cmp(&itloc->address, &loc->address)))
{
clib_warning("Duplicate locator");
return VNET_API_ERROR_VALUE_EXIST;
@@ -2099,7 +2099,14 @@ lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
({
u8 * msg = 0;
int next_line = 0;
- msg = format (msg, "%=16v", lsit->name);
+ if (lsit->local)
+ {
+ msg = format (msg, "%=16v", lsit->name);
+ }
+ else
+ {
+ msg = format (msg, "%=16s", "remote");
+ }
vec_foreach (locit, lsit->locator_indices)
{
if (next_line)
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c
index 3b2c91cf449..a2200660798 100644
--- a/vpp-api-test/vat/api_format.c
+++ b/vpp-api-test/vat/api_format.c
@@ -10488,6 +10488,14 @@ static int api_get_node_graph (vat_main_t * vam)
W;
}
+/** Used for transferring locators via VPP API */
+typedef CLIB_PACKED(struct
+{
+ u32 sw_if_index; /**< locator sw_if_index */
+ u8 priority; /**< locator priority */
+ u8 weight; /**< locator weight */
+}) ls_locator_t;
+
static int
api_lisp_add_del_locator_set(vat_main_t * vam)
{
@@ -10497,6 +10505,8 @@ api_lisp_add_del_locator_set(vat_main_t * vam)
u8 is_add = 1;
u8 *locator_set_name = NULL;
u8 locator_set_name_set = 0;
+ ls_locator_t locator, * locators = 0;
+ u32 sw_if_index, priority, weight;
/* Parse args required to build the message */
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
@@ -10504,18 +10514,32 @@ api_lisp_add_del_locator_set(vat_main_t * vam)
is_add = 0;
} else if (unformat(input, "locator-set %s", &locator_set_name)) {
locator_set_name_set = 1;
+ } else if (unformat(input, "sw_if_index %u p %u w %u",
+ &sw_if_index, &priority, &weight)) {
+ locator.sw_if_index = htonl(sw_if_index);
+ locator.priority = priority;
+ locator.weight = weight;
+ vec_add1(locators, locator);
+ } else if (unformat(input, "iface %U p %u w %u", unformat_sw_if_index,
+ vam, &sw_if_index, &priority, &weight)) {
+ locator.sw_if_index = htonl(sw_if_index);
+ locator.priority = priority;
+ locator.weight = weight;
+ vec_add1(locators, locator);
} else
break;
}
if (locator_set_name_set == 0) {
errmsg ("missing locator-set name");
+ vec_free(locators);
return -99;
}
if (vec_len(locator_set_name) > 64) {
errmsg ("locator-set name too long\n");
vec_free(locator_set_name);
+ vec_free(locators);
return -99;
}
vec_add1(locator_set_name, 0);
@@ -10528,6 +10552,11 @@ api_lisp_add_del_locator_set(vat_main_t * vam)
vec_len(locator_set_name));
vec_free(locator_set_name);
+ mp->locator_num = vec_len (locators);
+ clib_memcpy (mp->locators, locators,
+ (sizeof (ls_locator_t) * vec_len (locators)));
+ vec_free (locators);
+
/* send it... */
S;
@@ -13147,7 +13176,9 @@ _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
_(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
" vrf_id <nn> add | pop | none") \
_(trace_profile_del, "") \
-_(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
+_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
+ " sw_if_index <sw_if_index> p <priority> " \
+ "w <weight>] [del]") \
_(lisp_add_del_locator, "locator-set <locator_name> " \
"iface <intf> | sw_if_index <sw_if_index> " \
"p <priority> w <weight> [del]") \
diff --git a/vpp/vpp-api/api.c b/vpp/vpp-api/api.c
index 822b9906c15..076d16a30f3 100644
--- a/vpp/vpp-api/api.c
+++ b/vpp/vpp-api/api.c
@@ -4777,27 +4777,52 @@ static void vl_api_vxlan_gpe_tunnel_dump_t_handler
}
}
+/** Used for transferring locators via VPP API */
+typedef CLIB_PACKED(struct
+{
+ u32 sw_if_index; /**< locator sw_if_index */
+ u8 priority; /**< locator priority */
+ u8 weight; /**< locator weight */
+}) ls_locator_t;
+
static void
vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
{
vl_api_lisp_add_del_locator_set_reply_t *rmp;
int rv = 0;
vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
+ locator_t locator;
+ ls_locator_t *ls_loc;
u32 ls_index = ~0;
u8 *locator_name = NULL;
+ int i;
memset(a, 0, sizeof(a[0]));
locator_name = format(0, "%s", mp->locator_set_name);
a->name = locator_name;
- a->locators = NULL;
a->is_add = mp->is_add;
a->local = 1;
+ memset(&locator, 0, sizeof(locator));
+ for (i = 0; i < mp->locator_num; i++) {
+ ls_loc = &((ls_locator_t *) mp->locators)[i];
+ VALIDATE_SW_IF_INDEX(ls_loc);
+
+ locator.sw_if_index = htonl(ls_loc->sw_if_index);
+ locator.priority = ls_loc->priority;
+ locator.weight = ls_loc->weight;
+ locator.local = 1;
+ vec_add1(a->locators, locator);
+ }
+
rv = vnet_lisp_add_del_locator_set(a, &ls_index);
+ BAD_SW_IF_INDEX_LABEL;
+
vec_free(locator_name);
+ vec_free(a->locators);
REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
}
diff --git a/vpp/vpp-api/vpe.api b/vpp/vpp-api/vpe.api
index 4571c92df4d..6aa221388c4 100644
--- a/vpp/vpp-api/vpe.api
+++ b/vpp/vpp-api/vpe.api
@@ -2163,6 +2163,8 @@ define lisp_add_del_locator_set {
u32 context;
u8 is_add;
u8 locator_set_name[64];
+ u32 locator_num;
+ u8 locators[0];
};
/** \brief Reply for locator_set add/del
end local fname = "/tmp/lute-"..s.."-pid.txt" session_exec(s, "echo $$ >" .. fname) -- it's a dirty hack but it's quick sleep(0.5) local pid = io.lines(fname)() print("Got pid for " .. s .. " : " .. tostring(pid)) return(tonumber(pid)) end function session_connect_with(s0, s1) -- local pid0 = tostring(session_get_bash_pid(s0)) local pid1 = tostring(session_get_bash_pid(s1)) local eth_options = { "rx", "tx", "sg", "tso", "ufo", "gso", "gro", "lro", "rxvlan", "txvlan", "rxhash" } local this_end = s0 .. "_" .. s1 local other_end = s1 .. "_" .. s0 session_exec(s0, "ip link add name " .. this_end .. " type veth peer name " .. other_end) session_exec(s0, "ip link set dev " .. this_end .. " up promisc on") for i, option in ipairs(eth_options) do session_exec(s0, "/sbin/ethtool --offload " .. this_end .. " " .. option .. " off") session_exec(s0, "/sbin/ethtool --offload " .. other_end .. " " .. option .. " off") end session_exec(s0, "ip link set dev " .. other_end .. " up promisc on netns /proc/" .. pid1 .. "/ns/net") sleep(0.5) end ^D^D^D run lua session_connect_with("s0", "s1") run lua session_connect_with("s0", "s2") cd s1 ip -6 addr add dev s1_s0 2001:db8:1::1/64 ip -4 addr add dev s1_s0 192.0.2.1/24 ip link set dev s1_s0 up promisc on ^D^D^D cd s2 ip -6 addr add dev s2_s0 2001:db8:1::2/64 ip -6 addr add dev s2_s0 2001:db8:1::3/64 ip -6 addr add dev s2_s0 2001:db8:1::4/64 ip -4 addr add dev s2_s0 192.0.2.2/24 ip -4 addr add dev s2_s0:1 192.0.2.3/24 ip -4 addr add dev s2_s0:2 192.0.2.4/24 ip link set dev s2_s0 up promisc on ^D^D^D run s1 ip addr run s2 ip addr shell VPP cd VPP cd /home/ubuntu/vpp make debug r ^D^D^D expect VPP DBGvpp# cd lua -- Initialization of the Lua environment for talking to VPP vpp = require("vpp-lapi") root_dir = "/home/ubuntu/vpp" pneum_path = root_dir .. "/build-root/install-vpp_debug-native/vpp-api/lib64/libpneum.so" vpp:init({ pneum_path = pneum_path }) vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vlib-api/vlibmemory/memclnt.api") vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vpp/vpp-api/vpe.api") vpp:connect("aytest") vpp:consume_api(root_dir .. "/plugins/acl-plugin/acl/acl.api", "acl") ^D^D^D cd lua reply = vpp:api_call("af_packet_create", { host_if_name = "s0_s1", hw_addr = "AAAAAA" }) vpp_if_to_s1 = reply[1].sw_if_index reply = vpp:api_call("af_packet_create", { host_if_name = "s0_s2", hw_addr = "AAAAAA" }) vpp_if_to_s2 = reply[1].sw_if_index ifaces = { vpp_if_to_s1, vpp_if_to_s2 } reply = vpp:api_call("sw_interface_set_flags", { sw_if_index = vpp_if_to_s1, admin_up_down = 1, link_up_down = 1 }) print(vpp.dump(reply)) reply = vpp:api_call("sw_interface_set_flags", { sw_if_index = vpp_if_to_s2, admin_up_down = 1, link_up_down = 1 }) print(vpp.dump(reply)) bd_id = 42 reply = vpp:api_call("bridge_domain_add_del", { bd_id = bd_id, flood = 1, uu_flood = 1, forward = 1, learn = 1, arp_term = 0, is_add = 1 }) print(vpp.dump(reply)) for i, v in ipairs(ifaces) do reply = vpp:api_call("sw_interface_set_l2_bridge", { rx_sw_if_index = v, bd_id = bd_id, shg = 0, bvi = 0, enable = 1 } ) print(vpp.dump(reply)) end ^D^D^D run s1 ping -c 3 192.0.2.2 expect s1 packet loss run s1 ping -c 3 192.0.2.3 expect s1 packet loss run s1 ping -c 3 192.0.2.4 expect s1 packet loss run s1 ping6 -c 3 2001:db8:1::2 expect s1 packet loss run s1 ping6 -c 3 2001:db8:1::3 expect s1 packet loss run s1 ping6 -c 3 2001:db8:1::4 expect s1 packet loss cd lua --- ACL testing --[[ temporary comment out reply = vpp:api_call("acl_del", { context = 42, acl_index = 230 }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_del", { context = 42, acl_index = 8 }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_del", { context = 42, acl_index = 15 }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_add", { context = 42, count = 2, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 } } }) print(vpp.dump(reply)) print("---") interface_acl_in = reply[1].acl_index reply = vpp:api_call("acl_add", { context = 42, count = 3, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 }, { is_permit = 1, is_ipv6 = 0 } } }) print(vpp.dump(reply)) print("---") interface_acl_out = reply[1].acl_index reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_add", { context = 42, count = 0 }) print(vpp.dump(reply)) print("---") acl_index_to_delete = reply[1].acl_index print("Deleting " .. tostring(acl_index_to_delete)) reply = vpp:api_call("acl_del", { context = 42, acl_index = acl_index_to_delete }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0}) for ri, rv in ipairs(reply) do print("Reply message #" .. tostring(ri)) print(vpp.dump(rv)) for ai, av in ipairs(rv.r) do print("ACL rule #" .. tostring(ai) .. " : " .. vpp.dump(av)) end end print("---") reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_out }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_in }) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0}) print(vpp.dump(reply)) print("---") reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 4294967295 }) print(vpp.dump(reply)) print("---") ]] -- end of comment out ---- Should be nothing ^^ r = { { is_permit = 1, is_ipv6 = 1, dst_ip_addr = ip46("2001:db8:1::2"), dst_ip_prefix_len = 128 }, { is_permit = 0, is_ipv6 = 1, dst_ip_addr = ip46("2001:db8:1::3"), dst_ip_prefix_len = 128 }, { is_permit = 1, is_ipv6 = 1, dst_ip_addr = ip46("2001:db8::"), dst_ip_prefix_len = 32 }, { is_permit = 1, is_ipv6 = 0, dst_ip_addr = ip46("192.0.2.2"), dst_ip_prefix_len = 32}, { is_permit = 0, is_ipv6 = 0, dst_ip_addr = ip46("192.0.2.3"), dst_ip_prefix_len = 32 }, } reply = vpp:api_call("acl_add", { context = 42, count = 5, r = r }) print(vpp.dump(reply)) print("---") interface_acl_in = reply[1].acl_index reply = vpp:api_call("acl_add", { context = 42, count = 3, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 }, { is_permit = 1, is_ipv6 = 0 } } }) print(vpp.dump(reply)) print("---") interface_acl_out = reply[1].acl_in reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = vpp_if_to_s1, is_add = 1, is_input = 1, acl_index = interface_acl_in }) print(vpp.dump(reply)) print("---") --reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = vpp_if_to_s2, is_add = 1, is_input = 0, acl_index = interface_acl_out }) -- print(vpp.dump(reply)) --print("---") ^D^D^D run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping6 -c 3 2001:db8:1::2 expect s1 packet loss run VPP show trace expect VPP match: inacl 0 rule 0 run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping6 -c 3 2001:db8:1::3 expect s1 packet loss run VPP show trace expect VPP match: inacl 0 rule 1 run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping6 -c 3 2001:db8:1::4 expect s1 packet loss run VPP show trace expect VPP match: inacl 0 rule 2 run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping -c 3 192.0.2.2 expect s1 packet loss run VPP show trace expect VPP match: inacl 0 rule 3 run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping -c 3 192.0.2.3 expect s1 packet loss run VPP show trace expect VPP match: inacl 0 rule 4 cd lua --- TEST OUTBOUND ACL r1 = { { is_permit = 1, is_ipv6 = 1, src_ip_addr = ip46("2001:db8:1::1"), src_ip_prefix_len = 128, dst_ip_addr = ip46("2001:db8:1::2"), dst_ip_prefix_len = 128 }, { is_permit = 0, is_ipv6 = 1, src_ip_addr = ip46("2001:db8:1::1"), src_ip_prefix_len = 128, dst_ip_addr = ip46("2001:db8:1::4"), dst_ip_prefix_len = 128 } } reply = vpp:api_call("acl_add", { context = 42, count = 3, r = r1 }) print(vpp.dump(reply)) print("---") interface_acl_out = reply[1].acl_index reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = vpp_if_to_s2, is_add = 1, is_input = 0, acl_index = interface_acl_out }) print(vpp.dump(reply)) print("---") ^D^D^D run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping6 -c 3 2001:db8:1::2 expect s1 packet loss run VPP show trace expect VPP match: outacl 2 rule 0 run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping6 -c 3 2001:db8:1::3 expect s1 packet loss run VPP show trace expect VPP match: inacl 0 rule 1 run VPP clear trace run VPP trace add af-packet-input 100 run s1 ping6 -c 3 2001:db8:1::4 expect s1 packet loss run VPP show trace expect VPP match: outacl 2 rule 1 run lua print("ALL GOOD!")