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 p
= self
.net
.ping([vnf
],manualdestip
=ip
)
143 self
.assertTrue(p
<= 0.0)
145 # stop Mininet network
149 #@unittest.skip("disabled")
150 def test_GK_Api_stop_service(self
):
152 self
.createNet(ndatacenter
=2, nhosts
=2)
154 self
.net
.addLink(self
.dc
[0], self
.h
[0])
155 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
156 self
.net
.addLink(self
.h
[1], self
.dc
[1])
157 # connect dummy GK to data centers
158 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
159 sdkg1
.connectDatacenter(self
.dc
[0])
160 sdkg1
.connectDatacenter(self
.dc
[1])
161 # run the dummy gatekeeper (in another thread, don't block)
163 # start Mininet network
167 print "starting tests"
169 files
= {"package": open(PACKAGE_PATH
, "rb")}
170 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
171 self
.assertEqual(r
.status_code
, 201)
172 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
174 # instantiate service
175 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
176 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
177 self
.assertEqual(r2
.status_code
, 201)
179 # give the emulator some time to instantiate everything
182 # check get request APIs
183 r3
= requests
.get("http://127.0.0.1:5000/packages")
184 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
185 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
186 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
188 # check number of running nodes
189 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
190 self
.assertTrue(len(self
.net
.hosts
) == 5)
191 self
.assertTrue(len(self
.net
.switches
) == 2)
192 # check compute list result
193 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
196 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
197 self
.assertTrue(service_instance_uuid
is not None)
198 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
200 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
201 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
203 # stop Mininet network
208 #@unittest.skip("disabled")
209 def test_GK_stress_service(self
):
211 self
.createNet(ndatacenter
=2, nhosts
=2)
212 # connect dummy GK to data centers
213 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
214 sdkg1
.connectDatacenter(self
.dc
[0])
215 sdkg1
.connectDatacenter(self
.dc
[1])
216 # run the dummy gatekeeper (in another thread, don't block)
218 # start Mininet network
222 print "starting tests"
224 files
= {"package": open("misc/sonata-stress-service.son", "rb")}
225 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
226 self
.assertEqual(r
.status_code
, 201)
227 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
229 # instantiate service
230 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
231 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
232 self
.assertEqual(r2
.status_code
, 201)
234 # give the emulator some time to instantiate everything
237 # check get request APIs
238 r3
= requests
.get("http://127.0.0.1:5000/packages")
239 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
240 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
241 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
244 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
245 self
.assertTrue(service_instance_uuid
is not None)
246 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
248 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
249 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
251 # stop Mininet network