2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
26 int cmd_lldp_conformance (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
28 struct mops_ext_lldp
* pd
= clipkt
->p_desc
;
31 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
!=1)) {
32 cli_print(cli
, "Enables or disables LLDP standard conformance mode.\n");
33 cli_print(cli
, "Keywords: enable | disable\n");
34 cli_print(cli
, "Per default, standard LLDP messages are created which require a fixed\r");
35 cli_print(cli
, "order of the mandatory TLVs. If the standard conformance mode is disabled\r");
36 cli_print(cli
, "then you can configure an arbitrary sequence of LLDP TLVs. \n");
37 cli_print(cli
, "Currently, the LLDP standard conformance mode is %s\n", (pd
->non_conform
) ? "DISABLED" : "ENABLED");
41 if (mz_strcmp(argv
[0], "enable", 1)==0) {
47 if (mz_strcmp(argv
[0], "disable", 1)==0) {
52 cli_print(cli
, "Enter enable or disable\n");
57 int cmd_lldp_chassis_id (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
59 struct mops_ext_lldp
* pd
= clipkt
->p_desc
;
65 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>2)) {
66 cli_print(cli
, "Configure a Chassis ID TLV.\n");
67 cli_print(cli
, "ARGUMENTS: [<subtype>] <chassis-id>\n");
68 cli_print(cli
, "By default the <subtype> is of kind 'mac address (4)' and the <chassis-id>\r");
69 cli_print(cli
, "must be a hexadecimal string (e. g. 00:01:ca:fe:de:ad) of max 255 bytes\n");
74 subtype
= (int) str2int(argv
[0]);
75 if ((subtype
>255) || (mz_strisnum(argv
[0])==0)) {
76 cli_print(cli
, "Invalid subtype\n");
83 cl
=strnlen(cid
, 1024);
86 cli_print(cli
, "Chassis-ID too long\n");
88 } else cidl
=str2hex(cid
, tmp
, 511);
90 if (pd
->non_conform
== 0) {
91 pd
->chassis_id_subtype
= subtype
;
92 memcpy((void*) pd
->chassis_id
, (void*)tmp
, cidl
);
93 pd
->chassis_id_len
= cidl
;
96 mops_lldp_opt_tlv_chassis (clipkt
, subtype
, cidl
, tmp
);
105 int cmd_lldp_port_id (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
107 struct mops_ext_lldp
* pd
= clipkt
->p_desc
;
112 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>2)) {
113 cli_print(cli
, "Configure a Port ID TLV.\n");
114 cli_print(cli
, "ARGUMENTS: [<subtype>] <port-id>\n");
115 cli_print(cli
, "By default the <subtype> is of kind 'Interface name (5)' and the <port-id>\r");
116 cli_print(cli
, "must be a ascii string (usually the name of the interface e. g. eth3) of\r");
117 cli_print(cli
, "max 255 bytes.\n");
122 subtype
= (int) str2int(argv
[0]);
123 if ((subtype
>255) || (mz_strisnum(argv
[0])==0)) {
124 cli_print(cli
, "Invalid subtype\n");
131 pl
=strnlen(pid
, 256);
134 cli_print(cli
, "Port-ID too long\n");
139 if (pd
->non_conform
== 0) {
140 pd
->port_id_subtype
= subtype
;
141 memcpy((void*) pd
->port_id
, (void*) pid
, pl
);
142 pd
->port_id_len
= pl
;
145 mops_lldp_opt_tlv_port (clipkt
, subtype
, pl
, (u_int8_t
*) pid
);
153 int cmd_lldp_ttl (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
155 struct mops_ext_lldp
* pd
= clipkt
->p_desc
;
158 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
!=1)) {
159 cli_print(cli
, "Configure the LLDP TTL.\n");
160 cli_print(cli
, "ARGUMENTS: <time-to-live>\n");
161 cli_print(cli
, "The TTL must be within 0..65535\n");
165 ttl
= (int) str2int(argv
[0]);
167 if (mz_strisnum(argv
[0])==0) {
168 cli_print(cli
, "Invalid argument\n");
173 cli_print(cli
, "TTL must be within 0..65535\n");
177 if (pd
->non_conform
== 0) {
181 mops_lldp_opt_tlv_TTL (clipkt
, ttl
);
189 int cmd_lldp_vlan (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
193 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
!=1)) {
194 cli_print(cli
, "Configure the LLDP Port VLAN-ID.\n");
195 cli_print(cli
, "ARGUMENTS: <vlan-id>\n");
196 cli_print(cli
, "The vlan-id must be within 0..65535\n");
200 vlan
= (int) str2int(argv
[0]);
202 if (mz_strisnum(argv
[0])==0) {
203 cli_print(cli
, "Invalid argument\n");
208 cli_print(cli
, "The VLAN-ID must be within 0..65535\n");
213 mops_lldp_opt_tlv_vlan (clipkt
, vlan
);
220 int cmd_lldp_opt_tlv (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
226 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
!=3)) {
227 cli_print(cli
, "Configure an arbitrary optional TLV.\n");
228 cli_print(cli
, "ARGUMENTS: ascii|hex <type> <value>\n");
229 cli_print(cli
, "The TLV type must be between 0..127, the value length is up to 511 bytes.\n");
234 if (mz_strcmp(argv
[0], "ascii", 1)==0) {
235 if ((len
=strnlen(argv
[2],512))>511) {
236 cli_print(cli
, "<value> must be smaller or equal 511 characters\n");
239 mz_strncpy((char*) tmp
, argv
[2], 511);
240 } else if (mz_strcmp(argv
[0], "hex", 1)==0) {
241 len
=str2hex(argv
[2], tmp
, 512);
243 cli_print(cli
, "<value> must be smaller or equal 511 bytes\n");
248 type
= (int) str2int(argv
[1]);
250 if (mz_strisnum(argv
[1])==0) {
251 cli_print(cli
, "Invalid type\n");
256 cli_print(cli
, "<type> must be within 0..127\n");
261 if (mops_lldp_opt_tlv (clipkt
, type
, len
, tmp
)==0)
262 cli_print(cli
, "Invalid TLV values\n");
270 int cmd_lldp_opt_tlv_bad (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
272 int type
, len
=0, wronglen
;
276 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
!=4)) {
277 cli_print(cli
, "Configure an arbitrary optional *BAD* TLV.\n");
278 cli_print(cli
, "ARGUMENTS: ascii|hex <type> <wrong-length> <value>\n");
279 cli_print(cli
, "Using this command you can add a custom TLV with a wrong length parameter.\r");
280 cli_print(cli
, "Such TLV can be used to verify whether LLDP receivers are robust enough\r\r");
281 cli_print(cli
, "since a too small <wrong-length> could cause a buffer overflow. The TLV type\r");
282 cli_print(cli
, "must be between 0..127, the <wrong-length> can be within 0..511 (and can be\r");
283 cli_print(cli
, "also the true length of course\n");
288 if (mz_strcmp(argv
[0], "ascii", 1)==0) {
289 if ((len
=strnlen(argv
[3],512))>511) {
290 cli_print(cli
, "<value> must be smaller or equal 511 characters\n");
293 mz_strncpy((char*) tmp
, argv
[3], 511);
294 } else if (mz_strcmp(argv
[0], "hex", 1)==0) {
295 len
=str2hex(argv
[3], tmp
, 512);
297 cli_print(cli
, "<value> must be smaller or equal 511 bytes\n");
302 type
= (int) str2int(argv
[1]);
304 if (mz_strisnum(argv
[1])==0) {
305 cli_print(cli
, "Invalid type\n");
310 cli_print(cli
, "<type> must be within 0..127\n");
314 wronglen
= (int) str2int(argv
[2]);
316 if (mz_strisnum(argv
[2])==0) {
317 cli_print(cli
, "Invalid length\n");
322 cli_print(cli
, "<wrong-length> must be within 0..511\n");
326 if (mops_lldp_opt_tlv_bad (clipkt
, type
, wronglen
, len
, tmp
)==0)
327 cli_print(cli
, "Invalid TLV values\n");
334 int cmd_lldp_opt_org (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
336 int subtype
, len
=0, oui
=0;
340 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
!=4)) {
341 cli_print(cli
, "Configure an organisational TLV.\n");
342 cli_print(cli
, "ARGUMENTS: ascii|hex <oui> <subtype> <value>\n");
343 cli_print(cli
, "Using this command you can add an arbitrary organisational TLV. The <oui> represents\r");
344 cli_print(cli
, "the 'Organisational Unique Identifier' and consists of exactly three bytes in hexadecimal\r");
345 cli_print(cli
, "format, such as '00005e' The <subtype> is a value between <0..255>, and the length of the\r");
346 cli_print(cli
, "value is up to 507 bytes.\n");
351 if (mz_strcmp(argv
[0], "ascii", 1)==0) {
352 if ((len
=strnlen(argv
[3],512))>511) {
353 cli_print(cli
, "<value> must be smaller or equal 511 characters\n");
356 mz_strncpy((char*) tmp
, argv
[3], 511);
357 } else if (mz_strcmp(argv
[0], "hex", 1)==0) {
358 len
=str2hex(argv
[3], tmp
, 512);
360 cli_print(cli
, "<value> must be smaller or equal 511 bytes\n");
365 oui
= xstr2int(argv
[1]);
366 if (mz_strishex(argv
[1])==0) {
367 cli_print(cli
, "Invalid oui value\n");
372 cli_print(cli
, "<oui> must be within 0..ffffff\n");
376 subtype
= (int) str2int(argv
[2]);
378 if (mz_strisnum(argv
[2])==0) {
379 cli_print(cli
, "Invalid subtype\n");
384 cli_print(cli
, "<subtype> must be within 0..255\n");
389 if (mops_lldp_opt_tlv_org (clipkt
, oui
, subtype
, len
, tmp
)==0)
390 cli_print(cli
, "Invalid TLV values\n");
399 int cmd_lldp_endtlv (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
402 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>0)) {
403 cli_print(cli
, "Add an 'End of LLDP' TLV\n");
404 cli_print(cli
, "ARGUMENTS: none\n");
405 cli_print(cli
, "This command allows you to insert an 'End of LLDP' TLV at any\r");
406 cli_print(cli
, "point within the optional TLV list. You usually want this to\r");
407 cli_print(cli
, "create an invalid LLDPU to test the receiver.\n");
412 mops_lldp_opt_tlv_end (clipkt
);
418 int cmd_lldp_reset (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
421 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>0)) {
422 cli_print(cli
, "Reset the LLPDU and clear all optional TLVs.\n");
423 cli_print(cli
, "ARGUMENTS: none\n");
424 cli_print(cli
, "All optional TLVs are added in the sequence as you configure them.\r");
425 cli_print(cli
, "Use this command to reset the LLDP and reconfigure all optional\r");
426 cli_print(cli
, "TLVs again. Additionally the parameters of the mandatory TLVs are\r");
427 cli_print(cli
, "reset to defaults.\n");
431 mops_init_pdesc_lldp(clipkt
);