summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-01-24 16:35:11 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2018-01-27 10:50:52 +0000
commitd1660e980031882627fc1aa42b650c219831dad4 (patch)
tree102c78a7b15c1ec686245431871b844f1e7ff1e8
parent568cc60b7097299cacb4341a4a70d8ef270f51b4 (diff)
jvpp: map VPP API enums to primitive types
Adding enum support (VPP-1153) requires JVPP generator refactoring (see: VPP-1154, VPP-1155, VPP-480) As a workaround we just update all the mappings used for VPP API definitions to JAVA and C/JNI translation. Change-Id: I9dff83e5199039a1a46a3d4685ce57cdeeeb2014 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
-rwxr-xr-xsrc/vpp-api/java/jvpp/gen/jvpp_gen.py10
-rw-r--r--src/vpp-api/java/jvpp/gen/jvppgen/enum_gen.py69
2 files changed, 76 insertions, 3 deletions
diff --git a/src/vpp-api/java/jvpp/gen/jvpp_gen.py b/src/vpp-api/java/jvpp/gen/jvpp_gen.py
index 79708abdf8a..2536b4eea42 100755
--- a/src/vpp-api/java/jvpp/gen/jvpp_gen.py
+++ b/src/vpp-api/java/jvpp/gen/jvpp_gen.py
@@ -29,6 +29,7 @@ from jvppgen import jvpp_future_facade_gen
from jvppgen import jvpp_impl_gen
from jvppgen import jvpp_c_gen
from jvppgen import util
+from jvppgen import enum_gen
# Invocation:
# ~/Projects/vpp/vpp-api/jvpp/gen$ mkdir -p java/io/fd/vpp/jvpp && cd java/io/fd/vpp/jvpp
@@ -88,6 +89,10 @@ os.chdir(work_dir)
for inputfile in args.inputfiles:
_cfg = json.load(open(cwd + "/" + inputfile, 'r'))
+ if 'enums' in cfg:
+ cfg['enums'].extend(_cfg['enums'])
+ else:
+ cfg['enums'] = _cfg['enums']
if 'types' in cfg:
cfg['types'].extend(_cfg['types'])
else:
@@ -184,11 +189,10 @@ future_package = 'future'
callback_facade_package = 'callfacade'
types_list, types_name = get_definitions(cfg['types'])
-
-types_gen.generate_types(types_list, plugin_package, types_package, args.inputfiles, logger)
-
func_list, func_name = get_definitions(cfg['messages'])
+enum_gen.generate_enums(cfg['enums'], args.inputfiles, logger)
+types_gen.generate_types(types_list, plugin_package, types_package, args.inputfiles, logger)
dto_gen.generate_dtos(func_list, base_package, plugin_package, plugin_name.title(), dto_package, args.inputfiles,
logger)
jvpp_impl_gen.generate_jvpp(func_list, base_package, plugin_package, plugin_name, dto_package, args.inputfiles, logger)
diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/enum_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/enum_gen.py
new file mode 100644
index 00000000000..51a74e678e2
--- /dev/null
+++ b/src/vpp-api/java/jvpp/gen/jvppgen/enum_gen.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2018 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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 License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import util
+import jni_gen
+
+
+def generate_enums(enum_list, inputfile, logger):
+ """
+ Generates Java representation of enum types defined in the provided JSON file.
+ """
+
+ if not enum_list:
+ logger.debug("Skipping enum generation (%s does not define enum types)." % inputfile)
+ return
+
+ logger.debug("Generating enums for %s" % inputfile)
+
+ for enum in enum_list:
+ enum_name = None
+ enum_type = None
+ for e in enum:
+ if isinstance(e, basestring):
+ enum_name = e
+ elif type(e) is dict and 'enumtype' in e:
+ enum_type = e['enumtype']
+
+ if not enum_name:
+ logger.warn("%s enum is missing name. Skipping" % enum)
+ continue
+
+ if not enum_type:
+ logger.warn("%s enum is missing value type. Skipping" % enum)
+ continue
+
+ # TODO(VPP-1153): add real enum support.
+ # But first refactor java api generation
+ # (either VPP-1154 or VPP-1155, see also VPP-480).
+
+ # As a workaround we just update all the mappings
+ # used for VPP API definitions to JAVA and C/JNI translation.
+ enum_array_type = enum_type + "[]"
+ type_name = "vl_api_" + enum_name + "_t"
+ array_type_name = type_name + "[]"
+ util.vpp_2_jni_type_mapping[type_name] = util.vpp_2_jni_type_mapping[enum_type]
+ util.vpp_2_jni_type_mapping[array_type_name] = util.vpp_2_jni_type_mapping[enum_array_type]
+ util.jni_2_java_type_mapping[type_name] = util.jni_2_java_type_mapping[enum_type]
+ util.jni_2_java_type_mapping[array_type_name] = util.jni_2_java_type_mapping[enum_array_type]
+ util.jni_2_signature_mapping[type_name] = util.jni_2_signature_mapping[enum_type]
+ util.jni_2_signature_mapping[array_type_name] = util.jni_2_signature_mapping[enum_array_type]
+ util.jni_field_accessors[type_name] = util.jni_field_accessors[enum_type]
+ util.jni_field_accessors[array_type_name] = util.jni_field_accessors[enum_array_type]
+ jni_gen.struct_setter_templates[type_name] = jni_gen.struct_setter_templates[enum_type]
+ jni_gen.struct_setter_templates[array_type_name] = jni_gen.struct_setter_templates[enum_array_type]
+ jni_gen.dto_field_setter_templates[type_name] = jni_gen.dto_field_setter_templates[enum_type]
+ jni_gen.dto_field_setter_templates[array_type_name] = jni_gen.dto_field_setter_templates[enum_array_type]
#dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __included_vnet_l2_input_classify_h__
#define __included_vnet_l2_input_classify_h__

#include <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vnet/pg/pg.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/ethernet/packet.h>
#include <vnet/ip/ip_packet.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/ip/ip6_packet.h>
#include <vlib/cli.h>
#include <vnet/l2/l2_input.h>
#include <vnet/l2/l2_output.h>
#include <vnet/l2/feat_bitmap.h>
#include <vppinfra/error.h>
#include <vppinfra/hash.h>
#include <vppinfra/cache.h>

#include <vnet/classify/vnet_classify.h>

typedef enum
{
  L2_INPUT_CLASSIFY_NEXT_DROP,
  L2_INPUT_CLASSIFY_NEXT_ETHERNET_INPUT,
  L2_INPUT_CLASSIFY_NEXT_IP4_INPUT,
  L2_INPUT_CLASSIFY_NEXT_IP6_INPUT,
  L2_INPUT_CLASSIFY_NEXT_LI,
  L2_INPUT_CLASSIFY_N_NEXT,
} l2_input_classify_next_t;

typedef enum
{
  L2_INPUT_CLASSIFY_TABLE_IP4,
  L2_INPUT_CLASSIFY_TABLE_IP6,
  L2_INPUT_CLASSIFY_TABLE_OTHER,
  L2_INPUT_CLASSIFY_N_TABLES,
} l2_input_classify_table_id_t;

typedef enum
{
  L2_OUTPUT_CLASSIFY_NEXT_DROP,
  L2_OUTPUT_CLASSIFY_N_NEXT,
} l2_output_classify_next_t;

typedef enum
{
  L2_OUTPUT_CLASSIFY_TABLE_IP4,
  L2_OUTPUT_CLASSIFY_TABLE_IP6,
  L2_OUTPUT_CLASSIFY_TABLE_OTHER,
  L2_OUTPUT_CLASSIFY_N_TABLES,
} l2_output_classify_table_id_t;

typedef struct _l2_classify_main
{
  /* Next nodes for each feature */
  u32 feat_next_node_index[32];

  /* Per-address-family classifier table vectors */
  u32 *classify_table_index_by_sw_if_index[L2_INPUT_CLASSIFY_N_TABLES];

  /* Next nodes for features and output interfaces */
  l2_output_next_nodes_st next_nodes;

  /* convenience variables */
  vlib_main_t *vlib_main;
  vnet_main_t *vnet_main;
  vnet_classify_main_t *vnet_classify_main;
} l2_input_classify_main_t;

typedef struct _l2_classify_main l2_output_classify_main_t;

extern l2_input_classify_main_t l2_input_classify_main;
extern vlib_node_registration_t l2_input_classify_node;

extern l2_output_classify_main_t l2_output_classify_main;
extern vlib_node_registration_t l2_output_classify_node;

void vnet_l2_input_classify_enable_disable (u32 sw_if_index,
					    int enable_disable);

int vnet_l2_input_classify_set_tables (u32 sw_if_index, u32 ip4_table_index,
				       u32 ip6_table_index,
				       u32 other_table_index);

void vnet_l2_output_classify_enable_disable (u32 sw_if_index,
					     int enable_disable);

int vnet_l2_output_classify_set_tables (u32 sw_if_index, u32 ip4_table_index,
					u32 ip6_table_index,
					u32 other_table_index);

#endif /* __included_vnet_l2_input_classify_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */