blob: f951bf828d190fd9d613ca428936c8d7d6347489 [file] [log] [blame]
Maros Marsalek45a42b52016-04-28 12:29:33 +02001#!/usr/bin/env python
2#
3# Copyright (c) 2016 Cisco and/or its affiliates.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at:
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Marek Gradzkid85036f2016-04-26 12:09:05 +020016import os, pprint
Maros Marsalek45a42b52016-04-28 12:29:33 +020017from os import removedirs
18
19
20def underscore_to_camelcase(name):
21 name = name.title().replace("_", "")
22 return name[0].lower() + name[1:]
23
24
25def underscore_to_camelcase_upper(name):
26 name = name.title().replace("_", "")
27 return name[0].upper() + name[1:]
28
29
30def remove_folder(folder):
31 """ Remove folder with all its files """
32 for root, dirs, files in os.walk(folder, topdown=False):
33 for name in files:
34 os.remove(os.path.join(root, name))
35 removedirs(folder)
36
37
38reply_suffixes = ("reply", "details", "l2fibtableentry")
39
40
41def is_reply(name):
42 return name.lower().endswith(reply_suffixes)
43
44
45def is_details(name):
46 return name.lower().endswith(reply_suffixes[1]) or name.lower().endswith(reply_suffixes[2])
47
48dump_suffix = "dump"
49
50
51def is_dump(name):
52 return name.lower().endswith(dump_suffix)
53
54
55def get_reply_suffix(name):
56 for reply_suffix in reply_suffixes:
57 if name.lower().endswith(reply_suffix):
58 if reply_suffix == reply_suffixes[2]:
59 # FIXME workaround for l2_fib_table_entry
60 return 'entry'
61 else:
62 return reply_suffix
63
64# http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html
65jni_2_java_type_mapping = {'jbyte': 'byte',
66 'jbyteArray': 'byte[]',
67 'jchar': 'char',
68 'jcharArray': 'char[]',
69 'jshort': 'short',
70 'jshortArray': 'short[]',
71 'jint': 'int',
72 'jintArray': 'int[]',
73 'jlong': 'long',
74 'jlongArray': 'long[]',
75 'jdouble': 'double',
76 'jdoubleArray': 'double[]',
77 'jfloat': 'float',
78 'jfloatArray': 'float[]',
79 'void': 'void',
80 'jstring': 'java.lang.String',
81 'jobject': 'java.lang.Object',
82 'jobjectArray': 'java.lang.Object[]'
83 }
84
85# https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html#type_signatures
86jni_2_signature_mapping = {'jbyte': 'B',
87 'jbyteArray': '[B',
88 'jchar': 'C',
89 'jcharArray': '[C',
90 'jshort': 'S',
91 'jshortArray': '[S',
92 'jint': 'I',
93 'jintArray': '[I',
94 'jlong': 'J',
95 'jlongArray': '[J',
96 'jdouble': 'D',
97 'jdoubleArray': '[D',
98 'jfloat': 'F',
99 'jfloatArray': '[F'
100 }
101
102# https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#Get_type_Field_routines
103jni_field_accessors = {
104 'jbyte': 'ByteField',
105 'jbyteArray': 'ObjectField',
106 'jchar': 'CharField',
107 'jcharArray': 'ObjectField',
108 'jshort': 'ShortField',
109 'jshortArray': 'ObjectField',
110 'jint': 'IntField',
111 'jintArray': 'ObjectField',
112 'jlong': 'LongField',
113 'jlongArray': 'ObjectField',
114 'jdouble': 'DoubleField',
115 'jdoubleArray': 'ObjectField',
116 'jfloat': 'FloatField',
117 'jfloatArray': 'ObjectField'
118}
119
120# TODO watch out for unsigned types
121# http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html
122vpp_2_jni_type_mapping = {'u8': 'jbyte', # fixme
123 'i8': 'jbyte',
124 'u16': 'jchar',
125 'i16': 'jshort',
126 'u32': 'jint', # fixme
127 'i32': 'jint',
128 'u64': 'jlong', # fixme
129 'i64': 'jlong',
130 'f64': 'jdouble'
131 }
132
133# vpe.api calls that do not follow naming conventions and have to be handled exceptionally when finding reply -> request mapping
134# FIXME in vpe.api
135unconventional_naming_rep_req = {
136 'cli_reply': 'cli_request',
137 'vnet_summary_stats_reply': 'vnet_get_summary_stats',
138 # This below is actually a sub-details callback. We cannot derive the mapping of dump request
139 # belonging to this sub-details from naming conventions. We need special mapping
140 'bridge_domain_sw_if_details': 'bridge_domain',
141 # This is standard dump call + details reply. However it's not called details but entry
142 'l2_fib_table_entry': 'l2_fib_table'
143 }
144
145#
146# FIXME no convention in the naming of events (notifications) in vpe.api
147notifications_message_suffixes = ("event", "counters")
148notification_messages = ["from_netconf_client", "from_netconf_server", "to_netconf_client", "to_netconf_server"]
149
150# messages that must be ignored. These messages are INSUFFICIENTLY marked as disabled in vpe.api
151# FIXME
152ignored_messages = ["is_address_reachable"]
153
154
155def is_notification(param):
156 return param.lower().endswith(notifications_message_suffixes) or param.lower() in notification_messages
157
158
159def is_ignored(param):
160 return param.lower() in ignored_messages
161
162
163def remove_reply_suffix(camel_case_name_with_suffix):
164 return remove_suffix(camel_case_name_with_suffix, get_reply_suffix(camel_case_name_with_suffix))
165
166
167def remove_suffix(camel_case_name_with_suffix, suffix):
168 suffix_length = len(suffix)
169 return camel_case_name_with_suffix[:-suffix_length] if suffix_length != 0 else camel_case_name_with_suffix
170
171
172def is_control_ping(camel_case_name_with_suffix):
173 return "controlping" in camel_case_name_with_suffix.lower()
Marek Gradzkid85036f2016-04-26 12:09:05 +0200174
175def api_message_to_javadoc(api_message):
176 """ Converts vpe.api message description to javadoc """
177 str = pprint.pformat(api_message, indent=4, width=120, depth=None)
178 return " * " + str.replace("\n", "\n * ")