mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #11279 from cy-jayasankar/pr/added-ipv6-link-local-address-api
Add API to get ipv6 link local addresspull/11810/head
commit
f27aec3377
|
@ -155,10 +155,14 @@ Test `NetworkInterface::get_connection_status()`.
|
||||||
1. Check that `get_connection_status()` returns status `NSAPI_STATUS_DISCONNECTED`.
|
1. Check that `get_connection_status()` returns status `NSAPI_STATUS_DISCONNECTED`.
|
||||||
2. Connect interface.
|
2. Connect interface.
|
||||||
3. Poll the `get_connection_status()` until it returns status `NSAPI_STATUS_GLOBAL_UP`.
|
3. Poll the `get_connection_status()` until it returns status `NSAPI_STATUS_GLOBAL_UP`.
|
||||||
4. Disconnect interface.
|
4. (IPv6 only) Get IPv6 link local address using `get_ipv6_link_local_address` API.
|
||||||
5. Check that `get_connection_status()` returns status `NSAPI_STATUS_DISCONNECTED`.
|
5. (IPv6 only) Check that `get_ipv6_link_local_address` returned status `NSAPI_ERROR_OK`.
|
||||||
6. Repeat connect and disconnect steps 2 to 5 four times.
|
6. (IPv6 only) Check that the IP address associated with the Socket Address is not `NULL`.
|
||||||
|
7. (IPv6 only) Check that the IP version of the IPv6 link local address is `NSAPI_IPv6`.
|
||||||
|
8. Disconnect interface.
|
||||||
|
9. Check that `get_connection_status()` returns status `NSAPI_STATUS_DISCONNECTED`.
|
||||||
|
10. Repeat connect and disconnect steps 2 to 5 four times.
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
|
|
||||||
`Connect()` and `disconnect()` calls return `NSAPI_ERROR_OK`. The right status is returned by `get_connection_status()`.
|
`Connect()`, `get_ipv6_link_local_address` and `disconnect()` calls return `NSAPI_ERROR_OK`. The right status is returned by `get_connection_status()`. And the right IPv6 link local address is returned by `get_ipv6_link_local_address`.
|
||||||
|
|
|
@ -156,6 +156,15 @@ void NETWORKINTERFACE_STATUS_GET()
|
||||||
ThisThread::sleep_for(500);
|
ThisThread::sleep_for(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MBED_CONF_LWIP_IPV6_ENABLED
|
||||||
|
/* if IPv6 is enabled, validate ipv6_link_local_address API*/
|
||||||
|
SocketAddress ipv6_link_local_address = NULL;
|
||||||
|
err = net->get_ipv6_link_local_address(&ipv6_link_local_address);
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||||
|
TEST_ASSERT_NOT_NULL(ipv6_link_local_address.get_ip_address());
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_IPv6, ipv6_link_local_address.get_ip_version());
|
||||||
|
#endif
|
||||||
|
|
||||||
err = net->disconnect();
|
err = net->disconnect();
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ public:
|
||||||
MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t());
|
MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t());
|
||||||
MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen));
|
MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen));
|
||||||
MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen));
|
MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen));
|
||||||
|
MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address));
|
||||||
MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen));
|
MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen));
|
||||||
MOCK_METHOD2(get_gateway, char *(char *buf, nsapi_size_t buflen));
|
MOCK_METHOD2(get_gateway, char *(char *buf, nsapi_size_t buflen));
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,6 +31,11 @@ const char *NetworkInterface::get_ip_address()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
const char *NetworkInterface::get_netmask()
|
const char *NetworkInterface::get_netmask()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -93,6 +93,12 @@ const char *NetworkStack::get_ip_address()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
const char *NetworkStack::get_ip_address_if(const char *interface_name)
|
const char *NetworkStack::get_ip_address_if(const char *interface_name)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
|
|
||||||
#include "LWIPStack.h"
|
#include "LWIPStack.h"
|
||||||
|
#include "lwip_tools.h"
|
||||||
|
|
||||||
LWIP::Interface *LWIP::Interface::list;
|
LWIP::Interface *LWIP::Interface::list;
|
||||||
|
|
||||||
|
@ -271,6 +272,30 @@ char *LWIP::Interface::get_interface_name(char *buf)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t LWIP::Interface::get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
#if LWIP_IPV6
|
||||||
|
const ip_addr_t *addr = LWIP::get_ipv6_link_local_addr(&netif);
|
||||||
|
nsapi_addr_t out;
|
||||||
|
bool ret;
|
||||||
|
|
||||||
|
if (!addr) {
|
||||||
|
return NSAPI_ERROR_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = convert_lwip_addr_to_mbed(&out, addr);
|
||||||
|
if (ret != true) {
|
||||||
|
return NSAPI_ERROR_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
address->set_addr(out);
|
||||||
|
|
||||||
|
return NSAPI_ERROR_OK;
|
||||||
|
#else
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
|
char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
|
||||||
{
|
{
|
||||||
const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif);
|
const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif);
|
||||||
|
|
|
@ -101,6 +101,13 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
|
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
|
||||||
|
|
||||||
|
/** Get the IPv6 link local address in SocketAddress representation
|
||||||
|
*
|
||||||
|
* @address SocketAddress representation of the link local IPv6 address
|
||||||
|
* @return NSAPI_ERROR_OK on success, or error code
|
||||||
|
*/
|
||||||
|
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
|
||||||
|
|
||||||
/** Copies IP address of the name based network interface to user supplied buffer
|
/** Copies IP address of the name based network interface to user supplied buffer
|
||||||
*
|
*
|
||||||
* @param buf buffer to which IP address will be copied as "W:X:Y:Z"
|
* @param buf buffer to which IP address will be copied as "W:X:Y:Z"
|
||||||
|
@ -571,6 +578,7 @@ private:
|
||||||
static const ip_addr_t *get_ip_addr(bool any_addr, const struct netif *netif);
|
static const ip_addr_t *get_ip_addr(bool any_addr, const struct netif *netif);
|
||||||
static const ip_addr_t *get_ipv4_addr(const struct netif *netif);
|
static const ip_addr_t *get_ipv4_addr(const struct netif *netif);
|
||||||
static const ip_addr_t *get_ipv6_addr(const struct netif *netif);
|
static const ip_addr_t *get_ipv6_addr(const struct netif *netif);
|
||||||
|
static const ip_addr_t *get_ipv6_link_local_addr(const struct netif *netif);
|
||||||
|
|
||||||
static void add_dns_addr(struct netif *lwip_netif, const char *interface_name);
|
static void add_dns_addr(struct netif *lwip_netif, const char *interface_name);
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,23 @@ const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ip_addr_t *LWIP::get_ipv6_link_local_addr(const struct netif *netif)
|
||||||
|
{
|
||||||
|
#if LWIP_IPV6
|
||||||
|
if (!netif_is_up(netif)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
|
||||||
|
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
|
||||||
|
ip6_addr_islinklocal(netif_ip6_addr(netif, i))) {
|
||||||
|
return netif_ip_addr6(netif, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
|
const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
|
||||||
{
|
{
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
|
|
|
@ -95,6 +95,15 @@ const char *EMACInterface::get_ip_address()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t EMACInterface::get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
if (_interface) {
|
||||||
|
return _interface->get_ipv6_link_local_address(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NSAPI_ERROR_NO_CONNECTION;
|
||||||
|
}
|
||||||
|
|
||||||
const char *EMACInterface::get_netmask()
|
const char *EMACInterface::get_netmask()
|
||||||
{
|
{
|
||||||
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
|
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
|
||||||
|
|
|
@ -103,6 +103,13 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const char *get_ip_address();
|
virtual const char *get_ip_address();
|
||||||
|
|
||||||
|
/** Get the IPv6 link local address
|
||||||
|
*
|
||||||
|
* @address SocketAddress representation of the link local IPv6 address
|
||||||
|
* @return 0 on success, negative error code on failure
|
||||||
|
*/
|
||||||
|
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
|
||||||
|
|
||||||
/** Get the local network mask
|
/** Get the local network mask
|
||||||
*
|
*
|
||||||
* @return Null-terminated representation of the local network mask
|
* @return Null-terminated representation of the local network mask
|
||||||
|
|
|
@ -37,6 +37,11 @@ const char *NetworkInterface::get_ip_address()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
const char *NetworkInterface::get_netmask()
|
const char *NetworkInterface::get_netmask()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -107,6 +107,13 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const char *get_ip_address();
|
virtual const char *get_ip_address();
|
||||||
|
|
||||||
|
/** Get the IPv6 link local address
|
||||||
|
*
|
||||||
|
* @address SocketAddress representation of the link local IPv6 address
|
||||||
|
* @return NSAPI_ERROR_OK on success, negative error code on failure
|
||||||
|
*/
|
||||||
|
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
|
||||||
|
|
||||||
/** Get the local network mask.
|
/** Get the local network mask.
|
||||||
*
|
*
|
||||||
* @return Null-terminated representation of the local network mask
|
* @return Null-terminated representation of the local network mask
|
||||||
|
|
|
@ -29,6 +29,11 @@ const char *NetworkStack::get_ip_address()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
const char *NetworkStack::get_ip_address_if(const char *interface_name)
|
const char *NetworkStack::get_ip_address_if(const char *interface_name)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -48,6 +48,13 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const char *get_ip_address();
|
virtual const char *get_ip_address();
|
||||||
|
|
||||||
|
/** Get the IPv6 link local address
|
||||||
|
*
|
||||||
|
* @address SocketAddress representation of the link local IPv6 address
|
||||||
|
* @return NSAPI_ERROR_OK on success, negative error code on failure
|
||||||
|
*/
|
||||||
|
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
|
||||||
|
|
||||||
/** Get the local IP address on interface name
|
/** Get the local IP address on interface name
|
||||||
*
|
*
|
||||||
* @param interface_name Network interface_name
|
* @param interface_name Network interface_name
|
||||||
|
|
|
@ -119,6 +119,16 @@ public:
|
||||||
|
|
||||||
virtual char *get_ip_address(char *buf, nsapi_size_t buflen) = 0;
|
virtual char *get_ip_address(char *buf, nsapi_size_t buflen) = 0;
|
||||||
|
|
||||||
|
/** Copies IPv6 link local address of the network interface in SocketAddress format
|
||||||
|
*
|
||||||
|
* @address SocketAddress representation of the link local IPv6 address
|
||||||
|
* @return NSAPI_ERROR_OK on success, negative error code on failure
|
||||||
|
*/
|
||||||
|
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
/** Copies IP address of the network interface to user supplied buffer
|
/** Copies IP address of the network interface to user supplied buffer
|
||||||
*
|
*
|
||||||
* @param buf buffer to which IP address will be copied as "W:X:Y:Z"
|
* @param buf buffer to which IP address will be copied as "W:X:Y:Z"
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue