Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 17 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 18 | # Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University |
| 19 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 20 | """ |
| 21 | Wrap scapy to satisfy pylint |
| 22 | """ |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 23 | from oftest import config |
Rich Lane | 720eaf2 | 2013-08-09 18:00:45 -0700 | [diff] [blame] | 24 | import sys |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 25 | |
| 26 | try: |
Rich Lane | 024f9d5 | 2013-08-12 15:56:39 -0700 | [diff] [blame] | 27 | import scapy.config |
| 28 | import scapy.route |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 29 | import scapy.layers.l2 |
| 30 | import scapy.layers.inet |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 31 | if not config["disable_ipv6"]: |
| 32 | import scapy.route6 |
| 33 | import scapy.layers.inet6 |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 34 | except ImportError: |
| 35 | sys.exit("Need to install scapy for packet parsing") |
| 36 | |
| 37 | Ether = scapy.layers.l2.Ether |
| 38 | LLC = scapy.layers.l2.LLC |
| 39 | SNAP = scapy.layers.l2.SNAP |
| 40 | Dot1Q = scapy.layers.l2.Dot1Q |
| 41 | IP = scapy.layers.inet.IP |
| 42 | IPOption = scapy.layers.inet.IPOption |
Rich Lane | a68176f | 2013-08-09 17:41:05 -0700 | [diff] [blame] | 43 | ARP = scapy.layers.inet.ARP |
| 44 | TCP = scapy.layers.inet.TCP |
| 45 | UDP = scapy.layers.inet.UDP |
| 46 | ICMP = scapy.layers.inet.ICMP |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 47 | |
macauley_cheng | eadac7a | 2015-08-31 15:19:04 +0800 | [diff] [blame] | 48 | |
macauley | ca2752d | 2015-07-27 17:41:14 +0800 | [diff] [blame] | 49 | from scapy.fields import * |
| 50 | from scapy.packet import * |
| 51 | |
| 52 | class ThreeBytesField(X3BytesField, ByteField): |
| 53 | def i2repr(self, pkt, x): |
| 54 | return ByteField.i2repr(self, pkt, x) |
| 55 | |
| 56 | class VXLAN(Packet): |
| 57 | name = "VXLAN" |
| 58 | fields_desc = [ FlagsField("flags", 0x08, 8, ['R', 'R', 'R', 'I', 'R', 'R', 'R', 'R']), |
| 59 | X3BytesField("reserved1", 0x000000), |
| 60 | ThreeBytesField("vni", 0), |
| 61 | XByteField("reserved2", 0x00)] |
| 62 | |
| 63 | def mysummary(self): |
| 64 | return self.sprintf("VXLAN (vni=%VXLAN.vni%)") |
| 65 | |
| 66 | bind_layers(UDP, VXLAN, dport=4789) |
| 67 | bind_layers(VXLAN, Ether) |
| 68 | |
macauley_cheng | eadac7a | 2015-08-31 15:19:04 +0800 | [diff] [blame] | 69 | |
| 70 | class MPLS(Packet): |
| 71 | name = "MPLS" |
| 72 | fields_desc = [ BitField("label", 3, 20), |
| 73 | BitField("cos", 0, 3), |
| 74 | BitField("s", 1, 1), |
| 75 | ByteField("ttl", 0) ] |
| 76 | |
| 77 | bind_layers(Ether, MPLS, type=0x8847) |
| 78 | |
Stephen Finucane | 7562d4e | 2014-03-13 15:10:29 +0000 | [diff] [blame] | 79 | if not config["disable_ipv6"]: |
| 80 | IPv6 = scapy.layers.inet6.IPv6 |
| 81 | ICMPv6Unknown = scapy.layers.inet6.ICMPv6Unknown |
| 82 | ICMPv6EchoRequest = scapy.layers.inet6.ICMPv6EchoRequest |