20

LAN/WAN DESIGN AND MANAGEMENT

TERM PROJECT

SNMP

Hakan KUTUCU

İzmir Institute of Tecnology, 2002-05-23

In this project I have installed UCD-SNMP 5.0 and NET-SNMP 4.2.5 in a linux machine from the following website http://net-snmp.sourceforge.net/download

I have used the following Makefile to compile codes.

# Warning: you may need more libraries than are included here on the

# build line. The agent frequently needs various libraries in order

# to compile pieces of it, but is OS dependent and we can't list all

# the combinations here. Instead, look at the libraries that were

# used when linking the snmpd master agent and copy those to this file

CC=gcc

CFLAGS=-I/usr/local/include -g

OBJS1=termproject.o

OBJS2=ustMain.o ustScalarSet.o

OBJS3=asyncapp.o

TARGETS=ustMain termproject asyncapp

# if ucd-snmp was compiled with openssl support

CRYPTO=-L/usr/local/ssl/lib -lcrypto

# for Solaris

#SYSLIBS=-lsocket -lnsl -lkstat

# for BSD

#SYSLIBS=-lkvm

# for Linux and many other OSes

#SYSLIBS=-ldl

# shared library flags (assumes gcc)

DLFLAGS=-fPIC -shared

all: $(TARGETS)

termproject: $(OBJS1)

$(CC) -o termproject $(OBJS1) -L/usr/local/lib -lsnmp $(SYSLIBS) $(CRYPTO)

asyncapp: $(OBJS3)

$(CC) -o asyncapp $(OBJS3) -L/usr/local/lib -lsnmp $(SYSLIBS) $(CRYPTO)

ustMain: $(OBJS2)

$(CC) -o ustMain $(OBJS2) -L/usr/local/lib -lucdagent -lucdmibs -lsnmp $(SYSLIBS) $(CRYPTO)

clean:

rm $(OBJS2) $(OBJS2) $(TARGETS)

ustScalarSet.so: ustScalarSet.c Makefile

$(CC) $(CFLAGS) $(DLFLAGS) -c -o ustScalarSet.o ustScalarSet.c

$(CC) $(CFLAGS) $(DLFLAGS) -o ustScalarSet.so ustScalarSet.o

STANDARD MIB TREE

OBJECTS UNDER SYSTEM

To get this information I used the command snmptranslate -Td .1.3.6.1.2.1.1.1 in the command line.

OID value: 1.3.6.1.2.1.1.1

OID description:

sysDescr OBJECT-TYPE

SYNTAX DisplayString (SIZE (0..255))

ACCESS read-only

STATUS mandatory

DESCRIPTION

"A textual description of the entity. This value

should include the full name and version

identification of the system's hardware type,

software operating-system, and networking

software. It is mandatory that this only contain

printable ASCII characters."

::= { system 1 }

OID value: 1.3.6.1.2.1.1.2

OID description:

sysObjectID OBJECT-TYPE

SYNTAX OBJECT IDENTIFIER

ACCESS read-only

STATUS mandatory

DESCRIPTION

"The vendor's authoritative identification of the

network management subsystem contained in the

entity. This value is allocated within the SMI

enterprises subtree (1.3.6.1.4.1) and provides an

easy and unambiguous means for determining `what

kind of box' is being managed. For example, if

vendor `Flintstones, Inc.' was assigned the

subtree 1.3.6.1.4.1.4242, it could assign the

identifier 1.3.6.1.4.1.4242.1.1 to its `Fred

Router'."

::= { system 2 }

OID value: 1.3.6.1.2.1.1.3

OID description:

sysUpTime OBJECT-TYPE

SYNTAX TimeTicks

ACCESS read-only

STATUS mandatory

DESCRIPTION

"The time (in hundredths of a second) since the

network management portion of the system was last

re-initialized."

::= { system 3 }

OID value: 1.3.6.1.2.1.1.4

OID description:

sysContact OBJECT-TYPE

SYNTAX DisplayString (SIZE (0..255))

ACCESS read-write

STATUS mandatory

DESCRIPTION

"The textual identification of the contact person

for this managed node, together with information

on how to contact this person."

::= { system 4 }

OID value: 1.3.6.1.2.1.1.5

OID description:

sysName OBJECT-TYPE

SYNTAX DisplayString (SIZE (0..255))

ACCESS read-write

STATUS mandatory

DESCRIPTION

"An administratively-assigned name for this

managed node. By convention, this is the node's

fully-qualified domain name."

::= { system 5 }

OID value: 1.3.6.1.2.1.1.6

OID description:

sysLocation OBJECT-TYPE

SYNTAX DisplayString (SIZE (0..255))

ACCESS read-write

STATUS mandatory

DESCRIPTION

"The physical location of this node (e.g.,

`telephone closet, 3rd floor')."

::= { system 6 }

OID value: 1.3.6.1.2.1.1.7

OID description:

sysServices OBJECT-TYPE

SYNTAX INTEGER (0..127)

ACCESS read-only

STATUS mandatory

DESCRIPTION

"A value which indicates the set of services that

this entity primarily offers.

The value is a sum. This sum initially takes the

value zero, Then, for each layer, L, in the range

1 through 7, that this node performs transactions

for, 2 raised to (L - 1) is added to the sum. For

example, a node which performs primarily routing

functions would have a value of 4 (2^(3-1)). In

contrast, a node which is a host offering

application services would have a value of 72

(2^(4-1) + 2^(7-1)). Note that in the context of

the Internet suite of protocols, values should be

calculated accordingly:

layer functionality

1 physical (e.g., repeaters)

2 datalink/subnetwork (e.g., bridges)

3 internet (e.g., IP gateways)

4 end-to-end (e.g., IP hosts)

7 applications (e.g., mail relays)

For systems including OSI protocols, layers 5 and

6 may also be counted."

::= { system 7 }

THE CODE OF THE PROGRAM WHICH GETTING GENERAL INFORMATIONS ABOUT THE SWITCH

#include <ucd-snmp/ucd-snmp-config.h>

#include <ucd-snmp/ucd-snmp-includes.h>

#include <ucd-snmp/system.h>

#include <string.h>

char *mib[7]={"system.sysDescr.0","system.sysObjectID.0",

"system.sysUpTime.0","system.sysContact.0","system.sysName.0",

"system.sysLocation.0","system.sysServices.0"};

int main(int argc, char ** argv)

{

struct snmp_session session, *ss;

struct snmp_pdu *pdu[10];

struct snmp_pdu *response[10];

oid anOID[MAX_OID_LEN];

size_t anOID_len = MAX_OID_LEN;

struct variable_list *vars;

int status,i=0;

int count=1;

/*

* Initialize the SNMP library

*/

init_snmp("snmpapp");

/*

* Initialize a "session" that defines who we're going to talk to

*/

snmp_sess_init( &session ); /* set up defaults */

session.peername = "193.140.248.3";

/* set the SNMP version number */

session.version = SNMP_VERSION_1;

/* set the SNMPv1 community name used for authentication */

session.community = "public";

session.community_len = strlen(session.community);

/*

* Open the session

*/

SOCK_STARTUP;

ss = snmp_open(&session); /* establish the session

*/

if (!ss) {

snmp_perror("ack");

snmp_log(LOG_ERR, "something horrible happened!!!\n");

exit(2);

}

/*

* Create the PDU for the data for our request.

* 1) We're going to GET the nodes which we have defined in mib[] variable.

*/

while(i<7) {

pdu[i] = snmp_pdu_create(SNMP_MSG_GET);

read_objid(mib[i], anOID, &anOID_len);

snmp_add_null_var(pdu[i], anOID, anOID_len);

/*

* Send the Request out.

*/

status = snmp_synch_response(ss, pdu[i], &response[i]);

/*

* Process the response.

*/

if (status == STAT_SUCCESS & response[i]->errstat ==

SNMP_ERR_NOERROR) {

/*

* SUCCESS: Print the result variables

*/

for(vars = response[i]->variables; vars; vars = vars->next_variable)

print_variable(vars->name, vars->name_length, vars);

/* manipuate the information ourselves */

for(vars = response[i]->variables; vars; vars = vars->next_variable)

{

if (vars->type == ASN_OCTET_STR) {

char *sp = (char *)malloc(1 + vars->val_len);

memcpy(sp, vars->val.string, vars->val_len);

sp[vars->val_len] = '\0';

printf("value #%d is a string: %s\n", count++, sp);

free(sp);

}

else

printf("value #%d is NOT a string! Ack!\n", count++);

}

} else {

/*

* FAILURE: print what went wrong!

*/

if (status == STAT_SUCCESS)

fprintf(stderr, "Error in packet\nReason: %s\n",

snmp_errstring(response[i]->errstat));

else

snmp_sess_perror("snmpget", ss);

}

/*

* Clean up:

* 1) free the response.

*/

if (response[i])

snmp_free_pdu(response[i]);

i++;

} /* while*/

/ * 2) close the session. */

snmp_close(ss);

SOCK_CLEANUP;

return (0);

} /* main() */

OUTPUT OF THE CODE

kutucu@galois:~$ ./termproject

system.sysDescr.0 = 3Com SuperStack II

value #1 is a string: 3Com SuperStack II

system.sysObjectID.0 = OID: enterprises.43.10.27.4.1.2.2

value #2 is NOT a string! Ack!

system.sysUpTime.0 = Timeticks: (813922) 2:15:39.22

value #3 is NOT a string! Ack!

system.sysContact.0 =

value #4 is a string:

system.sysName.0 = Switch 3300

value #5 is a string: Switch 3300

system.sysLocation.0 = Network LAB

value #6 is a string: Network LAB

system.sysServices.0 = 2

value #7 is NOT a string! Ack!

2. QUESTION: The information about ports is available in ifTable MIB structure.

To get this information I used the command snmptranslate -Tp interfaces.ifTable

+-ifTable(2)

|

+-ifEntry(1)

| Index: ifIndex

|

+- -R-- Integer32 ifIndex(1)

| Textual Convention: InterfaceIndex

| Range: 1..2147483647

+- -R-- String ifDescr(2)

| Textual Convention: DisplayString

| Size: 0..255

+- -R-- EnumVal ifType(3)

| Textual Convention: IANAifType

| Values: other(1), regular1822(2), hdh1822(3), ddnX25(4), rfc877x25(5), ethernetCsmacd(6), iso88023Csmacd(7), iso88024TokenBus(8), iso88025TokenRing(9), iso88026Man(10), starLan(11), proteon10Mbit(12), proteon80Mbit(13), hyperchannel(14), fddi(15), lapb(16), sdlc(17), ds1(18), e1(19), basicISDN(20), primaryISDN(21), propPointToPointSerial(22), ppp(23), softwareLoopback(24), eon(25), ethernet3Mbit(26), nsip(27), slip(28), ultra(29), ds3(30), sip(31), frameRelay(32), rs232(33), para(34), arcnet(35), arcnetPlus(36), atm(37), miox25(38), sonet(39), x25ple(40), iso88022llc(41), localTalk(42), smdsDxi(43), frameRelayService(44), v35(45), hssi(46), hippi(47), modem(48), aal5(49), sonetPath(50), sonetVT(51), smdsIcip(52), propVirtual(53), propMultiplexor(54), ieee80212(55), fibreChannel(56), hippiInterface(57), frameRelayInterconnect(58), aflane8023(59), aflane8025(60), cctEmul(61), fastEther(62), isdn(63), v11(64), v36(65), g703at64k(66), g703at2mb(67), qllc(68), fastEtherFX(69), channel(70), ieee80211(71), ibm370parChan(72), escon(73), dlsw(74), isdns(75), isdnu(76), lapd(77), ipSwitch(78), rsrb(79), atmLogical(80), ds0(81), ds0Bundle(82), bsc(83), async(84), cnr(85), iso88025Dtr(86), eplrs(87), arap(88), propCnls(89), hostPad(90), termPad(91), frameRelayMPI(92), x213(93), adsl(94), radsl(95), sdsl(96), vdsl(97), iso88025CRFPInt(98), myrinet(99), voiceEM(100), voiceFXO(101), voiceFXS(102), voiceEncap(103), voiceOverIp(104), atmDxi(105), atmFuni(106), atmIma(107), pppMultilinkBundle(108), ipOverCdlc(109), ipOverClaw(110), stackToStack(111), virtualIpAddress(112), mpc(113), ipOverAtm(114), iso88025Fiber(115), tdlc(116), gigabitEthernet(117), hdlc(118), lapf(119), v37(120), x25mlp(121), x25huntGroup(122), trasnpHdlc(123), interleave(124), fast(125), ip(126), docsCableMaclayer(127), docsCableDownstream(128), docsCableUpstream(129), a12MppSwitch(130), tunnel(131), coffee(132), ces(133), atmSubInterface(134), l2vlan(135), l3ipvlan(136), l3ipxvlan(137), digitalPowerline(138), mediaMailOverIp(139), dtm(140), dcn(141), ipForward(142), msdsl(143), ieee1394(144), if-gsn(145), dvbRccMacLayer(146), dvbRccDownstream(147), dvbRccUpstream(148), atmVirtual(149), mplsTunnel(150), srp(151), voiceOverAtm(152), voiceOverFrameRelay(153), idsl(154), compositeLink(155), ss7SigLink(156), propWirelessP2P(157), frForward(158), rfc1483(159), usb(160), ieee8023adLag(161), bgppolicyaccounting(162), frf16MfrBundle(163), h323Gatekeeper(164), h323Proxy(165), mpls(166), mfSigLink(167), hdsl2(168), shdsl(169), ds1FDL(170), pos(171), dvbAsiIn(172), dvbAsiOut(173), plc(174), nfas(175), tr008(176), gr303RDT(177), gr303IDT(178), isup(179), propDocsWirelessMaclayer(180), propDocsWirelessDownstream(181), propDocsWirelessUpstream(182), hiperlan2(183), propBWAp2Mp(184), sonetOverheadChannel(185), digitalWrapperOverheadChannel(186), aal2(187), radioMAC(188), atmRadio(189), imt(190), mvl(191), reachDSL(192), frDlciEndPt(193), atmVciEndPt(194), opticalChannel(195), opticalTransport(196), propAtm(197), voiceOverCable(198), infiniband(199), teLink(200), q2931(201), virtualTg(202), sipTg(203), sipSig(204), docsCableUpstreamChannel(205), econet(206), pon155(207), pon622(208), bridge(209), linegroup(210), voiceEMFGD(211), voiceFGDEANA(212), voiceDID(213)

+- -R-- Integer32 ifMtu(4)

+- -R-- Gauge ifSpeed(5)

+- -R-- String ifPhysAddress(6)

| Textual Convention: PhysAddress

+- -RW- EnumVal ifAdminStatus(7)

| Values: up(1), down(2), testing(3)

+- -R-- EnumVal ifOperStatus(8)

| Values: up(1), down(2), testing(3), unknown(4), dormant(5), notPresent(6), lowerLayerDown(7)

+- -R-- TimeTicks ifLastChange(9)

+- -R-- Counter ifInOctets(10)

+- -R-- Counter ifInUcastPkts(11)

+- -R-- Counter ifInNUcastPkts(12)

+- -R-- Counter ifInDiscards(13)

+- -R-- Counter ifInErrors(14)

+- -R-- Counter ifInUnknownProtos(15)

+- -R-- Counter ifOutOctets(16)

+- -R-- Counter ifOutUcastPkts(17)

+- -R-- Counter ifOutNUcastPkts(18)

+- -R-- Counter ifOutDiscards(19)

+- -R-- Counter ifOutErrors(20)

+- -R-- Gauge ifOutQLen(21)

+- -R-- ObjID ifSpecific(22)

THE CODE OF THE PROGRAM WHICH GETTING INFORMATIONS ABOUT PORTS OF THE SWITCH

#include <ucd-snmp/ucd-snmp-config.h>

#include <ucd-snmp/ucd-snmp-includes.h>

#include <ucd-snmp/system.h>

#include <string.h>

char *mib[12]={"interfaces.ifTable.ifEntry.ifDescr.100",

"interfaces.ifTable.ifEntry.ifDescr.101",

"interfaces.ifTable.ifEntry.ifDescr.102",

"interfaces.ifTable.ifEntry.ifDescr.103",

"interfaces.ifTable.ifEntry.ifDescr.104",

"interfaces.ifTable.ifEntry.ifDescr.105",

"interfaces.ifTable.ifEntry.ifDescr.106",

"interfaces.ifTable.ifEntry.ifDescr.107",

"interfaces.ifTable.ifEntry.ifDescr.108",

"interfaces.ifTable.ifEntry.ifDescr.109",

"interfaces.ifTable.ifEntry.ifDescr.110",

"interfaces.ifTable.ifEntry.ifDescr.111",},

*mib1[12]={"interfaces.ifTable.ifEntry.ifSpeed.100",

"interfaces.ifTable.ifEntry.ifSpeed.101",

"interfaces.ifTable.ifEntry.ifSpeed.102",

"interfaces.ifTable.ifEntry.ifSpeed.103",

"interfaces.ifTable.ifEntry.ifSpeed.104",

"interfaces.ifTable.ifEntry.ifSpeed.105",

"interfaces.ifTable.ifEntry.ifSpeed.106",

"interfaces.ifTable.ifEntry.ifSpeed.107",

"interfaces.ifTable.ifEntry.ifSpeed.108",

"interfaces.ifTable.ifEntry.ifSpeed.109",

"interfaces.ifTable.ifEntry.ifSpeed.110",

"interfaces.ifTable.ifEntry.ifSpeed.111",};

int main(int argc, char ** argv)

{

struct snmp_session session, *ss;

struct snmp_pdu *pdu[12],*pdu1[12];

struct snmp_pdu *response[12];

oid anOID[MAX_OID_LEN];

size_t anOID_len = MAX_OID_LEN;

struct variable_list *vars;

int status,i=0;

int count=1;

/*

* Initialize the SNMP library

*/

init_snmp("snmpapp");

/*

* Initialize a "session" that defines who we're going to talk to

*/

snmp_sess_init( &session ); /* set up defaults */

session.peername = "193.140.248.3";

/* set the SNMP version number */

session.version = SNMP_VERSION_1;

/* set the SNMPv1 community name used for authentication */

session.community = "public";

session.community_len = strlen(session.community);

/*

* Open the session

*/

SOCK_STARTUP;

ss = snmp_open(&session); /* establish the session

*/

if (!ss) {

snmp_perror("ack");

snmp_log(LOG_ERR, "something horrible happened!!!\n");

exit(2);

}

/*

* Create the PDU for the data for our request.

* 1) We're going to GET the nodes which we have defined in mib[] variable.

*/

while(i<12) {

pdu[i] = snmp_pdu_create(SNMP_MSG_GETNEXT);

read_objid(mib[i], anOID, &anOID_len);

snmp_add_null_var(pdu[i], anOID, anOID_len);

/*

* Send the Request out.

*/

status = snmp_synch_response(ss, pdu[i], &response[i]);

/*

* Process the response.

*/

if (status == STAT_SUCCESS & response[i]->errstat == SNMP_ERR_NOERROR) {

/*

* SUCCESS: Print the result variables

*/

for(vars = response[i]->variables; vars; vars = vars->next_variable)

print_variable(vars->name, vars->name_length,vars);

} else {

/*

* FAILURE: print what went wrong!

*/

if (status == STAT_SUCCESS)

fprintf(stderr, "Error in packet\nReason: %s\n",

snmp_errstring(response[i]->errstat));

else

snmp_sess_perror("snmpget", ss);

}

/*

* Clean up:

* 1) free the response.

* 2) close the session.

*/

if (response[i])

snmp_free_pdu(response[i]);

i++;

} /* while*/

i=0;

while(i<12) {

pdu1[i] = snmp_pdu_create(SNMP_MSG_GETNEXT);

read_objid(mib1[i], anOID, &anOID_len);

snmp_add_null_var(pdu1[i], anOID, anOID_len);

/*

* Send the Request out.

*/

status = snmp_synch_response(ss, pdu1[i], &response[i]);

/*

* Process the response.

*/

if (status == STAT_SUCCESS & response[i]->errstat == SNMP_ERR_NOERROR) {

/*

* SUCCESS: Print the result variables

*/

for(vars = response[i]->variables; vars; vars = vars->next_variable)

print_variable(vars->name, vars->name_length,vars);

} else {

/*

* FAILURE: print what went wrong!

*/

if (status == STAT_SUCCESS)

fprintf(stderr, "Error in packet\nReason: %s\n",

snmp_errstring(response[i]->errstat));

else

snmp_sess_perror("snmpget", ss);

}

/*

* Clean up:

* 1) free the response.

* 2) close the session.

*/

if (response[i])

snmp_free_pdu(response[i]);

i++;

}

snmp_close(ss);

SOCK_CLEANUP;

return (0);

} /* main() */

OUTPUT OF THE PROGRAM

interfaces.ifTable.ifEntry.ifDescr.101 = RMON:10/100 Port 1 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.102 = RMON:10/100 Port 2 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.103 = RMON:10/100 Port 3 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.104 = RMON:10/100 Port 4 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.105 = RMON:10/100 Port 5 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.106 = RMON:10/100 Port 6 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.107 = RMON:10/100 Port 7 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.108 = RMON:10/100 Port 8 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.109 = RMON:10/100 Port 9 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.110 = RMON:10/100 Port 10 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.111 = RMON:10/100 Port 11 on Unit 1

interfaces.ifTable.ifEntry.ifDescr.112 = RMON:10/100 Port 12 on Unit 1

interfaces.ifTable.ifEntry.ifSpeed.101 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.102 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.103 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.104 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.105 = Gauge32: 10000000

interfaces.ifTable.ifEntry.ifSpeed.106 = Gauge32: 10000000

interfaces.ifTable.ifEntry.ifSpeed.107 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.108 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.109 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.110 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.111 = Gauge32: 100000000

interfaces.ifTable.ifEntry.ifSpeed.112 = Gauge32: 100000000

20