[ovs-dev,V3,1/2] Makefiles: Generate datapath ovs key fields macros

Message ID 20190207164416.41555-2-elibr@mellanox.com
State Superseded
Headers show
Series
  • Do not rewrite fields with the same values as matched
Related show

Commit Message

Eli Britstein Feb. 7, 2019, 4:44 p.m.
Generate datapath ovs key fields macros as a pre-step of retrieving
field information, with no functional change.

Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
---
 .gitignore                              |  1 +
 build-aux/extract-odp-netlink-xmacros-h | 55 +++++++++++++++++++++++++++++++++
 include/automake.mk                     | 11 +++++--
 3 files changed, 64 insertions(+), 3 deletions(-)
 create mode 100755 build-aux/extract-odp-netlink-xmacros-h

Comments

0-day Robot Feb. 7, 2019, 5 p.m. | #1
Bleep bloop.  Greetings Eli Britstein, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line is 83 characters long (recommended limit is 79)
#69 FILE: build-aux/extract-odp-netlink-xmacros-h:34:
echo "/* Generated automatically from <include/odp-netlink.h> -- do not modify! */"

Lines checked: 117, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@bytheb.org

Thanks,
0-day Robot

Patch

diff --git a/.gitignore b/.gitignore
index 60e7818c3..9b9ea91c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,7 @@  cscope.*
 tags
 _debian
 odp-netlink.h
+odp-netlink-xmacros.h
 OvsDpInterface.h
 /.vagrant/
 testsuite.tmp.orig
diff --git a/build-aux/extract-odp-netlink-xmacros-h b/build-aux/extract-odp-netlink-xmacros-h
new file mode 100755
index 000000000..b91ba3a9a
--- /dev/null
+++ b/build-aux/extract-odp-netlink-xmacros-h
@@ -0,0 +1,55 @@ 
+#!/bin/bash
+
+hfile=$1
+
+function generate_fields_macros {
+    local struct_name=$1
+
+    # line_start is the line number where the definition of the struct begin
+    # line_end is the line number where the definition of the struct ends
+    line_start=`grep -nw $struct_name $hfile | grep { | cut -d ":" -f1`
+    num_lines=`tail -n +${line_start} $hfile | grep -n -m1 } | cut -d ":" -f1`
+    line_end=$((line_start+num_lines-1))
+
+
+    STRUCT=`echo $struct_name | tr [a-z] [A-Z]`
+    echo "#define __${STRUCT}_FIELDS \\"
+    # for all the field lines, including the terminating }, remove ";" and
+    # replace with a macro.
+    # 3 awk fields are for struct <struct name> <field_name>
+    # 2 awk fields are for <type> <field_name>
+    # else - terminating macro
+    awk -F ";" "NR>${line_start} && NR<=${line_end}"' {print $1}' $hfile |
+        awk '{
+            if (NF == 3)
+                print "    __OVS_KEY_FIELD(" $1,$2", " $3 ") \\";
+            else if (NF == 2)
+                print "    __OVS_KEY_FIELD(" $1", " $2 ") \\";
+            else
+                print "__OVS_KEY_FIELDS_END";
+            }'
+}
+
+
+echo "/* Generated automatically from <include/odp-netlink.h> -- do not modify! */"
+echo
+echo
+echo "#ifndef ODP_NETLINK_MACROS_H"
+echo "#define ODP_NETLINK_MACROS_H"
+echo
+echo "#define __OVS_KEY_FIELDS_END"
+echo
+
+generate_fields_macros "ovs_key_ethernet"
+generate_fields_macros "ovs_key_ipv4"
+generate_fields_macros "ovs_key_ipv6"
+generate_fields_macros "ovs_key_tcp"
+generate_fields_macros "ovs_key_udp"
+generate_fields_macros "ovs_key_sctp"
+generate_fields_macros "ovs_key_icmp"
+generate_fields_macros "ovs_key_icmpv6"
+generate_fields_macros "ovs_key_arp"
+generate_fields_macros "ovs_key_nd"
+
+echo
+echo "#endif"
diff --git a/include/automake.mk b/include/automake.mk
index 3f3ed1ccd..b54e77683 100644
--- a/include/automake.mk
+++ b/include/automake.mk
@@ -1,10 +1,15 @@ 
-BUILT_SOURCES += include/odp-netlink.h
+BUILT_SOURCES += include/odp-netlink.h include/odp-netlink-xmacros.h
 
 include/odp-netlink.h: datapath/linux/compat/include/linux/openvswitch.h \
                        build-aux/extract-odp-netlink-h
 	$(AM_V_GEN)sed -f $(srcdir)/build-aux/extract-odp-netlink-h < $< > $@
-EXTRA_DIST += build-aux/extract-odp-netlink-h
-CLEANFILES += include/odp-netlink.h
+
+include/odp-netlink-xmacros.h: include/odp-netlink.h \
+                              build-aux/extract-odp-netlink-xmacros-h
+	$(AM_V_GEN)bash -f $(srcdir)/build-aux/extract-odp-netlink-xmacros-h $< > $@
+
+EXTRA_DIST += build-aux/extract-odp-netlink-h build-aux/extract-odp-netlink-xmacros-h
+CLEANFILES += include/odp-netlink.h include/odp-netlink-xmacros.h
 
 include include/ovn/automake.mk
 include include/openflow/automake.mk