📄 routeconnect.java
字号:
package com.sitech.net.topo.netobj;
import java.util.List;
import java.util.Vector;
import sitech.www.frame.jdbc.SqlInsert;
import sitech.www.frame.jdbc.SqlQuery;
import com.sitech.net.topo.CommSnmpGet;
import com.sitech.net.topo.util.RandomGUID;
public class RouteConnect {
public Vector saveToDB(String nodeid, String ip) {
System.out.println("[处理NodeID: " + nodeid + " IpAddress: " + ip
+ " 路由信息]");
Vector vector = new Vector();
// 填充RouterConnect信息表
// iproutetype!=3为非直连设备,是路由过去的;不是router自身,但有可能是已经发现过的节点
String rc_sql = "select distinct(iproutenexthop) from tb_topo_iproutetable where iproutetype<>'3' and nodeid='"
+ nodeid
+ "' and iproutenexthop not in (select moni_ipaddr from tb_topo_node_info) and iproutenexthop not in (select ipaddr from tb_topo_ipaddrtable where nodeid='"
+ nodeid + "')";
List rc_list = SqlQuery.findList(rc_sql);
for (int i = 0; i < rc_list.size(); i++) {
String[] rc_item = (String[]) rc_list.get(i);
String ipaddr = rc_item[0];
RandomGUID myGUID = new RandomGUID();
String newNodeID = myGUID.toString();
// 添加新节点,排除已经发现过的节点
List list1 = SqlQuery
.findList("select * from tb_topo_ipaddrtable where ipaddr='"
+ ipaddr + "'");
if (!(list1.size() > 0)) {
CommSnmpGet snmpGet = new CommSnmpGet(ipaddr, 161, "ahnms2008");
snmpGet.init();
boolean isSwitch = snmpGet.isSwitch();
snmpGet.release();
String nodeType = "unknown";
if (isSwitch) {
nodeType = "switch";
} else {
nodeType = "router";
}
System.out.println("[发现新节点 NodeID: " + newNodeID
+ " IpAddress: " + ipaddr + "]");
String insert_ri_sql = "insert into tb_topo_node_info (node_id,node_type,moni_ipaddr,moni_port,moni_community,process_flag,root_flag,discover_nodeid,info_proc_flag,connect_type) values ('"
+ newNodeID
+ "','"
+ nodeType
+ "','"
+ ipaddr
+ "','161','ahnms2008','0','0','"
+ nodeid
+ "','0','4')";
SqlInsert.insert(insert_ri_sql);
// 填充vector
vector.add(newNodeID);
}
}
System.out.println("[NodeID: " + nodeid + " IpAddress: " + ip
+ " 路由信息处理完毕]");
// 处理链路信息
NetLink netLink = new NetLink();
netLink.saveToDB(nodeid, ip);
return vector;
}
public static void main(String args[]) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -