|
Packit |
e9ba0d |
/* -*- mode: c; c-file-style: "openbsd" -*- */
|
|
Packit |
e9ba0d |
/*
|
|
Packit |
e9ba0d |
* Copyright (c) 2015 Vincent Bernat <bernat@luffy.cx>
|
|
Packit |
e9ba0d |
*
|
|
Packit |
e9ba0d |
* Permission to use, copy, modify, and/or distribute this software for any
|
|
Packit |
e9ba0d |
* purpose with or without fee is hereby granted, provided that the above
|
|
Packit |
e9ba0d |
* copyright notice and this permission notice appear in all copies.
|
|
Packit |
e9ba0d |
*
|
|
Packit |
e9ba0d |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
Packit |
e9ba0d |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
Packit |
e9ba0d |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
Packit |
e9ba0d |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
Packit |
e9ba0d |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
Packit |
e9ba0d |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
Packit |
e9ba0d |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
Packit |
e9ba0d |
*/
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#include <stdlib.h>
|
|
Packit |
e9ba0d |
#include <sys/socket.h>
|
|
Packit |
e9ba0d |
#include <arpa/inet.h>
|
|
Packit |
e9ba0d |
#include <netinet/in.h>
|
|
Packit |
e9ba0d |
#include <check.h>
|
|
Packit |
e9ba0d |
#include "common.h"
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
char filenameprefix[] = "lldp_send";
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
static struct lldpd test_lldpd = {
|
|
Packit |
e9ba0d |
.g_config = {
|
|
Packit |
e9ba0d |
.c_cap_advertise = 1, /* Chassis capabilities advertisement */
|
|
Packit |
e9ba0d |
.c_mgmt_advertise = 1, /* Management addresses advertisement */
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
};
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#define ck_assert_str_eq_n(X, Y, N) \
|
|
Packit |
e9ba0d |
ck_assert_msg(!strncmp(X, Y, N), "Assertion '"#X"=="#Y"' failed: "#X"==\"%s\", "#Y"==\"%s\"", X, Y)
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
static void
|
|
Packit |
e9ba0d |
check_received_port(
|
|
Packit |
e9ba0d |
struct lldpd_port *sport,
|
|
Packit |
e9ba0d |
struct lldpd_port *rport)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_id_subtype, sport->p_id_subtype);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_id_len, sport->p_id_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq_n(rport->p_id, sport->p_id, sport->p_id_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rport->p_descr, sport->p_descr);
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT3
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_mfs, sport->p_mfs);
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
static void
|
|
Packit |
e9ba0d |
check_received_chassis(
|
|
Packit |
e9ba0d |
struct lldpd_chassis *schassis,
|
|
Packit |
e9ba0d |
struct lldpd_chassis *rchassis)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rchassis->c_id_subtype, schassis->c_id_subtype);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rchassis->c_id_len, schassis->c_id_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq_n(rchassis->c_id, schassis->c_id, schassis->c_id_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rchassis->c_name, schassis->c_name);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rchassis->c_descr, schassis->c_descr);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rchassis->c_cap_available, schassis->c_cap_available);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rchassis->c_cap_enabled, schassis->c_cap_enabled);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#ifdef ENABLE_LLDPMED
|
|
Packit |
e9ba0d |
static void
|
|
Packit |
e9ba0d |
check_received_port_med(
|
|
Packit |
e9ba0d |
struct lldpd_port *sport,
|
|
Packit |
e9ba0d |
struct lldpd_port *rport)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_med_cap_enabled, sport->p_med_cap_enabled);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_med_cap_enabled, sport->p_med_cap_enabled);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].format,
|
|
Packit |
e9ba0d |
sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].format);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len,
|
|
Packit |
e9ba0d |
sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq_n(
|
|
Packit |
e9ba0d |
rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data,
|
|
Packit |
e9ba0d |
sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data,
|
|
Packit |
e9ba0d |
sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].type,
|
|
Packit |
e9ba0d |
sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].type);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].tagged,
|
|
Packit |
e9ba0d |
sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].tagged);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].vid,
|
|
Packit |
e9ba0d |
sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].vid);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].priority,
|
|
Packit |
e9ba0d |
sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].priority);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].dscp,
|
|
Packit |
e9ba0d |
sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].dscp);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(
|
|
Packit |
e9ba0d |
rport->p_med_power.devicetype, sport->p_med_power.devicetype);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_med_power.source, sport->p_med_power.source);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_med_power.priority,
|
|
Packit |
e9ba0d |
sport->p_med_power.priority);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_med_power.val, sport->p_med_power.val);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
static void
|
|
Packit |
e9ba0d |
check_received_chassis_med(
|
|
Packit |
e9ba0d |
struct lldpd_chassis *schassis,
|
|
Packit |
e9ba0d |
struct lldpd_chassis *rchassis)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rchassis->c_med_cap_available,
|
|
Packit |
e9ba0d |
schassis->c_med_cap_available);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rchassis->c_med_type, schassis->c_med_type);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rchassis->c_med_hw, schassis->c_med_hw);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rchassis->c_med_fw, schassis->c_med_fw);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rchassis->c_med_sw, schassis->c_med_sw);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rchassis->c_med_sn, schassis->c_med_sn);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT3
|
|
Packit |
e9ba0d |
static void
|
|
Packit |
e9ba0d |
check_received_port_dot3(
|
|
Packit |
e9ba0d |
struct lldpd_port *sport,
|
|
Packit |
e9ba0d |
struct lldpd_port *rport)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_aggregid, sport->p_aggregid);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_macphy.autoneg_support,
|
|
Packit |
e9ba0d |
sport->p_macphy.autoneg_support);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_macphy.autoneg_enabled,
|
|
Packit |
e9ba0d |
sport->p_macphy.autoneg_enabled);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_macphy.autoneg_advertised,
|
|
Packit |
e9ba0d |
sport->p_macphy.autoneg_advertised);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rport->p_macphy.mau_type, sport->p_macphy.mau_type);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
START_TEST (test_send_rcv_basic)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
int n;
|
|
Packit |
e9ba0d |
struct packet *pkt;
|
|
Packit |
e9ba0d |
struct lldpd_chassis *nchassis = NULL;
|
|
Packit |
e9ba0d |
struct lldpd_port *nport = NULL;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Populate port and chassis */
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id = "FastEthernet 1/5";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
|
|
Packit |
e9ba0d |
hardware.h_lport.p_descr = "Fake port description";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_mfs = 1516;
|
|
Packit |
e9ba0d |
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
|
|
Packit |
e9ba0d |
chassis.c_id = macaddress;
|
|
Packit |
e9ba0d |
chassis.c_id_len = ETHER_ADDR_LEN;
|
|
Packit |
e9ba0d |
chassis.c_name = "First chassis";
|
|
Packit |
e9ba0d |
chassis.c_descr = "Chassis description";
|
|
Packit |
e9ba0d |
chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Build packet */
|
|
Packit |
e9ba0d |
n = lldp_send(&test_lldpd, &hardware);
|
|
Packit |
e9ba0d |
if (n != 0) {
|
|
Packit |
e9ba0d |
fail("unable to build packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&pkts)) {
|
|
Packit |
e9ba0d |
fail("no packets sent");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
pkt = TAILQ_FIRST(&pkts);
|
|
Packit |
e9ba0d |
fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* decode the retrieved packet calling lldp_decode() */
|
|
Packit |
e9ba0d |
fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware,
|
|
Packit |
e9ba0d |
&nchassis, &nport) != -1);
|
|
Packit |
e9ba0d |
if (!nchassis || !nport) {
|
|
Packit |
e9ba0d |
fail("unable to decode packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
/* verify port values */
|
|
Packit |
e9ba0d |
check_received_port(&hardware.h_lport, nport);
|
|
Packit |
e9ba0d |
/* verify chassis values */
|
|
Packit |
e9ba0d |
check_received_chassis(&chassis, nchassis);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
END_TEST
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT1
|
|
Packit |
e9ba0d |
/* This test case tests send and receive of all DOT1 TLVs(2005 and 2009):
|
|
Packit |
e9ba0d |
Port Valn ID, VLAN, Port Protocol VLAN ID, Protocol Identity,
|
|
Packit |
e9ba0d |
VID Usage Digest, Management VID, and 802.1ax Link Aggregation TLVs */
|
|
Packit |
e9ba0d |
START_TEST (test_send_rcv_dot1_tlvs)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
int n;
|
|
Packit |
e9ba0d |
struct lldpd_vlan *rvlan, vlan1, vlan2, vlan3;
|
|
Packit |
e9ba0d |
struct lldpd_ppvid ppvid, *rppvid;
|
|
Packit |
e9ba0d |
struct lldpd_pi pi1, pi2, *rpi;
|
|
Packit |
e9ba0d |
struct lldpd_chassis *nchassis = NULL;
|
|
Packit |
e9ba0d |
struct lldpd_port *nport = NULL;
|
|
Packit |
e9ba0d |
struct packet *pkt;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Populate port and chassis */
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id = macaddress;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_len = ETHER_ADDR_LEN;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_descr = "Fake port description";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_mfs = 1516;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_pvid = 1500;
|
|
Packit |
e9ba0d |
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
|
|
Packit |
e9ba0d |
chassis.c_id = "Chassis name";
|
|
Packit |
e9ba0d |
chassis.c_id_len = strlen(chassis.c_id);
|
|
Packit |
e9ba0d |
chassis.c_name = "Second chassis";
|
|
Packit |
e9ba0d |
chassis.c_descr = "Chassis description";
|
|
Packit |
e9ba0d |
chassis.c_cap_available = LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE;
|
|
Packit |
e9ba0d |
chassis.c_cap_enabled = LLDP_CAP_ROUTER;
|
|
Packit |
e9ba0d |
vlan1.v_name = "Voice"; vlan1.v_vid = 157;
|
|
Packit |
e9ba0d |
vlan2.v_name = "Data"; vlan2.v_vid = 1247;
|
|
Packit |
e9ba0d |
vlan3.v_name = "Control"; vlan3.v_vid = 741;
|
|
Packit |
e9ba0d |
TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan1, v_entries);
|
|
Packit |
e9ba0d |
TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan2, v_entries);
|
|
Packit |
e9ba0d |
TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan3, v_entries);
|
|
Packit |
e9ba0d |
ppvid.p_cap_status = 3;
|
|
Packit |
e9ba0d |
ppvid.p_ppvid = 1500;
|
|
Packit |
e9ba0d |
TAILQ_INSERT_TAIL(&hardware.h_lport.p_ppvids, &ppvid, p_entries);
|
|
Packit |
e9ba0d |
pi1.p_pi = "IEEE Link Aggregration Control Protocol 802.3ad";
|
|
Packit |
e9ba0d |
pi1.p_pi_len = strlen(pi1.p_pi);
|
|
Packit |
e9ba0d |
pi2.p_pi = "IEEE Link Layer Discovery Protocol 802.1ab-2005";
|
|
Packit |
e9ba0d |
pi2.p_pi_len = strlen(pi2.p_pi);
|
|
Packit |
e9ba0d |
TAILQ_INSERT_TAIL(&hardware.h_lport.p_pids, &pi1, p_entries);
|
|
Packit |
e9ba0d |
TAILQ_INSERT_TAIL(&hardware.h_lport.p_pids, &pi2, p_entries);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Build packet */
|
|
Packit |
e9ba0d |
n = lldp_send(&test_lldpd, &hardware);
|
|
Packit |
e9ba0d |
if (n != 0) {
|
|
Packit |
e9ba0d |
fail("unable to build packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&pkts)) {
|
|
Packit |
e9ba0d |
fail("no packets sent");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
pkt = TAILQ_FIRST(&pkts);
|
|
Packit |
e9ba0d |
fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* decode the retrieved packet calling lldp_decode() */
|
|
Packit |
e9ba0d |
fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware,
|
|
Packit |
e9ba0d |
&nchassis, &nport) != -1);
|
|
Packit |
e9ba0d |
if (!nchassis || !nport) {
|
|
Packit |
e9ba0d |
fail("unable to decode packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* verify port values */
|
|
Packit |
e9ba0d |
check_received_port(&hardware.h_lport, nport);
|
|
Packit |
e9ba0d |
/* verify chassis values */
|
|
Packit |
e9ba0d |
check_received_chassis(&chassis, nchassis);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&nport->p_vlans)) {
|
|
Packit |
e9ba0d |
fail("no VLAN");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
rvlan = TAILQ_FIRST(&nport->p_vlans);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rvlan->v_vid, vlan1.v_vid);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rvlan->v_name, vlan1.v_name);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
rvlan = TAILQ_NEXT(rvlan, v_entries);
|
|
Packit |
e9ba0d |
if (!rvlan) {
|
|
Packit |
e9ba0d |
fail("no more VLAN");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rvlan->v_vid, vlan2.v_vid);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rvlan->v_name, vlan2.v_name);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
rvlan = TAILQ_NEXT(rvlan, v_entries);
|
|
Packit |
e9ba0d |
if (!rvlan) {
|
|
Packit |
e9ba0d |
fail("no more VLAN");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rvlan->v_vid, vlan3.v_vid);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(rvlan->v_name, vlan3.v_name);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
rvlan = TAILQ_NEXT(rvlan, v_entries);
|
|
Packit |
e9ba0d |
fail_unless(rvlan == NULL);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_pvid, hardware.h_lport.p_pvid);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&nport->p_ppvids)) {
|
|
Packit |
e9ba0d |
fail("no Port Protocal VLAN ID");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
rppvid = TAILQ_FIRST(&nport->p_ppvids);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rppvid->p_cap_status, ppvid.p_cap_status);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rppvid->p_ppvid, ppvid.p_ppvid);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&nport->p_pids)) {
|
|
Packit |
e9ba0d |
fail("no Protocal Identity TLV");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
rpi = TAILQ_FIRST(&nport->p_pids);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rpi->p_pi_len, pi1.p_pi_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq_n(rpi->p_pi, pi1.p_pi, pi1.p_pi_len);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
rpi = TAILQ_NEXT(rpi, p_entries);
|
|
Packit |
e9ba0d |
if (!rpi) {
|
|
Packit |
e9ba0d |
fail("no more Protocol Identity TLVs");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
ck_assert_int_eq(rpi->p_pi_len, pi2.p_pi_len);
|
|
Packit |
e9ba0d |
ck_assert_str_eq_n(rpi->p_pi, pi2.p_pi, pi2.p_pi_len);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
rpi = TAILQ_NEXT(rpi, p_entries);
|
|
Packit |
e9ba0d |
fail_unless(rpi == NULL);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
END_TEST
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#ifdef ENABLE_LLDPMED
|
|
Packit |
e9ba0d |
START_TEST (test_send_rcv_med)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
int n;
|
|
Packit |
e9ba0d |
struct packet *pkt;
|
|
Packit |
e9ba0d |
struct lldpd_chassis *nchassis = NULL;
|
|
Packit |
e9ba0d |
struct lldpd_port *nport = NULL;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Populate port and chassis */
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id = macaddress;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_len = ETHER_ADDR_LEN;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_descr = "Fake port description";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_mfs = 1516;
|
|
Packit |
e9ba0d |
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
|
|
Packit |
e9ba0d |
chassis.c_id = "Chassis name";
|
|
Packit |
e9ba0d |
chassis.c_id_len = strlen(chassis.c_id);
|
|
Packit |
e9ba0d |
chassis.c_name = "Third chassis";
|
|
Packit |
e9ba0d |
chassis.c_descr = "Chassis description";
|
|
Packit |
e9ba0d |
chassis.c_cap_available = LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE;
|
|
Packit |
e9ba0d |
chassis.c_cap_enabled = LLDP_CAP_ROUTER;
|
|
Packit |
e9ba0d |
chassis.c_med_cap_available = LLDP_MED_CAP_CAP | LLDP_MED_CAP_POLICY |
|
|
Packit |
e9ba0d |
LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_MDI_PSE |
|
|
Packit |
e9ba0d |
LLDP_MED_CAP_IV;
|
|
Packit |
e9ba0d |
chassis.c_med_type = LLDP_MED_CLASS_III;
|
|
Packit |
e9ba0d |
chassis.c_med_hw = "hardware rev 5";
|
|
Packit |
e9ba0d |
chassis.c_med_fw = "47b5";
|
|
Packit |
e9ba0d |
chassis.c_med_sw = "2.6.22b5";
|
|
Packit |
e9ba0d |
chassis.c_med_sn = "SN 47842";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_cap_enabled = chassis.c_med_cap_available;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].format =
|
|
Packit |
e9ba0d |
LLDP_MED_LOCFORMAT_CIVIC;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data = "Your favorite city";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len =
|
|
Packit |
e9ba0d |
sizeof("Your favorite city");
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].type =
|
|
Packit |
e9ba0d |
LLDP_MED_APPTYPE_SOFTPHONEVOICE;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].tagged =
|
|
Packit |
e9ba0d |
1;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].vid =
|
|
Packit |
e9ba0d |
51;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].priority =
|
|
Packit |
e9ba0d |
6;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].dscp =
|
|
Packit |
e9ba0d |
46;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_power.devicetype = LLDP_MED_POW_TYPE_PSE;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_power.source = LLDP_MED_POW_SOURCE_PRIMARY;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_power.priority = LLDP_MED_POW_PRIO_HIGH;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_med_power.val = 65;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Build packet */
|
|
Packit |
e9ba0d |
n = lldp_send(&test_lldpd, &hardware);
|
|
Packit |
e9ba0d |
if (n != 0) {
|
|
Packit |
e9ba0d |
fail("unable to build packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&pkts)) {
|
|
Packit |
e9ba0d |
fail("no packets sent");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
pkt = TAILQ_FIRST(&pkts);
|
|
Packit |
e9ba0d |
fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* decode the retrieved packet calling lldp_decode() */
|
|
Packit |
e9ba0d |
fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware,
|
|
Packit |
e9ba0d |
&nchassis, &nport) != -1);
|
|
Packit |
e9ba0d |
if (!nchassis || !nport) {
|
|
Packit |
e9ba0d |
fail("unable to decode packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
/* verify port values */
|
|
Packit |
e9ba0d |
check_received_port(&hardware.h_lport, nport);
|
|
Packit |
e9ba0d |
/* verify chassis values */
|
|
Packit |
e9ba0d |
check_received_chassis(&chassis, nchassis);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* veridfy med content */
|
|
Packit |
e9ba0d |
check_received_port_med(&hardware.h_lport, nport);
|
|
Packit |
e9ba0d |
check_received_chassis_med(&chassis, nchassis);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
END_TEST
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT3
|
|
Packit |
e9ba0d |
START_TEST (test_send_rcv_dot3)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
int n;
|
|
Packit |
e9ba0d |
struct lldpd_chassis *nchassis = NULL;
|
|
Packit |
e9ba0d |
struct lldpd_port *nport = NULL;
|
|
Packit |
e9ba0d |
struct packet *pkt;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Populate port and chassis */
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id = "FastEthernet 1/5";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
|
|
Packit |
e9ba0d |
hardware.h_lport.p_descr = "Fake port description";
|
|
Packit |
e9ba0d |
hardware.h_lport.p_mfs = 1516;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_aggregid = 5;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_macphy.autoneg_support = 1;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_macphy.autoneg_enabled = 1;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_macphy.autoneg_advertised = LLDP_DOT3_LINK_AUTONEG_10BASE_T |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_10BASET_FD | LLDP_DOT3_LINK_AUTONEG_100BASE_TX |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD;
|
|
Packit |
e9ba0d |
hardware.h_lport.p_macphy.mau_type = LLDP_DOT3_MAU_100BASETXFD;
|
|
Packit |
e9ba0d |
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
|
|
Packit |
e9ba0d |
chassis.c_id = macaddress;
|
|
Packit |
e9ba0d |
chassis.c_id_len = ETHER_ADDR_LEN;
|
|
Packit |
e9ba0d |
chassis.c_name = "Fourth chassis";
|
|
Packit |
e9ba0d |
chassis.c_descr = "Long chassis description";
|
|
Packit |
e9ba0d |
chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER | LLDP_CAP_WLAN;
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Build packet */
|
|
Packit |
e9ba0d |
n = lldp_send(&test_lldpd, &hardware);
|
|
Packit |
e9ba0d |
if (n != 0) {
|
|
Packit |
e9ba0d |
fail("unable to build packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
if (TAILQ_EMPTY(&pkts)) {
|
|
Packit |
e9ba0d |
fail("no packets sent");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
pkt = TAILQ_FIRST(&pkts);
|
|
Packit |
e9ba0d |
fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* decode the retrieved packet calling lldp_decode() */
|
|
Packit |
e9ba0d |
fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware,
|
|
Packit |
e9ba0d |
&nchassis, &nport) != -1);
|
|
Packit |
e9ba0d |
if (!nchassis || !nport) {
|
|
Packit |
e9ba0d |
fail("unable to decode packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
/* verify port values */
|
|
Packit |
e9ba0d |
check_received_port(&hardware.h_lport, nport);
|
|
Packit |
e9ba0d |
/* verify chassis values */
|
|
Packit |
e9ba0d |
check_received_chassis(&chassis, nchassis);
|
|
Packit |
e9ba0d |
/* verify dot3 values */
|
|
Packit |
e9ba0d |
check_received_port_dot3(&hardware.h_lport, nport);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
END_TEST
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
START_TEST (test_recv_min)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
char pkt1[] = {
|
|
Packit |
e9ba0d |
0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x17,
|
|
Packit |
e9ba0d |
0xd1, 0xa8, 0x35, 0xbe, 0x88, 0xcc, 0x02, 0x07,
|
|
Packit |
e9ba0d |
0x04, 0x00, 0x17, 0xd1, 0xa8, 0x35, 0xbf, 0x04,
|
|
Packit |
e9ba0d |
0x07, 0x03, 0x00, 0x17, 0xd1, 0xa8, 0x36, 0x02,
|
|
Packit |
e9ba0d |
0x06, 0x02, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00,
|
|
Packit |
e9ba0d |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
Packit |
e9ba0d |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
Packit |
e9ba0d |
0x00, 0x00, 0x00, 0x00 };
|
|
Packit |
e9ba0d |
/* This is:
|
|
Packit |
e9ba0d |
Ethernet II, Src: Nortel_a8:35:be (00:17:d1:a8:35:be), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
|
|
Packit |
e9ba0d |
Destination: LLDP_Multicast (01:80:c2:00:00:0e)
|
|
Packit |
e9ba0d |
Source: Nortel_a8:35:be (00:17:d1:a8:35:be)
|
|
Packit |
e9ba0d |
Type: 802.1 Link Layer Discovery Protocol (LLDP) (0x88cc)
|
|
Packit |
e9ba0d |
Link Layer Discovery Protocol
|
|
Packit |
e9ba0d |
Chassis Subtype = MAC address
|
|
Packit |
e9ba0d |
0000 001. .... .... = TLV Type: Chassis Id (1)
|
|
Packit |
e9ba0d |
.... ...0 0000 0111 = TLV Length: 7
|
|
Packit |
e9ba0d |
Chassis Id Subtype: MAC address (4)
|
|
Packit |
e9ba0d |
Chassis Id: Nortel_a8:35:bf (00:17:d1:a8:35:bf)
|
|
Packit |
e9ba0d |
Port Subtype = MAC address
|
|
Packit |
e9ba0d |
0000 010. .... .... = TLV Type: Port Id (2)
|
|
Packit |
e9ba0d |
.... ...0 0000 0111 = TLV Length: 7
|
|
Packit |
e9ba0d |
Port Id Subtype: MAC address (3)
|
|
Packit |
e9ba0d |
Port Id: Nortel_a8:36:02 (00:17:d1:a8:36:02)
|
|
Packit |
e9ba0d |
Time To Live = 120 sec
|
|
Packit |
e9ba0d |
0000 011. .... .... = TLV Type: Time to Live (3)
|
|
Packit |
e9ba0d |
.... ...0 0000 0010 = TLV Length: 2
|
|
Packit |
e9ba0d |
Seconds: 120
|
|
Packit |
e9ba0d |
End of LLDPDU
|
|
Packit |
e9ba0d |
0000 000. .... .... = TLV Type: End of LLDPDU (0)
|
|
Packit |
e9ba0d |
.... ...0 0000 0000 = TLV Length: 0
|
|
Packit |
e9ba0d |
*/
|
|
Packit |
e9ba0d |
struct lldpd_chassis *nchassis = NULL;
|
|
Packit |
e9ba0d |
struct lldpd_port *nport = NULL;
|
|
Packit |
e9ba0d |
char mac1[] = { 0x0, 0x17, 0xd1, 0xa8, 0x35, 0xbf };
|
|
Packit |
e9ba0d |
char mac2[] = { 0x0, 0x17, 0xd1, 0xa8, 0x36, 0x02 };
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
|
|
Packit |
e9ba0d |
&nchassis, &nport) != -1);
|
|
Packit |
e9ba0d |
if (!nchassis || !nport) {
|
|
Packit |
e9ba0d |
fail("unable to decode packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_id_subtype,
|
|
Packit |
e9ba0d |
LLDP_CHASSISID_SUBTYPE_LLADDR);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN);
|
|
Packit |
e9ba0d |
fail_unless(memcmp(mac1, nchassis->c_id, ETHER_ADDR_LEN) == 0);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_id_subtype,
|
|
Packit |
e9ba0d |
LLDP_PORTID_SUBTYPE_LLADDR);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN);
|
|
Packit |
e9ba0d |
fail_unless(memcmp(mac2, nport->p_id, ETHER_ADDR_LEN) == 0);
|
|
Packit |
e9ba0d |
ck_assert_ptr_eq(nchassis->c_name, NULL);
|
|
Packit |
e9ba0d |
ck_assert_ptr_eq(nchassis->c_descr, NULL);
|
|
Packit |
e9ba0d |
ck_assert_ptr_eq(nport->p_descr, NULL);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_ttl, 120);
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
END_TEST
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
START_TEST (test_recv_lldpd)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
/* This is a frame generated by lldpd */
|
|
Packit |
e9ba0d |
char pkt1[] = {
|
|
Packit |
e9ba0d |
0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x16,
|
|
Packit |
e9ba0d |
0x17, 0x2f, 0xa1, 0xb6, 0x88, 0xcc, 0x02, 0x07,
|
|
Packit |
e9ba0d |
0x04, 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6, 0x04,
|
|
Packit |
e9ba0d |
0x07, 0x03, 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6,
|
|
Packit |
e9ba0d |
0x06, 0x02, 0x00, 0x78, 0x0a, 0x1a, 0x6e, 0x61,
|
|
Packit |
e9ba0d |
0x72, 0x75, 0x74, 0x6f, 0x2e, 0x58, 0x58, 0x58,
|
|
Packit |
e9ba0d |
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
Packit |
e9ba0d |
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
Packit |
e9ba0d |
0x0c, 0x3f, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x20,
|
|
Packit |
e9ba0d |
0x32, 0x2e, 0x36, 0x2e, 0x32, 0x39, 0x2d, 0x32,
|
|
Packit |
e9ba0d |
0x2d, 0x61, 0x6d, 0x64, 0x36, 0x34, 0x20, 0x23,
|
|
Packit |
e9ba0d |
0x31, 0x20, 0x53, 0x4d, 0x50, 0x20, 0x53, 0x75,
|
|
Packit |
e9ba0d |
0x6e, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x31, 0x37,
|
|
Packit |
e9ba0d |
0x20, 0x31, 0x37, 0x3a, 0x31, 0x35, 0x3a, 0x34,
|
|
Packit |
e9ba0d |
0x37, 0x20, 0x55, 0x54, 0x43, 0x20, 0x32, 0x30,
|
|
Packit |
e9ba0d |
0x30, 0x39, 0x20, 0x78, 0x38, 0x36, 0x5f, 0x36,
|
|
Packit |
e9ba0d |
0x34, 0x0e, 0x04, 0x00, 0x1c, 0x00, 0x14, 0x10,
|
|
Packit |
e9ba0d |
0x0c, 0x05, 0x01, 0x0a, 0xee, 0x50, 0x4b, 0x02,
|
|
Packit |
e9ba0d |
0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x04, 0x65,
|
|
Packit |
e9ba0d |
0x74, 0x68, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f,
|
|
Packit |
e9ba0d |
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09,
|
|
Packit |
e9ba0d |
0x00, 0x12, 0x0f, 0x01, 0x03, 0x6c, 0x03, 0x00,
|
|
Packit |
e9ba0d |
0x10, 0xfe, 0x06, 0x00, 0x12, 0x0f, 0x04, 0x05,
|
|
Packit |
e9ba0d |
0xdc, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00,
|
|
Packit |
e9ba0d |
0x00, 0x00, 0xfe, 0x0f, 0x00, 0x12, 0xbb, 0x05,
|
|
Packit |
e9ba0d |
0x4e, 0x44, 0x39, 0x39, 0x31, 0x37, 0x38, 0x39,
|
|
Packit |
e9ba0d |
0x37, 0x30, 0x32, 0xfe, 0x0b, 0x00, 0x12, 0xbb,
|
|
Packit |
e9ba0d |
0x06, 0x30, 0x38, 0x30, 0x30, 0x31, 0x32, 0x20,
|
|
Packit |
e9ba0d |
0xfe, 0x12, 0x00, 0x12, 0xbb, 0x07, 0x32, 0x2e,
|
|
Packit |
e9ba0d |
0x36, 0x2e, 0x32, 0x39, 0x2d, 0x32, 0x2d, 0x61,
|
|
Packit |
e9ba0d |
0x6d, 0x64, 0x36, 0x34, 0xfe, 0x10, 0x00, 0x12,
|
|
Packit |
e9ba0d |
0xbb, 0x08, 0x31, 0x30, 0x35, 0x38, 0x32, 0x30,
|
|
Packit |
e9ba0d |
0x38, 0x35, 0x30, 0x30, 0x30, 0x39, 0xfe, 0x15,
|
|
Packit |
e9ba0d |
0x00, 0x12, 0xbb, 0x09, 0x4e, 0x45, 0x43, 0x20,
|
|
Packit |
e9ba0d |
0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72,
|
|
Packit |
e9ba0d |
0x73, 0x20, 0x53, 0x41, 0x53, 0xfe, 0x13, 0x00,
|
|
Packit |
e9ba0d |
0x12, 0xbb, 0x0a, 0x50, 0x4f, 0x57, 0x45, 0x52,
|
|
Packit |
e9ba0d |
0x4d, 0x41, 0x54, 0x45, 0x20, 0x56, 0x4c, 0x33,
|
|
Packit |
e9ba0d |
0x35, 0x30, 0xfe, 0x0d, 0x00, 0x12, 0xbb, 0x0b,
|
|
Packit |
e9ba0d |
0x31, 0x30, 0x30, 0x32, 0x30, 0x37, 0x31, 0x32,
|
|
Packit |
e9ba0d |
0x30, 0x00, 0x00 };
|
|
Packit |
e9ba0d |
/* This is:
|
|
Packit |
e9ba0d |
Ethernet II, Src: Msi_2f:a1:b6 (00:16:17:2f:a1:b6), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
|
|
Packit |
e9ba0d |
Destination: LLDP_Multicast (01:80:c2:00:00:0e)
|
|
Packit |
e9ba0d |
Source: Msi_2f:a1:b6 (00:16:17:2f:a1:b6)
|
|
Packit |
e9ba0d |
Type: 802.1 Link Layer Discovery Protocol (LLDP) (0x88cc)
|
|
Packit |
e9ba0d |
Link Layer Discovery Protocol
|
|
Packit |
e9ba0d |
Chassis Subtype = MAC address
|
|
Packit |
e9ba0d |
0000 001. .... .... = TLV Type: Chassis Id (1)
|
|
Packit |
e9ba0d |
.... ...0 0000 0111 = TLV Length: 7
|
|
Packit |
e9ba0d |
Chassis Id Subtype: MAC address (4)
|
|
Packit |
e9ba0d |
Chassis Id: Msi_2f:a1:b6 (00:16:17:2f:a1:b6)
|
|
Packit |
e9ba0d |
Port Subtype = MAC address
|
|
Packit |
e9ba0d |
0000 010. .... .... = TLV Type: Port Id (2)
|
|
Packit |
e9ba0d |
.... ...0 0000 0111 = TLV Length: 7
|
|
Packit |
e9ba0d |
Port Id Subtype: MAC address (3)
|
|
Packit |
e9ba0d |
Port Id: Msi_2f:a1:b6 (00:16:17:2f:a1:b6)
|
|
Packit |
e9ba0d |
Time To Live = 120 sec
|
|
Packit |
e9ba0d |
0000 011. .... .... = TLV Type: Time to Live (3)
|
|
Packit |
e9ba0d |
.... ...0 0000 0010 = TLV Length: 2
|
|
Packit |
e9ba0d |
Seconds: 120
|
|
Packit |
e9ba0d |
System Name = naruto.XXXXXXXXXXXXXXXXXXX
|
|
Packit |
e9ba0d |
0000 101. .... .... = TLV Type: System Name (5)
|
|
Packit |
e9ba0d |
.... ...0 0001 1010 = TLV Length: 26
|
|
Packit |
e9ba0d |
System Name = naruto.bureau.b1.p.fti.net
|
|
Packit |
e9ba0d |
System Description = Linux 2.6.29-2-amd64 #1 SMP Sun May 17 17:15:47 UTC 2009 x86_64
|
|
Packit |
e9ba0d |
0000 110. .... .... = TLV Type: System Description (6)
|
|
Packit |
e9ba0d |
.... ...0 0011 1111 = TLV Length: 63
|
|
Packit |
e9ba0d |
System Description = Linux 2.6.29-2-amd64 #1 SMP Sun May 17 17:15:47 UTC 2009 x86_64
|
|
Packit |
e9ba0d |
Capabilities
|
|
Packit |
e9ba0d |
0000 111. .... .... = TLV Type: System Capabilities (7)
|
|
Packit |
e9ba0d |
.... ...0 0000 0100 = TLV Length: 4
|
|
Packit |
e9ba0d |
Capabilities: 0x001c
|
|
Packit |
e9ba0d |
.... .... .... .1.. = Bridge
|
|
Packit |
e9ba0d |
.... .... .... 1... = WLAN access point
|
|
Packit |
e9ba0d |
.... .... ...1 .... = Router
|
|
Packit |
e9ba0d |
Enabled Capabilities: 0x0014
|
|
Packit |
e9ba0d |
.... .... .... .1.. = Bridge
|
|
Packit |
e9ba0d |
.... .... ...1 .... = Router
|
|
Packit |
e9ba0d |
Management Address
|
|
Packit |
e9ba0d |
0001 000. .... .... = TLV Type: Management Address (8)
|
|
Packit |
e9ba0d |
.... ...0 0000 1100 = TLV Length: 12
|
|
Packit |
e9ba0d |
Address String Length: 5
|
|
Packit |
e9ba0d |
Address Subtype: IPv4 (1)
|
|
Packit |
e9ba0d |
Management Address: 10.238.80.75
|
|
Packit |
e9ba0d |
Interface Subtype: ifIndex (2)
|
|
Packit |
e9ba0d |
Interface Number: 3
|
|
Packit |
e9ba0d |
OID String Length: 0
|
|
Packit |
e9ba0d |
Port Description = eth0
|
|
Packit |
e9ba0d |
0000 100. .... .... = TLV Type: Port Description (4)
|
|
Packit |
e9ba0d |
.... ...0 0000 0100 = TLV Length: 4
|
|
Packit |
e9ba0d |
Port Description: eth0
|
|
Packit |
e9ba0d |
IEEE 802.3 - Link Aggregation
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 1001 = TLV Length: 9
|
|
Packit |
e9ba0d |
Organization Unique Code: IEEE 802.3 (0x00120f)
|
|
Packit |
e9ba0d |
IEEE 802.3 Subtype: Link Aggregation (0x03)
|
|
Packit |
e9ba0d |
Aggregation Status: 0x01
|
|
Packit |
e9ba0d |
.... ...1 = Aggregation Capability: Yes
|
|
Packit |
e9ba0d |
.... ..0. = Aggregation Status: Not Enabled
|
|
Packit |
e9ba0d |
Aggregated Port Id: 0
|
|
Packit |
e9ba0d |
IEEE 802.3 - MAC/PHY Configuration/Status
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 1001 = TLV Length: 9
|
|
Packit |
e9ba0d |
Organization Unique Code: IEEE 802.3 (0x00120f)
|
|
Packit |
e9ba0d |
IEEE 802.3 Subtype: MAC/PHY Configuration/Status (0x01)
|
|
Packit |
e9ba0d |
Auto-Negotiation Support/Status: 0x03
|
|
Packit |
e9ba0d |
.... ...1 = Auto-Negotiation: Supported
|
|
Packit |
e9ba0d |
.... ..1. = Auto-Negotiation: Enabled
|
|
Packit |
e9ba0d |
PMD Auto-Negotiation Advertised Capability: 0x6C03
|
|
Packit |
e9ba0d |
.... .... .... ...1 = 1000BASE-T (full duplex mode)
|
|
Packit |
e9ba0d |
.... .... .... ..1. = 1000BASE-T (half duplex mode)
|
|
Packit |
e9ba0d |
.... .1.. .... .... = 100BASE-TX (full duplex mode)
|
|
Packit |
e9ba0d |
.... 1... .... .... = 100BASE-TX (half duplex mode)
|
|
Packit |
e9ba0d |
..1. .... .... .... = 10BASE-T (full duplex mode)
|
|
Packit |
e9ba0d |
.1.. .... .... .... = 10BASE-T (half duplex mode)
|
|
Packit |
e9ba0d |
Operational MAU Type: 100BaseTXFD - 2 pair category 5 UTP, full duplex mode (0x0010)
|
|
Packit |
e9ba0d |
IEEE 802.3 - Maximum Frame Size
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 0110 = TLV Length: 6
|
|
Packit |
e9ba0d |
Organization Unique Code: IEEE 802.3 (0x00120f)
|
|
Packit |
e9ba0d |
IEEE 802.3 Subtype: Maximum Frame Size (0x04)
|
|
Packit |
e9ba0d |
Maximum Frame Size: 1500
|
|
Packit |
e9ba0d |
TIA - Media Capabilities
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 0111 = TLV Length: 7
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Media Capabilities (0x01)
|
|
Packit |
e9ba0d |
Capabilities: 0x0000
|
|
Packit |
e9ba0d |
Class Type: Type Not Defined
|
|
Packit |
e9ba0d |
TIA - Inventory - Hardware Revision
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 1111 = TLV Length: 15
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Hardware Revision (0x05)
|
|
Packit |
e9ba0d |
Hardware Revision: ND991789702
|
|
Packit |
e9ba0d |
TIA - Inventory - Firmware Revision
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 1011 = TLV Length: 10
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Firmware Revision (0x06)
|
|
Packit |
e9ba0d |
Firmware Revision: 080012
|
|
Packit |
e9ba0d |
TIA - Inventory - Software Revision
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0001 0010 = TLV Length: 18
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Software Revision (0x07)
|
|
Packit |
e9ba0d |
Software Revision: 2.6.29-2-amd64
|
|
Packit |
e9ba0d |
TIA - Inventory - Serial Number
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0001 0000 = TLV Length: 16
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Serial Number (0x08)
|
|
Packit |
e9ba0d |
Serial Number: 105820850009
|
|
Packit |
e9ba0d |
TIA - Inventory - Manufacturer Name
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0001 0101 = TLV Length: 21
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Manufacturer Name (0x09)
|
|
Packit |
e9ba0d |
Manufacturer Name: NEC Computers SAS
|
|
Packit |
e9ba0d |
TIA - Inventory - Model Name
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0001 0011 = TLV Length: 19
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Model Name (0x0a)
|
|
Packit |
e9ba0d |
Model Name: POWERMATE VL350
|
|
Packit |
e9ba0d |
TIA - Inventory - Asset ID
|
|
Packit |
e9ba0d |
1111 111. .... .... = TLV Type: Organization Specific (127)
|
|
Packit |
e9ba0d |
.... ...0 0000 1101 = TLV Length: 13
|
|
Packit |
e9ba0d |
Organization Unique Code: TIA (0x0012bb)
|
|
Packit |
e9ba0d |
Media Subtype: Inventory - Asset ID (0x0b)
|
|
Packit |
e9ba0d |
Asset ID: 100207120
|
|
Packit |
e9ba0d |
End of LLDPDU
|
|
Packit |
e9ba0d |
0000 000. .... .... = TLV Type: End of LLDPDU (0)
|
|
Packit |
e9ba0d |
.... ...0 0000 0000 = TLV Length: 0
|
|
Packit |
e9ba0d |
*/
|
|
Packit |
e9ba0d |
struct lldpd_chassis *nchassis = NULL;
|
|
Packit |
e9ba0d |
struct lldpd_port *nport = NULL;
|
|
Packit |
e9ba0d |
char mac1[] = { 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6 };
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
|
|
Packit |
e9ba0d |
&nchassis, &nport) != -1);
|
|
Packit |
e9ba0d |
if (!nchassis || !nport) {
|
|
Packit |
e9ba0d |
fail("unable to decode packet");
|
|
Packit |
e9ba0d |
return;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_id_subtype,
|
|
Packit |
e9ba0d |
LLDP_CHASSISID_SUBTYPE_LLADDR);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN);
|
|
Packit |
e9ba0d |
fail_unless(memcmp(mac1, nchassis->c_id, ETHER_ADDR_LEN) == 0);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_id_subtype,
|
|
Packit |
e9ba0d |
LLDP_PORTID_SUBTYPE_LLADDR);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN);
|
|
Packit |
e9ba0d |
fail_unless(memcmp(mac1, nport->p_id, ETHER_ADDR_LEN) == 0);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_ttl, 120);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_name, "naruto.XXXXXXXXXXXXXXXXXXX");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_descr,
|
|
Packit |
e9ba0d |
"Linux 2.6.29-2-amd64 #1 SMP Sun May 17 17:15:47 UTC 2009 x86_64");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nport->p_descr, "eth0");
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_cap_available,
|
|
Packit |
e9ba0d |
LLDP_CAP_WLAN | LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_cap_enabled,
|
|
Packit |
e9ba0d |
LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_mgmt.tqh_first->m_addr.inet.s_addr,
|
|
Packit |
e9ba0d |
(u_int32_t)inet_addr("10.238.80.75"));
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_mgmt.tqh_first->m_iface, 3);
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT3
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_aggregid, 0);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_macphy.autoneg_enabled, 1);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_macphy.autoneg_support, 1);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_macphy.autoneg_advertised,
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_1000BASE_T |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_100BASE_TX |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_10BASET_FD |
|
|
Packit |
e9ba0d |
LLDP_DOT3_LINK_AUTONEG_10BASE_T);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_macphy.mau_type,
|
|
Packit |
e9ba0d |
LLDP_DOT3_MAU_100BASETXFD);
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nport->p_mfs, 1500);
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
#ifdef ENABLE_LLDPMED
|
|
Packit |
e9ba0d |
ck_assert_int_eq(nchassis->c_med_type, 0);
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_hw, "ND991789702");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_fw, "080012 "); /* Extra space */
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_sw, "2.6.29-2-amd64");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_sn, "105820850009");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_manuf, "NEC Computers SAS");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_model, "POWERMATE VL350");
|
|
Packit |
e9ba0d |
ck_assert_str_eq(nchassis->c_med_asset, "100207120");
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
END_TEST
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
Suite *
|
|
Packit |
e9ba0d |
lldp_suite(void)
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
Suite *s = suite_create("LLDP");
|
|
Packit |
e9ba0d |
TCase *tc_send = tcase_create("Send LLDP packets");
|
|
Packit |
e9ba0d |
TCase *tc_receive = tcase_create("Receive LLDP packets");
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
/* Send tests are first run without knowing the result. The
|
|
Packit |
e9ba0d |
result is then checked with:
|
|
Packit |
e9ba0d |
tshark -V -T text -r tests/lldp_send_0000.pcap
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
If the result is correct, then, we get the packet as C
|
|
Packit |
e9ba0d |
bytes using wireshark export to C arrays (tshark seems not
|
|
Packit |
e9ba0d |
be able to do this).
|
|
Packit |
e9ba0d |
*/
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown);
|
|
Packit |
e9ba0d |
tcase_add_test(tc_send, test_send_rcv_basic);
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT1
|
|
Packit |
e9ba0d |
tcase_add_test(tc_send, test_send_rcv_dot1_tlvs);
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
#ifdef ENABLE_LLDPMED
|
|
Packit |
e9ba0d |
tcase_add_test(tc_send, test_send_rcv_med);
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
#ifdef ENABLE_DOT3
|
|
Packit |
e9ba0d |
tcase_add_test(tc_send, test_send_rcv_dot3);
|
|
Packit |
e9ba0d |
#endif
|
|
Packit |
e9ba0d |
suite_add_tcase(s, tc_send);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
tcase_add_test(tc_receive, test_recv_min);
|
|
Packit |
e9ba0d |
tcase_add_test(tc_receive, test_recv_lldpd);
|
|
Packit |
e9ba0d |
suite_add_tcase(s, tc_receive);
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
return s;
|
|
Packit |
e9ba0d |
}
|
|
Packit |
e9ba0d |
|
|
Packit |
e9ba0d |
int
|
|
Packit |
e9ba0d |
main()
|
|
Packit |
e9ba0d |
{
|
|
Packit |
e9ba0d |
int number_failed;
|
|
Packit |
e9ba0d |
Suite *s = lldp_suite ();
|
|
Packit |
e9ba0d |
SRunner *sr = srunner_create (s);
|
|
Packit |
e9ba0d |
srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because
|
|
Packit |
e9ba0d |
we need to write
|
|
Packit |
e9ba0d |
files */
|
|
Packit |
e9ba0d |
srunner_run_all (sr, CK_ENV);
|
|
Packit |
e9ba0d |
number_failed = srunner_ntests_failed (sr);
|
|
Packit |
e9ba0d |
srunner_free (sr);
|
|
Packit |
e9ba0d |
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
Packit |
e9ba0d |
}
|