LLDP Frame Generator
Author: Alexandru Nicolae
email: alexandru.nicolae0807@gmail.com
UPDATE (16.05.2016): added support for LLDP-MED TLVs
I. Introduction
This project represents a LLDP frame generator. Based on Command Line commands, users can issue different LLDP frames containing different TLVs.
The ussage mode is a combination between a classic CLI command(e.g. ping, traceroute) and a command issued on a Cisco device where the user can interogate everytime
the application for possible commands.
For the program to run successfully, the following features are required:
* Linux environmnent
* Python
* Scapy - http://www.secdev.org/projects/scapy/doc/installation.html
* IPy - https://pypi.python.org/pypi/IPy/
II. Modules
The aplication contains four python modules(files):
1. tool
2. Packet_Generator
3. LLDP_TLV
4. NotificationBox
1. tool
This module represents the main module where the user introduces the commands as a list of arguments. After introducing the CLI command, the list is send as a
parameter to the method create_packet() from Packet_Generator module. Then, the result is send on network using sendp() method defined in Scapy.
2. Packet_Generator
This module is the central point of the application where the CLI commands are interpreted and a LLDP frame is created.
There are basically two cases for sending a frame:
a) Sending a basic frame(only mandatory TLVs are included: Chassis ID, Port ID, TTL, EndOfPDU)
b) Sending a complex frame.
It contains the TLVs introduced by user. If a mandatory TLV is not specified, then it is generated automatically because, according to LLDP RFC 802.1 AB,
a mandatory TLV cannot miss from a LLDPDU.
NOTE:
In my implementation, when it is not specified an output interface(with -i ethX), the frame will be send to a default interface(in my case: eth1). Also,
the program can send frames only on eth1 and loopback0 interfaces and it does not permit other interfaces. To change this behaviour, please modify lines 85,87,
88 and 157 from Packet_Generator.py file.
3. LLDP_TLV
This module represents the definition of all LLDP TLVs. Each TLV was created using Scapy's capability for adding new layers(http://www.secdev.org/projects/scapy/doc/build_dissect.html).
4. NotificationBox
This modules represents the source for displaying messages to the user. This compoment is used by Packet_Generator module when user introduces a bad command,
a bad TLV name or a bad interface name. Practically, this component makes the ussage mode to be more like an IOS command, rather than a CLI command.
III. Ussage
After installing Python, Scapy and IPy on a Linux distribution(in my case, Ubuntu 12.10), we can run the main program in a terminal as ROOT.
Examples:
1. We can type: ./tool.py (and hit Enter). We can see then an utilization example.
2. ./tool.py -p lldp (and hit Enter) for sending a basic frame on the default interface(in my case, eth1)
3. ./tool.py -p lldp -i eth3 (and hit Enter) for sending a basic frame on eth3 interface.
4. Let's say we want now to create a LLDP frame containing Chassis ID and Port ID TLVs having values introduced by us.
By typing ./tool.py -p lldp -tlv (and hit Enter) all possible TLVs are shown. First, we choose from there 'chid'.
By typing ./tool.py -p lldp -tlv chid (and hit Enter) all possible Chassis ID subtypes are shown. We choose 'ipv4' as a subtype.
The command is now: ./tool.py -p lldp -tlv chid -ipv4 10.10.10.10
If we hit enter now, a frame with a Chassis ID value of 10.10.10.10 will be send on the default output interface. As I mentioned before, the other mandatory
TLVs will be randomly generated.
For adding the Port ID TLV in frame we continue the command by specifying again '-tlv' parameter.
The complete command is: ./tool.py -p lldp -tlv chid -ipv4 10.10.10.10 -tlv portid -mac-addr 00:11:22:33:44:55 -i eth3 (and hit Enter)
This ussage type is available for all other TLVs. A frame can contain all TLVs supported by LLDP protocol. When we want help we just try to type
something( '-tlv', '-i') and hit enter and a help message will be displayed.
I considered this ussage type to be useful because the user is helped step by step.
I hope this application will be helpful and if you have questions or observations don't hesitate to contact me.