blob: eb31c3c897f9a5f80283183d1348520febca5bd2 [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"""
stevenvanrossem73efd192016-06-29 01:44:07 +020028import logging
29from flask_restful import Resource
30from flask import request
31import json
32
33logging.basicConfig(level=logging.INFO)
34
35net = None
36
37
38class NetworkAction(Resource):
39 """
40 Add or remove chains between VNFs. These chain links are implemented as flow entries in the networks' SDN switches.
41 :param vnf_src_name: VNF name of the source of the link
42 :param vnf_dst_name: VNF name of the destination of the link
43 :param vnf_src_interface: VNF interface name of the source of the link
44 :param vnf_dst_interface: VNF interface name of the destination of the link
45 :param weight: weight of the link (can be useful for routing calculations)
46 :param match: OpenFlow match format of the flow entry
47 :param bidirectional: boolean value if the link needs to be implemented from src to dst and back
48 :param cookie: cookie value, identifier of the flow entry to be installed.
49 :return: message string indicating if the chain action is succesful or not
50 """
51
52 global net
53
54 def put(self, vnf_src_name, vnf_dst_name):
55 logging.debug("REST CALL: network chain add")
56 command = 'add-flow'
57 return self._NetworkAction(vnf_src_name, vnf_dst_name, command=command)
58
59 def delete(self, vnf_src_name, vnf_dst_name):
60 logging.debug("REST CALL: network chain remove")
61 command = 'del-flows'
62 return self._NetworkAction(vnf_src_name, vnf_dst_name, command=command)
63
64 def _NetworkAction(self, vnf_src_name, vnf_dst_name, command=None):
65 # call DCNetwork method, not really datacenter specific API for now...
66 # no check if vnfs are really connected to this datacenter...
67 try:
68 vnf_src_interface = json.loads(request.json).get("vnf_src_interface")
69 vnf_dst_interface = json.loads(request.json).get("vnf_dst_interface")
70 weight = json.loads(request.json).get("weight")
71 match = json.loads(request.json).get("match")
72 bidirectional = json.loads(request.json).get("bidirectional")
73 cookie = json.loads(request.json).get("cookie")
74 c = net.setChain(
75 vnf_src_name, vnf_dst_name,
76 vnf_src_interface=vnf_src_interface,
77 vnf_dst_interface=vnf_dst_interface,
78 cmd=command,
79 weight=weight,
80 match=match,
81 bidirectional=bidirectional,
82 cookie=cookie)
83 # return setChain response
84 return str(c), 200
85 except Exception as ex:
86 logging.exception("API error.")
87 return ex.message, 500