6 class PortChain(object):
7 def __init__(self
, name
):
8 self
.id = str(uuid
.uuid4())
9 self
.tenant_id
= "abcdefghijklmnopqrstuvwxyz123456"
12 self
.port_pair_groups
= list()
13 self
.flow_classifiers
= list()
14 self
.chain_parameters
= dict()
16 # Cookie for internal identification of installed flows (e.g. to delete them)
17 self
.cookie
= random
.randint(1, 0xffffffff)
19 def create_dict(self
, compute
):
22 "tenant_id": self
.tenant_id
,
23 "description": self
.description
,
24 "flow_classifiers": self
.flow_classifiers
,
25 "port_pair_groups": self
.port_pair_groups
,
30 def install(self
, compute
):
31 for flow_classifier_id
in self
.flow_classifiers
:
32 flow_classifier
= compute
.find_flow_classifier_by_name_or_id(flow_classifier_id
)
35 # TODO: for every flow classifier create match and pass it to setChain
37 for group_id
in self
.port_pair_groups
:
38 port_pair_group
= compute
.find_port_pair_group_by_name_or_id(group_id
)
39 for port_pair_id
in port_pair_group
.port_pairs
:
40 port_pair
= compute
.find_port_pair_by_name_or_id(port_pair_id
)
44 for server
in compute
.computeUnits
.values():
45 if port_pair
.ingress
.name
in server
.port_names
:
46 server_ingress
= server
47 elif port_pair
.egress
.name
in server
.port_names
:
48 server_egress
= server
50 # TODO: Not sure, if this should throw an error
51 if not server_ingress
:
52 logging
.warn("Neutron SFC: ingress port %s not connected." % str(port_pair
.ingress
.name
))
55 logging
.warn("Neutron SFC: egress port %s not connected." % str(port_pair
.egress
.name
))
58 compute
.dc
.net
.setChain(
59 server_ingress
.name
, server_egress
.name
,
60 port_pair
.ingress
.intf_name
, port_pair
.egress
.intf_name
,
61 cmd
="add-flow", cookie
=self
.cookie
, priority
=10, bidirectional
=False,
65 def uninstall(self
, compute
):
67 logging
.warn("Removing flows is currently not implemented.")
71 logging
.warn("Updating flows is currently not implemented.")