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)
60 # start Mininet network
64 print "starting tests"
66 files
= {"package": open(PACKAGE_PATH
, "rb")}
67 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
68 self
.assertEqual(r
.status_code
, 201)
69 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
72 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
73 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
74 self
.assertEqual(r2
.status_code
, 201)
76 # give the emulator some time to instantiate everything
79 # check get request APIs
80 r3
= requests
.get("http://127.0.0.1:5000/packages")
81 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
82 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
83 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
85 # check number of running nodes
86 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
87 self
.assertTrue(len(self
.net
.hosts
) == 5)
88 self
.assertTrue(len(self
.net
.switches
) == 2)
89 # check compute list result
90 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
91 # check connectivity by using ping
94 # check E-Line connection, by checking the IP addresses
95 for link
in self
.net
.deployed_elines
:
96 vnf_src
, intf_src
, vnf_sap_docker_name
= parse_interface(link
['connection_points_reference'][0])
97 print vnf_src
, intf_src
98 src
= self
.net
.getNodeByName(vnf_src
)
101 network_list
= src
.getNetworkStatus()
102 src_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == intf_src
][0]
103 src_mask
= [intf
['netmask'] for intf
in network_list
if intf
['intf_name'] == intf_src
][0]
105 vnf_dst
, intf_dst
, vnf_sap_docker_name
= parse_interface(link
['connection_points_reference'][1])
106 dst
= self
.net
.getNodeByName(vnf_dst
)
109 network_list
= dst
.getNetworkStatus()
110 dst_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == intf_dst
][0]
111 dst_mask
= [intf
['netmask'] for intf
in network_list
if intf
['intf_name'] == intf_dst
][0]
113 print "src = {0}:{1} ip={2} ".format(vnf_src
, intf_src
, src_ip
, src_mask
)
114 print "dst = {0}:{1} ip={2} ".format(vnf_dst
, intf_dst
, dst_ip
, dst_mask
)
116 # check if the E-Line IP's are in the same subnet
117 ret
= ip_network(u
'{0}'.format(src_ip
, src_mask
), strict
=False)\
118 .compare_networks(ip_network(u
'{0}'.format(dst_ip
, dst_mask
),strict
=False))
119 self
.assertTrue(ret
== 0)
122 for vnf
in self
.dc
[0].listCompute():
123 # check E LAN connection
124 network_list
= vnf
.getNetworkStatus()
125 mgmt_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == 'mgmt']
126 self
.assertTrue(len(mgmt_ip
) > 0)
127 ip_address
= mgmt_ip
[0]
128 ELAN_list
.append(ip_address
)
131 # check ELAN connection by ping over the mgmt network (needs to be configured as ELAN in the test service)
132 for vnf
in self
.dc
[0].listCompute():
133 network_list
= vnf
.getNetworkStatus()
134 mgmt_ip
= [intf
['ip'] for intf
in network_list
if intf
['intf_name'] == 'mgmt']
135 self
.assertTrue(len(mgmt_ip
) > 0)
136 ip_address
= mgmt_ip
[0]
139 test_ip_list
= list(ELAN_list
)
140 test_ip_list
.remove(ip_address
)
141 for ip
in test_ip_list
:
142 # only take ip address, without netmask
143 p
= self
.net
.ping([vnf
],manualdestip
=ip
.split('/')[0])
145 self
.assertTrue(p
<= 0.0)
147 # stop Mininet network
151 #@unittest.skip("disabled")
152 def test_GK_Api_stop_service(self
):
154 self
.createNet(ndatacenter
=2, nhosts
=2)
156 self
.net
.addLink(self
.dc
[0], self
.h
[0])
157 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
158 self
.net
.addLink(self
.h
[1], self
.dc
[1])
159 # connect dummy GK to data centers
160 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
161 sdkg1
.connectDatacenter(self
.dc
[0])
162 sdkg1
.connectDatacenter(self
.dc
[1])
163 # run the dummy gatekeeper (in another thread, don't block)
166 # start Mininet network
170 print "starting tests"
172 files
= {"package": open(PACKAGE_PATH
, "rb")}
173 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
174 self
.assertEqual(r
.status_code
, 201)
175 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
177 # instantiate service
178 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
179 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
180 self
.assertEqual(r2
.status_code
, 201)
182 # give the emulator some time to instantiate everything
185 # check get request APIs
186 r3
= requests
.get("http://127.0.0.1:5000/packages")
187 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
188 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
189 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
191 # check number of running nodes
192 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
193 self
.assertTrue(len(self
.net
.hosts
) == 5)
194 self
.assertTrue(len(self
.net
.switches
) == 2)
195 # check compute list result
196 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
199 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
200 self
.assertTrue(service_instance_uuid
is not None)
201 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
203 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
204 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
206 # stop Mininet network
211 #@unittest.skip("disabled")
212 def test_GK_stress_service(self
):
214 self
.createNet(ndatacenter
=2, nhosts
=2)
215 # connect dummy GK to data centers
216 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
217 sdkg1
.connectDatacenter(self
.dc
[0])
218 sdkg1
.connectDatacenter(self
.dc
[1])
219 # run the dummy gatekeeper (in another thread, don't block)
222 # start Mininet network
226 print "starting tests"
228 files
= {"package": open("misc/sonata-stress-service.son", "rb")}
229 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
230 self
.assertEqual(r
.status_code
, 201)
231 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
233 # instantiate service
234 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
235 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
236 self
.assertEqual(r2
.status_code
, 201)
238 # give the emulator some time to instantiate everything
241 # check get request APIs
242 r3
= requests
.get("http://127.0.0.1:5000/packages")
243 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
244 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
245 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
248 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
249 self
.assertTrue(service_instance_uuid
is not None)
250 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
252 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
253 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
255 # stop Mininet network