def utest(): p = scapy.Ether() / scapy.IP() / scapy.TCP() m = Mask(p) assert (m.pkt_match(p)) p1 = scapy.Ether() / scapy.IP() / scapy.TCP(sport=97) assert (not m.pkt_match(p1)) m.set_do_not_care_scapy(scapy.TCP, "sport") assert (not m.pkt_match(p1)) m.set_do_not_care_scapy(scapy.TCP, "chksum") assert (m.pkt_match(p1))
def utest(): p = scapy.Ether() / scapy.IP() / scapy.TCP() m = Mask(p) assert(m.pkt_match(p)) p1 = scapy.Ether() / scapy.IP() / scapy.TCP(sport=97) assert(not m.pkt_match(p1)) m.set_do_not_care_scapy(scapy.TCP, "sport") assert(not m.pkt_match(p1)) m.set_do_not_care_scapy(scapy.TCP, "chksum") assert(m.pkt_match(p1)) exp_pkt = "\x01\x02\x03\x04\x05\x06" pkt = "\x01\x00\x00\x04\x05\x06\x07\x08" m1 = Mask(exp_pkt, ignore_extra_bytes=True) m1.set_do_not_care(8, 16) assert(m1.pkt_match(pkt))
def test_tcp(self): import loxi.of12 as ofp self.maxDiff = None pkt = scapy.Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')/ \ scapy.IP(src='192.168.0.1', dst='192.168.0.2', tos=2 | (32 << 2), ttl=64)/ \ scapy.TCP(sport=1234, dport=80) expected = [ ofp.oxm.eth_dst([0x00, 0x01, 0x02, 0x03, 0x04, 0x05]), ofp.oxm.eth_src([0x00, 0x06, 0x07, 0x08, 0x09, 0x0a]), ofp.oxm.eth_type(0x0800), ofp.oxm.vlan_vid(ofp.OFP_VLAN_NONE), ofp.oxm.ip_proto(6), ofp.oxm.ip_dscp(32), ofp.oxm.ip_ecn(2), ofp.oxm.ipv4_src(0xc0a80001), ofp.oxm.ipv4_dst(0xc0a80002), ofp.oxm.tcp_src(1234), ofp.oxm.tcp_dst(80) ] result = parse.packet_to_flow_match_v3(pkt).oxm_list self.assertEquals([x.show() for x in expected], [x.show() for x in result])