From: "Henkel, Michael" <michael.hen...@hp.com>

Signed-off-by: FUJITA Tomonori <fujita.tomon...@lab.ntt.co.jp>
---
 ryu/lib/packet/ipv6.py |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 ryu/lib/packet/tcp.py  |    6 ++++-
 ryu/lib/packet/vlan.py |    2 ++
 3 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 ryu/lib/packet/ipv6.py

diff --git a/ryu/lib/packet/ipv6.py b/ryu/lib/packet/ipv6.py
new file mode 100644
index 0000000..8fc9d0d
--- /dev/null
+++ b/ryu/lib/packet/ipv6.py
@@ -0,0 +1,67 @@
+# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
+#
+# 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 struct
+import socket
+from . import packet_base
+from . import packet_utils
+from . import tcp
+from ryu.ofproto import inet
+
+
+class ipv6(packet_base.PacketBase):
+    _PACK_STR = '!IHBB16s16s'
+    _MIN_LEN = struct.calcsize(_PACK_STR)
+
+    def __init__(self, version, traffic_class, flow_label, payload_length,
+                 nxt, hop_limit, src, dst):
+        super(ipv6, self).__init__()
+        self.version = version
+        self.traffic_class = traffic_class
+        self.flow_label = flow_label
+        self.payload_length = payload_length
+        self.nxt = nxt
+        self.hop_limit = hop_limit
+        self.src = src
+        self.dst = dst
+        self.length = 40
+
+    @classmethod
+    def parser(cls, buf):
+        (v_tc_flow, plen, nxt, hlim, src, dst) = struct.unpack_from(
+            cls._PACK_STR, buf)
+        version = v_tc_flow >> 28
+        traffic_class = (v_tc_flow >> 20) & 0xff
+        flow_label = v_tc_flow & 0xfffff
+        payload_length = plen
+        hop_limit = hlim
+        msg = cls(version, traffic_class, flow_label, payload_length,
+                 nxt, hop_limit, src, dst)
+
+        if msg.length > ipv6._MIN_LEN:
+            msg.option = buf[ipv6._MIN_LEN:msg.length]
+
+        return msg, ipv6.get_packet_type(nxt)
+
+    def serialize(self, payload, prev):
+        hdr = bytearray(40)
+        v_tc_flow = (self.version << 28 | self.traffic_class << 20 |
+                     self.flow_label << 12)
+        struct.pack_into(ipv6._PACK_STR, hdr, 0, v_tc_flow,
+                         self.payload_length, self.nxt, self.hop_limit,
+                         self.src, self.dst)
+        return hdr
+
+ipv6.register_packet_type(tcp.tcp, inet.IPPROTO_TCP)
diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py
index 81c7933..bd3442d 100644
--- a/ryu/lib/packet/tcp.py
+++ b/ryu/lib/packet/tcp.py
@@ -66,7 +66,11 @@ class tcp(packet_base.PacketBase):
 
         if self.csum == 0:
             length = self.length + len(payload)
-            ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 6, length)
+            if prev.version == 4:
+                ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 6, length)
+            elif prev.version == 6:
+                ph = struct.pack('!16s16sBBH', prev.src, prev.dst, 0, 6,
+                                 length)
             f = ph + h + payload
             if len(f) % 2:
                 f += '\x00'
diff --git a/ryu/lib/packet/vlan.py b/ryu/lib/packet/vlan.py
index fba8394..164241e 100644
--- a/ryu/lib/packet/vlan.py
+++ b/ryu/lib/packet/vlan.py
@@ -17,6 +17,7 @@ import struct
 from . import packet_base
 from . import arp
 from . import ipv4
+from . import ipv6
 from . import lldp
 from ryu.ofproto import ether
 from ryu.ofproto.ofproto_parser import msg_pack_into
@@ -48,4 +49,5 @@ class vlan(packet_base.PacketBase):
 
 vlan.register_packet_type(arp.arp, ether.ETH_TYPE_ARP)
 vlan.register_packet_type(ipv4.ipv4, ether.ETH_TYPE_IP)
+vlan.register_packet_type(ipv6.ipv6, ether.ETH_TYPE_IPV6)
 vlan.register_packet_type(lldp.lldp, ether.ETH_TYPE_LLDP)
-- 
1.7.10.4


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to