Add an individual conversion process to ethernet.py and ipv4.py

Individual conversion is needed to the variable it cannot be
understood that does not conversion, like MAC address or IP address.

and it is required for other packet libraries.


Signed-off-by: WATANABE Fumitaka <watanabe.fumit...@nttcom.co.jp>
---
 ryu/lib/packet/ethernet.py |    6 ++++++
 ryu/lib/packet/ipv4.py     |    8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/ryu/lib/packet/ethernet.py b/ryu/lib/packet/ethernet.py
index 7bc18ef..73185f2 100644
--- a/ryu/lib/packet/ethernet.py
+++ b/ryu/lib/packet/ethernet.py
@@ -17,6 +17,7 @@ import struct
 from . import packet_base
 from . import vlan
 from . import mpls
+from ryu.lib import mac
 from ryu.ofproto import ether


@@ -45,6 +46,11 @@ class ethernet(packet_base.PacketBase):
         self.ethertype = ethertype
         self.length = ethernet._MIN_LEN

+        # for convert to string
+        self._STR_CONVERT = {'dst': mac.haddr_to_str,
+                             'src': mac.haddr_to_str,
+                             'ethertype': lambda value: '0x%04x' % value}
+
     @classmethod
     def parser(cls, buf):
         dst, src, ethertype = struct.unpack_from(cls._PACK_STR, buf)
diff --git a/ryu/lib/packet/ipv4.py b/ryu/lib/packet/ipv4.py
index 09ed734..daba81d 100644
--- a/ryu/lib/packet/ipv4.py
+++ b/ryu/lib/packet/ipv4.py
@@ -20,6 +20,7 @@ from . import packet_utils
 from . import icmp
 from . import udp
 from . import tcp
+from ryu.lib import ip
 from ryu.ofproto import inet


@@ -83,6 +84,13 @@ class ipv4(packet_base.PacketBase):
         self.length = header_length * 4
         self.option = option

+        # for convert to string
+        self._STR_CONVERT = {'identification': hex,
+                             'flags': lambda value: '0x%02x' % value,
+                             'csum': hex,
+                             'src': ip.ipv4_to_str,
+                             'dst': ip.ipv4_to_str}
+
     @classmethod
     def parser(cls, buf):
         (version, tos, total_length, identification, flags, ttl, proto, csum,
-- 1.7.10.4


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to