Skip to content

Commit 4914137

Browse files
tymoteuszblochmobicaSeppo Takalo
authored andcommitted
Multihoming initial release
Added Multihoming feature to LWIP (ability to use more than one network interfaces) for increasing networking reliability. This involves: LWIP interface LWIP IP routing DNS storage Sockets (bind to interface name possibility) possibility to add non default network interface cellular middleware modifications if cellular connection is used
1 parent 400fd82 commit 4914137

File tree

81 files changed

+2402
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2402
-209
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#include "mbed_interface.h"
20+
#include "netsocket/nsapi_types.h"
21+
#include "cellular_driver_l3ip.h"
22+
23+
Cellular_driver_L3IP::Cellular_driver_L3IP()
24+
{
25+
}
26+
27+
28+
bool Cellular_driver_L3IP::link_out(net_stack_mem_buf_t *buf)
29+
{
30+
31+
return true;
32+
}
33+
34+
35+
bool Cellular_driver_L3IP::power_up()
36+
{
37+
38+
return true;
39+
}
40+
41+
uint32_t Cellular_driver_L3IP::get_mtu_size() const
42+
{
43+
return 0;
44+
}
45+
46+
uint32_t Cellular_driver_L3IP::get_align_preference() const
47+
{
48+
return 0;
49+
}
50+
51+
void Cellular_driver_L3IP::get_ifname(char *name, uint8_t size) const
52+
{
53+
54+
}
55+
56+
57+
58+
void Cellular_driver_L3IP::set_link_input_cb(l3ip_link_input_cb_t input_cb)
59+
{
60+
l3ip_link_input_cb = input_cb;
61+
}
62+
63+
void Cellular_driver_L3IP::set_link_state_cb(l3ip_link_state_change_cb_t state_cb)
64+
{
65+
l3ip_link_state_cb = state_cb;
66+
}
67+
68+
void Cellular_driver_L3IP::add_ipv4_multicast_group(const char *address)
69+
{
70+
71+
}
72+
73+
void Cellular_driver_L3IP::add_ipv6_multicast_group(const char *address)
74+
{
75+
76+
}
77+
78+
void Cellular_driver_L3IP::remove_ipv4_multicast_group(const char *address)
79+
{
80+
81+
}
82+
83+
void Cellular_driver_L3IP::remove_ipv6_multicast_group(const char *address)
84+
{
85+
86+
}
87+
88+
void Cellular_driver_L3IP::set_all_multicast(bool all)
89+
{
90+
91+
}
92+
93+
void Cellular_driver_L3IP::power_down()
94+
{
95+
96+
}
97+
98+
void Cellular_driver_L3IP::set_memory_manager(NetStackMemoryManager &mem_mngr)
99+
{
100+
memory_manager = &mem_mngr;
101+
}
102+
103+
104+
Cellular_driver_L3IP &Cellular_driver_L3IP::get_instance()
105+
{
106+
static Cellular_driver_L3IP l3ip_test_driver;
107+
return l3ip_test_driver;
108+
}
109+
110+
// Weak so a module can override
111+
MBED_WEAK L3IP &L3IP::get_default_instance()
112+
{
113+
return Cellular_driver_L3IP::get_instance();
114+
}
115+
116+
/**
117+
* @}
118+
*/
119+
120+
/* --------------------------------- End Of File ------------------------------ */
121+
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef CELLULAR_DRIVER_L3IP_H_
19+
#define CELLULAR_DRIVER_L3IP_H_
20+
21+
#include "L3IP.h"
22+
23+
24+
class Cellular_driver_L3IP : public L3IP {
25+
public:
26+
Cellular_driver_L3IP();
27+
28+
static Cellular_driver_L3IP &get_instance();
29+
30+
/**
31+
* Return maximum transmission unit
32+
*
33+
* @return MTU in bytes
34+
*/
35+
virtual uint32_t get_mtu_size() const;
36+
37+
/**
38+
* Gets memory buffer alignment preference
39+
*
40+
* Gets preferred memory buffer alignment of the cellular device.
41+
* @return Memory alignment requirement in bytes
42+
*/
43+
virtual uint32_t get_align_preference() const;
44+
45+
/**
46+
* Return interface name
47+
*
48+
* @param name Pointer to where the name should be written
49+
* @param size Maximum number of characters to copy
50+
*/
51+
virtual void get_ifname(char *name, uint8_t size) const;
52+
53+
/**
54+
* Sends the packet over the link
55+
*
56+
* That cannot be called from an interrupt context.
57+
*
58+
* @param buf Packet to be sent
59+
* @return True if the packet was sent, false otherwise
60+
*/
61+
virtual bool link_out(net_stack_mem_buf_t *buf);
62+
63+
/**
64+
* Initializes the hardware
65+
*
66+
* @return True on success, False in case of an error.
67+
*/
68+
virtual bool power_up();
69+
70+
/**
71+
* Deinitializes the hardware
72+
*
73+
*/
74+
virtual void power_down();
75+
76+
/**
77+
* Sets a callback that needs to be called for packets received for that interface
78+
*
79+
* @param input_cb Function to be register as a callback
80+
*/
81+
virtual void set_link_input_cb(l3ip_link_input_cb_t input_cb);
82+
83+
/**
84+
* Sets a callback that needs to be called on link status changes for given interface
85+
*
86+
* @param state_cb Function to be register as a callback
87+
*/
88+
virtual void set_link_state_cb(l3ip_link_state_change_cb_t state_cb);
89+
90+
/** Add device to an IP4 multicast group
91+
*
92+
* @param address an IP4 multicast group address
93+
*/
94+
virtual void add_ipv4_multicast_group(const char *address);
95+
96+
/** Add device to an IP6 multicast group
97+
*
98+
* @param address an IP6 multicast group address
99+
*/
100+
virtual void add_ipv6_multicast_group(const char *address);
101+
102+
/** Remove device from an IPV4 multicast group
103+
*
104+
* @param address An IPV4 multicast group address
105+
*/
106+
virtual void remove_ipv4_multicast_group(const char *address);
107+
108+
/** Remove device from an IPV6 multicast group
109+
*
110+
* @param address An IPV6 multicast group address
111+
*/
112+
virtual void remove_ipv6_multicast_group(const char *address);
113+
114+
/** Request reception of all multicast packets
115+
*
116+
* @param all True to receive all multicasts
117+
* False to receive only multicasts addressed to specified groups
118+
*/
119+
virtual void set_all_multicast(bool all);
120+
121+
/** Sets memory manager that is used to handle memory buffers
122+
*
123+
* @param mem_mngr Pointer to memory manager
124+
*/
125+
virtual void set_memory_manager(NetStackMemoryManager &mem_mngr);
126+
127+
private:
128+
129+
l3ip_link_input_cb_t l3ip_link_input_cb; /**< Callback for incoming data */
130+
l3ip_link_state_change_cb_t l3ip_link_state_cb; /**< Link state change callback */
131+
NetStackMemoryManager *memory_manager; /**< Memory manager */
132+
133+
};
134+
135+
#endif /* CELLULAR_DRIVER_L3IP_H_ */

TESTS/network/l3ip/main.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2018, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#include "mbed.h"
20+
#include "greentea-client/test_env.h"
21+
#include "unity/unity.h"
22+
#include "utest.h"
23+
#include "utest/utest_stack_trace.h"
24+
#include "L3IPInterface.h"
25+
26+
using namespace utest::v1;
27+
28+
namespace {
29+
NetworkInterface *l3interface;
30+
}
31+
32+
void L3IP_START()
33+
{
34+
printf("MBED: L3IP_START\n");
35+
}
36+
37+
void L3IP_STOP()
38+
{
39+
printf("MBED: L3IP_STOP\n");
40+
}
41+
42+
43+
static void _ifup()
44+
{
45+
printf("MBED: ifdown\n");
46+
}
47+
48+
static void _ifdown()
49+
{
50+
printf("MBED: ifdown\n");
51+
}
52+
53+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
54+
int fetch_stats()
55+
{
56+
return SocketStats::mbed_stats_socket_get_each(&udp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
57+
}
58+
#endif
59+
60+
// Test setup
61+
utest::v1::status_t greentea_setup(const size_t number_of_cases)
62+
{
63+
GREENTEA_SETUP(480, "default_auto");
64+
_ifup();
65+
return greentea_test_setup_handler(number_of_cases);
66+
}
67+
68+
void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
69+
{
70+
_ifdown();
71+
return greentea_test_teardown_handler(passed, failed, failure);
72+
}
73+
74+
Case cases[] = {
75+
Case("L3IP_START", L3IP_START),
76+
Case("L3IP_STOP", L3IP_STOP),
77+
};
78+
79+
Specification specification(greentea_setup, cases, greentea_teardown, greentea_continue_handlers);
80+
81+
int main()
82+
{
83+
return !Harness::run(specification);
84+
}

0 commit comments

Comments
 (0)