blob: fa887bc4d18918222f71501855bf84471b5ecc77 [file] [log] [blame]
Sreeju Sreedhare3fefd92019-04-02 15:57:15 -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
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"""
21Wrap scapy to satisfy pylint
22"""
23from oftest import config
24import sys
25
26try:
27 import scapy.config
28 import scapy.route
29 import scapy.layers.l2
30 import scapy.layers.inet
31 if not config["disable_ipv6"]:
32 import scapy.route6
33 import scapy.layers.inet6
34except 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
43ARP = scapy.layers.inet.ARP
44TCP = scapy.layers.inet.TCP
45UDP = scapy.layers.inet.UDP
46ICMP = scapy.layers.inet.ICMP
47
48
49from 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
69
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
79if not config["disable_ipv6"]:
80 IPv6 = scapy.layers.inet6.IPv6
81 ICMPv6Unknown = scapy.layers.inet6.ICMPv6Unknown
82 ICMPv6EchoRequest = scapy.layers.inet6.ICMPv6EchoRequest