need help on a plugins: bitwise of CDP value

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Moderators, Developers

Post Reply
Author
Message
Rno
Cacti User
Posts: 329
Joined: Wed Dec 07, 2011 9:19 am

need help on a plugins: bitwise of CDP value

#1 Post by Rno » Wed Jan 25, 2017 1:37 am

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 ?
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.36

Test
Cacti 1.2.1
Spine 1.2.1
thold 1.0.6
monitor 2.3.5
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.4
Map 1.2.5

cigamit
Developer
Posts: 2779
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

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

#2 Post by cigamit » Wed Jan 25, 2017 3:48 am

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 User
Posts: 329
Joined: Wed Dec 07, 2011 9:19 am

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

#3 Post by Rno » Thu Jan 26, 2017 9:30 am

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!!
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.36

Test
Cacti 1.2.1
Spine 1.2.1
thold 1.0.6
monitor 2.3.5
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.4
Map 1.2.5

Post Reply