blob: 45d954116dd3ad4c81df4b6752e2361abc504570 [file] [log] [blame]
peusterm79ef6ae2016-07-08 13:53:57 +02001"""
2Copyright (c) 2015 SONATA-NFV and Paderborn University
3ALL RIGHTS RESERVED.
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18nor the names of its contributors may be used to endorse or promote
19products derived from this software without specific prior written
20permission.
21
22This work has been performed in the framework of the SONATA project,
23funded by the European Commission under Grant number 671517 through
24the Horizon 2020 and 5G-PPP programmes. The authors would like to
25acknowledge the contributions of their colleagues of the SONATA
26partner consortium (www.sonata-nfv.eu).
27"""
stevenvanrosseme131bf52016-07-14 11:42:09 +020028
29"""
30Distributed Cloud Emulator (dcemulator)
31Networking and monitoring functions
32(c) 2015 by Steven Van Rossem <steven.vanrossem@intec.ugent.be>
33"""
34
stevenvanrossem73efd192016-06-29 01:44:07 +020035import logging
36from flask_restful import Resource
37from flask import request
38import json
39
40logging.basicConfig(level=logging.INFO)
41
42net = None
43
44
45
46class MonitorInterfaceAction(Resource):
47 """
48 Monitor the counters of a VNF interface
49 :param vnf_name: name of the VNF to be monitored
50 :param vnf_interface: name of the VNF interface to be monitored
51 :param metric: tx_bytes, rx_bytes, tx_packets, rx_packets
52 :return: message string indicating if the monitor action is succesful or not
53 """
54 global net
55
stevenvanrossem9c8a4122016-07-16 03:23:13 +020056 def put(self, vnf_name, vnf_interface=None, metric='tx_packets'):
stevenvanrossem73efd192016-06-29 01:44:07 +020057 logging.debug("REST CALL: start monitor VNF interface")
58 try:
59 c = net.monitor_agent.setup_metric(vnf_name, vnf_interface, metric)
60 # return monitor message response
61 return str(c), 200
62 except Exception as ex:
63 logging.exception("API error.")
64 return ex.message, 500
65
stevenvanrossem9c8a4122016-07-16 03:23:13 +020066 def delete(self, vnf_name, vnf_interface=None, metric='tx_packets'):
stevenvanrossem73efd192016-06-29 01:44:07 +020067 logging.debug("REST CALL: stop monitor VNF interface")
68 try:
69 c = net.monitor_agent.stop_metric(vnf_name, vnf_interface, metric)
70 # return monitor message response
71 return str(c), 200
72 except Exception as ex:
73 logging.exception("API error.")
74 return ex.message, 500
75
76
77class MonitorFlowAction(Resource):
78 """
79 Monitor the counters of a specific flow
80 :param vnf_name: name of the VNF to be monitored
81 :param vnf_interface: name of the VNF interface to be monitored
82 :param metric: tx_bytes, rx_bytes, tx_packets, rx_packets
83 :param cookie: specific identifier of flows to monitor
84 :return: message string indicating if the monitor action is succesful or not
85 """
86 global net
87
stevenvanrossem9c8a4122016-07-16 03:23:13 +020088 def put(self, vnf_name, vnf_interface=None, metric='tx_packets', cookie=0):
stevenvanrossem73efd192016-06-29 01:44:07 +020089 logging.debug("REST CALL: start monitor VNF interface")
90 try:
91 c = net.monitor_agent.setup_flow(vnf_name, vnf_interface, metric, cookie)
92 # return monitor message response
93 return str(c), 200
94 except Exception as ex:
95 logging.exception("API error.")
96 return ex.message, 500
97
stevenvanrossem9c8a4122016-07-16 03:23:13 +020098 def delete(self, vnf_name, vnf_interface=None, metric='tx_packets', cookie=0):
stevenvanrossem73efd192016-06-29 01:44:07 +020099 logging.debug("REST CALL: stop monitor VNF interface")
100 try:
101 c = net.monitor_agent.stop_flow(vnf_name, vnf_interface, metric, cookie)
102 # return monitor message response
103 return str(c), 200
104 except Exception as ex:
105 logging.exception("API error.")
106 return ex.message, 500