Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | # Copyright 2013, Big Switch Networks, Inc. |
| 2 | # |
| 3 | # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| 4 | # the following special exception: |
| 5 | # |
| 6 | # LOXI Exception |
| 7 | # |
| 8 | # As a special exception to the terms of the EPL, you may distribute libraries |
| 9 | # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| 10 | # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| 11 | # from the LoxiGen Libraries and the notice provided below is (i) included in |
| 12 | # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| 13 | # documentation for the LoxiGen Libraries, if distributed in binary form. |
| 14 | # |
| 15 | # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| 16 | # |
| 17 | # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| 18 | # a copy of the EPL at: |
| 19 | # |
| 20 | # http://www.eclipse.org/legal/epl-v10.html |
| 21 | # |
| 22 | # Unless required by applicable law or agreed to in writing, software |
| 23 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 25 | # EPL for the specific language governing permissions and limitations |
| 26 | # under the EPL. |
| 27 | |
| 28 | ## |
| 29 | # @brief Process identifiers for updating of_g.identifiers |
| 30 | # |
| 31 | |
| 32 | import sys |
| 33 | import of_h_utils |
| 34 | from generic_utils import * |
| 35 | import of_g |
| 36 | |
| 37 | ## |
| 38 | # The value to use when an identifier is not defined for a version |
| 39 | UNDEFINED_IDENT_VALUE = 0 |
| 40 | |
| 41 | def add_identifiers(all_idents, idents_by_group, version, contents): |
| 42 | """ |
| 43 | Update all_idents with identifiers from an openflow.h header file |
| 44 | @param all_idents A dict, usually of_g.identifiers |
| 45 | @param idents_by_group A dict for mapping LOXI idents to groups, |
| 46 | usually of_g.identifiers_by_group |
| 47 | @param version The OF wire version |
| 48 | @param contents The contents of an openflow.h file |
| 49 | """ |
| 50 | |
| 51 | # Get the dictionary of enums from the file text |
| 52 | enum_dict = of_h_utils.get_enum_dict(version, |
| 53 | contents) |
| 54 | for name, info in enum_dict.items(): |
| 55 | |
| 56 | # info is a DotDict w/ keys ofp_name, ofp_group and value. |
| 57 | if name in all_idents: |
| 58 | all_idents[name]["values_by_version"][version] = info.value |
| 59 | if ((all_idents[name]["ofp_name"] != info.ofp_name or |
| 60 | all_idents[name]["ofp_group"] != info.ofp_group) and |
| 61 | info.ofp_name.find("OFPP_") != 0): |
| 62 | log(""" |
| 63 | NOTE: Identifier %s has different ofp name or group in version %s |
| 64 | From ofp name %s, group %s to name %s, group %s. |
| 65 | This could indicate a name collision in LOXI identifier translation. |
| 66 | """ % (name, str(version), all_idents[name]["ofp_name"], |
| 67 | all_idents[name]["ofp_group"], info.ofp_name, info.ofp_group)) |
| 68 | # Update stuff assuming newer versions processed later |
| 69 | all_idents[name]["ofp_name"] = info.ofp_name |
| 70 | all_idents[name]["ofp_group"] = info.ofp_group |
| 71 | |
| 72 | else: # New name |
| 73 | all_idents[name] = dict( |
| 74 | values_by_version = {version:info.value}, |
| 75 | common_value = info["value"], |
| 76 | ofp_name = info["ofp_name"], |
| 77 | ofp_group = info["ofp_group"] |
| 78 | ) |
| 79 | if info["ofp_group"] not in idents_by_group: |
| 80 | idents_by_group[info["ofp_group"]] = [] |
| 81 | if name not in idents_by_group[info["ofp_group"]]: |
| 82 | idents_by_group[info["ofp_group"]].append(name) |
| 83 | |
| 84 | def all_versions_agree(all_idents, version_list, name): |
| 85 | val_list = all_idents[name]["values_by_version"] |
| 86 | for version in version_list: |
| 87 | if not version in val_list: |
| 88 | return False |
| 89 | if str(val_list[version]) != str(all_idents[name]["common_value"]): |
| 90 | return False |
| 91 | return True |
| 92 | |
| 93 | def defined_versions_agree(all_idents, version_list, name): |
| 94 | val_list = all_idents[name]["values_by_version"] |
| 95 | for version in version_list: |
| 96 | if version in val_list: |
| 97 | if str(val_list[version]) != str(all_idents[name]["common_value"]): |
| 98 | return False |
| 99 | return True |