I'm resending the patches which appease pep8 fletcher checksum function for OSPF LSA checksum. refer to RFC1008.
Signed-off-by: Wataru ISHIDA <[email protected]> --- ryu/lib/packet/packet_utils.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ryu/lib/packet/packet_utils.py b/ryu/lib/packet/packet_utils.py index 9331472..e797e6e 100644 --- a/ryu/lib/packet/packet_utils.py +++ b/ryu/lib/packet/packet_utils.py @@ -97,3 +97,40 @@ def checksum_ip(ipvx, length, payload): buf = header + payload return checksum(buf) + +_MODX = 4102 + + +def fletcher_checksum(data, offset): + """ + Fletcher Checksum -- Refer to RFC1008 + + calling with offset == _FLETCHER_CHECKSUM_VALIDATE will validate the + checksum without modifying the buffer; a valid checksum returns 0. + """ + c0 = 0 + c1 = 0 + pos = 0 + length = len(data) + data = bytearray(data) + data[offset:offset+2] = [0]*2 + + while pos < length: + tlen = min(length - pos, _MODX) + for d in data[pos:pos+tlen]: + c0 += d + c1 += c0 + c0 %= 255 + c1 %= 255 + pos += tlen + + x = ((length - offset - 1) * c0 - c1) % 255 + if x <= 0: + x += 255 + y = 510 - c0 - x + if y > 255: + y -= 255 + + data[offset] = x + data[offset+1] = y + return (x << 8) | (y & 0xff) -- 1.8.1.2 ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
