Skip to content

Commit

Permalink
Fix NMS-6912: lldpchassisid not properly decoded for DragonWave
Browse files Browse the repository at this point in the history
We have a check for sanity for tdecoding either lldpchassid
and lldpport.
Also we check that the lldp is valid before persisting
  • Loading branch information
rssntn67 committed Mar 11, 2015
1 parent 7e037b7 commit 89e849e
Show file tree
Hide file tree
Showing 10 changed files with 560 additions and 175 deletions.
Expand Up @@ -102,7 +102,11 @@ protected void runCollection() {
LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {

public void processLldpRemRow(final LldpRemRow row) {
m_linkd.getQueryManager().store(getNodeId(),row.getLldpLink(lldpLocPort));
// Fix for DragonWave, we avoid to store if target has the same chassis id then the source
if (lldpLocalGroup.getLldpLocChassisid().equals(row.getLldpRemChassisId())
&& lldpLocalGroup.getLldpLocChassisidSubType().intValue() == row.getLldpRemChassisidSubtype().intValue())
return;
m_linkd.getQueryManager().store(getNodeId(),row.getLldpLink(lldpLocPort));
}
};

Expand Down

This file was deleted.

Expand Up @@ -63,7 +63,7 @@ public LldpLink get(Integer lldpRemLocalPortNum) {
return null;
LldpLink lldplink = new LldpLink();
lldplink.setLldpLocalPortNum(lldpRemLocalPortNum);
lldplink.setLldpPortId(LldpHelper.decodeLldpPortId(val[0].toInt(),val[1]));
lldplink.setLldpPortId(LldpRemTableTracker.decodeLldpPortId(val[0].toInt(),val[1]));
lldplink.setLldpPortIdSubType(LldpPortIdSubType.get(val[0].toInt()));
if (val[2] != null)
lldplink.setLldpPortDescr((val[2].toDisplayString()));
Expand Down
Expand Up @@ -28,6 +28,7 @@

package org.opennms.netmgt.enlinkd.snmp;

import org.opennms.core.utils.LldpUtils;
import org.opennms.core.utils.LldpUtils.LldpChassisIdSubType;
import org.opennms.netmgt.model.LldpElement;
import org.opennms.netmgt.snmp.AggregateTracker;
Expand All @@ -40,7 +41,7 @@

public final class LldpLocalGroupTracker extends AggregateTracker {

private final static Logger LOG = LoggerFactory.getLogger(LldpLocalGroupTracker.class);
private final static Logger LOG = LoggerFactory.getLogger(LldpLocalGroupTracker.class);

public final static String LLDP_LOC_CHASSISID_SUBTYPE_ALIAS = "lldpLocChassisIdSubtype";
public final static String LLDP_LOC_CHASSISID_SUBTYPE_OID = ".1.0.8802.1.1.2.1.3.1";
Expand Down Expand Up @@ -86,6 +87,142 @@ public final class LldpLocalGroupTracker extends AggregateTracker {

public static final String LLDP_LOC_OID = ".1.0.8802.1.1.2.1.3";

public static String decodeLldpChassisId(final SnmpValue lldpchassisid, Integer lldpLocChassisidSubType) {
try {
LldpChassisIdSubType type = LldpChassisIdSubType.get(lldpLocChassisidSubType);

/*
* If the associated LldpChassisIdSubtype object has a value of
* 'chassisComponent(1)', then the octet string identifies
* a particular instance of the entPhysicalAlias object
* (defined in IETF RFC 2737) for a chassis component (i.e.,
* an entPhysicalClass value of 'chassis(3)').
*
* If the associated LldpChassisIdSubtype object has a value
* of 'interfaceAlias(2)', then the octet string identifies
* a particular instance of the ifAlias object (defined in
* IETF RFC 2863) for an interface on the containing chassis.
* If the particular ifAlias object does not contain any values,
* another chassis identifier type should be used.
*
* If the associated LldpChassisIdSubtype object has a value
* of 'portComponent(3)', then the octet string identifies a
* particular instance of the entPhysicalAlias object (defined
* in IETF RFC 2737) for a port or backplane component within
* the containing chassis.
*
* If the associated LldpChassisIdSubtype object has a value of
* 'macAddress(4)', then this string identifies a particular
* unicast source address (encoded in network byte order and
* IEEE 802.3 canonical bit order), of a port on the containing
* chassis as defined in IEEE Std 802-2001.
*
* If the associated LldpChassisIdSubtype object has a value of
* 'networkAddress(5)', then this string identifies a particular
* network address, encoded in network byte order, associated
* with one or more ports on the containing chassis. The first
* octet contains the IANA Address Family Numbers enumeration
* value for the specific address type, and octets 2 through
* N contain the network address value in network byte order.
*
* If the associated LldpChassisIdSubtype object has a value
* of 'interfaceName(6)', then the octet string identifies
* a particular instance of the ifName object (defined in
* IETF RFC 2863) for an interface on the containing chassis.
* If the particular ifName object does not contain any values,
* another chassis identifier type should be used.
*
* If the associated LldpChassisIdSubtype object has a value of
* 'local(7)', then this string identifies a locally assigned
* Chassis ID.
*
*
*/
switch (type) {
/*
* entPhysicalAlias SnmpAdminString
*
* SnmpAdminString ::= TEXTUAL-CONVENTION
* DISPLAY-HINT "255a"
* STATUS current
* DESCRIPTION "An octet string containing administrative
* information, preferably in human-readable form.
*
* To facilitate internationalization, this
* information is represented using the ISO/IEC
* IS 10646-1 character set, encoded as an octet
* string using the UTF-8 transformation format
* described in [RFC2279].
*
* Since additional code points are added by
* amendments to the 10646 standard from time
* to time, implementations must be prepared to
* encounter any code point from 0x00000000 to
* 0x7fffffff. Byte sequences that do not
* correspond to the valid UTF-8 encoding of a
* code point or are outside this range are
* prohibited.
*
* The use of control codes should be avoided.
*
* When it is necessary to represent a newline,
* the control code sequence CR LF should be used.
*
* The use of leading or trailing white space should
* be avoided.
*
* For code points not directly supported by user
* interface hardware or software, an alternative
* means of entry and display, such as hexadecimal,
* may be provided.
*
* For information encoded in 7-bit US-ASCII,
* the UTF-8 encoding is identical to the
* US-ASCII encoding.
*
* UTF-8 may require multiple bytes to represent a
* single character / code point; thus the length
* of this object in octets may be different from
* the number of characters encoded. Similarly,
* size constraints refer to the number of encoded
* octets, not the number of characters represented
* by an encoding.
* Note that when this TC is used for an object that
* is used or envisioned to be used as an index, then
* a SIZE restriction MUST be specified so that the
* number of sub-identifiers for any object instance
* does not exceed the limit of 128, as defined by
* [RFC1905].
*
* Note that the size of an SnmpAdminString object is
* measured in octets, not characters.
* "
* SYNTAX OCTET STRING (SIZE (0..255))
*/
case LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT:
case LLDP_CHASSISID_SUBTYPE_PORTCOMPONENT:
case LLDP_CHASSISID_SUBTYPE_INTERFACEALIAS:
case LLDP_CHASSISID_SUBTYPE_INTERFACENAME:
case LLDP_CHASSISID_SUBTYPE_LOCAL:
if (lldpchassisid.isDisplayable())
return lldpchassisid.toDisplayString();
else
return lldpchassisid.toHexString();
case LLDP_CHASSISID_SUBTYPE_MACADDRESS:
return lldpchassisid.toHexString();
case LLDP_CHASSISID_SUBTYPE_NETWORKADDRESS:
LldpUtils.decodeNetworkAddress(lldpchassisid.toDisplayString());
}
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
} catch (IndexOutOfBoundsException ioe) {
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return lldpchassisid.toHexString();
}

private SnmpStore m_store;

public LldpLocalGroupTracker() {
Expand All @@ -97,8 +234,8 @@ public Integer getLldpLocChassisidSubType() {
return m_store.getInt32(LLDP_LOC_CHASSISID_SUBTYPE_ALIAS);
}

public SnmpValue getLldpLocChassisid() {
return m_store.getValue(LLDP_LOC_CHASSISID_ALIAS);
public String getLldpLocChassisid() {
return decodeLldpChassisId(m_store.getValue(LLDP_LOC_CHASSISID_ALIAS),getLldpLocChassisidSubType());
}

public String getLldpLocSysname() {
Expand All @@ -120,12 +257,12 @@ protected void reportNoSuchNameErr(String msg) {
LOG.info("Error retrieving lldpLocalGroup: {}",msg);
}

public LldpElement getLldpElement() {
public LldpElement getLldpElement() {
LldpElement lldpElement = new LldpElement();
lldpElement.setLldpChassisId(LldpHelper.decodeLldpChassisId(getLldpLocChassisid(), getLldpLocChassisidSubType()));
lldpElement.setLldpChassisId(getLldpLocChassisid());
lldpElement.setLldpChassisIdSubType(LldpChassisIdSubType.get(getLldpLocChassisidSubType()));
lldpElement.setLldpSysname(getLldpLocSysname());
return lldpElement;
}
}

}

0 comments on commit 89e849e

Please sign in to comment.