forked from floodlight/loxigen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:floodlight/loxigen
- Loading branch information
Showing
13 changed files
with
699 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# 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. | ||
|
||
""" | ||
Wireshark dissector backend for LOXI | ||
Target directory structure: | ||
wireshark: | ||
openflow.lua | ||
The user will copy openflow.lua into ~/.wireshark/plugins, where it will be | ||
loaded automatically by Wireshark. | ||
""" | ||
|
||
import wireshark_gen | ||
|
||
targets = { | ||
'wireshark/openflow.lua' : wireshark_gen.generate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# 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 * | ||
import field_info | ||
|
||
templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates') | ||
|
||
DissectorField = namedtuple("DissectorField", ["fullname", "name", "type", "base"]) | ||
|
||
proto_names = { 1: 'of10', 2: 'of11', 3: 'of12', 4: 'of13' } | ||
def make_field_name(wire_version, ofclass_name, member_name): | ||
return "%s.%s.%s" % (proto_names[wire_version], | ||
ofclass_name[3:], | ||
member_name) | ||
|
||
def get_field_info(version, cls, name, oftype): | ||
""" | ||
Decide on a Wireshark type and base for a given field. | ||
Returns (type, base) | ||
""" | ||
if oftype.startswith("list"): | ||
return "bytes", "NONE" | ||
|
||
ofproto = of_g.ir[version] | ||
enum = ofproto.enum_by_name(oftype) | ||
|
||
if enum: | ||
field_type = "uint32" | ||
elif oftype in field_info.oftype_to_wireshark_type: | ||
field_type = field_info.oftype_to_wireshark_type[oftype] | ||
else: | ||
print "WARN missing oftype_to_wireshark_type for", oftype | ||
field_type = "bytes" | ||
|
||
if enum: | ||
if enum.is_bitmask: | ||
field_base = "HEX" | ||
else: | ||
field_base = "DEC" | ||
elif oftype in field_info.field_to_base: | ||
field_base = field_info.field_to_base[name] | ||
elif oftype in field_info.oftype_to_base: | ||
field_base = field_info.oftype_to_base[oftype] | ||
else: | ||
print "WARN missing oftype_to_base for", oftype | ||
field_base = "NONE" | ||
|
||
return field_type, field_base | ||
|
||
def create_fields(): | ||
r = [] | ||
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 = make_field_name(wire_version, ofclass.name, m.name) | ||
field_type, field_base = get_field_info(wire_version, ofclass.name, m.name, m.oftype) | ||
r.append(DissectorField(fullname, m.name, field_type, field_base)) | ||
|
||
return r | ||
|
||
def generate(out, name): | ||
context = { | ||
'fields': create_fields(), | ||
} | ||
utils.render_template(out, "openflow.lua", [templates_dir], context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 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. | ||
|
||
# Map from LOXI types to Wireshark types | ||
oftype_to_wireshark_type = { | ||
"char": "int8", | ||
"uint8_t": "uint8", | ||
"uint16_t": "uint16", | ||
"uint32_t": "uint32", | ||
"uint64_t": "uint64", | ||
"of_mac_addr_t": "ether", | ||
"of_ipv4_t": "ipv4", | ||
"of_ipv6_t": "ipv6", | ||
"of_port_name_t": "stringz", | ||
"of_table_name_t": "stringz", | ||
"of_desc_str_t": "stringz", | ||
"of_serial_num_t": "stringz", | ||
"of_octets_t": "bytes", | ||
"of_port_no_t": "uint32", | ||
"of_port_desc_t": "stringz", | ||
"of_bsn_vport_t": "bytes", | ||
"of_bsn_vport_q_in_q_t": "bytes", | ||
"of_fm_cmd_t": "uint16", | ||
"of_wc_bmap_t": "uint64", | ||
"of_match_bmap_t": "uint64", | ||
"of_match_t": "bytes", | ||
"of_oxm_t": "bytes", | ||
"of_meter_features_t": "bytes", | ||
"of_bitmap_128_t": "bytes", | ||
} | ||
|
||
# Map from LOXI type to Wireshark base | ||
oftype_to_base = { | ||
"char": "DEC", | ||
"uint8_t": "DEC", | ||
"uint16_t": "DEC", | ||
"uint32_t": "DEC", | ||
"uint64_t": "DEC", | ||
"of_mac_addr_t": "NONE", | ||
"of_ipv4_t": "NONE", | ||
"of_ipv6_t": "NONE", | ||
"of_port_name_t": "NONE", | ||
"of_table_name_t": "NONE", | ||
"of_desc_str_t": "NONE", | ||
"of_serial_num_t": "NONE", | ||
"of_octets_t": "NONE", | ||
"of_port_no_t": "DEC", | ||
"of_port_desc_t": "NONE", | ||
"of_bsn_vport_t": "NONE", | ||
"of_bsn_vport_q_in_q_t": "NONE", | ||
"of_fm_cmd_t": "DEC", | ||
"of_wc_bmap_t": "HEX", | ||
"of_match_bmap_t": "HEX", | ||
"of_match_t": "NONE", | ||
"of_oxm_t": "NONE", | ||
"of_meter_features_t": "NONE", | ||
"of_bitmap_128_t": "NONE", | ||
} | ||
|
||
# Override oftype_to_base for certain field names | ||
field_to_base = { | ||
"eth_type": "HEX", | ||
"cookie": "HEX", | ||
"datapath_id": "HEX", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
:: # 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. | ||
:: | ||
-- Copyright 2013, Big Switch Networks, Inc. This library was generated | ||
-- by the LoxiGen Compiler. | ||
-- | ||
-- This program is free software: you can redistribute it and/or modify | ||
-- it under the terms of the GNU General Public License as published by | ||
-- the Free Software Foundation, either version 2 of the License, or | ||
-- (at your option) any later version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, | ||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
-- GNU General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License | ||
-- along with this program. If not, see <http://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
:: # 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. | ||
:: | ||
:: from loxi_ir import * | ||
:: from wireshark_gen import make_field_name | ||
:: attrs = [] | ||
:: if ofclass.virtual: attrs.append("virtual") | ||
:: if ofclass.superclass: attrs.append("child") | ||
:: if not ofclass.superclass: attrs.append("top-level") | ||
-- ${' '.join(attrs)} class ${ofclass.name} | ||
:: if ofclass.superclass: | ||
-- Child of ${ofclass.superclass} | ||
:: #endif | ||
:: if ofclass.virtual: | ||
-- Discriminator is ${ofclass.discriminator.name} | ||
:: #endif | ||
function ${name}(reader, subtree) | ||
:: for m in ofclass.members: | ||
:: if isinstance(m, OFPadMember): | ||
reader.skip(${m.length}) | ||
:: continue | ||
:: #endif | ||
:: field_name = make_field_name(version, ofclass.name, m.name) | ||
:: reader_name = "read_" + m.oftype.replace(')', '').replace('(', '_') | ||
${reader_name}(reader, ${version}, subtree, '${field_name}') | ||
:: #endfor | ||
return '${ofclass.name}' | ||
end |
Oops, something went wrong.