mirror of https://github.com/secdev/scapy.git
More Openflow tests
This commit is contained in:
parent
2b29648592
commit
d80bb3dc80
|
@ -16,7 +16,7 @@ import struct
|
|||
from scapy.fields import *
|
||||
from scapy.layers.l2 import *
|
||||
from scapy.layers.inet import *
|
||||
from scapy.compat import orb
|
||||
from scapy.compat import orb, raw
|
||||
|
||||
### If prereq_autocomplete is True then match prerequisites will be
|
||||
### automatically handled. See OFPMatch class.
|
||||
|
@ -95,7 +95,7 @@ class OFPPhyPort(Packet):
|
|||
FlagsField("peer", 0, 32, ofp_port_features) ]
|
||||
|
||||
def extract_padding(self, s):
|
||||
return "", s
|
||||
return b"", s
|
||||
|
||||
class OFPMatch(Packet):
|
||||
name = "OFP_MATCH"
|
||||
|
@ -127,7 +127,7 @@ class OFPMatch(Packet):
|
|||
ShortField("tp_dst", None) ]
|
||||
|
||||
def extract_padding(self, s):
|
||||
return "", s
|
||||
return b"", s
|
||||
|
||||
### with post_build we create the wildcards field bit by bit
|
||||
def post_build(self, p, pay):
|
||||
|
@ -398,7 +398,7 @@ class QueuePropertyPacketListField(PacketListField):
|
|||
def getfield(self, pkt, s):
|
||||
lst = []
|
||||
l = 0
|
||||
ret = ""
|
||||
ret = b""
|
||||
remain = s
|
||||
|
||||
while remain:
|
||||
|
@ -413,11 +413,11 @@ class QueuePropertyPacketListField(PacketListField):
|
|||
class OFPPacketQueue(Packet):
|
||||
|
||||
def extract_padding(self, s):
|
||||
return "", s
|
||||
return b"", s
|
||||
|
||||
def post_build(self, p, pay):
|
||||
if self.properties == []:
|
||||
p += str(OFPQTNone())
|
||||
p += raw(OFPQTNone())
|
||||
if self.len is None:
|
||||
l = len(p)+len(pay)
|
||||
p = p[:4] + struct.pack("!H", l) + p[6:]
|
||||
|
@ -439,7 +439,7 @@ class QueuePacketListField(PacketListField):
|
|||
def getfield(self, pkt, s):
|
||||
lst = []
|
||||
l = 0
|
||||
ret = ""
|
||||
ret = b""
|
||||
remain = s
|
||||
|
||||
while remain:
|
||||
|
@ -969,7 +969,7 @@ class OFPTStatsRequestTable(_ofp_header):
|
|||
class OFPTableStats(Packet):
|
||||
|
||||
def extract_padding(self, s):
|
||||
return "", s
|
||||
return b"", s
|
||||
|
||||
name = "OFP_TABLE_STATS"
|
||||
fields_desc = [ ByteField("table_id", 0),
|
||||
|
@ -1019,7 +1019,7 @@ class OFPTStatsRequestPort(_ofp_header):
|
|||
class OFPPortStats(Packet):
|
||||
|
||||
def extract_padding(self, s):
|
||||
return "", s
|
||||
return b"", s
|
||||
|
||||
name = "OFP_PORT_STATS"
|
||||
fields_desc = [ ShortEnumField("port_no", 0, ofp_port_no),
|
||||
|
|
|
@ -14,7 +14,7 @@ raw(ofm) == b'\x01\x02\x00\x08\x00\x00\x00\x00'
|
|||
ofm = OFPMatch(in_port=1, nw_tos=8)
|
||||
ofm = OFPMatch(raw(ofm))
|
||||
assert(ofm.wildcards1 == 0x1)
|
||||
ofm.wildcards2 == 0xfe
|
||||
ofm.wildcards2 == 0xee
|
||||
|
||||
= OpenFlow(), generic method test with OFPTEchoRequest()
|
||||
ofm = OFPTEchoRequest()
|
||||
|
@ -37,7 +37,7 @@ act2 = OFPATOutput(port='CONTROLLER')
|
|||
act3 = OFPATSetDlSrc(dl_addr='1a:d5:cb:4e:3c:64')
|
||||
ofm = OFPTFlowMod(priority=1000, match=mtc, flags='CHECK_OVERLAP', actions=[act1,act2,act3])
|
||||
raw(ofm)
|
||||
s = b'\x01\x0e\x00h\x00\x00\x00\x00\x00?\xc8\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\xc0\xa8*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe8\xff\xff\xff\xff\xff\xff\x00\x02\x00\x06\x00\x08\xc0\xa8*\x01\x00\x00\x00\x08\xff\xfd\xff\xff\x00\x04\x00\x10\x1a\xd5\xcbN<d\x00\x00\x00\x00\x00\x00'
|
||||
s = b'\x01\x0e\x00h\x00\x00\x00\x00\x00?\xc8\xed\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x08\x00\x00\x00\x00\x00\xc0\xa8*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe8\xff\xff\xff\xff\xff\xff\x00\x02\x00\x06\x00\x08\xc0\xa8*\x01\x00\x00\x00\x08\xff\xfd\xff\xff\x00\x04\x00\x10\x1a\xd5\xcbN<d\x00\x00\x00\x00\x00\x00'
|
||||
raw(ofm) == s
|
||||
|
||||
= OFPETBadRequest() containing a flow_mod with wrong table_id
|
||||
|
@ -55,6 +55,21 @@ assert(isinstance(dat, Ether))
|
|||
assert(isinstance(dat.payload, IP))
|
||||
isinstance(dat.payload.payload, ICMP)
|
||||
|
||||
= OFPTStatsReplyFlow()
|
||||
pkt = TCP()/OFPTStatsReplyFlow(flow_stats=[OFPFlowStats(actions=[OFPATSetTpSrc()])])
|
||||
pkt = TCP(raw(pkt))
|
||||
assert isinstance(pkt.flow_stats[0].actions[0], OFPATSetTpSrc)
|
||||
|
||||
= OFPTQueueGetConfigReply()
|
||||
pkt = TCP()/OFPTQueueGetConfigReply(queues=[OFPPacketQueue(properties=[OFPQTMinRate(rate=123)])])
|
||||
pkt = TCP(raw(pkt))
|
||||
assert pkt.queues[0].properties[0].rate == 123
|
||||
|
||||
= OFPETHelloFailed()
|
||||
pkt = OFPETHelloFailed(data=OFPTEchoRequest())
|
||||
pkt = OFPETHelloFailed(raw(pkt))
|
||||
assert isinstance(pkt.data, OFPTEchoRequest)
|
||||
|
||||
+ Layer bindings
|
||||
|
||||
= TCP()/OFPTStatsRequestDesc(), check default sport
|
||||
|
|
Loading…
Reference in New Issue