need help on a plugins: bitwise of CDP value

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Developers, Moderators

Post Reply
Rno
Cacti Pro User
Posts: 704
Joined: Wed Dec 07, 2011 9:19 am

need help on a plugins: bitwise of CDP value

Post by Rno »

Hello,
I'm developing a plugin that scan my network and via CDP memorise all switch/router, and the link between them.
For that I'm using CDP and the capabilities of the device. This capabilities is a binary ORed field with the following value:
Router: 0x01
TB Bridge: 0x02
SR Bridge: 0x04
Switch: 0x08
Host: 0x10
IGMP conditional filtering: 0x20
Repeater: 0x40
VoIP Phone: 0x80
Remotely-Managed Device: 0x100

for a switch it has to be 0x08, and that match most device; for Cisco Nexus switch, in L3 config, it's look like I have to get the code 0x200, to avoid Wifi Access point.
But I can make it work, the cdp data I get is an hex string with this value:
00 00 02 29

I try many different mix and data conversion, i'm still unable to figure out how to do a binary & between the CDP data and the hexcode of the Switch I have.

anyone willing to give me some help on this ?
Test
Almalinux
php 8.2.14
mariadb 10.6.16
Cacti 1.2.27
Spine 1.2.27
RRD 1.7.2
thold 1.8
monitor 2.5
syslog 3.2
flowview: 3.3
weathermap 1.0 Beta
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: need help on a plugins: bitwise of CDP value

Post by cigamit »

This should give you an example of how to decode it.

Code: Select all

$code = 0x0229;

$types = array(
  'Router' => 0x01,
  'TB Bridge' => 0x02,
  'SR Bridge' => 0x4,
  'Switch' => 0x08,
  'Host' => 0x10,
  'IGMP conditional filtering' => 0x20,
  'Repeater' => 0x40,
  'VoIP Phone' => 0x80,
  'Remotely-Managed Device' => 0x100,
  'Wifi AP' => 0x200
);

foreach ($types as $t => $c) {
	if ($code & $c) {
		print "$t\n";
	}
}
This should print
Router
Switch
IGMP conditional filtering
Wifi AP
Rno
Cacti Pro User
Posts: 704
Joined: Wed Dec 07, 2011 9:19 am

Re: need help on a plugins: bitwise of CDP value

Post by Rno »

Thanks finally I decide to use a case/switch situation, that let me filter some device that advertise itself as switch, but dose not fit my needs!!
Test
Almalinux
php 8.2.14
mariadb 10.6.16
Cacti 1.2.27
Spine 1.2.27
RRD 1.7.2
thold 1.8
monitor 2.5
syslog 3.2
flowview: 3.3
weathermap 1.0 Beta
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest