2 Copyright (c) 2017 SONATA-NFV and Paderborn University
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, Paderborn University
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).
33 class PortChain(object):
34 def __init__(self
, name
):
35 self
.id = str(uuid
.uuid4())
36 self
.tenant_id
= "abcdefghijklmnopqrstuvwxyz123456"
39 self
.port_pair_groups
= list()
40 self
.flow_classifiers
= list()
41 self
.chain_parameters
= dict()
43 # Cookie for internal identification of installed flows (e.g. to delete them)
44 self
.cookie
= random
.randint(1, 0xffffffff)
46 def create_dict(self
, compute
):
49 "tenant_id": self
.tenant_id
,
50 "description": self
.description
,
51 "flow_classifiers": self
.flow_classifiers
,
52 "port_pair_groups": self
.port_pair_groups
,
57 def install(self
, compute
):
58 for flow_classifier_id
in self
.flow_classifiers
:
59 flow_classifier
= compute
.find_flow_classifier_by_name_or_id(flow_classifier_id
)
62 # TODO: for every flow classifier create match and pass it to setChain
64 for group_id
in self
.port_pair_groups
:
65 port_pair_group
= compute
.find_port_pair_group_by_name_or_id(group_id
)
66 for port_pair_id
in port_pair_group
.port_pairs
:
67 port_pair
= compute
.find_port_pair_by_name_or_id(port_pair_id
)
71 for server
in compute
.computeUnits
.values():
72 if port_pair
.ingress
.name
in server
.port_names
:
73 server_ingress
= server
74 elif port_pair
.egress
.name
in server
.port_names
:
75 server_egress
= server
77 # TODO: Not sure, if this should throw an error
78 if not server_ingress
:
79 logging
.warn("Neutron SFC: ingress port %s not connected." % str(port_pair
.ingress
.name
))
82 logging
.warn("Neutron SFC: egress port %s not connected." % str(port_pair
.egress
.name
))
85 compute
.dc
.net
.setChain(
86 server_ingress
.name
, server_egress
.name
,
87 port_pair
.ingress
.intf_name
, port_pair
.egress
.intf_name
,
88 cmd
="add-flow", cookie
=self
.cookie
, priority
=10, bidirectional
=False,
92 def uninstall(self
, compute
):
94 logging
.warn("Removing flows is currently not implemented.")
98 logging
.warn("Updating flows is currently not implemented.")