org.snmp4j.util.TreeEvent Java Examples

The following examples show how to use org.snmp4j.util.TreeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LumentumSdnRoadmFlowRuleProgrammable.java    From onos with Apache License 2.0 6 votes vote down vote up
private PortNumber getAddDropPort(int channel, boolean isAddPort) {
    OID oid = new OID(CTRL_CHANNEL_ADD_DROP_PORT_INDEX + (isAddPort ? "1" : "2"));

    for (TreeEvent event : snmp.get(oid)) {
        if (event == null) {
            return null;
        }

        VariableBinding[] varBindings = event.getVariableBindings();

        for (VariableBinding varBinding : varBindings) {
            if (varBinding.getOid().last() == channel) {
                int port = varBinding.getVariable().toInt();
                if (!isAddPort) {
                    port += DROP_PORT_OFFSET;
                }
                return PortNumber.portNumber(port);

            }
        }

    }

    return null;
}
 
Example #2
Source File: SNMPGetter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a SNMP walk and returns the list of {@link TreeEvent}
 * @return the list of {@link TreeEvent}
 */
public List<TreeEvent> walk() {
    TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory());
    @SuppressWarnings("unchecked")
    List<TreeEvent> events = treeUtils.getSubtree(this.target, this.oid);
    return events;
}
 
Example #3
Source File: LumentumAlarmConsumer.java    From onos with Apache License 2.0 5 votes vote down vote up
private int getAlarmId(TreeEvent treeEvents) {
    VariableBinding[] varBindings = treeEvents.getVariableBindings();
    for (VariableBinding varBinding : varBindings) {
        return varBinding.getVariable().toInt();
    }
    return -1;
}
 
Example #4
Source File: SNMPGetter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a SNMP walk and returns the list of {@link TreeEvent}
 * @return the list of {@link TreeEvent}
 */
public List<TreeEvent> walk() {
    TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory());
    @SuppressWarnings("unchecked")
    List<TreeEvent> events = treeUtils.getSubtree(this.target, this.oid);
    return events;
}
 
Example #5
Source File: LumentumSdnRoadmFlowRuleProgrammable.java    From onos with Apache License 2.0 4 votes vote down vote up
private List<FlowRule> fetchRules(OID oid, boolean isAdd, PortNumber linePort) {
    List<FlowRule> rules = new LinkedList<>();

    for (TreeEvent event : snmp.get(oid)) {
        if (event == null) {
            continue;
        }

        VariableBinding[] varBindings = event.getVariableBindings();
        for (VariableBinding varBinding : varBindings) {
            CrossConnectCache cache = this.handler().get(CrossConnectCache.class);

            if (varBinding.getVariable().toInt() == IN_SERVICE) {
                int channel = varBinding.getOid().removeLast();

                PortNumber addDropPort = getAddDropPort(channel, isAdd);
                if (addDropPort == null) {
                    continue;
                }

                TrafficSelector selector = DefaultTrafficSelector.builder()
                        .matchInPort(isAdd ? addDropPort : linePort)
                        .add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID))
                        .add(Criteria.matchLambda(toOchSignal(channel)))
                        .build();
                TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                        .setOutput(isAdd ? linePort : addDropPort)
                        .build();

                // Lookup flow ID and priority
                int hash = Objects.hash(data().deviceId(), selector, treatment);
                Pair<FlowId, Integer> lookup = cache.get(hash);
                if (lookup == null) {
                    continue;
                }

                FlowRule fr = DefaultFlowRule.builder()
                        .forDevice(data().deviceId())
                        .makePermanent()
                        .withSelector(selector)
                        .withTreatment(treatment)
                        .withPriority(lookup.getRight())
                        .withCookie(lookup.getLeft().value())
                        .build();
                rules.add(fr);
            }
        }
    }

    return rules;
}
 
Example #6
Source File: LumentumSnmpDevice.java    From onos with Apache License 2.0 4 votes vote down vote up
public List<TreeEvent> get(OID oid) {
    TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory());
    treeUtils.setMaxRepetitions(MAX_REPETITIONS);
    return treeUtils.getSubtree(target, oid);
}
 
Example #7
Source File: LumentumRoadmDiscovery.java    From onos with Apache License 2.0 4 votes vote down vote up
private List<PortDescription> getPorts() {
    try {
        snmp = new LumentumSnmpDevice(handler().data().deviceId());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);

        return Collections.emptyList();
    }

    List<PortDescription> ports = Lists.newLinkedList();

    OID[] oids = {
            new OID(CTRL_PORT_STATE + "1"),
            new OID(CTRL_PORT_STATE + "2")
    };

    for (OID oid : oids) {

        for (TreeEvent event : snmp.get(oid)) {
            if (event != null) {
                VariableBinding[] varBindings = event.getVariableBindings();
                for (VariableBinding varBinding : varBindings) {
                    if (varBinding.getVariable().toInt() == 1) {
                        int portNumber = varBinding.getOid().removeLast();
                        int portDirection = varBinding.getOid().removeLast();
                        SparseAnnotations ann = DefaultAnnotations.builder()
                                .set(AnnotationKeys.PORT_NAME, portDirection + "-" + portNumber)
                                .build();
                        PortDescription p = omsPortDescription(
                                PortNumber.portNumber(ports.size() + 1L),
                                true,
                                LumentumSnmpDevice.START_CENTER_FREQ,
                                LumentumSnmpDevice.END_CENTER_FREQ,
                                LumentumSnmpDevice.CHANNEL_SPACING.frequency(),
                                ann);
                        ports.add(p);
                    }
                }
            }
        }
    }

    // Create LINE IN and LINE OUT ports as these are not reported through SNMP
    SparseAnnotations annLineIn = DefaultAnnotations.builder()
            .set(AnnotationKeys.PORT_NAME, "LINE IN")
            .build();
    ports.add(omsPortDescription(
            PortNumber.portNumber(ports.size() + 1L),
            true,
            LumentumSnmpDevice.START_CENTER_FREQ,
            LumentumSnmpDevice.END_CENTER_FREQ,
            LumentumSnmpDevice.CHANNEL_SPACING.frequency(),
            annLineIn
    ));

    SparseAnnotations annLineOut = DefaultAnnotations.builder()
            .set(AnnotationKeys.PORT_NAME, "LINE OUT")
            .build();
    ports.add(omsPortDescription(
            PortNumber.portNumber(ports.size() + 1L),
            true,
            LumentumSnmpDevice.START_CENTER_FREQ,
            LumentumSnmpDevice.END_CENTER_FREQ,
            LumentumSnmpDevice.CHANNEL_SPACING.frequency(),
            annLineOut
    ));

    return ports;
}
 
Example #8
Source File: SNMPUtils.java    From localization_nifi with Apache License 2.0 3 votes vote down vote up
/**
 * Method to construct {@link FlowFile} attributes from a {@link TreeEvent}
 * @param treeEvent a {@link TreeEvent}
 * @param flowFile instance of the {@link FlowFile} to update
 * @param processSession instance of {@link ProcessSession}
 * @return updated {@link FlowFile}
 */
public static FlowFile updateFlowFileAttributesWithTreeEventProperties(TreeEvent treeEvent, FlowFile flowFile, ProcessSession processSession) {
    Map<String, String> attributes = new HashMap<String, String>();
    addWalkOidValues(attributes, treeEvent.getVariableBindings());
    flowFile = processSession.putAllAttributes(flowFile, attributes);
    return flowFile;
}
 
Example #9
Source File: SNMPUtils.java    From nifi with Apache License 2.0 3 votes vote down vote up
/**
 * Method to construct {@link FlowFile} attributes from a {@link TreeEvent}
 * @param treeEvent a {@link TreeEvent}
 * @param flowFile instance of the {@link FlowFile} to update
 * @param processSession instance of {@link ProcessSession}
 * @return updated {@link FlowFile}
 */
public static FlowFile updateFlowFileAttributesWithTreeEventProperties(TreeEvent treeEvent, FlowFile flowFile, ProcessSession processSession) {
    Map<String, String> attributes = new HashMap<String, String>();
    addWalkOidValues(attributes, treeEvent.getVariableBindings());
    flowFile = processSession.putAllAttributes(flowFile, attributes);
    return flowFile;
}