f712312fc64b06d9b0ecbe9b477e0a1d45e594f2
1 # Copyright (c) 2015 SONATA-NFV and Paderborn University
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # Neither the name of the SONATA-NFV, Paderborn University
17 # nor the names of its contributors may be used to endorse or promote
18 # products derived from this software without specific prior written
21 # This work has been performed in the framework of the SONATA project,
22 # funded by the European Commission under Grant number 671517 through
23 # the Horizon 2020 and 5G-PPP programmes. The authors would like to
24 # acknowledge the contributions of their colleagues of the SONATA
25 # partner consortium (www.sonata-nfv.eu).
31 class PortChain(object):
32 def __init__(self
, name
):
33 self
.id = str(uuid
.uuid4())
34 self
.tenant_id
= "abcdefghijklmnopqrstuvwxyz123456"
37 self
.port_pair_groups
= list()
38 self
.flow_classifiers
= list()
39 self
.chain_parameters
= dict()
41 # Cookie for internal identification of installed flows (e.g. to delete
43 self
.cookie
= random
.randint(1, 0xffffffff)
45 def create_dict(self
, compute
):
48 "tenant_id": self
.tenant_id
,
49 "description": self
.description
,
50 "flow_classifiers": self
.flow_classifiers
,
51 "port_pair_groups": self
.port_pair_groups
,
56 def install(self
, compute
):
57 for flow_classifier_id
in self
.flow_classifiers
:
58 flow_classifier
= compute
.find_flow_classifier_by_name_or_id(
62 # TODO: for every flow classifier create match and pass it to
65 for group_id
in self
.port_pair_groups
:
66 port_pair_group
= compute
.find_port_pair_group_by_name_or_id(
68 for port_pair_id
in port_pair_group
.port_pairs
:
69 port_pair
= compute
.find_port_pair_by_name_or_id(port_pair_id
)
73 for server
in compute
.computeUnits
.values():
74 if port_pair
.ingress
.name
in server
.port_names
or port_pair
.ingress
.id in server
.port_names
:
75 server_ingress
= server
76 elif port_pair
.egress
.name
in server
.port_names
or port_pair
.egress
.id in server
.port_names
:
77 server_egress
= server
79 # TODO: Not sure, if this should throw an error
80 if not server_ingress
:
81 logging
.warn("Neutron SFC: ingress port %s not connected." % str(
82 port_pair
.ingress
.name
))
85 logging
.warn("Neutron SFC: egress port %s not connected." % str(
86 port_pair
.egress
.name
))
89 compute
.dc
.net
.setChain(
90 server_ingress
.name
, server_egress
.name
,
91 port_pair
.ingress
.intf_name
, port_pair
.egress
.intf_name
,
92 cmd
="add-flow", cookie
=self
.cookie
, priority
=10, bidirectional
=False,
96 def uninstall(self
, compute
):
98 logging
.warn("Removing flows is currently not implemented.")
102 logging
.warn("Updating flows is currently not implemented.")