wireshark: begin populating fields
diff --git a/wireshark_gen/__init__.py b/wireshark_gen/__init__.py
index 174abf8..c2de4a6 100644
--- a/wireshark_gen/__init__.py
+++ b/wireshark_gen/__init__.py
@@ -36,18 +36,20 @@
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 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)
+ fullname = make_field_name(wire_version, ofclass.name, m.name)
r.append(DissectorField(fullname, m.name, "UINT8", "DEC"))
return r
diff --git a/wireshark_gen/templates/_ofclass_dissector.lua b/wireshark_gen/templates/_ofclass_dissector.lua
index ae50d00..54b6749 100644
--- a/wireshark_gen/templates/_ofclass_dissector.lua
+++ b/wireshark_gen/templates/_ofclass_dissector.lua
@@ -26,6 +26,7 @@
:: # 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")
@@ -39,17 +40,12 @@
:: #endif
function ${name}(reader, subtree)
:: for m in ofclass.members:
-:: if isinstance(m, OFTypeMember):
- -- type ${m.name}
-:: elif isinstance(m, OFDiscriminatorMember):
- -- discriminator ${m.name}
-:: elif isinstance(m, OFDataMember):
- -- data ${m.name}
-:: elif isinstance(m, OFLengthMember):
- -- length ${m.name}
-:: elif isinstance(m, OFPadMember):
- -- pad
+:: 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
end
-
diff --git a/wireshark_gen/templates/_oftype_readers.lua b/wireshark_gen/templates/_oftype_readers.lua
new file mode 100644
index 0000000..d21d03a
--- /dev/null
+++ b/wireshark_gen/templates/_oftype_readers.lua
@@ -0,0 +1,54 @@
+:: # 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.
+
+function read_scalar(reader, subtree, field_name, length)
+ subtree:add(fields[field_name], reader.read(length))
+end
+
+function read_uint8_t(reader, version, subtree, field_name)
+ read_scalar(reader, subtree, field_name, 1)
+end
+
+function read_uint16_t(reader, version, subtree, field_name)
+ read_scalar(reader, subtree, field_name, 2)
+end
+
+function read_uint32_t(reader, version, subtree, field_name)
+ read_scalar(reader, subtree, field_name, 4)
+end
+
+function read_uint64_t(reader, version, subtree, field_name)
+ read_scalar(reader, subtree, field_name, 8)
+end
+
+function read_of_octets_t(reader, version, subtree, field_name)
+ subtree:add(fields[field_name], reader.read_all())
+end
+
+function read_list_of_hello_elem_t(reader, version, subtree, field_name)
+ -- TODO
+end
diff --git a/wireshark_gen/templates/openflow.lua b/wireshark_gen/templates/openflow.lua
index 120dfa3..16945d2 100644
--- a/wireshark_gen/templates/openflow.lua
+++ b/wireshark_gen/templates/openflow.lua
@@ -31,6 +31,8 @@
:: include('_ofreader.lua')
+:: include('_oftype_readers.lua')
+
p_of = Proto ("of", "OpenFlow")
local openflow_versions = {
@@ -76,7 +78,7 @@
:: for version, ofproto in ir.items():
:: for ofclass in ofproto.classes:
:: name = 'dissect_%s_v%d' % (ofclass.name, version)
-:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass)
+:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
:: if ofclass.superclass:
:: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator
:: discriminator_value = ofclass.member_by_name(discriminator.name).value
@@ -95,11 +97,6 @@
function dissect_of_message(buf, root)
local reader = OFReader.new(buf)
local subtree = root:add(p_of, buf(0))
- subtree:add(fields['of10.header.version'], reader.read(1))
- subtree:add(fields['of10.header.type'], reader.read(1))
- subtree:add(fields['of10.header.length'], reader.read(2))
- subtree:add(fields['of10.header.xid'], reader.read(4))
-
local version_val = buf(0,1):uint()
local type_val = buf(1,1):uint()
if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then