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 with a single data center for usage in son-profile.
34 from mininet
.log
import setLogLevel
35 from emuvim
.dcemulator
.net
import DCNetwork
36 from emuvim
.api
.rest
.rest_api_endpoint
import RestApiEndpoint
37 from emuvim
.api
.sonata
import SonataDummyGatekeeperEndpoint
38 from mininet
.node
import RemoteController
39 from time
import sleep
45 LOG
= logging
.getLogger("sonata-profiling")
46 LOG
.setLevel(logging
.DEBUG
)
47 logging
.getLogger("werkzeug").setLevel(logging
.WARNING
)
50 Catches SIGINT and SIGTERM to shut the topology down gracefully.
53 def __init__(self
, to_be_killed
):
54 signal
.signal(signal
.SIGINT
, self
.exit_gracefully
)
55 signal
.signal(signal
.SIGTERM
, self
.exit_gracefully
)
56 self
.to_be_killed
= to_be_killed
58 def exit_gracefully(self
, signum
, frame
):
59 self
.to_be_killed
.stop_it()
63 A simple topology with only one data center which will stop when another thread tells it to or when a time limit is reached.
70 Set up a simple topology and start it
71 :port: the port the REST interface will be using, port+1 will be in use as well
73 def __init__(self
, port
=5000):
76 self
.net
= DCNetwork(controller
=RemoteController
, monitor
=False, enable_learning
=False)
77 self
.dc
= self
.net
.addDatacenter("dc1")
79 # add the command line interface endpoint to each DC (REST API)
80 self
.rapi1
= RestApiEndpoint("0.0.0.0", port
+1)
81 self
.rapi1
.connectDCNetwork(self
.net
)
82 self
.rapi1
.connectDatacenter(self
.dc
)
83 # run API endpoint server (in another thread, don't block)
86 # add the SONATA dummy gatekeeper to each DC
87 self
.sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", port
, deploy_sap
=False)
88 self
.sdkg1
.connectDatacenter(self
.dc
)
89 # run the dummy gatekeeper (in another thread, don't block)
94 LOG
.info("Started topology")
95 while(not self
.stop_now
):
98 LOG
.info("Stopped topology")
101 Set stop value to stop the topology
108 setLogLevel('info') # set Mininet loglevel
109 p
= Profiling(args
.get('port'))
112 if __name__
== '__main__':
113 parser
= argparse
.ArgumentParser(description
="Run a simple topology")
114 parser
.add_argument('--port', '-p', type=int, help='the port for the REST interface', default
=5000, required
=False, dest
='port')
115 arg_list
= vars(parser
.parse_args(sys
.argv
[1:]))