Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / test_driver / happy / tests / standalone / inet / test_inet_multicast_five_nodes_on_wifi.py
1 #!/usr/bin/env python3
2
3 #
4 #    Copyright (c) 2020 Project CHIP Authors
5 #    Copyright (c) 2016-2017 Nest Labs, Inc.
6 #    All rights reserved.
7 #
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
11 #
12 #        http://www.apache.org/licenses/LICENSE-2.0
13 #
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.
19 #
20
21 ##
22 #    @file
23 #       Calls CHIP Inet Multicast test among sender and receiver nodes.
24 #
25
26 import itertools
27 import os
28 import unittest
29 import set_test_path
30
31 from happy.Utils import *
32 import happy.HappyNodeList
33
34 import ChipStateLoad
35 import ChipStateUnload
36 import ChipUtilities
37 import ChipInetMulticast
38
39
40 class test_chip_inet_multicast_five_nodes_on_wifi(unittest.TestCase):
41     def setUp(self):
42         self.using_lwip = False
43
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"
47         self.tap = None
48
49         self.show_strace = False
50
51         options = ChipStateLoad.option()
52         options["quiet"] = True
53         options["json_file"] = self.topology_file
54
55         setup_network = ChipStateLoad.ChipStateLoad(options)
56         ret = setup_network.run()
57
58     def tearDown(self):
59         """cleaning up"""
60         options = ChipStateUnload.option()
61         options["quiet"] = True
62         options["json_file"] = self.topology_file
63
64         teardown_network = ChipStateUnload.ChipStateUnload(options)
65         teardown_network.run()
66
67     def test_chip_inet_multicast(self):
68         options = happy.HappyNodeList.option()
69         options["quiet"] = True
70
71         # This test runs four (4) separate invocations / runs:
72         #
73         #   1) UDP over IPv6
74         #   2) UDP over IPv4
75         #   3) ICMPv6 over IPv6
76         #   4) ICMPv4 over IPv4
77         #
78         # each with one sender and four receivers. Each receiver
79         # varies in the number of multicast groups it participates in.
80         #
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.
84
85         configuration = {
86             'sender': {
87                 '00-WifiNode-TxFourMulticastAddresses': {
88                     'groups': [
89                         {
90                             'id': 1,
91                             'send': 1,
92                             'receive': 0
93                         },
94                         {
95                             'id': 2,
96                             'send': 2,
97                             'receive': 0
98                         },
99                         {
100                             'id': 3,
101                             'send': 3,
102                             'receive': 0
103                         },
104                         {
105                             'id': 4,
106                             'send': 5,
107                             'receive': 0
108                         },
109                     ],
110                     'tap-ipv4-local-addr': "192.168.1.0"
111                 }
112             },
113             'receivers': {
114                 '01-WifiNode-RxOneMulticastAddress': {
115                     'groups': [
116                          {
117                              'id': 1,
118                              'send': 0,
119                              'receive': 1
120                          }
121                     ],
122                     'tap-ipv4-local-addr': "192.168.1.1"
123                 },
124                 '02-WifiNode-RxTwoMulticastAddresses': {
125                     'groups': [
126                         {
127                             'id': 1,
128                             'send': 0,
129                             'receive': 1
130                         },
131                         {
132                             'id': 2,
133                             'send': 0,
134                             'receive': 2
135                         }
136                     ],
137                     'tap-ipv4-local-addr': "192.168.1.2"
138                 },
139                 '03-WifiNode-RxThreeMulticastAddresses': {
140                     'groups': [
141                         {
142                             'id': 1,
143                             'send': 0,
144                             'receive': 1
145                         },
146                         {
147                             'id': 2,
148                             'send': 0,
149                             'receive': 2
150                         },
151                         {
152                             'id': 3,
153                             'send': 0,
154                             'receive': 3
155                         }
156                     ],
157                     'tap-ipv4-local-addr': "192.168.1.3"
158                 },
159                 '04-WifiNode-RxFourMulticastAddresses': {
160                     'groups': [
161                         {
162                             'id': 1,
163                             'send': 0,
164                             'receive': 1
165                         },
166                         {
167                             'id': 2,
168                             'send': 0,
169                             'receive': 2
170                         },
171                         {
172                             'id': 3,
173                             'send': 0,
174                             'receive': 3
175                         },
176                         {
177                             'id': 4,
178                             'send': 0,
179                             'receive': 5
180                         }
181                     ],
182                     'tap-ipv4-local-addr': "192.168.1.4"
183                 }
184             }
185         }
186
187         # Topology-independent test parameters:
188
189         transports = ["udp", "raw"]
190         networks = ["6", "4"]
191
192         for network in networks:
193             for transport in transports:
194
195                 # Run the test.
196
197                 value, data = self.__run_inet_multicast_test(
198                     configuration, self.interface, network, transport)
199
200                 # Process and report the results.
201
202                 self.__process_result(
203                     configuration, self.interface, network, transport, value, data)
204
205     def __process_result(self, configuration, interface, network, transport, value, data):
206         nodes = len(configuration['sender']) + len(configuration['receivers'])
207
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))
210
211         if value:
212             print("PASSED")
213         else:
214             print("FAILED")
215             raise ValueError("Chip Inet Multicast Test Failed")
216
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.
223         """
224
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
233
234         chip_inet_multicast = ChipInetMulticast.ChipInetMulticast(options)
235         ret = chip_inet_multicast.run()
236
237         value = ret.Value()
238         data = ret.Data()
239
240         return value, data
241
242
243 if __name__ == "__main__":
244     ChipUtilities.run_unittest()