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 | :: include('_copyright.py') |
| 29 | |
| 30 | :: include('_autogen.py') |
| 31 | |
| 32 | import loxi |
| 33 | import const |
Rich Lane | d4e0869 | 2013-02-20 17:40:33 -0800 | [diff] [blame] | 34 | import struct |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 35 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 36 | def pretty_mac(mac): |
| 37 | return ':'.join(["%02x" % x for x in mac]) |
| 38 | |
| 39 | def pretty_ipv4(v): |
| 40 | return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF) |
| 41 | |
| 42 | def pretty_flags(v, flag_names): |
| 43 | set_flags = [] |
| 44 | for flag_name in flag_names: |
| 45 | flag_value = getattr(const, flag_name) |
| 46 | if v & flag_value == flag_value: |
| 47 | set_flags.append(flag_name) |
| 48 | elif v & flag_value: |
| 49 | set_flags.append('%s&%#x' % (flag_name, v & flag_value)) |
| 50 | v &= ~flag_value |
| 51 | if v: |
| 52 | set_flags.append("%#x" % v) |
| 53 | return '|'.join(set_flags) or '0' |
| 54 | |
Rich Lane | adb7983 | 2013-05-02 17:14:33 -0700 | [diff] [blame] | 55 | :: if version in [1,2]: |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 56 | def pretty_wildcards(v): |
| 57 | if v == const.OFPFW_ALL: |
| 58 | return 'OFPFW_ALL' |
| 59 | flag_names = ['OFPFW_IN_PORT', 'OFPFW_DL_VLAN', 'OFPFW_DL_SRC', 'OFPFW_DL_DST', |
| 60 | 'OFPFW_DL_TYPE', 'OFPFW_NW_PROTO', 'OFPFW_TP_SRC', 'OFPFW_TP_DST', |
| 61 | 'OFPFW_NW_SRC_MASK', 'OFPFW_NW_DST_MASK', 'OFPFW_DL_VLAN_PCP', |
| 62 | 'OFPFW_NW_TOS'] |
| 63 | return pretty_flags(v, flag_names) |
Rich Lane | adb7983 | 2013-05-02 17:14:33 -0700 | [diff] [blame] | 64 | :: #endif |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 65 | |
| 66 | def pretty_port(v): |
| 67 | named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')] |
| 68 | for (k, v2) in named_ports: |
| 69 | if v == v2: |
| 70 | return k |
| 71 | return v |