khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 the original author or authors. |
| 3 | # |
| 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 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. |
| 15 | # |
| 16 | |
| 17 | |
| 18 | from adapters.protos import openflow_13_pb2 as ofp |
| 19 | |
| 20 | OUTPUT = ofp.OFPAT_OUTPUT |
| 21 | ETH_TYPE = ofp.OFPXMT_OFB_ETH_TYPE |
| 22 | IP_PROTO = ofp.OFPXMT_OFB_IP_PROTO |
| 23 | |
| 24 | def get_ofb_fields(flow): |
| 25 | assert isinstance(flow, ofp.ofp_flow_stats) |
| 26 | assert flow.match.type == ofp.OFPMT_OXM |
| 27 | ofb_fields = [] |
| 28 | for field in flow.match.oxm_fields: |
| 29 | assert field.oxm_class == ofp.OFPXMC_OPENFLOW_BASIC |
| 30 | ofb_fields.append(field.ofb_field) |
| 31 | return ofb_fields |
| 32 | |
| 33 | def get_actions(flow): |
| 34 | """Extract list of ofp_action objects from flow spec object""" |
| 35 | assert isinstance(flow, ofp.ofp_flow_stats) |
| 36 | # we have the following hard assumptions for now |
| 37 | for instruction in flow.instructions: |
| 38 | if instruction.type == ofp.OFPIT_APPLY_ACTIONS: |
| 39 | return instruction.actions.actions |
| 40 | |
| 41 | def get_out_port(flow): |
| 42 | for action in get_actions(flow): |
| 43 | if action.type == OUTPUT: |
| 44 | return action.output.port |
| 45 | return None |