Java Code Examples for org.onosproject.net.Port#isEnabled()

The following examples show how to use org.onosproject.net.Port#isEnabled() . 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: OpenConfigGnmiPortStatisticsDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
private Duration getDurationActive(PortNumber portNumber, Duration timestamp) {
    Port port = deviceService.getPort(deviceId, portNumber);
    if (port == null || !port.isEnabled()) {
        //FIXME log
        return Duration.ZERO;
    }
    String lastChangedStr = port.annotations().value(LAST_CHANGE);
    if (lastChangedStr == null) {
        //FIXME log
        // Falling back to the hack...
        // FIXME: This is a workaround since we cannot determine the port
        // duration from gNMI now
        final long now = System.currentTimeMillis() / 1000;
        final Long startTime = PORT_START_TIMES.putIfAbsent(
                Pair.of(deviceId, portNumber), now);
        return Duration.ofSeconds(startTime == null ? now : now - startTime);
    }

    try {
        long lastChanged = Long.parseLong(lastChangedStr);
        return timestamp.minus(lastChanged, ChronoUnit.NANOS);
    } catch (NullPointerException | NumberFormatException ex) {
        //FIXME log
        return Duration.ZERO;
    }
}
 
Example 2
Source File: LldpLinkProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Updates discovery helper state of the specified port.
 *
 * Adds a port to the discovery helper if up and discovery is enabled,
 * or calls {@link #removePort(Port)} otherwise.
 */
private void updatePort(LinkDiscovery discoverer, Port port) {
    if (port == null) {
        return;
    }
    if (port.number().isLogical()) {
        // silently ignore logical ports
        return;
    }

    if (rules.isSuppressed(port) || isBlacklisted(port)) {
        log.trace("LinkDiscovery from {} disabled by configuration", port);
        removePort(port);
        return;
    }

    // check if enabled and turn off discovery?
    if (!port.isEnabled()) {
        removePort(port);
        return;
    }

    discoverer.addPort(port);
}
 
Example 3
Source File: PointToPointIntentCompiler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void updateFailoverGroup(PointToPointIntent pointIntent) {
    DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
    GroupKey groupKey = makeGroupKey(pointIntent.id());
    Group group = waitForGroup(deviceId, groupKey);
    Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();
    while (groupIterator.hasNext()) {
        GroupBucket bucket = groupIterator.next();
        Instruction individualInstruction = bucket.treatment().allInstructions().get(0);
        if (individualInstruction instanceof Instructions.OutputInstruction) {
            Instructions.OutputInstruction outInstruction =
                    (Instructions.OutputInstruction) individualInstruction;
            Port port = deviceService.getPort(deviceId, outInstruction.port());
            if (port == null || !port.isEnabled()) {
                GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
                groupService.removeBucketsFromGroup(deviceId, groupKey,
                                                    removeBuckets, groupKey,
                                                    pointIntent.appId());
            }
        }
    }
}
 
Example 4
Source File: SegmentRoutingManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processEdgePort(DeviceId deviceId, Port port, VlanId vlanId,
                             boolean popVlan) {
    boolean portUp = port.isEnabled();
    if (portUp) {
        log.info("Device:EdgePort {}:{} is enabled in vlan: {}", deviceId,
                 port.number(), vlanId);
        hostEventExecutor.execute(() -> hostHandler.processPortUp(new ConnectPoint(deviceId, port.number())));
    } else {
        log.info("Device:EdgePort {}:{} is disabled in vlan: {}", deviceId,
                 port.number(), vlanId);
    }

    DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
    if (groupHandler != null) {
        groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
    } else {
        log.warn("Group handler not found for dev:{}. Not handling edge port"
                + " {} event for port:{}", deviceId,
                (portUp) ? "UP" : "DOWN", port.number());
    }
}
 
Example 5
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Updates filtering rules for unconfigured ports on all devices for which
 * this controller instance is master.
 *
 * @param pushVlan true if the filtering rule requires a push vlan action
 * @param oldVlanId the vlanId to be removed
 * @param newVlanId the vlanId to be added
 */
void updateSpecialVlanFilteringRules(boolean pushVlan, VlanId oldVlanId,
                                     VlanId newVlanId) {
    for (Device dev : srManager.deviceService.getAvailableDevices()) {
        if (srManager.mastershipService.isLocalMaster(dev.id())) {
            for (Port p : srManager.deviceService.getPorts(dev.id())) {
                if (!hasIPConfiguration(new ConnectPoint(dev.id(), p.number()))
                        && p.isEnabled()) {
                    updateSinglePortFilters(dev.id(), p.number(), pushVlan,
                                            oldVlanId, false);
                    updateSinglePortFilters(dev.id(), p.number(), pushVlan,
                                            newVlanId, true);
                }
            }
        }
    }
}
 
Example 6
Source File: GossipDeviceStore.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceEvent updatePort(Device device, Port oldPort,
                               Port newPort,
                               Map<PortNumber, Port> ports) {

    if (oldPort.isEnabled() != newPort.isEnabled() ||
            oldPort.type() != newPort.type() ||
            oldPort.portSpeed() != newPort.portSpeed() ||
            !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) {
        ports.put(oldPort.number(), newPort);
        return new DeviceEvent(PORT_UPDATED, device, newPort);
    }
    return null;
}
 
Example 7
Source File: SimpleDeviceStore.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceEvent updatePort(Device device, Port oldPort,
                               Port newPort,
                               Map<PortNumber, Port> ports) {
    if (oldPort.isEnabled() != newPort.isEnabled() ||
            oldPort.type() != newPort.type() ||
            oldPort.portSpeed() != newPort.portSpeed() ||
            !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) {
        ports.put(oldPort.number(), newPort);
        return new DeviceEvent(PORT_UPDATED, device, newPort);
    }
    return null;
}
 
Example 8
Source File: DefaultOFSwitch.java    From onos with Apache License 2.0 5 votes vote down vote up
private OFPortDesc portDesc(Port port) {
    OFPort ofPort = OFPort.of((int) port.number().toLong());
    Set<OFPortConfig> portConfigs = Sets.newHashSet();
    Set<OFPortState> portStates = Sets.newHashSet();
    if (!port.isEnabled()) {
        portConfigs.add(OFPortConfig.PORT_DOWN);
        portStates.add(OFPortState.LINK_DOWN);
    }
    OFPortDesc ofPortDesc = FACTORY.buildPortDesc()
            .setPortNo(ofPort)
            .setState(portStates)
            .setConfig(portConfigs)
            .build();
    return ofPortDesc;
}
 
Example 9
Source File: SegmentRoutingManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Adds or remove filtering rules for the given switchport. If switchport is
 * an edge facing port, additionally handles host probing and broadcast
 * rules. Must be called by local master of device.
 *
 * @param deviceId the device identifier
 * @param port the port to update
 */
void processPortUpdated(DeviceId deviceId, Port port) {
    // first we handle filtering rules associated with the port
    if (port.isEnabled()) {
        log.info("Switchport {}/{} enabled..programming filters",
                 deviceId, port.number());
        routingRulePopulator.processSinglePortFilters(deviceId, port.number(), true);
    } else {
        log.info("Switchport {}/{} disabled..removing filters",
                 deviceId, port.number());
        routingRulePopulator.processSinglePortFilters(deviceId, port.number(), false);
    }

    // portUpdated calls are for ports that have gone down or up. For switch
    // to switch ports, link-events should take care of any re-routing or
    // group editing necessary for port up/down. Here we only process edge ports
    // that are already configured.
    ConnectPoint cp = new ConnectPoint(deviceId, port.number());
    VlanId untaggedVlan = interfaceService.getUntaggedVlanId(cp);
    VlanId nativeVlan = interfaceService.getNativeVlanId(cp);
    Set<VlanId> taggedVlans = interfaceService.getTaggedVlanId(cp);

    if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
        log.debug("Not handling port updated event for non-edge port (unconfigured) "
                + "dev/port: {}/{}", deviceId, port.number());
        return;
    }
    if (untaggedVlan != null) {
        processEdgePort(deviceId, port, untaggedVlan, true);
    }
    if (nativeVlan != null) {
        processEdgePort(deviceId, port, nativeVlan, true);
    }
    if (!taggedVlans.isEmpty()) {
        taggedVlans.forEach(tag -> processEdgePort(deviceId, port, tag, false));
    }
}
 
Example 10
Source File: McastHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processPortUpdateInternal(Device affectedDevice, Port affectedPort) {
    // Clean the filtering obj store. Edge port case.
    lastMcastChange.set(Instant.now());
    ConnectPoint portDown = new ConnectPoint(affectedDevice.id(), affectedPort.number());
    if (!affectedPort.isEnabled()) {
        log.info("Processing port down {}", portDown);
        updateFilterObjStoreByPort(portDown);
    }
}
 
Example 11
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a filtering objective to permit all untagged packets with a
 * dstMac corresponding to the router's MAC address. For those pipelines
 * that need to internally assign vlans to untagged packets, this method
 * provides per-subnet vlan-ids as metadata.
 * <p>
 * Note that the vlan assignment and filter programming should only be done by
 * the master for a switch. This method is typically called at deviceAdd and
 * programs filters only for the enabled ports of the device. For port-updates,
 * that enable/disable ports after device add, singlePortFilter methods should
 * be called.
 *
 * @param deviceId  the switch dpid for the router
 * @return PortFilterInfo information about the processed ports
 */
PortFilterInfo populateVlanMacFilters(DeviceId deviceId) {
    log.debug("Installing per-port filtering objective for untagged "
            + "packets in device {}", deviceId);

    List<Port> devPorts = srManager.deviceService.getPorts(deviceId);
    if (devPorts == null || devPorts.isEmpty()) {
        log.warn("Device {} ports not available. Unable to add MacVlan filters",
                 deviceId);
        return null;
    }
    int disabledPorts = 0, errorPorts = 0, filteredPorts = 0;
    for (Port port : devPorts) {
        if (!port.isEnabled()) {
            disabledPorts++;
            continue;
        }
        if (processSinglePortFilters(deviceId, port.number(), true)) {
            filteredPorts++;
        } else {
            errorPorts++;
        }
    }
    log.debug("Filtering on dev:{}, disabledPorts:{}, errorPorts:{}, filteredPorts:{}",
              deviceId, disabledPorts, errorPorts, filteredPorts);
    return new PortFilterInfo(disabledPorts, errorPorts, filteredPorts);
}
 
Example 12
Source File: PortQueryVlansCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
private void printPort(Port port) {
    String portName = portName(port.number());
    Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
    String portType = port.type().toString().toLowerCase();
    String annotations = annotations(port.annotations());
    print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations);
}
 
Example 13
Source File: DevicePortsListCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
protected void printPorts(DeviceService service, Device device) {
    List<Port> ports = new ArrayList<>(service.getPorts(device.id()));
    Collections.sort(ports, Comparators.PORT_COMPARATOR);
    for (Port port : ports) {
        if (!isIncluded(port)) {
            continue;
        }
        String portName = port.number().toString();
        Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
        String portType = port.type().toString().toLowerCase();
        String annotations = annotations(port.annotations());
        print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations);
    }
}
 
Example 14
Source File: OpticalPortsListCommand.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
protected void printPorts(DeviceService service, Device device) {
    List<Port> ports = new ArrayList<>(service.getPorts(device.id()));
    ports.sort((p1, p2) ->
         Long.signum(p1.number().toLong() - p2.number().toLong())
    );
    for (Port port : ports) {
        if (!isIncluded(port)) {
            continue;
        }
        String portName = port.number().toString();
        String portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
        String portType = port.type().toString().toLowerCase();
        switch (port.type()) {
            case OCH:
                if (port instanceof OchPort) {
                    OchPort och = (OchPort) port;
                    print(FMT_OCH, portName, portIsEnabled, portType,
                          och.signalType().toString(),
                          och.isTunable() ? "yes" : "no",
                          annotations(och.unhandledAnnotations()));
                   break;
                }
                print("WARN: OchPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            case ODUCLT:
                if (port instanceof OduCltPort) {
                    OduCltPort oduCltPort = (OduCltPort) port;
                    print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType,
                          oduCltPort.signalType().toString(),
                          annotations(oduCltPort.unhandledAnnotations()));
                    break;
                }
                print("WARN: OduCltPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            case OMS:
                if (port instanceof OmsPort) {
                    OmsPort oms = (OmsPort) port;
                    print(FMT_OMS, portName, portIsEnabled, portType,
                          oms.minFrequency().asHz() / Frequency.ofGHz(1).asHz(),
                          oms.maxFrequency().asHz() / Frequency.ofGHz(1).asHz(),
                          oms.grid().asHz() / Frequency.ofGHz(1).asHz(),
                          oms.totalChannels(),
                          annotations(oms.unhandledAnnotations()));
                    break;
                }
                print("WARN: OmsPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            case OTU:
                if (port instanceof OtuPort) {
                    OtuPort otuPort = (OtuPort) port;
                    print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType,
                          otuPort.signalType().toString(),
                          annotations(otuPort.unhandledAnnotations()));
                    break;
                }
                print("WARN: OtuPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            default:
                // do not print non-optical ports
                break;
        }
    }
}
 
Example 15
Source File: DevicePortsListCommand.java    From onos with Apache License 2.0 4 votes vote down vote up
protected boolean isIncluded(Port port) {
    return enabled && port.isEnabled() || disabled && !port.isEnabled() ||
            !enabled && !disabled;
}
 
Example 16
Source File: LldpLinkProvider.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    Device device = event.subject();
    Port port = event.port();
    if (device == null) {
        log.error("Device is null.");
        return;
    }
    log.trace("{} {} {}", event.type(), event.subject(), event);
    final DeviceId deviceId = device.id();
    switch (event.type()) {
        case DEVICE_ADDED:
        case DEVICE_UPDATED:
            updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
            break;
        case PORT_ADDED:
        case PORT_UPDATED:
            if (port.isEnabled()) {
                updateDevice(device).ifPresent(ld -> updatePort(ld, port));
            } else {
                log.debug("Port down {}", port);
                removePort(port);
                providerService.linksVanished(new ConnectPoint(port.element().id(),
                                                               port.number()));
            }
            break;
        case PORT_REMOVED:
            log.debug("Port removed {}", port);
            removePort(port);
            providerService.linksVanished(new ConnectPoint(port.element().id(),
                                                           port.number()));
            break;
        case DEVICE_REMOVED:
        case DEVICE_SUSPENDED:
            log.debug("Device removed {}", deviceId);
            removeDevice(deviceId);
            providerService.linksVanished(deviceId);
            break;
        case DEVICE_AVAILABILITY_CHANGED:
            if (deviceService.isAvailable(deviceId)) {
                log.debug("Device up {}", deviceId);
                updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
            } else {
                log.debug("Device down {}", deviceId);
                removeDevice(deviceId);
                providerService.linksVanished(deviceId);
            }
            break;
        case PORT_STATS_UPDATED:
            break;
        default:
            log.debug("Unknown event {}", event);
    }
}
 
Example 17
Source File: LinkDiscoveryCiscoImpl.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Set<LinkDescription> getLinks() {
    String response = retrieveResponse(SHOW_LLDP_NEIGHBOR_DETAIL_CMD);
    DeviceId localDeviceId = this.handler().data().deviceId();
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Set<LinkDescription> linkDescriptions = Sets.newHashSet();
    List<Port> ports = deviceService.getPorts(localDeviceId);

    if (ports.size() == 0 || Objects.isNull(response)) {
        return linkDescriptions;
    }
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        if (json == null) {
            return linkDescriptions;
        }

        JsonNode res = json.at("/" + JSON_RESULT);
        if (res.isMissingNode()) {
            return linkDescriptions;
        }

        JsonNode lldpNeighborsRow = res.at("/" + TABLE_NBOR_DETAIL);
        if (lldpNeighborsRow.isMissingNode()) {
            return linkDescriptions;
        }

        JsonNode lldpNeighbors = lldpNeighborsRow.at("/" + ROW_NBOR_DETAIL);
        if (lldpNeighbors.isMissingNode()) {
            return linkDescriptions;
        }

        Iterator<JsonNode> iterator = lldpNeighbors.elements();

        while (iterator.hasNext()) {
            JsonNode neighbors = iterator.next();
            String remoteChassisId = neighbors.get(CHASSIS_ID).asText();
            String remotePortName = neighbors.get(PORT_ID).asText();
            String remotePortDesc = neighbors.get(PORT_DESC).asText();
            String lldpLocalPort = neighbors.get(LOCAL_PORT_ID).asText()
                    .replaceAll("(Eth.{0,5})(.\\d{0,5}/\\d{0,5})", "Ethernet$2");

            Port localPort = findLocalPortByName(ports, lldpLocalPort);
            if (localPort == null) {
                log.warn("local port not found. LldpLocalPort value: {}", lldpLocalPort);
                continue;
            }

            Device remoteDevice = findRemoteDeviceByChassisId(deviceService, remoteChassisId);
            Port remotePort = findDestinationPortByName(remotePortName,
                                                        remotePortDesc,
                                                        deviceService,
                                                        remoteDevice);

            if (!localPort.isEnabled() || !remotePort.isEnabled()) {
                log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}",
                          localDeviceId, localPort, remoteDevice.id(), remotePort);
                continue;
            }

            linkDescriptions.addAll(buildLinkPair(localDeviceId, localPort, remoteDevice.id(), remotePort));
        }
    } catch (IOException e) {
        log.error("Failed to get links ", e);
    }

    log.debug("Returning linkDescriptions: {}", linkDescriptions);
    return linkDescriptions;

}