Skip to content

Commit

Permalink
Fix NMS-7184: lldp decode exception
Browse files Browse the repository at this point in the history
Reviewed LLDP decoding, fixed bug and crated a test class
  • Loading branch information
rssntn67 committed Mar 4, 2015
1 parent 1a33bab commit bc23e1a
Show file tree
Hide file tree
Showing 10 changed files with 692 additions and 255 deletions.
509 changes: 509 additions & 0 deletions core/lib/src/main/java/org/opennms/core/utils/LldpUtils.java

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions core/lib/src/test/java/org/opennms/core/utils/LldpUtilsTest.java
@@ -0,0 +1,47 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2011-2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.core.utils;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class LldpUtilsTest {

@Test
/*
* From NMS-7148: 01:ac:14:14:8b
* 01 is IP version 4 end the address is 172.20.20.139
*/
public void testNMS7184() throws Exception {
String ianafamilyaddress = "01:ac:14:14:8b";
assertEquals(1, LldpUtils.IanaFamilyAddressStringToType(ianafamilyaddress).intValue());
assertEquals("172.20.20.139",LldpUtils.decodeNetworkAddress(ianafamilyaddress));
}

}
Expand Up @@ -36,7 +36,7 @@
import org.hibernate.HibernateException;
import org.hibernate.type.EnumType;
import org.hibernate.type.IntegerType;
import org.opennms.netmgt.model.LldpElement.LldpChassisIdSubType;
import org.opennms.core.utils.LldpUtils.LldpChassisIdSubType;

public class LldpChassisIdSubTypeUserType extends EnumType {

Expand Down
120 changes: 3 additions & 117 deletions opennms-model/src/main/java/org/opennms/netmgt/model/LldpElement.java
Expand Up @@ -30,8 +30,6 @@

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -47,6 +45,7 @@

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Type;
import org.opennms.core.utils.LldpUtils.LldpChassisIdSubType;

@Entity
@Table(name="lldpElement")
Expand All @@ -55,125 +54,12 @@ public final class LldpElement implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3134355798509685991L;
private static final long serialVersionUID = -3134355798509685991L;

public enum LldpChassisIdSubType {
/*
* LldpChassisIdSubtype ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"This TC describes the source of a chassis identifier.
The enumeration 'chassisComponent(1)' represents a chassis
identifier based on the value of entPhysicalAlias object
(defined in IETF RFC 2737) for a chassis component (i.e.,
an entPhysicalClass value of 'chassis(3)').
The enumeration 'interfaceAlias(2)' represents a chassis
identifier based on the value of ifAlias object (defined in
IETF RFC 2863) for an interface on the containing chassis.
The enumeration 'portComponent(3)' represents a chassis
identifier based on the value of entPhysicalAlias object
(defined in IETF RFC 2737) for a port or backplane
component (i.e., entPhysicalClass value of 'port(10)' or
'backplane(4)'), within the containing chassis.
The enumeration 'macAddress(4)' represents a chassis
identifier based on the value of a 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.
The enumeration 'networkAddress(5)' represents a chassis
identifier based on a network address, associated with
a particular chassis. The encoded address is actually
composed of two fields. The first field is a single octet,
representing the IANA AddressFamilyNumbers value for the
specific address type, and the second field is the network
address value.
The enumeration 'interfaceName(6)' represents a chassis
identifier based on the value of ifName object (defined in
IETF RFC 2863) for an interface on the containing chassis.
The enumeration 'local(7)' represents a chassis identifier
based on a locally defined value."
SYNTAX INTEGER {
chassisComponent(1),
interfaceAlias(2),
portComponent(3),
macAddress(4),
networkAddress(5),
interfaceName(6),
local(7)
}
*/
LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT(1),
LLDP_CHASSISID_SUBTYPE_INTERFACEALIAS(2),
LLDP_CHASSISID_SUBTYPE_PORTCOMPONENT(3),
LLDP_CHASSISID_SUBTYPE_MACADDRESS(4),
LLDP_CHASSISID_SUBTYPE_NETWORKADDRESS(5),
LLDP_CHASSISID_SUBTYPE_INTERFACENAME(6),
LLDP_CHASSISID_SUBTYPE_LOCAL(7);

private int m_type;

LldpChassisIdSubType(int type) {
m_type=type;
}

protected static final Map<Integer, String> s_typeMap = new HashMap<Integer, String>();

static {
s_typeMap.put(1, "chassisComponent" );
s_typeMap.put(2, "interfaceAlias" );
s_typeMap.put(3, "portComponent" );
s_typeMap.put(4, "macAddress" );
s_typeMap.put(5, "networkAddress" );
s_typeMap.put(6, "interfaceName" );
s_typeMap.put(7, "local" );
}

/**
* <p>ElementIdentifierTypeString</p>
*
* @return a {@link java.lang.String} object.
*/
/**
*/
public static String getTypeString(Integer code) {
if (s_typeMap.containsKey(code))
return s_typeMap.get( code);
return null;
}

public Integer getValue() {
return m_type;
}

public static LldpChassisIdSubType get(Integer code) {
if (code == null)
throw new IllegalArgumentException("Cannot create LldpChassisIdSubType from null code");
switch (code) {
case 1: return LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT;
case 2: return LLDP_CHASSISID_SUBTYPE_INTERFACEALIAS;
case 3: return LLDP_CHASSISID_SUBTYPE_PORTCOMPONENT;
case 4: return LLDP_CHASSISID_SUBTYPE_MACADDRESS;
case 5: return LLDP_CHASSISID_SUBTYPE_NETWORKADDRESS;
case 6: return LLDP_CHASSISID_SUBTYPE_INTERFACENAME;
case 7: return LLDP_CHASSISID_SUBTYPE_LOCAL;
default:
throw new IllegalArgumentException("Cannot create LldpChassisIdSubType from code "+code);
}
}

}

private Integer m_id;
private String m_lldpChassisId;
private String m_lldpSysname;
private String m_lldpSysname;
private LldpChassisIdSubType m_lldpChassisIdSubType;
private Date m_lldpNodeCreateTime = new Date();
private Date m_lldpNodeLastPollTime;
Expand Down
115 changes: 3 additions & 112 deletions opennms-model/src/main/java/org/opennms/netmgt/model/LldpLink.java
Expand Up @@ -30,8 +30,6 @@

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -47,7 +45,8 @@

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Type;
import org.opennms.netmgt.model.LldpElement.LldpChassisIdSubType;
import org.opennms.core.utils.LldpUtils.LldpPortIdSubType;
import org.opennms.core.utils.LldpUtils.LldpChassisIdSubType;

@Entity
@Table(name="lldpLink")
Expand All @@ -59,114 +58,6 @@ public class LldpLink implements Serializable {
private static final long serialVersionUID = 3813247749765614567L;


public enum LldpPortIdSubType{
LLDP_PORTID_SUBTYPE_INTERFACEALIAS(1),
LLDP_PORTID_SUBTYPE_PORTCOMPONENT(2),
LLDP_PORTID_SUBTYPE_MACADDRESS(3),
LLDP_PORTID_SUBTYPE_NETWORKADDRESS(4),
LLDP_PORTID_SUBTYPE_INTERFACENAME(5),
LLDP_PORTID_SUBTYPE_AGENTCIRCUITID(6),
LLDP_PORTID_SUBTYPE_LOCAL(7);
/*
* LldpPortIdSubtype ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"This TC describes the source of a particular type of port
identifier used in the LLDP MIB.
The enumeration 'interfaceAlias(1)' represents a port
identifier based on the ifAlias MIB object, defined in IETF
RFC 2863.
The enumeration 'portComponent(2)' represents a port
identifier based on the value of entPhysicalAlias (defined in
IETF RFC 2737) for a port component (i.e., entPhysicalClass
value of 'port(10)'), within the containing chassis.
The enumeration 'macAddress(3)' represents a port identifier
based on a unicast source address (encoded in network
byte order and IEEE 802.3 canonical bit order), which has
been detected by the agent and associated with a particular
port (IEEE Std 802-2001).
The enumeration 'networkAddress(4)' represents a port
identifier based on a network address, detected by the agent
and associated with a particular port.
The enumeration 'interfaceName(5)' represents a port
identifier based on the ifName MIB object, defined in IETF
RFC 2863.
The enumeration 'agentCircuitId(6)' represents a port
identifier based on the agent-local identifier of the circuit
(defined in RFC 3046), detected by the agent and associated
with a particular port.
The enumeration 'local(7)' represents a port identifier
based on a value locally assigned."
SYNTAX INTEGER {
interfaceAlias(1),
portComponent(2),
macAddress(3),
networkAddress(4),
interfaceName(5),
agentCircuitId(6),
local(7)
}
*/
private int m_type;

LldpPortIdSubType(Integer chassisIdsubtype) {
m_type = chassisIdsubtype;
}

protected static final Map<Integer, String> s_typeMap = new HashMap<Integer, String>();

static {
s_typeMap.put(1, "interfaceAlias" );
s_typeMap.put(2, "portComponent" );
s_typeMap.put(3, "macAddress" );
s_typeMap.put(4, "networkAddress" );
s_typeMap.put(5, "interfaceName" );
s_typeMap.put(6, "agentCircuitId" );
s_typeMap.put(7, "local" );
}

/**
* <p>ElementIdentifierTypeString</p>
*
* @return a {@link java.lang.String} object.
*/
/**
*/
public static String getTypeString(Integer code) {
if (s_typeMap.containsKey(code))
return s_typeMap.get( code);
return null;
}

public static LldpPortIdSubType get(Integer code) {
if (code == null)
throw new IllegalArgumentException("Cannot create LldpPortIdSubType from null code");
switch (code) {
case 1: return LLDP_PORTID_SUBTYPE_INTERFACEALIAS;
case 2: return LLDP_PORTID_SUBTYPE_PORTCOMPONENT;
case 3: return LLDP_PORTID_SUBTYPE_MACADDRESS;
case 4: return LLDP_PORTID_SUBTYPE_NETWORKADDRESS;
case 5: return LLDP_PORTID_SUBTYPE_INTERFACENAME;
case 6: return LLDP_PORTID_SUBTYPE_AGENTCIRCUITID;
case 7: return LLDP_PORTID_SUBTYPE_LOCAL;
default:
throw new IllegalArgumentException("Cannot create LldpPortIdSubType from code "+code);
}
}

public Integer getValue() {
return m_type;
}

}

private Integer m_id;
private OnmsNode m_node;
Expand All @@ -179,7 +70,7 @@ public Integer getValue() {

private String m_lldpRemChassisId;
private String m_lldpRemSysname;
private LldpChassisIdSubType m_lldpRemChassisIdSubType;
private org.opennms.core.utils.LldpUtils.LldpChassisIdSubType m_lldpRemChassisIdSubType;
private LldpPortIdSubType m_lldpRemPortIdSubType;
private String m_lldpRemPortId;
private String m_lldpRemPortDescr;
Expand Down
Expand Up @@ -36,7 +36,7 @@
import org.hibernate.HibernateException;
import org.hibernate.type.EnumType;
import org.hibernate.type.IntegerType;
import org.opennms.netmgt.model.LldpLink.LldpPortIdSubType;
import org.opennms.core.utils.LldpUtils.LldpPortIdSubType;

public class LldpPortIdSubTypeUserType extends EnumType {

Expand Down

0 comments on commit bc23e1a

Please sign in to comment.