Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 1 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 2 | # Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | """ |
| 5 | Wrap scapy to satisfy pylint |
| 6 | """ |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 7 | from oftest import config |
Rich Lane | 720eaf2 | 2013-08-09 18:00:45 -0700 | [diff] [blame] | 8 | import sys |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 9 | |
| 10 | try: |
Rich Lane | 024f9d5 | 2013-08-12 15:56:39 -0700 | [diff] [blame] | 11 | import scapy.config |
| 12 | import scapy.route |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 13 | import scapy.layers.l2 |
| 14 | import scapy.layers.inet |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 15 | if not config["disable_ipv6"]: |
| 16 | import scapy.route6 |
| 17 | import scapy.layers.inet6 |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 18 | except ImportError: |
| 19 | sys.exit("Need to install scapy for packet parsing") |
| 20 | |
| 21 | Ether = scapy.layers.l2.Ether |
| 22 | LLC = scapy.layers.l2.LLC |
| 23 | SNAP = scapy.layers.l2.SNAP |
| 24 | Dot1Q = scapy.layers.l2.Dot1Q |
| 25 | IP = scapy.layers.inet.IP |
| 26 | IPOption = scapy.layers.inet.IPOption |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 27 | ARP = scapy.layers.inet.ARP |
| 28 | TCP = scapy.layers.inet.TCP |
| 29 | UDP = scapy.layers.inet.UDP |
| 30 | ICMP = scapy.layers.inet.ICMP |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 31 | |
macauley_cheng | eadac7a | 2015-08-31 15:19:04 +0800 | [diff] [blame^] | 32 | |
macauley | ca2752d | 2015-07-27 17:41:14 +0800 | [diff] [blame] | 33 | from scapy.fields import * |
| 34 | from scapy.packet import * |
| 35 | |
| 36 | class ThreeBytesField(X3BytesField, ByteField): |
| 37 | def i2repr(self, pkt, x): |
| 38 | return ByteField.i2repr(self, pkt, x) |
| 39 | |
| 40 | class VXLAN(Packet): |
| 41 | name = "VXLAN" |
| 42 | fields_desc = [ FlagsField("flags", 0x08, 8, ['R', 'R', 'R', 'I', 'R', 'R', 'R', 'R']), |
| 43 | X3BytesField("reserved1", 0x000000), |
| 44 | ThreeBytesField("vni", 0), |
| 45 | XByteField("reserved2", 0x00)] |
| 46 | |
| 47 | def mysummary(self): |
| 48 | return self.sprintf("VXLAN (vni=%VXLAN.vni%)") |
| 49 | |
| 50 | bind_layers(UDP, VXLAN, dport=4789) |
| 51 | bind_layers(VXLAN, Ether) |
| 52 | |
macauley_cheng | eadac7a | 2015-08-31 15:19:04 +0800 | [diff] [blame^] | 53 | |
| 54 | class MPLS(Packet): |
| 55 | name = "MPLS" |
| 56 | fields_desc = [ BitField("label", 3, 20), |
| 57 | BitField("cos", 0, 3), |
| 58 | BitField("s", 1, 1), |
| 59 | ByteField("ttl", 0) ] |
| 60 | |
| 61 | bind_layers(Ether, MPLS, type=0x8847) |
| 62 | |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 63 | if not config["disable_ipv6"]: |
| 64 | IPv6 = scapy.layers.inet6.IPv6 |
| 65 | ICMPv6Unknown = scapy.layers.inet6.ICMPv6Unknown |
| 66 | ICMPv6EchoRequest = scapy.layers.inet6.ICMPv6EchoRequest |