1 # Copyright 2015 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 """Utility functions for working with vSwitches and flows
20 def add_ports_to_flow(flow, in_port, out_port):
21 """Creates a new flow based on the given flow and adds in port and out port
24 The flow dictionary structure is described in IVswitch
26 :param flow: Description of the flow as a dictionary
27 :param in_port: OpenFlow number of the ingress port for the rule
28 :param out_port: OpenFlow number of the eggress port for the rule
30 :returns: A new dictionary describing a flow combining the parameters
32 new_flow = copy.deepcopy(flow)
33 new_flow['in_port'] = in_port
35 if 'actions' in new_flow:
36 new_flow['actions'].append('output:' + str(out_port))
38 new_flow['actions'] = ['output:' + str(out_port)]