S
S
Sdelan_v_CCCP2014-08-19 07:09:48
linux
Sdelan_v_CCCP, 2014-08-19 07:09:48

How to generate an Ethernet OAM PDU in Scapy?

Hello! I just can’t catch up with how to form Ethernet OAM packets / PDUs there, specifying their values ​​​​in the type, subtype, flags, code fields. Is this even possible in Scapy? If not, are there tools that allow you to generate and send such PDUs?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
throughtheether, 2014-08-19
@Sdelan_v_CCCP

Is this even possible in Scapy?
You can create a frame using the constructor e=Ether(src='AA:AA:AA:AA:AA:AA',dst='01:80:c2:00:00:02',type=0x8809), and so on set the value of the data field yourself (e.payload=data, where data is of the Packet or str type)
Example (the size of the fields may not be quite correct):
e=Ether(src='AA:AA:AA:AA:AA:AA',dst='01:80:c2:00:00:02',type=0x8809)
class EthernetOAM(Packet):
    name='Ethernet OAM'
    fields_desc=[
         ByteField('Subtype',3),
         ByteField('Flags',0),
         ByteField('Code',0),
    ]
OAM=EtherOAM()
OAM.payload="data+padding"
e.payload=OAM
OAM
>>> <EthernetOAM  |<Raw  load='data+padding' |>>
e
>>> <Ether  dst=01:80:c2:00:00:02 src=AA:AA:AA:AA:AA:AA type=0x8809 |<EthernetOAM  |<Raw  load='data+padding' |>>>

If not, are there tools that allow you to generate and send such PDUs?
There are many tools (for example, trafgen or mausezahn as part of the netsniff-ng package), but you will most likely have to form the data field yourself.

S
Sdelan_v_CCCP, 2014-08-20
@Sdelan_v_CCCP

Thank you throughtheether! Your answer helped me. I figured out which direction to go)) I'll add it a little more from myself) Maybe someone will need it))
I created a test_packet.py file with something like this

#! /usr/bin/env python
#! /usr/bin/env python

# Set log level to benefit from Scapy warnings
import logging
logging.getLogger("scapy").setLevel(1)

from scapy.all import *

class EthernetOAM(Packet):
  name = "Ethernet OAM"
  fields_desc = [ 
                                XByteField("Subtype", 0x03),
        XByteField("Flags1", 	0x00),
        XByteField("Flags2", 	0x02), 
        XByteField("Code",	0x00)
         ]

if __name__ == "__main__":
  interact(mydict=globals(), mybanner="I am Batman")

#End of file

ran:
#sudo python test_packet.py
>>> e = Ether(src='AA:AA:AA:AA:AA:AA',dst='01:80:c2:00:00:02',type=0x8809 )/EthernetOAM()
>>>sendp(e)
In principle, that's all I needed) It's
best of course to smoke the official documentation:
www.secdev.org/projects/scapy/build_your_own_tools.html
www.secdev.org/projects/scapy /doc/build_dissect.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question