summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extras/vom/vom/dhcp_client.cpp7
-rw-r--r--extras/vom/vom/dhcp_client_cmds.cpp7
-rw-r--r--src/vat/api_format.c19
-rw-r--r--src/vnet/dhcp/dhcp.api122
-rw-r--r--src/vnet/dhcp/dhcp6_ia_na_client_cp.c4
-rw-r--r--src/vnet/dhcp/dhcp6_ia_na_client_dp.c7
-rw-r--r--src/vnet/dhcp/dhcp6_pd_client_cp.c14
-rw-r--r--src/vnet/dhcp/dhcp6_pd_client_dp.c11
-rw-r--r--src/vnet/dhcp/dhcp_api.c44
-rw-r--r--src/vpp/api/custom_dump.c19
-rw-r--r--test/test_dhcp.py263
-rw-r--r--test/test_dhcp6.py46
-rw-r--r--test/vpp_dhcp.py128
-rw-r--r--test/vpp_papi_provider.py100
14 files changed, 421 insertions, 370 deletions
diff --git a/extras/vom/vom/dhcp_client.cpp b/extras/vom/vom/dhcp_client.cpp
index e3a5b9d5559..23911b3df0e 100644
--- a/extras/vom/vom/dhcp_client.cpp
+++ b/extras/vom/vom/dhcp_client.cpp
@@ -278,7 +278,8 @@ dhcp_client::event_handler::handle_populate(const client_db::key_t& key)
const dhcp_client::state_t& s =
dhcp_client::state_t::from_vpp(payload.lease.state);
- route::prefix_t pfx(payload.lease.is_ipv6, payload.lease.host_address,
+ route::prefix_t pfx(payload.lease.is_ipv6,
+ (uint8_t*)&payload.lease.host_address.un,
payload.lease.mask_width);
std::string hostname =
reinterpret_cast<const char*>(payload.lease.hostname);
@@ -286,8 +287,8 @@ dhcp_client::event_handler::handle_populate(const client_db::key_t& key)
dhcp_client dc(*itf, hostname, l2, payload.client.set_broadcast_flag,
from_api(payload.client.dscp));
dc.lease(std::make_shared<dhcp_client::lease_t>(
- s, itf, from_bytes(0, payload.lease.router_address), pfx, hostname,
- mac_address_t(payload.lease.host_mac)));
+ s, itf, from_bytes(0, (uint8_t*)&payload.lease.router_address.un), pfx,
+ hostname, mac_address_t(payload.lease.host_mac)));
OM::commit(key, dc);
}
}
diff --git a/extras/vom/vom/dhcp_client_cmds.cpp b/extras/vom/vom/dhcp_client_cmds.cpp
index c1d4d49a495..3f899a63c01 100644
--- a/extras/vom/vom/dhcp_client_cmds.cpp
+++ b/extras/vom/vom/dhcp_client_cmds.cpp
@@ -173,15 +173,16 @@ events_cmd::notify()
const dhcp_client::state_t& s =
dhcp_client::state_t::from_vpp(payload.lease.state);
- route::prefix_t pfx(payload.lease.is_ipv6, payload.lease.host_address,
+ route::prefix_t pfx(payload.lease.is_ipv6,
+ (uint8_t*)&payload.lease.host_address.un,
payload.lease.mask_width);
std::shared_ptr<interface> itf = interface::find(payload.lease.sw_if_index);
if (itf) {
std::shared_ptr<dhcp_client::lease_t> ev =
std::make_shared<dhcp_client::lease_t>(
- s, itf, from_bytes(0, payload.lease.router_address), pfx,
- reinterpret_cast<const char*>(payload.lease.hostname),
+ s, itf, from_bytes(0, (uint8_t*)&payload.lease.router_address.un),
+ pfx, reinterpret_cast<const char*>(payload.lease.hostname),
mac_address_t(payload.lease.host_mac));
m_listener.handle_dhcp_event(ev);
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 5823055221f..16abf45e3d9 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -2671,10 +2671,9 @@ vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
{
u8 *s, i;
- s = format (0, "DHCP compl event: pid %d %s hostname %s host_addr %U "
+ s = format (0, "DHCP compl event: pid %d hostname %s host_addr %U "
"host_mac %U router_addr %U",
- ntohl (mp->pid), mp->lease.is_ipv6 ? "ipv6" : "ipv4",
- mp->lease.hostname,
+ ntohl (mp->pid), mp->lease.hostname,
format_ip4_address, mp->lease.host_address,
format_ethernet_address, mp->lease.host_mac,
format_ip4_address, mp->lease.router_address);
@@ -9355,14 +9354,15 @@ api_dhcp_proxy_config (vat_main_t * vam)
mp->server_vrf_id = ntohl (server_vrf_id);
if (v6_address_set)
{
- mp->is_ipv6 = 1;
- clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
- clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
+ clib_memcpy (&mp->dhcp_server.un, &v6address, sizeof (v6address));
+ clib_memcpy (&mp->dhcp_src_address.un, &v6srcaddress,
+ sizeof (v6address));
}
else
{
- clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
- clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
+ clib_memcpy (&mp->dhcp_server.un, &v4address, sizeof (v4address));
+ clib_memcpy (&mp->dhcp_src_address.un, &v4srcaddress,
+ sizeof (v4address));
}
/* send it... */
@@ -9434,8 +9434,7 @@ static void vl_api_dhcp_proxy_details_t_handler_json
vat_json_init_object (node);
vat_json_object_add_uint (node, "rx-table-id", ntohl (mp->rx_vrf_id));
- vat_json_object_add_bytes (node, "vss-type", &mp->vss_type,
- sizeof (mp->vss_type));
+ vat_json_object_add_uint (node, "vss-type", ntohl (mp->vss_type));
vat_json_object_add_string_copy (node, "vss-vpn-ascii-id",
mp->vss_vpn_ascii_id);
vat_json_object_add_uint (node, "vss-fib-id", ntohl (mp->vss_fib_id));
diff --git a/src/vnet/dhcp/dhcp.api b/src/vnet/dhcp/dhcp.api
index c84b3639103..f3fef5135f1 100644
--- a/src/vnet/dhcp/dhcp.api
+++ b/src/vnet/dhcp/dhcp.api
@@ -13,16 +13,47 @@
* limitations under the License.
*/
-option version = "2.0.1";
+option version = "3.0.1";
+import "vnet/interface_types.api";
import "vnet/ip/ip_types.api";
+import "vnet/ethernet/ethernet_types.api";
+
+enum vss_type {
+ VSS_TYPE_API_ASCII = 0,
+ VSS_TYPE_API_VPN_ID = 1,
+ VSS_TYPE_API_INVALID = 123,
+ VSS_TYPE_API_DEFAULT = 255,
+};
+
+enum dhcp_client_state {
+ DHCP_CLIENT_STATE_API_DISCOVER,
+ DHCP_CLIENT_STATE_API_REQUEST,
+ DHCP_CLIENT_STATE_API_BOUND,
+};
+
+enum dhcpv6_msg_type
+{
+ DHCPV6_MSG_API_SOLICIT = 1,
+ DHCPV6_MSG_API_ADVERTISE = 2,
+ DHCPV6_MSG_API_REQUEST = 3,
+ DHCPV6_MSG_API_CONFIRM = 4,
+ DHCPV6_MSG_API_RENEW = 5,
+ DHCPV6_MSG_API_REBIND = 6,
+ DHCPV6_MSG_API_REPLY = 7,
+ DHCPV6_MSG_API_RELEASE = 8,
+ DHCPV6_MSG_API_DECLINE = 9,
+ DHCPV6_MSG_API_RECONFIGURE = 10,
+ DHCPV6_MSG_API_INFORMATION_REQUEST = 11,
+ DHCPV6_MSG_API_RELAY_FORW = 12,
+ DHCPV6_MSG_API_RELAY_REPL = 13,
+};
/** \brief DHCP Proxy config add / del request
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param rx_vrf_id - Rx/interface vrf id
@param server_vrf_id - server vrf id
- @param if_ipv6 - ipv6 if non-zero, else ipv4
@param is_add - add the config if non-zero, else delete
@param insert_circuit_id - option82 suboption 1 fib number
@param dhcp_server[] - server address
@@ -34,10 +65,9 @@ autoreply define dhcp_proxy_config
u32 context;
u32 rx_vrf_id;
u32 server_vrf_id;
- u8 is_ipv6;
- u8 is_add;
- u8 dhcp_server[16];
- u8 dhcp_src_address[16];
+ bool is_add;
+ vl_api_address_t dhcp_server;
+ vl_api_address_t dhcp_src_address;
};
/** \brief DHCP Proxy set / unset vss request
@@ -46,7 +76,7 @@ autoreply define dhcp_proxy_config
@param tbl_id - table id
@vss_type - 0: use ASCI vpn_id; 1: use oui/vpn_index; 255: global vpn
@vpn_ascii - null terminated ASCII VPN ID up to 128 characters
- @param oui - first part of rfc2685 vpn id, 3 bytes oui
+ @param oui - first part of rfc2685 vpn id, 3 bytes oui
@param vpn_index - second part of rfc2685 vpn id, 4 bytes vpn index
@param is_ipv6 - ip6 if non-zero, else ip4
@param is_add - set vss if non-zero, else delete
@@ -56,12 +86,12 @@ autoreply define dhcp_proxy_set_vss
u32 client_index;
u32 context;
u32 tbl_id;
- u8 vss_type;
- u8 vpn_ascii_id[129];
+ vl_api_vss_type_t vss_type;
+ string vpn_ascii_id[129];
u32 oui;
u32 vpn_index;
- u8 is_ipv6;
- u8 is_add;
+ bool is_ipv6;
+ bool is_add;
};
/** \brief DHCP Client config data
@@ -77,11 +107,11 @@ autoreply define dhcp_proxy_set_vss
*/
typedef dhcp_client
{
- u32 sw_if_index;
- u8 hostname[64];
+ vl_api_interface_index_t sw_if_index;
+ string hostname[64];
u8 id[64];
- u8 want_dhcp_event;
- u8 set_broadcast_flag;
+ bool want_dhcp_event;
+ bool set_broadcast_flag;
vl_api_ip_dscp_t dscp;
u32 pid;
};
@@ -96,7 +126,7 @@ autoreply define dhcp_client_config
{
u32 client_index;
u32 context;
- u8 is_add;
+ bool is_add;
vl_api_dhcp_client_t client;
};
@@ -105,12 +135,12 @@ autoreply define dhcp_client_config
*/
typedef domain_server
{
- u8 address[16];
+ vl_api_address_t address;
};
/** \brief Data learned by the client during the DHCP process
@param sw_if_index - the interface on which the client is configured
- @param state - the state of the lease (see dhcp_client_state_t)
+ @param state - the state of the lease
@param is_ipv6 - if non-zero the address is ipv6, else ipv4
@param mask_width - The length of the subnet mask assigned
@param host_address - Host IP address
@@ -119,14 +149,14 @@ typedef domain_server
*/
typedef dhcp_lease
{
- u32 sw_if_index;
- u8 state;
- u8 hostname[64];
- u8 is_ipv6;
+ vl_api_interface_index_t sw_if_index;
+ vl_api_dhcp_client_state_t state;
+ bool is_ipv6;
+ string hostname[64];
u8 mask_width;
- u8 host_address[16];
- u8 router_address[16];
- u8 host_mac[6];
+ vl_api_address_t host_address;
+ vl_api_address_t router_address;
+ vl_api_mac_address_t host_mac;
u8 count;
vl_api_domain_server_t domain_server[count];
};
@@ -174,13 +204,13 @@ define dhcp_proxy_dump
{
u32 client_index;
u32 context;
- u8 is_ip6;
+ bool is_ip6;
};
typedef dhcp_server
{
u32 server_vrf_id;
- u8 dhcp_server[16];
+ vl_api_address_t dhcp_server;
};
/** \brief Tell client about a DHCP completion event
@@ -192,10 +222,10 @@ manual_endian manual_print define dhcp_proxy_details
u32 rx_vrf_id;
u32 vss_oui;
u32 vss_fib_id;
- u8 vss_type;
- u8 vss_vpn_ascii_id[129];
- u8 is_ipv6;
- u8 dhcp_src_address[16];
+ vl_api_vss_type_t vss_type;
+ bool is_ipv6;
+ string vss_vpn_ascii_id[129];
+ vl_api_address_t dhcp_src_address;
u8 count;
vl_api_dhcp_server_t servers[count];
};
@@ -220,7 +250,7 @@ autoreply define dhcp6_clients_enable_disable
{
u32 client_index;
u32 context;
- u8 enable;
+ bool enable;
};
/** \brief Struct representing DHCPv6 address
@@ -230,21 +260,19 @@ autoreply define dhcp6_clients_enable_disable
*/
typedef dhcp6_address_info
{
- u8 address[16];
+ vl_api_ip6_address_t address;
u32 valid_time;
u32 preferred_time;
};
/** \brief Struct representing DHCPv6 PD prefix
@param prefix - prefix
- @param prefix_length - prefix length
@param valid_time - valid lifetime
@param preferred_time - preferred lifetime
*/
typedef dhcp6_pd_prefix_info
{
- u8 prefix[16];
- u8 prefix_length;
+ vl_api_ip6_prefix_t prefix;
u32 valid_time;
u32 preferred_time;
};
@@ -274,14 +302,14 @@ autoreply define dhcp6_send_client_message
{
u32 client_index;
u32 context;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
u32 irt;
u32 mrt;
u32 mrc;
u32 mrd;
- u8 stop;
- u8 msg_type;
+ bool stop;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u32 n_addresses;
@@ -313,14 +341,14 @@ autoreply define dhcp6_pd_send_client_message
{
u32 client_index;
u32 context;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
u32 irt;
u32 mrt;
u32 mrc;
u32 mrd;
- u8 stop;
- u8 msg_type;
+ bool stop;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u32 n_prefixes;
@@ -361,7 +389,7 @@ autoreply define want_dhcp6_pd_reply_events
{
u32 client_index;
u32 context;
- u8 enable_disable;
+ bool enable_disable;
u32 pid;
};
@@ -384,9 +412,9 @@ define dhcp6_reply_event
{
u32 client_index;
u32 pid;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
- u8 msg_type;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u16 inner_status_code;
@@ -415,9 +443,9 @@ define dhcp6_pd_reply_event
{
u32 client_index;
u32 pid;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
- u8 msg_type;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u16 inner_status_code;
diff --git a/src/vnet/dhcp/dhcp6_ia_na_client_cp.c b/src/vnet/dhcp/dhcp6_ia_na_client_cp.c
index ad0ca8e3e93..e440805d707 100644
--- a/src/vnet/dhcp/dhcp6_ia_na_client_cp.c
+++ b/src/vnet/dhcp/dhcp6_ia_na_client_cp.c
@@ -214,7 +214,7 @@ dhcp6_reply_event_handler (vl_api_dhcp6_reply_event_t * mp)
inner_status_code = ntohs (mp->inner_status_code);
status_code = ntohs (mp->status_code);
- if (mp->msg_type == DHCPV6_MSG_ADVERTISE
+ if (mp->msg_type == DHCPV6_MSG_API_ADVERTISE
&& client_state->server_index == ~0)
{
address_info_t *address_list = 0, *address_info;
@@ -246,7 +246,7 @@ dhcp6_reply_event_handler (vl_api_dhcp6_reply_event_t * mp)
vec_free (address_list);
}
- if (mp->msg_type != DHCPV6_MSG_REPLY)
+ if (mp->msg_type != DHCPV6_MSG_API_REPLY)
return 0;
if (!client_state->rebinding && client_state->server_index != server_index)
diff --git a/src/vnet/dhcp/dhcp6_ia_na_client_dp.c b/src/vnet/dhcp/dhcp6_ia_na_client_dp.c
index 5f940c33687..f49017b0236 100644
--- a/src/vnet/dhcp/dhcp6_ia_na_client_dp.c
+++ b/src/vnet/dhcp/dhcp6_ia_na_client_dp.c
@@ -25,6 +25,7 @@
#include <vlibmemory/api.h>
#include <vnet/dhcp/dhcp6_ia_na_client_dp.h>
#include <vnet/dhcp/dhcp6_client_common_dp.h>
+#include <vnet/ip/ip_types_api.h>
#include <vnet/vnet_msg_enum.h>
@@ -454,7 +455,7 @@ void
params.mrt = ntohl (mp->mrt);
params.mrc = ntohl (mp->mrc);
params.mrd = ntohl (mp->mrd);
- params.msg_type = mp->msg_type;
+ params.msg_type = ntohl (mp->msg_type);
params.T1 = ntohl (mp->T1);
params.T2 = ntohl (mp->T2);
n_addresses = ntohl (mp->n_addresses);
@@ -467,7 +468,7 @@ void
dhcp6_send_client_message_params_address_t *addr = &params.addresses[i];
addr->preferred_lt = ntohl (ai->preferred_time);
addr->valid_lt = ntohl (ai->valid_time);
- memcpy (addr->address.as_u8, ai->address, 16);
+ ip6_address_decode (ai->address, &addr->address);
}
dhcp6_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop, &params);
@@ -535,7 +536,7 @@ dhcp6_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
for (j = 0; j < vec_len (events[i].addresses); j++)
{
dhcp6_address_info_t *info = &events[i].addresses[j];
- memcpy (address->address, &info->address, 16);
+ ip6_address_encode (&info->address, address->address);
address->valid_time = htonl (info->valid_time);
address->preferred_time = htonl (info->preferred_time);
address++;
diff --git a/src/vnet/dhcp/dhcp6_pd_client_cp.c b/src/vnet/dhcp/dhcp6_pd_client_cp.c
index a157b16d491..804f62a79e7 100644
--- a/src/vnet/dhcp/dhcp6_pd_client_cp.c
+++ b/src/vnet/dhcp/dhcp6_pd_client_cp.c
@@ -323,7 +323,7 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
inner_status_code = ntohs (mp->inner_status_code);
status_code = ntohs (mp->status_code);
- if (mp->msg_type == DHCPV6_MSG_ADVERTISE
+ if (mp->msg_type == DHCPV6_MSG_API_ADVERTISE
&& client_state->server_index == ~0)
{
prefix_info_t *prefix_list = 0, *prefix_info;
@@ -341,8 +341,8 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
for (i = 0; i < n_prefixes; i++)
{
api_prefix = &mp->prefixes[i];
- prefix = (ip6_address_t *) api_prefix->prefix;
- prefix_length = api_prefix->prefix_length;
+ prefix = (ip6_address_t *) api_prefix->prefix.address;
+ prefix_length = api_prefix->prefix.len;
prefix_info = &prefix_list[i];
prefix_info->prefix = *prefix;
@@ -358,7 +358,7 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
vec_free (prefix_list);
}
- if (mp->msg_type != DHCPV6_MSG_REPLY)
+ if (mp->msg_type != DHCPV6_MSG_API_REPLY)
return 0;
if (!client_state->rebinding && client_state->server_index != server_index)
@@ -398,15 +398,15 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
api_prefix = &mp->prefixes[i];
- prefix = (ip6_address_t *) api_prefix->prefix;
- prefix_length = api_prefix->prefix_length;
+ prefix = (ip6_address_t *) api_prefix->prefix.address;
+ prefix_length = api_prefix->prefix.len;
if (ip6_address_is_link_local_unicast (prefix))
continue;
valid_time = ntohl (api_prefix->valid_time);
preferred_time = ntohl (api_prefix->preferred_time);
- prefix_length = api_prefix->prefix_length;
+ prefix_length = api_prefix->prefix.len;
if (preferred_time > valid_time)
continue;
diff --git a/src/vnet/dhcp/dhcp6_pd_client_dp.c b/src/vnet/dhcp/dhcp6_pd_client_dp.c
index c1bf5f8844f..c665b17281a 100644
--- a/src/vnet/dhcp/dhcp6_pd_client_dp.c
+++ b/src/vnet/dhcp/dhcp6_pd_client_dp.c
@@ -25,6 +25,7 @@
#include <vlibmemory/api.h>
#include <vnet/dhcp/dhcp6_pd_client_dp.h>
#include <vnet/dhcp/dhcp6_client_common_dp.h>
+#include <vnet/ip/ip_types_api.h>
#include <vnet/vnet_msg_enum.h>
@@ -457,7 +458,7 @@ void
params.mrt = ntohl (mp->mrt);
params.mrc = ntohl (mp->mrc);
params.mrd = ntohl (mp->mrd);
- params.msg_type = mp->msg_type;
+ params.msg_type = ntohl (mp->msg_type);
params.T1 = ntohl (mp->T1);
params.T2 = ntohl (mp->T2);
n_prefixes = ntohl (mp->n_prefixes);
@@ -471,8 +472,8 @@ void
&params.prefixes[i];
pref->preferred_lt = ntohl (pi->preferred_time);
pref->valid_lt = ntohl (pi->valid_time);
- memcpy (pref->prefix.as_u8, pi->prefix, 16);
- pref->prefix_length = pi->prefix_length;
+ ip6_address_decode (pi->prefix.address, &pref->prefix);
+ pref->prefix_length = pi->prefix.len;
}
dhcp6_pd_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop,
@@ -542,8 +543,8 @@ dhcp6_pd_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
for (j = 0; j < vec_len (events[i].prefixes); j++)
{
dhcp6_prefix_info_t *info = &events[i].prefixes[j];
- memcpy (prefix->prefix, &info->prefix, 16);
- prefix->prefix_length = info->prefix_length;
+ ip6_address_encode (&info->prefix, prefix->prefix.address);
+ prefix->prefix.len = info->prefix_length;
prefix->valid_time = htonl (info->valid_time);
prefix->preferred_time = htonl (info->preferred_time);
prefix++;
diff --git a/src/vnet/dhcp/dhcp_api.c b/src/vnet/dhcp/dhcp_api.c
index 7935ad8ba01..252f2df7d6b 100644
--- a/src/vnet/dhcp/dhcp_api.c
+++ b/src/vnet/dhcp/dhcp_api.c
@@ -73,8 +73,8 @@ vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
vpn_ascii_id = format (0, "%s", mp->vpn_ascii_id);
rv =
dhcp_proxy_set_vss ((mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4),
- ntohl (mp->tbl_id), mp->vss_type, vpn_ascii_id,
- ntohl (mp->oui), ntohl (mp->vpn_index),
+ ntohl (mp->tbl_id), ntohl (mp->vss_type),
+ vpn_ascii_id, ntohl (mp->oui), ntohl (mp->vpn_index),
mp->is_add == 0);
REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
@@ -88,12 +88,18 @@ static void vl_api_dhcp_proxy_config_t_handler
ip46_address_t src, server;
int rv = -1;
- if (mp->is_ipv6)
+ if (mp->dhcp_src_address.af != mp->dhcp_server.af)
{
- clib_memcpy (&src.ip6, mp->dhcp_src_address, sizeof (src.ip6));
- clib_memcpy (&server.ip6, mp->dhcp_server, sizeof (server.ip6));
+ rv = VNET_API_ERROR_INVALID_ARGUMENT;
+ goto reply;
+ }
- rv = dhcp6_proxy_set_server (&server,
+ ip_address_decode (&mp->dhcp_src_address, &src);
+ ip_address_decode (&mp->dhcp_server, &server);
+
+ if (mp->dhcp_src_address.af == ADDRESS_IP4)
+ {
+ rv = dhcp4_proxy_set_server (&server,
&src,
(u32) ntohl (mp->rx_vrf_id),
(u32) ntohl (mp->server_vrf_id),
@@ -101,20 +107,14 @@ static void vl_api_dhcp_proxy_config_t_handler
}
else
{
- ip46_address_reset (&src);
- ip46_address_reset (&server);
-
- clib_memcpy (&src.ip4, mp->dhcp_src_address, sizeof (src.ip4));
- clib_memcpy (&server.ip4, mp->dhcp_server, sizeof (server.ip4));
-
- rv = dhcp4_proxy_set_server (&server,
+ rv = dhcp6_proxy_set_server (&server,
&src,
(u32) ntohl (mp->rx_vrf_id),
(u32) ntohl (mp->server_vrf_id),
(int) (mp->is_add == 0));
}
-
+reply:
REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
}
@@ -162,7 +162,7 @@ dhcp_send_details (fib_protocol_t proto,
if (vss)
{
- mp->vss_type = vss->vss_type;
+ mp->vss_type = ntohl (vss->vss_type);
if (vss->vss_type == VSS_TYPE_ASCII)
{
u32 id_len = vec_len (vss->vpn_ascii_id);
@@ -193,23 +193,23 @@ dhcp_send_details (fib_protocol_t proto,
if (mp->is_ipv6)
{
- memcpy (v_server->dhcp_server, &server->dhcp_server.ip6, 16);
+ memcpy (&v_server->dhcp_server.un, &server->dhcp_server.ip6, 16);
}
else
{
/* put the address in the first bytes */
- memcpy (v_server->dhcp_server, &server->dhcp_server.ip4, 4);
+ memcpy (&v_server->dhcp_server.un, &server->dhcp_server.ip4, 4);
}
}
if (mp->is_ipv6)
{
- memcpy (mp->dhcp_src_address, &proxy->dhcp_src_address.ip6, 16);
+ memcpy (&mp->dhcp_src_address.un, &proxy->dhcp_src_address.ip6, 16);
}
else
{
/* put the address in the first bytes */
- memcpy (mp->dhcp_src_address, &proxy->dhcp_src_address.ip4, 4);
+ memcpy (&mp->dhcp_src_address.un, &proxy->dhcp_src_address.ip4, 4);
}
vl_api_send_msg (reg, (u8 *) mp);
}
@@ -223,15 +223,15 @@ dhcp_client_lease_encode (vl_api_dhcp_lease_t * lease,
lease->is_ipv6 = 0; // only support IPv6 clients
lease->sw_if_index = ntohl (client->sw_if_index);
- lease->state = client->state;
+ lease->state = ntohl (client->state);
len = clib_min (sizeof (lease->hostname) - 1, vec_len (client->hostname));
clib_memcpy (&lease->hostname, client->hostname, len);
lease->hostname[len] = 0;
lease->mask_width = client->subnet_mask_width;
- clib_memcpy (&lease->host_address[0], (u8 *) & client->leased_address,
+ clib_memcpy (&lease->host_address.un, (u8 *) & client->leased_address,
sizeof (ip4_address_t));
- clib_memcpy (&lease->router_address[0], (u8 *) & client->router_address,
+ clib_memcpy (&lease->router_address.un, (u8 *) & client->router_address,
sizeof (ip4_address_t));
lease->count = vec_len (client->domain_server_address);
diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c
index 36ffe5ef53d..0d342a5b420 100644
--- a/src/vpp/api/custom_dump.c
+++ b/src/vpp/api/custom_dump.c
@@ -1047,20 +1047,11 @@ static void *vl_api_dhcp_proxy_config_t_print
s = format (s, "rx_vrf_id %d ", (mp->rx_vrf_id));
s = format (s, "server_vrf_id %d ", (mp->server_vrf_id));
- if (mp->is_ipv6)
- {
- s = format (s, "svr %U ", format_ip6_address,
- (ip6_address_t *) mp->dhcp_server);
- s = format (s, "src %U ", format_ip6_address,
- (ip6_address_t *) mp->dhcp_src_address);
- }
- else
- {
- s = format (s, "svr %U ", format_ip4_address,
- (ip4_address_t *) mp->dhcp_server);
- s = format (s, "src %U ", format_ip4_address,
- (ip4_address_t *) mp->dhcp_src_address);
- }
+ s = format (s, "svr %U ", format_ip46_address,
+ (ip46_address_t *) & mp->dhcp_server.un);
+ s = format (s, "src %U ", format_ip46_address,
+ (ip46_address_t *) & mp->dhcp_src_address.un);
+
if (mp->is_add == 0)
s = format (s, "del ");
diff --git a/test/test_dhcp.py b/test/test_dhcp.py
index 175f6493eb7..39b0af77f9d 100644
--- a/test/test_dhcp.py
+++ b/test/test_dhcp.py
@@ -23,6 +23,7 @@ from scapy.utils6 import in6_ptop
from vpp_papi import mac_pton, VppEnum
from vpp_sub_interface import VppDot1QSubint
from vpp_qos import VppQosEgressMap, VppQosMark
+from vpp_dhcp import VppDHCPClient, VppDHCPProxy
DHCP4_CLIENT_PORT = 68
@@ -94,7 +95,7 @@ class TestDHCP(VppTestCase):
found = False
for i in dhcp.options:
- if type(i) is tuple:
+ if isinstance(i, tuple):
if i[0] == option:
self.assertEqual(i[1], value)
found = True
@@ -108,7 +109,7 @@ class TestDHCP(VppTestCase):
id_len = len(vpn_id)
for i in dhcp.options:
- if type(i) is tuple:
+ if isinstance(i, tuple):
if i[0] == "relay_agent_Information":
#
# There are two sb-options present - each of length 6.
@@ -117,7 +118,7 @@ class TestDHCP(VppTestCase):
if oui != 0:
self.assertEqual(len(data), 24)
elif len(vpn_id) > 0:
- self.assertEqual(len(data), len(vpn_id)+17)
+ self.assertEqual(len(data), len(vpn_id) + 17)
else:
self.assertEqual(len(data), 12)
@@ -173,13 +174,13 @@ class TestDHCP(VppTestCase):
# followerd by vpn_id in ascii
self.assertEqual(oui, 0)
self.assertEqual(ord(data[12]), 151)
- self.assertEqual(ord(data[13]), id_len+1)
+ self.assertEqual(ord(data[13]), id_len + 1)
self.assertEqual(ord(data[14]), 0)
- self.assertEqual(data[15:15+id_len], vpn_id)
+ self.assertEqual(data[15:15 + id_len], vpn_id)
# VSS control sub-option
- self.assertEqual(ord(data[15+len(vpn_id)]), 152)
- self.assertEqual(ord(data[16+len(vpn_id)]), 0)
+ self.assertEqual(ord(data[15 + len(vpn_id)]), 152)
+ self.assertEqual(ord(data[16 + len(vpn_id)]), 0)
found = 1
self.assertTrue(found)
@@ -190,7 +191,7 @@ class TestDHCP(VppTestCase):
dhcp = pkt[DHCP]
found = False
for o in dhcp.options:
- if type(o) is tuple:
+ if isinstance(o, tuple):
if o[0] == "message-type" \
and DHCPTypes[o[1]] == name:
found = True
@@ -298,7 +299,7 @@ class TestDHCP(VppTestCase):
is_discover = False
for o in dhcp.options:
- if type(o) is tuple:
+ if isinstance(o, tuple):
if o[0] == "message-type" \
and DHCPTypes[o[1]] == "discover":
is_discover = True
@@ -362,7 +363,7 @@ class TestDHCP(VppTestCase):
if id_len > 0:
self.assertEqual(oui, 0)
vss = pkt[DHCP6OptVSS]
- self.assertEqual(vss.optlen, id_len+1)
+ self.assertEqual(vss.optlen, id_len + 1)
self.assertEqual(vss.type, 0)
self.assertEqual(vss.data[0:id_len], vpn_id)
@@ -439,12 +440,11 @@ class TestDHCP(VppTestCase):
#
# Enable DHCP proxy in VRF 0
#
- server_addr = self.pg0.remote_ip4n
- src_addr = self.pg0.local_ip4n
+ server_addr = self.pg0.remote_ip4
+ src_addr = self.pg0.local_ip4
- self.vapi.dhcp_proxy_config(server_addr,
- src_addr,
- rx_table_id=0)
+ Proxy = VppDHCPProxy(self, server_addr, src_addr, rx_vrf_id=0)
+ Proxy.add_vpp_config()
#
# Discover packets from the client are dropped because there is no
@@ -555,10 +555,7 @@ class TestDHCP(VppTestCase):
# Delete the DHCP config in VRF 0
# Should now drop requests.
#
- self.vapi.dhcp_proxy_config(server_addr,
- src_addr,
- rx_table_id=0,
- is_add=0)
+ Proxy.remove_vpp_config()
self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
"DHCP config removed VRF 0")
@@ -568,18 +565,25 @@ class TestDHCP(VppTestCase):
#
# Add DHCP config for VRF 1 & 2
#
- server_addr1 = self.pg1.remote_ip4n
- src_addr1 = self.pg1.local_ip4n
- self.vapi.dhcp_proxy_config(server_addr1,
- src_addr1,
- rx_table_id=1,
- server_table_id=1)
- server_addr2 = self.pg2.remote_ip4n
- src_addr2 = self.pg2.local_ip4n
- self.vapi.dhcp_proxy_config(server_addr2,
- src_addr2,
- rx_table_id=2,
- server_table_id=2)
+ server_addr1 = self.pg1.remote_ip4
+ src_addr1 = self.pg1.local_ip4
+ Proxy1 = VppDHCPProxy(
+ self,
+ server_addr1,
+ src_addr1,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy1.add_vpp_config()
+
+ server_addr2 = self.pg2.remote_ip4
+ src_addr2 = self.pg2.local_ip4
+ Proxy2 = VppDHCPProxy(
+ self,
+ server_addr2,
+ src_addr2,
+ rx_vrf_id=2,
+ server_vrf_id=2)
+ Proxy2.add_vpp_config()
#
# Confim DHCP requests ok in VRF 1 & 2.
@@ -641,13 +645,15 @@ class TestDHCP(VppTestCase):
# expect clients messages to be relay to both configured servers
#
self.pg1.generate_remote_hosts(2)
- server_addr12 = socket.inet_pton(AF_INET, self.pg1.remote_hosts[1].ip4)
+ server_addr12 = self.pg1.remote_hosts[1].ip4
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr1,
- rx_table_id=1,
- server_table_id=1,
- is_add=1)
+ Proxy12 = VppDHCPProxy(
+ self,
+ server_addr12,
+ src_addr,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy12.add_vpp_config()
#
# We'll need an ARP entry for the server to send it packets
@@ -741,11 +747,7 @@ class TestDHCP(VppTestCase):
#
# Remove the second DHCP server
#
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr1,
- rx_table_id=1,
- server_table_id=1,
- is_add=0)
+ Proxy12.remove_vpp_config()
#
# Test we can still relay with the first
@@ -778,16 +780,8 @@ class TestDHCP(VppTestCase):
#
# remove DHCP config to cleanup
#
- self.vapi.dhcp_proxy_config(server_addr1,
- src_addr1,
- rx_table_id=1,
- server_table_id=1,
- is_add=0)
- self.vapi.dhcp_proxy_config(server_addr2,
- src_addr2,
- rx_table_id=2,
- server_table_id=2,
- is_add=0)
+ Proxy1.remove_vpp_config()
+ Proxy2.remove_vpp_config()
self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
"DHCP cleanup VRF 0")
@@ -809,12 +803,12 @@ class TestDHCP(VppTestCase):
dhcp_solicit_src_vrf0 = mk_ll_addr(self.pg3.remote_mac)
dhcp_solicit_src_vrf1 = mk_ll_addr(self.pg4.remote_mac)
dhcp_solicit_src_vrf2 = mk_ll_addr(self.pg5.remote_mac)
- server_addr_vrf0 = self.pg0.remote_ip6n
- src_addr_vrf0 = self.pg0.local_ip6n
- server_addr_vrf1 = self.pg1.remote_ip6n
- src_addr_vrf1 = self.pg1.local_ip6n
- server_addr_vrf2 = self.pg2.remote_ip6n
- src_addr_vrf2 = self.pg2.local_ip6n
+ server_addr_vrf0 = self.pg0.remote_ip6
+ src_addr_vrf0 = self.pg0.local_ip6
+ server_addr_vrf1 = self.pg1.remote_ip6
+ src_addr_vrf1 = self.pg1.local_ip6
+ server_addr_vrf2 = self.pg2.remote_ip6
+ src_addr_vrf2 = self.pg2.local_ip6
dmac = in6_getnsmac(inet_pton(socket.AF_INET6, dhcp_solicit_dst))
p_solicit_vrf0 = (Ether(dst=dmac, src=self.pg3.remote_mac) /
@@ -848,11 +842,13 @@ class TestDHCP(VppTestCase):
# Packets still dropped because the client facing interface has no
# IPv6 config
#
- self.vapi.dhcp_proxy_config(server_addr_vrf0,
- src_addr_vrf0,
- rx_table_id=0,
- server_table_id=0,
- is_ipv6=1)
+ Proxy = VppDHCPProxy(
+ self,
+ server_addr_vrf0,
+ src_addr_vrf0,
+ rx_vrf_id=0,
+ server_vrf_id=0)
+ Proxy.add_vpp_config()
self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0,
"DHCP with no configuration")
@@ -963,18 +959,22 @@ class TestDHCP(VppTestCase):
#
# Add all the config for VRF 1 & 2
#
- self.vapi.dhcp_proxy_config(server_addr_vrf1,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1)
+ Proxy1 = VppDHCPProxy(
+ self,
+ server_addr_vrf1,
+ src_addr_vrf1,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy1.add_vpp_config()
self.pg4.config_ip6()
- self.vapi.dhcp_proxy_config(server_addr_vrf2,
- src_addr_vrf2,
- rx_table_id=2,
- server_table_id=2,
- is_ipv6=1)
+ Proxy2 = VppDHCPProxy(
+ self,
+ server_addr_vrf2,
+ src_addr_vrf2,
+ rx_vrf_id=2,
+ server_vrf_id=2)
+ Proxy2.add_vpp_config()
self.pg5.config_ip6()
#
@@ -1026,10 +1026,14 @@ class TestDHCP(VppTestCase):
#
# Add VSS config
- # table=1, vss_type=1, vpn_index=1, oui=4
- # table=2, vss_type=0, vpn_id = "ip6-table-2"
- self.vapi.dhcp_proxy_set_vss(1, 1, oui=4, vpn_index=1, is_ip6=1)
- self.vapi.dhcp_proxy_set_vss(2, 0, "IPv6-table-2", is_ip6=1)
+ #
+ self.vapi.dhcp_proxy_set_vss(
+ tbl_id=1, vss_type=1, oui=4, vpn_index=1, is_ipv6=1)
+ self.vapi.dhcp_proxy_set_vss(
+ tbl_id=2,
+ vss_type=0,
+ vpn_ascii_id="IPv6-table-2",
+ is_ipv6=1)
self.pg4.add_stream(p_solicit_vrf1)
self.pg_enable_capture(self.pg_interfaces)
@@ -1058,7 +1062,7 @@ class TestDHCP(VppTestCase):
# Remove the VSS config
# relayed DHCP has default vlaues in the option.
#
- self.vapi.dhcp_proxy_set_vss(1, is_ip6=1, is_add=0)
+ self.vapi.dhcp_proxy_set_vss(1, is_ipv6=1, is_add=0)
self.pg4.add_stream(p_solicit_vrf1)
self.pg_enable_capture(self.pg_interfaces)
@@ -1075,14 +1079,15 @@ class TestDHCP(VppTestCase):
# expect clients messages to be relay to both configured servers
#
self.pg1.generate_remote_hosts(2)
- server_addr12 = socket.inet_pton(AF_INET6,
- self.pg1.remote_hosts[1].ip6)
+ server_addr12 = self.pg1.remote_hosts[1].ip6
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1)
+ Proxy12 = VppDHCPProxy(
+ self,
+ server_addr12,
+ src_addr_vrf1,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy12.add_vpp_config()
#
# We'll need an ND entry for the server to send it packets
@@ -1178,12 +1183,7 @@ class TestDHCP(VppTestCase):
#
# Remove the second DHCP server
#
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1,
- is_add=0)
+ Proxy12.remove_vpp_config()
#
# Test we can still relay with the first
@@ -1201,32 +1201,10 @@ class TestDHCP(VppTestCase):
#
# Cleanup
#
- self.vapi.dhcp_proxy_config(server_addr_vrf2,
- src_addr_vrf2,
- rx_table_id=2,
- server_table_id=2,
- is_ipv6=1,
- is_add=0)
- self.vapi.dhcp_proxy_config(server_addr_vrf1,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1,
- is_add=0)
- self.vapi.dhcp_proxy_config(server_addr_vrf0,
- src_addr_vrf0,
- rx_table_id=0,
- server_table_id=0,
- is_ipv6=1,
- is_add=0)
-
- # duplicate delete
- self.vapi.dhcp_proxy_config(server_addr_vrf0,
- src_addr_vrf0,
- rx_table_id=0,
- server_table_id=0,
- is_ipv6=1,
- is_add=0)
+ Proxy.remove_vpp_config()
+ Proxy1.remove_vpp_config()
+ Proxy2.remove_vpp_config()
+
self.pg3.unconfig_ip6()
self.pg4.unconfig_ip6()
self.pg5.unconfig_ip6()
@@ -1242,7 +1220,9 @@ class TestDHCP(VppTestCase):
#
# Configure DHCP client on PG3 and capture the discover sent
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname)
+ Client = VppDHCPClient(self, self.pg3.sw_if_index, hostname)
+ Client.add_vpp_config()
+ self.assertTrue(Client.query_vpp_config())
rx = self.pg3.get_capture(1)
@@ -1312,7 +1292,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
#
# and now the route should be gone
@@ -1327,9 +1307,10 @@ class TestDHCP(VppTestCase):
self.pg3.admin_down()
self.sleep(1)
self.pg3.admin_up()
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname,
- client_id=self.pg3.local_mac,
- dscp=vdscp.IP_API_DSCP_EF)
+ Client.set_client(self.pg3.sw_if_index, hostname,
+ id=self.pg3.local_mac,
+ dscp=vdscp.IP_API_DSCP_EF)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1388,7 +1369,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
@@ -1400,8 +1381,11 @@ class TestDHCP(VppTestCase):
#
# Configure DHCP client on PG3 and capture the discover sent
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname,
- set_broadcast_flag=0)
+ Client.set_client(
+ self.pg3.sw_if_index,
+ hostname,
+ set_broadcast_flag=False)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1507,14 +1491,13 @@ class TestDHCP(VppTestCase):
hostname)
self.assertEqual(clients[0].lease.hostname.rstrip('\0'),
hostname)
- self.assertEqual(clients[0].lease.is_ipv6, 0)
# 0 = DISCOVER, 1 = REQUEST, 2 = BOUND
self.assertEqual(clients[0].lease.state, 2)
self.assertEqual(clients[0].lease.mask_width, 24)
- self.assertEqual(clients[0].lease.router_address.rstrip('\0'),
- self.pg3.remote_ip4n)
- self.assertEqual(clients[0].lease.host_address.rstrip('\0'),
- self.pg3.local_ip4n)
+ self.assertEqual(str(clients[0].lease.router_address),
+ self.pg3.remote_ip4)
+ self.assertEqual(str(clients[0].lease.host_address),
+ self.pg3.local_ip4)
# remove the left over ARP entry
self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
@@ -1525,7 +1508,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
#
# and now the route should be gone
@@ -1541,7 +1524,8 @@ class TestDHCP(VppTestCase):
self.sleep(1)
self.pg3.admin_up()
self.pg_enable_capture(self.pg_interfaces)
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname)
+ Client.set_client(self.pg3.sw_if_index, hostname)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1618,7 +1602,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
def test_dhcp_client_vlan(self):
""" DHCP Client w/ VLAN"""
@@ -1646,9 +1630,12 @@ class TestDHCP(VppTestCase):
#
# Configure DHCP client on PG3 and capture the discover sent
#
- self.vapi.dhcp_client_config(vlan_100.sw_if_index,
- hostname,
- dscp=vdscp.IP_API_DSCP_EF)
+ Client = VppDHCPClient(
+ self,
+ vlan_100.sw_if_index,
+ hostname,
+ dscp=vdscp.IP_API_DSCP_EF)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1658,10 +1645,6 @@ class TestDHCP(VppTestCase):
self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname,
dscp=vdscp.IP_API_DSCP_EF)
- self.vapi.dhcp_client_config(vlan_100.sw_if_index,
- hostname,
- is_add=0)
-
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/test_dhcp6.py b/test/test_dhcp6.py
index 2037e62e9ea..4c6b7d3ca8b 100644
--- a/test/test_dhcp6.py
+++ b/test/test_dhcp6.py
@@ -10,6 +10,7 @@ from scapy.utils6 import in6_mactoifaceid
from scapy.utils import inet_ntop, inet_pton
from framework import VppTestCase
+from vpp_papi import VppEnum
import util
@@ -52,14 +53,17 @@ class TestDHCPv6DataPlane(VppTestCase):
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
- address_bin = '\00\01\00\02\00\03' + '\00' * 8 + '\00\05'
- address = {'address': address_bin,
+ address = {'address': '1:2:3::5',
'preferred_time': 60,
'valid_time': 120}
- self.vapi.dhcp6_send_client_message(msg_type=1,
- sw_if_index=self.pg0.sw_if_index,
- T1=20, T2=40, addresses=[address],
- n_addresses=len([address]))
+ self.vapi.dhcp6_send_client_message(
+ msg_type=VppEnum.vl_api_dhcpv6_msg_type_t.DHCPV6_MSG_API_SOLICIT,
+ sw_if_index=self.pg0.sw_if_index,
+ T1=20,
+ T2=40,
+ addresses=[address],
+ n_addresses=len(
+ [address]))
rx_list = self.pg0.get_capture(1)
self.assertEqual(len(rx_list), 1)
packet = rx_list[0]
@@ -112,8 +116,8 @@ class TestDHCPv6DataPlane(VppTestCase):
self.assert_equal(ev.T2, 40)
reported_address = ev.addresses[0]
- address = inet_pton(AF_INET6, ia_na_opts.getfieldval("addr"))
- self.assert_equal(reported_address.address, address)
+ address = ia_na_opts.getfieldval("addr")
+ self.assert_equal(str(reported_address.address), address)
self.assert_equal(reported_address.preferred_time,
ia_na_opts.getfieldval("preflft"))
self.assert_equal(reported_address.valid_time,
@@ -129,13 +133,18 @@ class TestDHCPv6DataPlane(VppTestCase):
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
- prefix_bin = '\00\01\00\02\00\03' + '\00' * 10
- prefix = {'prefix': prefix_bin,
- 'prefix_length': 50,
+
+ prefix = {'prefix': {'address': '1:2:3::', 'len': 50},
'preferred_time': 60,
'valid_time': 120}
- self.vapi.dhcp6_pd_send_client_message(1, self.pg0.sw_if_index,
- T1=20, T2=40, prefixes=[prefix])
+ prefixes = [prefix]
+ self.vapi.dhcp6_pd_send_client_message(
+ msg_type=VppEnum.vl_api_dhcpv6_msg_type_t.DHCPV6_MSG_API_SOLICIT,
+ sw_if_index=self.pg0.sw_if_index,
+ T1=20,
+ T2=40,
+ prefixes=prefixes,
+ n_prefixes=len(prefixes))
rx_list = self.pg0.get_capture(1)
self.assertEqual(len(rx_list), 1)
packet = rx_list[0]
@@ -189,9 +198,10 @@ class TestDHCPv6DataPlane(VppTestCase):
self.assert_equal(ev.T2, 40)
reported_prefix = ev.prefixes[0]
- prefix = inet_pton(AF_INET6, ia_pd_opts.getfieldval("prefix"))
- self.assert_equal(reported_prefix.prefix, prefix)
- self.assert_equal(reported_prefix.prefix_length,
+ prefix = ia_pd_opts.getfieldval("prefix")
+ self.assert_equal(
+ str(reported_prefix.prefix).split('/')[0], prefix)
+ self.assert_equal(int(str(reported_prefix.prefix).split('/')[1]),
ia_pd_opts.getfieldval("plen"))
self.assert_equal(reported_prefix.preferred_time,
ia_pd_opts.getfieldval("preflft"))
@@ -288,7 +298,7 @@ class TestDHCPv6IANAControlPlane(VppTestCase):
self.assertNotEqual(elapsed_time.elapsedtime, 0)
else:
self.assertEqual(elapsed_time.elapsedtime, 0)
- except:
+ except BaseException:
packet.show()
raise
@@ -544,7 +554,7 @@ class TestDHCPv6PDControlPlane(VppTestCase):
self.assertNotEqual(elapsed_time.elapsedtime, 0)
else:
self.assertEqual(elapsed_time.elapsedtime, 0)
- except:
+ except BaseException:
packet.show()
raise
diff --git a/test/vpp_dhcp.py b/test/vpp_dhcp.py
new file mode 100644
index 00000000000..54448810042
--- /dev/null
+++ b/test/vpp_dhcp.py
@@ -0,0 +1,128 @@
+from vpp_object import VppObject
+
+
+class VppDHCPProxy(VppObject):
+
+ def __init__(
+ self,
+ test,
+ dhcp_server,
+ dhcp_src_address,
+ rx_vrf_id=0,
+ server_vrf_id=0,
+ ):
+ self._test = test
+ self._rx_vrf_id = rx_vrf_id
+ self._server_vrf_id = server_vrf_id
+ self._dhcp_server = dhcp_server
+ self._dhcp_src_address = dhcp_src_address
+
+ def set_proxy(
+ self,
+ dhcp_server,
+ dhcp_src_address,
+ rx_vrf_id=0,
+ server_vrf_id=0):
+ if self.query_vpp_config():
+ raise Exception('Vpp config present')
+ self._rx_vrf_id = rx_vrf_id
+ self._server_vrf_id = server_vrf_id
+ self._dhcp_server = dhcp_server
+ self._dhcp_src_address = dhcp_src_address
+
+ def add_vpp_config(self):
+ self._test.vapi.dhcp_proxy_config(
+ rx_vrf_id=self._rx_vrf_id,
+ server_vrf_id=self._server_vrf_id,
+ dhcp_server=self._dhcp_server,
+ dhcp_src_address=self._dhcp_src_address)
+ self._test.registry.register(self, self._test.logger)
+
+ def remove_vpp_config(self):
+ self._test.vapi.dhcp_proxy_config(
+ rx_vrf_id=self._rx_vrf_id,
+ server_vrf_id=self._server_vrf_id,
+ dhcp_server=self._dhcp_server,
+ dhcp_src_address=self._dhcp_src_address,
+ is_add=0)
+
+ def get_vpp_dump(self):
+ dump = self._test.vapi.dhcp_proxy_dump()
+ for entry in dump:
+ if entry.rx_vrf_id == self._rx_vrf_id:
+ return entry
+
+ def query_vpp_config(self):
+ dump = self.get_vpp_dump()
+ return True if dump else False
+
+ def object_id(self):
+ return "dhcp-proxy-%d" % self._rx_vrf_id
+
+
+class VppDHCPClient(VppObject):
+
+ def __init__(
+ self,
+ test,
+ sw_if_index,
+ hostname,
+ id=None,
+ want_dhcp_event=False,
+ set_broadcast_flag=True,
+ dscp=None,
+ pid=None):
+ self._test = test
+ self._sw_if_index = sw_if_index
+ self._hostname = hostname
+ self._id = id
+ self._want_dhcp_event = want_dhcp_event
+ self._set_broadcast_flag = set_broadcast_flag
+ self._dscp = dscp
+ self._pid = pid
+
+ def set_client(
+ self,
+ sw_if_index,
+ hostname,
+ id=None,
+ want_dhcp_event=False,
+ set_broadcast_flag=True,
+ dscp=None,
+ pid=None):
+ if self.query_vpp_config():
+ raise Exception('Vpp config present')
+ self._sw_if_index = sw_if_index
+ self._hostname = hostname
+ self._id = id
+ self._want_dhcp_event = want_dhcp_event
+ self._set_broadcast_flag = set_broadcast_flag
+ self._dscp = dscp
+ self._pid = pid
+
+ def add_vpp_config(self):
+ client = {'sw_if_index': self._sw_if_index, 'hostname': self._hostname,
+ 'id': self._id, 'want_dhcp_event': self._want_dhcp_event,
+ 'set_broadcast_flag': self._set_broadcast_flag,
+ 'dscp': self._dscp, 'pid': self._pid}
+ self._test.vapi.dhcp_client_config(client=client)
+ self._test.registry.register(self, self._test.logger)
+
+ def remove_vpp_config(self):
+ client = client = {
+ 'sw_if_index': self._sw_if_index,
+ 'hostname': self._hostname}
+ self._test.vapi.dhcp_client_config(client=client, is_add=0)
+
+ def get_vpp_dump(self):
+ dump = self._test.vapi.dhcp_client_dump()
+ for entry in dump:
+ if entry.client.sw_if_index == self._sw_if_index:
+ return entry
+
+ def query_vpp_config(self):
+ dump = self.get_vpp_dump()
+ return True if dump else False
+
+ def object_id(self):
+ return "dhcp-client-%s/%d" % (self._hostname, self._sw_if_index)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 13babf28a51..0ba8af1f800 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -50,7 +50,8 @@ defaultmapping = {
'dhcp6_clients_enable_disable': {'enable': 1, },
'dhcp6_pd_client_enable_disable': {'enable': 1, },
'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
- 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
+ 'dhcp6_pd_send_client_message': {'server_index': 0xFFFFFFFF, 'mrc': 1},
+ 'dhcp_client_config': {'is_add': 1, 'client': {'set_broadcast_flag': 1}, },
'dhcp_proxy_config': {'is_add': 1, },
'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
@@ -147,6 +148,8 @@ defaultmapping = {
'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
'want_ip6_ra_events': {'enable_disable': 1, },
'want_l2_macs_events': {'enable_disable': 1, },
+ 'want_dhcp6_reply_events': {'enable_disable': 1, 'pid': os.getpid(), },
+ 'want_dhcp6_pd_reply_events': {'enable_disable': 1, 'pid': os.getpid(), },
}
@@ -409,41 +412,6 @@ class VppPapiProvider(object):
'learn_limit': learn_limit,
'pid': os.getpid(), })
- def want_dhcp6_reply_events(self, enable_disable=1):
- return self.api(self.papi.want_dhcp6_reply_events,
- {'enable_disable': enable_disable,
- 'pid': os.getpid()})
-
- def want_dhcp6_pd_reply_events(self, enable_disable=1):
- return self.api(self.papi.want_dhcp6_pd_reply_events,
- {'enable_disable': enable_disable,
- 'pid': os.getpid()})
-
- def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
- prefixes, server_index=0xFFFFFFFF,
- irt=0, mrt=0, mrc=1, mrd=0, stop=0,
- ):
- return self.api(self.papi.dhcp6_pd_send_client_message,
- {'sw_if_index': sw_if_index,
- 'server_index': server_index,
- 'irt': irt,
- 'mrt': mrt,
- 'mrc': mrc,
- 'mrd': mrd,
- 'stop': stop,
- 'msg_type': msg_type,
- 'T1': T1,
- 'T2': T2,
- 'n_prefixes': len(prefixes),
- 'prefixes': prefixes})
-
- def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
- enable=1):
- return self.api(self.papi.dhcp6_pd_client_enable_disable,
- {'sw_if_index': sw_if_index,
- 'prefix_group': prefix_group,
- 'enable': enable})
-
def ip6_add_del_address_using_prefix(self, sw_if_index, address,
prefix_length, prefix_group,
is_add=1):
@@ -907,66 +875,6 @@ class VppPapiProvider(object):
'udp_checksum': udp_checksum,
})
- def dhcp_proxy_config(self,
- dhcp_server,
- dhcp_src_address,
- rx_table_id=0,
- server_table_id=0,
- is_add=1,
- is_ipv6=0):
- return self.api(
- self.papi.dhcp_proxy_config,
- {
- 'rx_vrf_id': rx_table_id,
- 'server_vrf_id': server_table_id,
- 'is_ipv6': is_ipv6,
- 'is_add': is_add,
- 'dhcp_server': dhcp_server,
- 'dhcp_src_address': dhcp_src_address,
- })
-
- def dhcp_proxy_set_vss(self,
- table_id,
- vss_type=255,
- vpn_ascii_id="",
- oui=0,
- vpn_index=0,
- is_add=1,
- is_ip6=0):
- return self.api(
- self.papi.dhcp_proxy_set_vss,
- {
- 'tbl_id': table_id,
- 'vss_type': vss_type,
- 'vpn_ascii_id': vpn_ascii_id,
- 'oui': oui,
- 'vpn_index': vpn_index,
- 'is_add': is_add,
- 'is_ipv6': is_ip6,
- })
-
- def dhcp_client_config(self,
- sw_if_index,
- hostname,
- client_id='',
- is_add=1,
- set_broadcast_flag=1,
- want_dhcp_events=0,
- dscp=0):
- return self.api(
- self.papi.dhcp_client_config,
- {
- 'is_add': is_add,
- 'client': {
- 'sw_if_index': sw_if_index,
- 'hostname': hostname,
- 'id': client_id,
- 'want_dhcp_event': want_dhcp_events,
- 'set_broadcast_flag': set_broadcast_flag,
- 'dscp': dscp,
- 'pid': os.getpid()}
- })
-
def ip_mroute_add_del(self,
table_id,
prefix,