blob: fa887bc4d18918222f71501855bf84471b5ecc77 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Lanea68176f2013-08-09 17:41:05 -070017# 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"""
21Wrap scapy to satisfy pylint
22"""
Stephen Finucane7562d4e2014-03-13 15:10:29 +000023from oftest import config
Rich Lane720eaf22013-08-09 18:00:45 -070024import sys
Rich Lanea68176f2013-08-09 17:41:05 -070025
26try:
Rich Lane024f9d52013-08-12 15:56:39 -070027 import scapy.config
28 import scapy.route
Rich Lanea68176f2013-08-09 17:41:05 -070029 import scapy.layers.l2
30 import scapy.layers.inet
Stephen Finucane7562d4e2014-03-13 15:10:29 +000031 if not config["disable_ipv6"]:
32 import scapy.route6
33 import scapy.layers.inet6
Rich Lanea68176f2013-08-09 17:41:05 -070034except ImportError:
35 sys.exit("Need to install scapy for packet parsing")
36
37Ether = scapy.layers.l2.Ether
38LLC = scapy.layers.l2.LLC
39SNAP = scapy.layers.l2.SNAP
40Dot1Q = scapy.layers.l2.Dot1Q
41IP = scapy.layers.inet.IP
42IPOption = scapy.layers.inet.IPOption
Rich Lanea68176f2013-08-09 17:41:05 -070043ARP = scapy.layers.inet.ARP
44TCP = scapy.layers.inet.TCP
45UDP = scapy.layers.inet.UDP
46ICMP = scapy.layers.inet.ICMP
Stephen Finucane7562d4e2014-03-13 15:10:29 +000047
macauley_chengeadac7a2015-08-31 15:19:04 +080048
macauleyca2752d2015-07-27 17:41:14 +080049from scapy.fields import *
50from scapy.packet import *
51
52class ThreeBytesField(X3BytesField, ByteField):
53 def i2repr(self, pkt, x):
54 return ByteField.i2repr(self, pkt, x)
55
56class 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
66bind_layers(UDP, VXLAN, dport=4789)
67bind_layers(VXLAN, Ether)
68
macauley_chengeadac7a2015-08-31 15:19:04 +080069
70class 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
77bind_layers(Ether, MPLS, type=0x8847)
78
Stephen Finucane7562d4e2014-03-13 15:10:29 +000079if not config["disable_ipv6"]:
80 IPv6 = scapy.layers.inet6.IPv6
81 ICMPv6Unknown = scapy.layers.inet6.ICMPv6Unknown
82 ICMPv6EchoRequest = scapy.layers.inet6.ICMPv6EchoRequest