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 |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 33 | from generic_utils import * |
| 34 | import of_g |
| 35 | |
| 36 | ## |
| 37 | # The value to use when an identifier is not defined for a version |
| 38 | UNDEFINED_IDENT_VALUE = 0 |
| 39 | |
Rich Lane | ba7feb1 | 2013-04-08 14:07:00 -0700 | [diff] [blame] | 40 | def add_identifier(name, ofp_name, ofp_group, value, version, all_idents, idents_by_group): |
ederlf | 46abbb9 | 2013-04-24 17:07:50 -0300 | [diff] [blame^] | 41 | assert(isinstance(value, (int,long))) |
Rich Lane | ba7feb1 | 2013-04-08 14:07:00 -0700 | [diff] [blame] | 42 | if name in all_idents: |
| 43 | all_idents[name]["values_by_version"][version] = value |
| 44 | if ((all_idents[name]["ofp_name"] != ofp_name or |
| 45 | all_idents[name]["ofp_group"] != ofp_group) and |
| 46 | ofp_name.find("OFPP_") != 0): |
| 47 | log(""" |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 48 | NOTE: Identifier %s has different ofp name or group in version %s |
| 49 | From ofp name %s, group %s to name %s, group %s. |
| 50 | This could indicate a name collision in LOXI identifier translation. |
| 51 | """ % (name, str(version), all_idents[name]["ofp_name"], |
Rich Lane | ba7feb1 | 2013-04-08 14:07:00 -0700 | [diff] [blame] | 52 | all_idents[name]["ofp_group"], ofp_name, ofp_group)) |
| 53 | # Update stuff assuming newer versions processed later |
| 54 | all_idents[name]["ofp_name"] = ofp_name |
| 55 | all_idents[name]["ofp_group"] = ofp_group |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 56 | |
Rich Lane | ba7feb1 | 2013-04-08 14:07:00 -0700 | [diff] [blame] | 57 | else: # New name |
| 58 | all_idents[name] = dict( |
| 59 | values_by_version = {version:value}, |
| 60 | common_value = value, |
| 61 | ofp_name = ofp_name, |
| 62 | ofp_group = ofp_group |
| 63 | ) |
| 64 | if ofp_group not in idents_by_group: |
| 65 | idents_by_group[ofp_group] = [] |
| 66 | if name not in idents_by_group[ofp_group]: |
| 67 | idents_by_group[ofp_group].append(name) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 68 | |
| 69 | def all_versions_agree(all_idents, version_list, name): |
| 70 | val_list = all_idents[name]["values_by_version"] |
| 71 | for version in version_list: |
| 72 | if not version in val_list: |
| 73 | return False |
| 74 | if str(val_list[version]) != str(all_idents[name]["common_value"]): |
| 75 | return False |
| 76 | return True |
| 77 | |
| 78 | def defined_versions_agree(all_idents, version_list, name): |
| 79 | val_list = all_idents[name]["values_by_version"] |
| 80 | for version in version_list: |
| 81 | if version in val_list: |
| 82 | if str(val_list[version]) != str(all_idents[name]["common_value"]): |
| 83 | return False |
| 84 | return True |