1 # Copyright (c) 2015 SONATA-NFV and Paderborn University
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # Neither the name of the SONATA-NFV, Paderborn University
17 # nor the names of its contributors may be used to endorse or promote
18 # products derived from this software without specific prior written
21 # This work has been performed in the framework of the SONATA project,
22 # funded by the European Commission under Grant number 671517 through
23 # the Horizon 2020 and 5G-PPP programmes. The authors would like to
24 # acknowledge the contributions of their colleagues of the SONATA
25 # partner consortium (www.sonata-nfv.eu).
30 from emuvim
.test
.base
import SimpleTestTopology
31 from emuvim
.api
.sonata
import SonataDummyGatekeeperEndpoint
32 from emuvim
.api
.sonata
.dummygatekeeper
import initialize_GK
, parse_interface
33 from ipaddress
import ip_network
35 PACKAGE_PATH
= "misc/sonata-demo-service.son"
38 class testSonataDummyGatekeeper(SimpleTestTopology
):
40 # @unittest.skip("disabled")
41 def test_GK_Api_start_service(self
):
43 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2,
44 ndockers
=0, enable_learning
=True)
46 self
.net
.addLink(self
.dc
[0], self
.h
[0])
47 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
48 self
.net
.addLink(self
.h
[1], self
.dc
[1])
49 # connect dummy GK to data centers
50 sdkg1
= SonataDummyGatekeeperEndpoint("127.0.0.1", 55000)
51 sdkg1
.connectDatacenter(self
.dc
[0])
52 sdkg1
.connectDatacenter(self
.dc
[1])
53 # run the dummy gatekeeper (in another thread, don't block)
56 # start Mininet network
60 print "starting tests"
62 files
= {"package": open(PACKAGE_PATH
, "rb")}
63 r
= requests
.post("http://127.0.0.1:55000/packages", files
=files
)
64 self
.assertEqual(r
.status_code
, 201)
65 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
68 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
69 r2
= requests
.post("http://127.0.0.1:55000/instantiations",
70 data
=json
.dumps({"service_uuid": self
.service_uuid
}))
71 self
.assertEqual(r2
.status_code
, 201)
73 # give the emulator some time to instantiate everything
76 # check get request APIs
77 r3
= requests
.get("http://127.0.0.1:55000/packages")
78 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
79 r4
= requests
.get("http://127.0.0.1:55000/instantiations")
80 self
.assertEqual(len(json
.loads(r4
.text
).get(
81 "service_instantiations_list")), 1)
83 # check number of running nodes
84 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
85 self
.assertTrue(len(self
.net
.hosts
) == 5)
86 self
.assertTrue(len(self
.net
.switches
) == 2)
87 # check compute list result
88 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
89 # check connectivity by using ping
92 # check E-Line connection, by checking the IP addresses
93 for link
in self
.net
.deployed_elines
:
94 vnf_src
, intf_src
, vnf_sap_docker_name
= parse_interface(
95 link
['connection_points_reference'][0])
96 print vnf_src
, intf_src
97 src
= self
.net
.getNodeByName(vnf_src
)
100 network_list
= src
.getNetworkStatus()
102 for intf
in network_list
if intf
['intf_name'] == intf_src
][0]
103 src_mask
= [intf
['netmask']
104 for intf
in network_list
if intf
['intf_name'] == intf_src
][0]
106 vnf_dst
, intf_dst
, vnf_sap_docker_name
= parse_interface(
107 link
['connection_points_reference'][1])
108 dst
= self
.net
.getNodeByName(vnf_dst
)
111 network_list
= dst
.getNetworkStatus()
113 for intf
in network_list
if intf
['intf_name'] == intf_dst
][0]
114 dst_mask
= [intf
['netmask']
115 for intf
in network_list
if intf
['intf_name'] == intf_dst
][0]
117 print "src = {0}:{1} ip={2} ".format(
118 vnf_src
, intf_src
, src_ip
, src_mask
)
119 print "dst = {0}:{1} ip={2} ".format(
120 vnf_dst
, intf_dst
, dst_ip
, dst_mask
)
122 # check if the E-Line IP's are in the same subnet
123 ret
= ip_network(u
'{0}'.format(src_ip
, src_mask
), strict
=False)\
124 .compare_networks(ip_network(u
'{0}'.format(dst_ip
, dst_mask
), strict
=False))
125 self
.assertTrue(ret
== 0)
127 for vnf
in self
.dc
[0].listCompute():
128 # check E LAN connection
129 network_list
= vnf
.getNetworkStatus()
130 mgmt_ip
= [intf
['ip']
131 for intf
in network_list
if intf
['intf_name'] == 'mgmt']
132 self
.assertTrue(len(mgmt_ip
) > 0)
133 ip_address
= mgmt_ip
[0]
134 ELAN_list
.append(ip_address
)
137 # check ELAN connection by ping over the mgmt network (needs to be
138 # configured as ELAN in the test service)
139 for vnf
in self
.dc
[0].listCompute():
140 network_list
= vnf
.getNetworkStatus()
141 mgmt_ip
= [intf
['ip']
142 for intf
in network_list
if intf
['intf_name'] == 'mgmt']
143 self
.assertTrue(len(mgmt_ip
) > 0)
144 ip_address
= mgmt_ip
[0]
147 test_ip_list
= list(ELAN_list
)
148 test_ip_list
.remove(ip_address
)
149 for ip
in test_ip_list
:
150 # only take ip address, without netmask
151 p
= self
.net
.ping([vnf
], manualdestip
=ip
.split('/')[0])
153 self
.assertTrue(p
<= 0.0)
155 # stop Mininet network
159 # @unittest.skip("disabled")
160 def test_GK_Api_stop_service(self
):
162 self
.createNet(ndatacenter
=2, nhosts
=2)
164 self
.net
.addLink(self
.dc
[0], self
.h
[0])
165 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
166 self
.net
.addLink(self
.h
[1], self
.dc
[1])
167 # connect dummy GK to data centers
168 sdkg1
= SonataDummyGatekeeperEndpoint("127.0.0.1", 55001)
169 sdkg1
.connectDatacenter(self
.dc
[0])
170 sdkg1
.connectDatacenter(self
.dc
[1])
171 # run the dummy gatekeeper (in another thread, don't block)
174 # start Mininet network
178 print "starting tests"
180 files
= {"package": open(PACKAGE_PATH
, "rb")}
181 r
= requests
.post("http://127.0.0.1:55001/packages", files
=files
)
182 self
.assertEqual(r
.status_code
, 201)
183 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
185 # instantiate service
186 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
187 r2
= requests
.post("http://127.0.0.1:55001/instantiations",
188 data
=json
.dumps({"service_uuid": self
.service_uuid
}))
189 self
.assertEqual(r2
.status_code
, 201)
191 # give the emulator some time to instantiate everything
194 # check get request APIs
195 r3
= requests
.get("http://127.0.0.1:55001/packages")
196 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
197 r4
= requests
.get("http://127.0.0.1:55001/instantiations")
198 self
.assertEqual(len(json
.loads(r4
.text
).get(
199 "service_instantiations_list")), 1)
201 # check number of running nodes
202 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
203 self
.assertTrue(len(self
.net
.hosts
) == 5)
204 self
.assertTrue(len(self
.net
.switches
) == 2)
205 # check compute list result
206 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
209 service_instance_uuid
= json
.loads(
210 r2
.text
).get("service_instance_uuid")
211 self
.assertTrue(service_instance_uuid
is not None)
212 requests
.delete("http://127.0.0.1:55001/instantiations", data
=json
.dumps(
213 {"service_uuid": self
.service_uuid
, "service_instance_uuid": service_instance_uuid
}))
215 r5
= requests
.get("http://127.0.0.1:55001/instantiations")
216 # note that there was 1 instance before
217 self
.assertTrue(len(json
.loads(r5
.text
).get(
218 "service_instantiations_list")), 0)
220 # stop Mininet network
224 @unittest.skip("disabled")
225 def test_GK_stress_service(self
):
227 self
.createNet(ndatacenter
=2, nhosts
=2)
228 # connect dummy GK to data centers
229 sdkg1
= SonataDummyGatekeeperEndpoint("127.0.0.1", 55002)
230 sdkg1
.connectDatacenter(self
.dc
[0])
231 sdkg1
.connectDatacenter(self
.dc
[1])
232 # run the dummy gatekeeper (in another thread, don't block)
235 # start Mininet network
239 print "starting tests"
241 files
= {"package": open("misc/sonata-stress-service.son", "rb")}
242 r
= requests
.post("http://127.0.0.1:55002/packages", files
=files
)
243 self
.assertEqual(r
.status_code
, 201)
244 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
246 # instantiate service
247 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
248 r2
= requests
.post("http://127.0.0.1:55002/instantiations",
249 data
=json
.dumps({"service_uuid": self
.service_uuid
}))
250 self
.assertEqual(r2
.status_code
, 201)
252 # give the emulator some time to instantiate everything
255 # check get request APIs
256 r3
= requests
.get("http://127.0.0.1:55002/packages")
257 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
258 r4
= requests
.get("http://127.0.0.1:55002/instantiations")
259 self
.assertEqual(len(json
.loads(r4
.text
).get(
260 "service_instantiations_list")), 1)
263 service_instance_uuid
= json
.loads(
264 r2
.text
).get("service_instance_uuid")
265 self
.assertTrue(service_instance_uuid
is not None)
266 requests
.delete("http://127.0.0.1:55002/instantiations", data
=json
.dumps(
267 {"service_uuid": self
.service_uuid
, "service_instance_uuid": service_instance_uuid
}))
269 r5
= requests
.get("http://127.0.0.1:55002/instantiations")
270 # note that there was 1 instance before
271 self
.assertTrue(len(json
.loads(r5
.text
).get(
272 "service_instantiations_list")), 0)
274 # stop Mininet network