/
LldpLinkdNodeDiscovery.java
140 lines (122 loc) · 5.34 KB
/
LldpLinkdNodeDiscovery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2006-2012 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2012 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 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.netmgt.enlinkd;
import static org.opennms.core.utils.InetAddressUtils.str;
import java.util.Date;
import org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter;
import org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker;
import org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker;
import org.opennms.netmgt.model.topology.LinkableSnmpNode;
import org.opennms.netmgt.snmp.SnmpUtils;
import org.opennms.netmgt.snmp.SnmpWalker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class is designed to collect the necessary SNMP information from the
* target address and store the collected information. When the class is
* initially constructed no information is collected. The SNMP Session
* creating and collection occurs in the main run method of the instance. This
* allows the collection to occur in a thread if necessary.
*/
public final class LldpLinkdNodeDiscovery extends AbstractLinkdNodeDiscovery {
private final static Logger LOG = LoggerFactory.getLogger(LldpLinkdNodeDiscovery.class);
/**
* Constructs a new SNMP collector for Lldp Node Discovery.
* The collection does not occur until the
* <code>run</code> method is invoked.
*
* @param EnhancedLinkd linkd
* @param LinkableNode node
*/
public LldpLinkdNodeDiscovery(final EnhancedLinkd linkd, final LinkableSnmpNode node) {
super(linkd, node);
}
protected void runCollection() {
final Date now = new Date();
String trackerName = "lldpLocalGroup";
final LldpLocalGroupTracker lldpLocalGroup = new LldpLocalGroupTracker();
LOG.info( "run: collecting {} on: {}",trackerName, str(getTarget()));
SnmpWalker walker = SnmpUtils.createWalker(getPeer(), trackerName, lldpLocalGroup);
walker.start();
try {
walker.waitFor();
if (walker.timedOut()) {
LOG.info(
"run:Aborting Lldp Linkd node scan : Agent timed out while scanning the {} table", trackerName);
return;
} else if (walker.failed()) {
LOG.info(
"run:Aborting Lldp Linkd node scan : Agent failed while scanning the {} table: {}", trackerName,walker.getErrorMessage());
return;
}
} catch (final InterruptedException e) {
LOG.error("run: Lldp Linkd node collection interrupted, exiting", e);
return;
}
if (lldpLocalGroup.getLldpLocChassisid() == null ) {
LOG.info( "lldp mib not supported on: {}", str(getPeer().getAddress()));
return;
} else {
LOG.info( "found lldp identifier : {}", lldpLocalGroup.getLldpElement());
}
m_linkd.getQueryManager().store(getNodeId(), lldpLocalGroup.getLldpElement());
final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(getPeer());
trackerName = "lldpRemTable";
LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {
public void processLldpRemRow(final LldpRemRow row) {
m_linkd.getQueryManager().store(getNodeId(),row.getLldpLink(lldpLocPort));
}
};
LOG.info( "run: collecting {} on: {}",trackerName, str(getTarget()));
walker = SnmpUtils.createWalker(getPeer(), trackerName, lldpRemTable);
walker.start();
try {
walker.waitFor();
if (walker.timedOut()) {
LOG.info(
"run:Aborting node scan : Agent timed out while scanning the {} table", trackerName);
} else if (walker.failed()) {
LOG.info(
"run:Aborting node scan : Agent failed while scanning the {} table: {}", trackerName,walker.getErrorMessage());
}
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting",e);
return;
}
m_linkd.getQueryManager().reconcileLldp(getNodeId(),now);
}
@Override
public String getInfo() {
return "ReadyRunnable:LldpLinkNodeDiscovery node: "+ getNodeId() + " ip:" + str(getTarget())
+ " package:" + getPackageName();
}
@Override
public String getName() {
return "LldpLinkDiscovery";
}
}