# Copyright 2013, Big Switch Networks, Inc.
#
# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
# the following special exception:
#
# LOXI Exception
#
# As a special exception to the terms of the EPL, you may distribute libraries
# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
# that copyright and licensing notices generated by LoxiGen are not altered or removed
# from the LoxiGen Libraries and the notice provided below is (i) included in
# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
# documentation for the LoxiGen Libraries, if distributed in binary form.
#
# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
#
# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
# a copy of the EPL at:
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# EPL for the specific language governing permissions and limitations
# under the EPL.

import os
from collections import namedtuple
import loxi_utils.loxi_utils as utils
import loxi_front_end
import of_g
from loxi_ir import *

templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')

DissectorField = namedtuple("DissectorField", ["fullname", "name", "type", "base"])

def create_fields():
    r = []
    proto_names = { 1: 'of10', 2: 'of11', 3: 'of12', 4: 'of13' }
    for wire_version, ofproto in of_g.ir.items():
        for ofclass in ofproto.classes:
            for m in ofclass.members:
                if isinstance(m, OFPadMember):
                    continue
                fullname = "%s.%s.%s" % (
                    proto_names[wire_version],
                    ofclass.name[3:],
                    m.name)
                r.append(DissectorField(fullname, m.name, "UINT8", "DEC"))

    return r

def generate(out, name):
    context = {
        'fields': create_fields(),
    }
    utils.render_template(out, "openflow.lua", [templates_dir], context)
