aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/L2Util.py
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2017-08-14 16:25:46 +0200
committerTibor Frank <tifrank@cisco.com>2017-10-11 13:45:40 +0000
commitbdfca054d8425a57496cca8308da36c118b5340f (patch)
tree4fd5627975df0ac3fbd35bab64ba6bd493084919 /resources/libraries/python/L2Util.py
parent66039913f070f4bb81e10f6ed503e0f2242ff70d (diff)
CSIT-778: Add mac-ip binding acl l2bd perf test
Change-Id: Iaced68458b0e4070f861be7854ee428ae8ca4e13 Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources/libraries/python/L2Util.py')
-rw-r--r--resources/libraries/python/L2Util.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py
index a909e8611b..6b8bc042e3 100644
--- a/resources/libraries/python/L2Util.py
+++ b/resources/libraries/python/L2Util.py
@@ -13,6 +13,8 @@
"""L2 Utilities Library."""
+from textwrap import wrap
+
from robot.api.deco import keyword
from resources.libraries.python.topology import Topology
@@ -24,6 +26,30 @@ class L2Util(object):
"""Utilities for l2 configuration."""
@staticmethod
+ def mac_to_int(mac_str):
+ """Convert MAC address from string format (e.g. 01:02:03:04:05:06) to
+ integer representation (1108152157446).
+
+ :param mac_str: MAC address in string representation.
+ :type mac_str: str
+ :returns: Integer representation of MAC address.
+ :rtype: int
+ """
+ return int(mac_str.replace(':', ''), 16)
+
+ @staticmethod
+ def int_to_mac(mac_int):
+ """Convert MAC address from integer representation (e.g. 1108152157446)
+ to string format (01:02:03:04:05:06).
+
+ :param mac_int: MAC address in integer representation.
+ :type mac_int: str
+ :returns: String representation of MAC address.
+ :rtype: int
+ """
+ return ':'.join(wrap("{:012x}".format(mac_int), width=2))
+
+ @staticmethod
def vpp_add_l2fib_entry(node, mac, interface, bd_id):
""" Create a static L2FIB entry on a vpp node.
>lex_tokens_by_name; /* Hash mapping c string keyword name to token index. */ uword *lex_keywords; vlib_lex_token_t *pushback_vector; i32 pushback_sp; u32 current_table_index; uword current_token_value; uword current_number_base; /* Input string we are lex-ing. */ u8 *input_vector; /* Current index into input vector. */ u32 current_index; /* Re-used vector for forming token strings and hashing them. */ u8 *token_buffer; } vlib_lex_main_t; extern vlib_lex_main_t vlib_lex_main; always_inline void vlib_lex_cleanup_token (vlib_lex_token_t * t) { if (t->token == VLIB_LEX_word) { u8 *tv = t->value.as_pointer; vec_free (tv); } } u16 vlib_lex_add_table (char *name); void vlib_lex_get_token (vlib_lex_main_t * lm, vlib_lex_token_t * result); u16 vlib_lex_add_token (vlib_lex_main_t * lm, char *token_name); void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action, u16 token, u32 next_table_index); void vlib_lex_reset (vlib_lex_main_t * lm, u8 * input_vector); format_function_t format_vlib_lex_token; #endif /* included_vlib_lex_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */