PERFORCE change 143069 for review
Victor Hugo Bilouro
bilouro at FreeBSD.org
Sat Jun 7 05:15:30 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=143069
Change 143069 by bilouro at bilouro_tcptest on 2008/06/07 05:14:42
3wayhandshake and finalization DONE.
Simple tcb covered 3wayhandshake and finalization fine.
Several asserts created (e.g.
* assertSequencePresent/assertExpectedSequence
* assertAcknowledgmentPresent/assertExpectedAck...
* assertSyn, assertFin
Several "creates" created (e.g.
* create[ip|tcp|syn|fin]
Next Steps
* create some pushs
* see tcb needs for that
Affected files ...
.. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/cthreewayhandshake_nooptions.py#3 edit
Differences ...
==== //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/cthreewayhandshake_nooptions.py#3 (text+ko) ====
@@ -42,7 +42,6 @@
class TestThreeWayHandshakeWithoutAnyOptions(unittest.TestCase):
"""This class tests the threeway handshake without any options"""
-
def setUp(self):
"""
As it's the first test, I will use this method as a simple TCB.
@@ -93,19 +92,20 @@
def testTestThreeWayHandshakeWithoutAnyOptions(self):
"""active open - three way handshake"""
#RFC793-P31-p1
- #THISSIDE
-
+ #Reference to 3way handshake
#
#Sendind SYN
#
#THISSIDE
- (ipsyn, tcpsyn) = createsyn(self, self.tcb, self.tcb.thisside, self.tcb.thatside)
+ (ipsyn, tcpsyn) = createsyn(self, self.tcb, self.tcb.thisside, \
+ self.tcb.thatside)
createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.tcb.thisside, \
self.tcb.thatside)
#THATHSIDE
- #Receiving SYN (unfurtunately this time we are receiving from the same board)
+ #Receiving SYN (unfurtunately this time we are receiving from
+ #the same board)
(ipsynreceived, tcpsynreceived) = receive(self, self.tcb, self.tcb.thatside, \
self.tcb.thisside)
@@ -118,34 +118,18 @@
#Receiving SYN+ACK
#
#THISSIDE
- #Receivinig SYN + ACK
- (ipsynack, tcpsynack) = receive(self, self.tcb, self.tcb.thisside, self.tcb.thatside)
+ #Receivinig SYN + ACK
+ (ipsynack, tcpsynack) = receive(self, self.tcb, self.tcb.thisside, \
+ self.tcb.thatside)
- #test conformance of header fields (todo)
+ #Some blackmagic to use assertSequenceAcknowledgmentOK at SYN
+ self.tcb.tcpsequence[ self.tcb.thatside ] = tcpsynack.sequence
+ assertSequenceAcknowledgmentOK(self, self.tcb, tcpsynack, \
+ self.tcb.thisside, self.tcb.thatside)
+
-
- #RFC793-P24-p1
- #A fundamental notion in the design is that every octet of data sent
- #over a TCP connection has a sequence number.
- #
- self.assertNotEqual(tcpsynack.sequence, 0)
- self.assertNotEqual(tcpsynack.sequence, None)
-
- #RFC793-P27-p5~P28-p2
- #As we are testing 3wayhandshake it must be SYN+ACK
- #
- #self.assertEqual(tcpsynack.syn,1)
- self.failIf(tcpsynack.syn < 1)
- self.failIf(tcpsynack.ack < 1)
-
- #RFC793-P16-p2
- #Acknowledgment Number, value of the next sequence number the sender of
- #the segment is expecting to receive
- #
- self.assertEqual(tcpsynack.ack_number, self.tcb.tcpsequence[ self.tcb.thisside ])
-
- #OK Its a SYN+ACK
- self.tcb.tcpsequence[ self.tcb.thatside ] = tcpsynack.sequence + 1
+ #OK Its a SYN+ACK --> SYN consumes a sequence
+ self.tcb.tcpsequence[ self.tcb.thatside ] = tcpsynack.sequence + 1
print tcpsynack
@@ -153,46 +137,143 @@
#Sending ACK
#
#THISSIDE
- (ipack, tcpack) = createip(self, self.tcb, self.tcb.thisside, self.tcb.thatside)
+ (ipack, tcpack) = createip(self, self.tcb, self.tcb.thisside, \
+ self.tcb.thatside)
+
createwritepacket(self, self.tcb, ipack, tcpack, self.tcb.thisside, \
self.tcb.thatside)
print tcpack
#THATHSIDE
#Receiving SYN (unfurtunately this time we are receiving from the same board)
- #(ipackreceived, tcpackreceived) = receive(self, self.tcb, self.tcb.thatside, \
- # self.tcb.thisside)
- #pcs is assigning values different then 0 and 1 to tcpflags
+ (ipackreceived, tcpackreceived) = receive(self, self.tcb, self.tcb.thatside, \
+ self.tcb.thisside)
+ #Different values then 0 and 1 to tcpflags TODO
#self.assertEqual(ipack, ipackreceived)
#self.assertEqual(tcpack, tcpackreceived)
+
#
#Sending FIN
#
#THISSIDE
- (ipfin, tcpfin) = createip(self, self.tcb, self.tcb.thisside, self.tcb.thatside)
-
- tcpfin.fin=1
- self.tcb.tcpsequence[ self.tcb.thisside ] += 1
-
+ (ipfin, tcpfin) = createfin(self, self.tcb, self.tcb.thisside, self.tcb.thatside)
createwritepacket(self, self.tcb, ipfin, tcpfin, self.tcb.thisside, \
self.tcb.thatside)
print tcpfin
-
+ #THATHSIDE
+ #Receiving SYN (unfurtunately this time we are receiving from the same board)
+ (ipfinreceived, tcpfinreceived) = receive(self, self.tcb, self.tcb.thatside, \
+ self.tcb.thisside)
+ #Different values then 0 and 1 to tcpflags TODO
+ #self.assertEqual(ipfin, ipfinreceived)
+ #self.assertEqual(tcpfin, tcpfinreceived)
+
#
- #Receiving ACK
+ #Receiving ACK from FIN sent
#
- #OK - this is enougth...
- #reduce code redundance (fasttodo)
+
+ #THISSIDE
+ #Receiving ACK
+ (ipfinack, tcpfinack) = receive(self, self.tcb, self.tcb.thisside, self.tcb.thatside)
+ assertSequenceAcknowledgmentOK(self, self.tcb, tcpfinack, self.tcb.thisside, self.tcb.thatside)
+
+ print tcpfinack
+
#
#Receiving FIN
#
+ #test if FIN was sent in the same segment
+ if (tcpfinack.fin == None or tcpfinack.fin == 0):
+
+ #TODO same attribute used (ipfinack, tcpfinack)
+ (ipfinack, tcpfinack) = receive(self, self.tcb, self.tcb.thisside,\
+ self.tcb.thatside)
+ assertSequenceAcknowledgmentOK(self, self.tcb, tcpfinack, \
+ self.tcb.thisside, self.tcb.thatside)
+
+ assertFin(self, tcpfinack)
+ print tcpfinack
+
+ #Fin consumes a sequence
+ self.tcb.tcpsequence[ self.tcb.thatside ] += 1
+
#
#Sending ACK
#
+ #THISSIDE
+ (ipackfin, tcpackfin) = createip(self, self.tcb, self.tcb.thisside,
+ self.tcb.thatside)
+ createwritepacket(self, self.tcb, ipackfin, tcpackfin, \
+ self.tcb.thisside, self.tcb.thatside)
+ print tcpackfin
+
+ #THATHSIDE
+ #Receiving SYN (receiving from the same board)
+ (ipackfinreceived, tcpackfinreceived) = receive(self, self.tcb, \
+ self.tcb.thatside, self.tcb.thisside)
+
+ #Different values then 0 and 1 to tcpflags TODO
+ #self.assertEqual(ipackfin, ipackfinreceived)
+ #self.assertEqual(tcpackfin, tcpackfinreceived)
+
+
+
+def assertAcknowledgmentPresent(self, tcp):
+ """RFC??
+ ...ack must be present in every packet since step #2 of 3wayhand
+ """
+ self.failIf(tcp.ack < 1)
+ self.assertNotEqual(tcp.ack_number, 0)
+ self.assertNotEqual(tcp.ack_number, None)
+
+def assertSynPresent(self, tcp):
+ """
+ """
+ self.failIf(tcp.syn < 1)
+ assertSequencePresent(self, tcp)
+
+def assertSequencePresent(self, tcp):
+ """RFC793-P24-p1
+ A fundamental notion in the design is that every octet of data sent
+ over a TCP connection has a sequence number.
+ """
+ self.assertNotEqual(tcp.sequence, 0)
+ self.assertNotEqual(tcp.sequence, None)
+
+def assertExpectedSequence(self, tcb, tcp, from_, to):
+ """RFC??
+ """
+ self.assertEqual(tcp.sequence, tcb.tcpsequence[ to ])
+
+def assertExpectedAcknowledgment(self, tcb, tcp, from_, to):
+ """RFC793-P16-p2
+ Acknowledgment Number, value of the next sequence number the sender of
+ the segment is expecting to receive
+ """
+ self.assertEqual(tcp.ack_number, tcb.tcpsequence[ from_ ])
+
+def assertSequenceAcknowledgmentOK(self, tcb, tcp, from_, to):
+
+ #RFC793-P24-p1
+ assertSequencePresent(self, tcp)
+ #RFC TODO
+ assertAcknowledgmentPresent(self, tcp)
+ #RFC793-P16-p2
+ assertExpectedAcknowledgment(self, tcb, tcp, from_, to)
+ #RFC TODO
+ assertExpectedSequence(self, tcb, tcp, from_, to)
+
+
+def assertFin(self, tcp):
+ """is fin flag on?
+ """
+ self.failIf(tcp.fin<0)
+
+
def createsyn(self, tcb, from_, to):
"""Create tcp syn flag expertise"""
@@ -205,6 +286,16 @@
return (ip, tcp)
+def createfin(self, tcb, from_, to):
+ """Create tcp fin flag expertise"""
+
+ (ip, tcp) = createip(self, tcb, from_, to)
+
+ #business
+ tcp.fin = 1
+ tcb.tcpsequence[ from_ ] += 1
+
+ return (ip, tcp)
def createip(self, tcb, from_, to):
"""Create ip packet
@@ -278,6 +369,16 @@
return (ip, tcp)
+def createethernet(self, tcb, from_, to):
+ """Create ethernet header"""
+ ether1 = ethernet.ethernet()
+ ether1.src = tcb.ether[ from_ ]
+ ether1.dst = tcb.ether[ to ]
+ ether1.type = 0x800
+
+ return ether1
+
+
def createwritepacket(self, tcb, ip, tcp, from_, to):
ether = createethernet(self, tcb, from_, to)
@@ -288,18 +389,8 @@
packet = pcs.Chain([ ether, ip, tcp ])
tcb.output[ from_ ].write(packet.bytes, len(packet.bytes))
+
-
-def createethernet(self, tcb, from_, to):
- """Create ethernet header"""
- ether1 = ethernet.ethernet()
- ether1.src = tcb.ether[ from_ ]
- ether1.dst = tcb.ether[ to ]
- ether1.type = 0x800
-
- return ether1
-
-
def tcp_cksum(self, ip, data = ""): #TODO: add this method to pcs tcp.py
"""return tcpv4 checksum"""
import struct
@@ -347,3 +438,4 @@
if __name__ == '__main__':
unittest.main()
+
More information about the p4-projects
mailing list