summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-08-27 11:37:30 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-08-28 05:58:25 +0900
commit1241dafde4e64644e6d8a38cbec97d84d3789c3b (patch)
treedba2ed99fc72ee8e92c30683eaff6be4b9595fd9
parent2814763bb86cc136fa7882446cd14e9e6b2e5339 (diff)
packet lib: convert ip to use the checksum helper function
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/ipv4.py15
1 files changed, 2 insertions, 13 deletions
diff --git a/ryu/lib/packet/ipv4.py b/ryu/lib/packet/ipv4.py
index fa7c5250..cb5bc4e4 100644
--- a/ryu/lib/packet/ipv4.py
+++ b/ryu/lib/packet/ipv4.py
@@ -15,6 +15,7 @@
import struct
from . import packet_base
+from . import packet_utils
from . import udp
from ryu.ofproto import inet
@@ -56,18 +57,6 @@ class ipv4(packet_base.PacketBase):
return msg, ipv4.get_packet_type(proto)
- @staticmethod
- def carry_around_add(a, b):
- c = a + b
- return (c & 0xffff) + (c >> 16)
-
- def checksum(self, data):
- s = 0
- for i in range(0, len(data), 2):
- w = data[i] + (data[i + 1] << 8)
- s = self.carry_around_add(s, w)
- return ~s & 0xffff
-
def serialize(self, payload, prev):
hdr = bytearray().zfill(self.header_length * 4)
version = self.version << 4 | self.header_length
@@ -77,7 +66,7 @@ class ipv4(packet_base.PacketBase):
struct.pack_into(ipv4._PACK_STR, hdr, 0, version, self.tos,
self.total_length, self.identification, flags,
self.ttl, self.proto, 0, self.src, self.dst)
- self.csum = self.checksum(hdr)
+ self.csum = packet_utils.checksum(hdr)
struct.pack_into('H', hdr, 10, self.csum)
return hdr