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).
29 A simple topology to test resource model support.
35 from mininet
.log
import setLogLevel
36 from mininet
.node
import Controller
37 from emuvim
.dcemulator
.net
import DCNetwork
38 from emuvim
.api
.zerorpc
.compute
import ZeroRpcApiEndpoint
39 from emuvim
.api
.sonata
import SonataDummyGatekeeperEndpoint
40 from emuvim
.dcemulator
.resourcemodel
.upb
.simple
import UpbSimpleCloudDcRM
, UpbOverprovisioningCloudDcRM
42 logging
.basicConfig(level
=logging
.INFO
)
45 RESOURCE_LOG_PATH
= "resource.log"
48 def create_topology1():
51 # use a maximum of 50% cpu time for containers added to data centers
52 net
= DCNetwork(dc_emulation_max_cpu
=0.5, controller
=Controller
)
53 # add some data centers and create a topology
54 dc1
= net
.addDatacenter("dc1", resource_log_path
=RESOURCE_LOG_PATH
)
55 dc2
= net
.addDatacenter("dc2", resource_log_path
=RESOURCE_LOG_PATH
)
56 s1
= net
.addSwitch("s1")
57 net
.addLink(dc1
, s1
, delay
="10ms")
58 net
.addLink(dc2
, s1
, delay
="20ms")
60 # create and assign resource models for each DC
61 rm1
= UpbSimpleCloudDcRM(max_cu
=4, max_mu
=1024)
62 rm2
= UpbOverprovisioningCloudDcRM(max_cu
=4)
63 dc1
.assignResourceModel(rm1
)
64 dc2
.assignResourceModel(rm2
)
66 # add the command line interface endpoint to each DC
67 zapi1
= ZeroRpcApiEndpoint("0.0.0.0", 4242)
68 zapi1
.connectDatacenter(dc1
)
69 zapi1
.connectDatacenter(dc2
)
70 # run API endpoint server (in another thread, don't block)
73 # start the emulation platform
75 print "Wait a moment and allocate some compute start some compute resources..."
77 dc1
.startCompute("vnf1")
78 dc1
.startCompute("vnf2", flavor_name
="tiny")
79 dc1
.startCompute("vnf3", flavor_name
="small")
80 dc2
.startCompute("vnf4", flavor_name
="medium")
81 dc2
.startCompute("vnf5", flavor_name
="medium")
82 dc2
.startCompute("vnf6", flavor_name
="medium")
85 print "Removing instances ..."
86 dc1
.stopCompute("vnf1")
87 dc2
.stopCompute("vnf4")
95 os
.remove(RESOURCE_LOG_PATH
)
101 setLogLevel('info') # set Mininet loglevel
105 if __name__
== '__main__':