2 Copyright (c) 2015 SONATA-NFV
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
17 Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18 nor the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
22 This work has been performed in the framework of the SONATA project,
23 funded by the European Commission under Grant number 671517 through
24 the Horizon 2020 and 5G-PPP programmes. The authors would like to
25 acknowledge the contributions of their colleagues of the SONATA
26 partner consortium (www.sonata-nfv.eu).
34 from emuvim
.test
.base
import SimpleTestTopology
35 from emuvim
.api
.sonata
import SonataDummyGatekeeperEndpoint
36 from emuvim
.api
.sonata
.dummygatekeeper
import initialize_GK
, parse_interface
38 from ipaddress
import ip_network
40 PACKAGE_PATH
= "misc/sonata-demo-service.son"
43 class testSonataDummyGatekeeper(SimpleTestTopology
):
45 # @unittest.skip("disabled")
46 def test_GK_Api_start_service(self
):
48 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0, enable_learning
=True)
50 self
.net
.addLink(self
.dc
[0], self
.h
[0])
51 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
52 self
.net
.addLink(self
.h
[1], self
.dc
[1])
53 # connect dummy GK to data centers
54 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
55 sdkg1
.connectDatacenter(self
.dc
[0])
56 sdkg1
.connectDatacenter(self
.dc
[1])
57 # run the dummy gatekeeper (in another thread, don't block)
59 # start Mininet network
63 print "starting tests"
65 files
= {"package": open(PACKAGE_PATH
, "rb")}
66 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
67 self
.assertEqual(r
.status_code
, 201)
68 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
71 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
72 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
73 self
.assertEqual(r2
.status_code
, 201)
75 # give the emulator some time to instantiate everything
78 # check get request APIs
79 r3
= requests
.get("http://127.0.0.1:5000/packages")
80 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
81 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
82 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
84 # check number of running nodes
85 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
86 self
.assertTrue(len(self
.net
.hosts
) == 5)
87 self
.assertTrue(len(self
.net
.switches
) == 2)
88 # check compute list result
89 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
90 # check connectivity by using ping
93 # check E-Line connection, by checking the IP addresses
94 for link
in self
.net
.deployed_elines
:
95 vnf_src
, intf_src
, vnf_sap_docker_name
= parse_interface(link
['connection_points_reference'][0])
96 print vnf_src
, intf_src
97 src
= self
.net
.getNodeByName(vnf_src
)
100 network_list
= src
.getNetworkStatus()
101 src_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == intf_src
][0]
102 src_mask
= [intf
['netmask'] for intf
in network_list
if intf
['intf_name'] == intf_src
][0]
104 vnf_dst
, intf_dst
, vnf_sap_docker_name
= parse_interface(link
['connection_points_reference'][1])
105 dst
= self
.net
.getNodeByName(vnf_dst
)
108 network_list
= dst
.getNetworkStatus()
109 dst_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == intf_dst
][0]
110 dst_mask
= [intf
['netmask'] for intf
in network_list
if intf
['intf_name'] == intf_dst
][0]
112 print "src = {0}:{1} ip={2} ".format(vnf_src
, intf_src
, src_ip
, src_mask
)
113 print "dst = {0}:{1} ip={2} ".format(vnf_dst
, intf_dst
, dst_ip
, dst_mask
)
115 # check if the E-Line IP's are in the same subnet
116 ret
= ip_network(u
'{0}'.format(src_ip
, src_mask
), strict
=False)\
117 .compare_networks(ip_network(u
'{0}'.format(dst_ip
, dst_mask
),strict
=False))
118 self
.assertTrue(ret
== 0)
121 for vnf
in self
.dc
[0].listCompute():
122 # check E LAN connection
123 network_list
= vnf
.getNetworkStatus()
124 mgmt_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == 'mgmt']
125 self
.assertTrue(len(mgmt_ip
) > 0)
126 ip_address
= mgmt_ip
[0]
127 ELAN_list
.append(ip_address
)
130 # check ELAN connection by ping over the mgmt network (needs to be configured as ELAN in the test service)
131 for vnf
in self
.dc
[0].listCompute():
132 network_list
= vnf
.getNetworkStatus()
133 mgmt_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == 'mgmt']
134 self
.assertTrue(len(mgmt_ip
) > 0)
135 ip_address
= mgmt_ip
[0]
138 test_ip_list
= list(ELAN_list
)
139 test_ip_list
.remove(ip_address
)
140 for ip
in test_ip_list
:
141 # only take ip address, without netmask
142 p
= self
.net
.ping([vnf
],manualdestip
=ip
.split('/')[0])
144 self
.assertTrue(p
<= 0.0)
146 # stop Mininet network
150 #@unittest.skip("disabled")
151 def test_GK_Api_stop_service(self
):
153 self
.createNet(ndatacenter
=2, nhosts
=2)
155 self
.net
.addLink(self
.dc
[0], self
.h
[0])
156 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
157 self
.net
.addLink(self
.h
[1], self
.dc
[1])
158 # connect dummy GK to data centers
159 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
160 sdkg1
.connectDatacenter(self
.dc
[0])
161 sdkg1
.connectDatacenter(self
.dc
[1])
162 # run the dummy gatekeeper (in another thread, don't block)
164 # start Mininet network
168 print "starting tests"
170 files
= {"package": open(PACKAGE_PATH
, "rb")}
171 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
172 self
.assertEqual(r
.status_code
, 201)
173 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
175 # instantiate service
176 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
177 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
178 self
.assertEqual(r2
.status_code
, 201)
180 # give the emulator some time to instantiate everything
183 # check get request APIs
184 r3
= requests
.get("http://127.0.0.1:5000/packages")
185 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
186 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
187 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
189 # check number of running nodes
190 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
191 self
.assertTrue(len(self
.net
.hosts
) == 5)
192 self
.assertTrue(len(self
.net
.switches
) == 2)
193 # check compute list result
194 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
197 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
198 self
.assertTrue(service_instance_uuid
is not None)
199 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
201 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
202 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
204 # stop Mininet network
209 #@unittest.skip("disabled")
210 def test_GK_stress_service(self
):
212 self
.createNet(ndatacenter
=2, nhosts
=2)
213 # connect dummy GK to data centers
214 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
215 sdkg1
.connectDatacenter(self
.dc
[0])
216 sdkg1
.connectDatacenter(self
.dc
[1])
217 # run the dummy gatekeeper (in another thread, don't block)
219 # start Mininet network
223 print "starting tests"
225 files
= {"package": open("misc/sonata-stress-service.son", "rb")}
226 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
227 self
.assertEqual(r
.status_code
, 201)
228 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
230 # instantiate service
231 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
232 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
233 self
.assertEqual(r2
.status_code
, 201)
235 # give the emulator some time to instantiate everything
238 # check get request APIs
239 r3
= requests
.get("http://127.0.0.1:5000/packages")
240 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
241 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
242 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
245 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
246 self
.assertTrue(service_instance_uuid
is not None)
247 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
249 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
250 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
252 # stop Mininet network