<commit_before>package org.opennms.netmgt.enlinkd.snmp;

import java.net.InetAddress;

import org.opennms.netmgt.model.OspfElement;
import org.opennms.netmgt.model.OspfLink;

import org.opennms.netmgt.snmp.SnmpAgentConfig;
import org.opennms.netmgt.snmp.SnmpObjId;
import org.opennms.netmgt.snmp.SnmpUtils;
import org.opennms.netmgt.snmp.SnmpValue;
import org.opennms.netmgt.snmp.TableTracker;

public class OspfIpAddrTableGetter extends TableTracker {

    public final static SnmpObjId IPADENT_IFINDEX = SnmpObjId.get(".1.3.6.1.2.1.4.20.1.2");
    public final static SnmpObjId IPADENT_NETMASK = SnmpObjId.get(".1.3.6.1.2.1.4.20.1.3");

	/**
	 * The SnmpPeer object used to communicate via SNMP with the remote host.
	 */
	private SnmpAgentConfig m_agentConfig;

	public OspfIpAddrTableGetter(SnmpAgentConfig peer) {
		m_agentConfig = peer;
	}

	public OspfElement get(OspfElement element) {
		SnmpValue[] val = get(element.getOspfRouterId());
		if (val != null && val.length == 2 ) {
			if (!val[0].isNull() && val[0].isNumeric() )
				element.setOspfRouterIdIfindex(val[0].toInt());
			if (!val[1].isNull()) {
				element.setOspfRouterIdNetmask(val[1].toInetAddress());
			}
		}
		return element;
	}
	
	public OspfLink get(OspfLink link) {
		
		SnmpValue[] val = get(link.getOspfIpAddr());
		if (val != null && val.length == 2 ) {
			if (!val[0].isNull() && val[0].isNumeric() )
				link.setOspfIfIndex(val[0].toInt());
			if (!val[1].isNull()) {
				link.setOspfIpMask(val[1].toInetAddress());
			}
		}
		return link;
	}
	private SnmpValue[] get(InetAddress addr) {
		SnmpObjId instance = SnmpObjId.get(addr.getHostAddress());
		SnmpObjId[] oids = new SnmpObjId[]
				{SnmpObjId.get(IPADENT_IFINDEX, instance),
					SnmpObjId.get(IPADENT_NETMASK, instance)};
		
		return SnmpUtils.get(m_agentConfig, oids);
	}

}<commit_msg>Fix for NMS-6911: Illegal Argument Exception in EnhancedLink Ospf Node Discovery<commit_after>package org.opennms.netmgt.enlinkd.snmp;

import java.net.InetAddress;

import org.opennms.netmgt.model.OspfElement;
import org.opennms.netmgt.model.OspfLink;

import org.opennms.netmgt.snmp.SnmpAgentConfig;
import org.opennms.netmgt.snmp.SnmpObjId;
import org.opennms.netmgt.snmp.SnmpUtils;
import org.opennms.netmgt.snmp.SnmpValue;
import org.opennms.netmgt.snmp.TableTracker;

public class OspfIpAddrTableGetter extends TableTracker {

    public final static SnmpObjId IPADENT_IFINDEX = SnmpObjId.get(".1.3.6.1.2.172.16.31.10.2");
    public final static SnmpObjId IPADENT_NETMASK = SnmpObjId.get(".1.3.6.1.2.1.4.20.1.3");

	/**
	 * The SnmpPeer object used to communicate via SNMP with the remote host.
	 */
	private SnmpAgentConfig m_agentConfig;

	public OspfIpAddrTableGetter(SnmpAgentConfig peer) {
		m_agentConfig = peer;
	}

	public OspfElement get(OspfElement element) {
		SnmpValue[] val = get(element.getOspfRouterId());
		if (val != null && val.length == 2 ) {
			if (!val[0].isNull() && val[0].isNumeric() )
				element.setOspfRouterIdIfindex(val[0].toInt());
			if (!val[1].isNull() && !val[1].isError()) {
				try {
					element.setOspfRouterIdNetmask(val[1].toInetAddress());
				} catch (IllegalArgumentException e) {
					
				}
			}
		}
		return element;
	}
	
	public OspfLink get(OspfLink link) {
		
		SnmpValue[] val = get(link.getOspfIpAddr());
		if (val != null && val.length == 2 ) {
			if (!val[0].isNull() && val[0].isNumeric() )
				link.setOspfIfIndex(val[0].toInt());
			if (!val[1].isNull() && !val[1].isError()) {
				try {
					link.setOspfIpMask(val[1].toInetAddress());
				} catch (IllegalArgumentException e) {
					
				}
			}
		}
		return link;
	}

	private SnmpValue[] get(InetAddress addr) {
		SnmpObjId instance = SnmpObjId.get(addr.getHostAddress());
		SnmpObjId[] oids = new SnmpObjId[]
				{SnmpObjId.get(IPADENT_IFINDEX, instance),
					SnmpObjId.get(IPADENT_NETMASK, instance)};
		
		return SnmpUtils.get(m_agentConfig, oids);
	}

}
{'fraction_non_alphanumeric': 0.1449795081967213, 'fraction_numerical': 0.019979508196721313, 'mean_word_length': 4.158520475561427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5741904', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1530, 'n_words': 250}