4 # Copyright (c) 2020 Project CHIP Authors
5 # Copyright (c) 2016-2017 Nest Labs, Inc.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
23 # Calls CHIP Inet Multicast test among sender and receiver nodes.
31 from happy.Utils import *
32 import happy.HappyNodeList
35 import ChipStateUnload
37 import ChipInetMulticast
40 class test_chip_inet_multicast_five_nodes_on_wifi(unittest.TestCase):
42 self.using_lwip = False
44 self.topology_file = os.path.join(os.path.dirname(os.path.realpath(
45 __file__)), "../../../topologies/standalone/five_nodes_on_wifi.json")
46 self.interface = "wlan0"
49 self.show_strace = False
51 options = ChipStateLoad.option()
52 options["quiet"] = True
53 options["json_file"] = self.topology_file
55 setup_network = ChipStateLoad.ChipStateLoad(options)
56 ret = setup_network.run()
60 options = ChipStateUnload.option()
61 options["quiet"] = True
62 options["json_file"] = self.topology_file
64 teardown_network = ChipStateUnload.ChipStateUnload(options)
65 teardown_network.run()
67 def test_chip_inet_multicast(self):
68 options = happy.HappyNodeList.option()
69 options["quiet"] = True
71 # This test runs four (4) separate invocations / runs:
78 # each with one sender and four receivers. Each receiver
79 # varies in the number of multicast groups it participates in.
81 # The ipv4-local-addr configuration key-value pairs are only
82 # used for LwIP hosted OS topologies where a network tap
83 # device is configured.
87 '00-WifiNode-TxFourMulticastAddresses': {
110 'tap-ipv4-local-addr': "192.168.1.0"
114 '01-WifiNode-RxOneMulticastAddress': {
122 'tap-ipv4-local-addr': "192.168.1.1"
124 '02-WifiNode-RxTwoMulticastAddresses': {
137 'tap-ipv4-local-addr': "192.168.1.2"
139 '03-WifiNode-RxThreeMulticastAddresses': {
157 'tap-ipv4-local-addr': "192.168.1.3"
159 '04-WifiNode-RxFourMulticastAddresses': {
182 'tap-ipv4-local-addr': "192.168.1.4"
187 # Topology-independent test parameters:
189 transports = ["udp", "raw"]
190 networks = ["6", "4"]
192 for network in networks:
193 for transport in transports:
197 value, data = self.__run_inet_multicast_test(
198 configuration, self.interface, network, transport)
200 # Process and report the results.
202 self.__process_result(
203 configuration, self.interface, network, transport, value, data)
205 def __process_result(self, configuration, interface, network, transport, value, data):
206 nodes = len(configuration['sender']) + len(configuration['receivers'])
208 print("Inet multicast test using %sIPv%s w/ device interface: %s (w/%s LwIP) with %u nodes:" % ("UDP/" if transport ==
209 "udp" else "", network, "<none>" if interface == None else interface, "" if self.using_lwip else "o", nodes))
215 raise ValueError("Chip Inet Multicast Test Failed")
217 def __run_inet_multicast_test(self, configuration, interface, network, transport):
218 """ Run Inet Multicast test on configured topology
219 The default interval is 1 s (1000 ms). This is a good
220 default for interactive test operation; however, for
221 automated continuous integration, we prefer it to run much
222 faster. Consequently, use 250 ms as the interval.
225 options = ChipInetMulticast.option()
226 options["quiet"] = False
227 options["configuration"] = configuration
228 options["interface"] = interface
229 options["ipversion"] = network
230 options["transport"] = transport
231 options["interval"] = str(250)
232 options["tap"] = self.tap
234 chip_inet_multicast = ChipInetMulticast.ChipInetMulticast(options)
235 ret = chip_inet_multicast.run()
243 if __name__ == "__main__":
244 ChipUtilities.run_unittest()